Bullets and Characters

edited May 2016 in Questions about Code

So what I'm trying to do with my code is have continuous bullets shooting down from the guns that the soldiers are holding, and I want to create a character at the bottom of the wall that I can control with all four arrow keys and have it avoid the bullets coming from the guns. Because the goal is to have that character reach the top of the wall and then the wall should increase when my character reaches the top.

Please help! This is super important and I'm kinda new to Processing.

Here's my code so far with my brick wall and soldiers:

PImage soldier;  
int numBrickRows = 10;
int pixelsize = 4;
int brickWidth = 50;
int brickHeight = 20;
int c = 16;
int d = 5; 
int e = 253;
int f = 60;
int g = 80;
ArrayList bullets = new ArrayList(); 

Brick[] bricks = new Brick[0];


void setup() {
  size(400,400);
  background(255); 
  soldier = loadImage("soldier.jpeg"); 
  soldier(); 
  smooth();  
  for (int j=0; j < numBrickRows; j++) 
  { 

    int y = brickHeight * c + j * brickHeight;
    int offset = 0;
    if (j % 2 == 0) {
      offset = brickWidth / 2;
    }
    for (int i=offset; i < width+brickWidth/2.0; i += brickWidth) { // columns
      bricks = (Brick[]) append(bricks, new Brick(i,y));
    }
  }
}

void draw() {
  for (int i=0; i < bricks.length; i++) {
    if (bricks[i] != null) {
      bricks[i].draw();
    }
  }
}

class Brick {
  int xPosition;
  int yPosition;
  color c;

Brick(int x, int y) {
    xPosition = x;
    yPosition = y;
    c = color(107, 115, 117);
  }

  void draw() {
   rectMode(CENTER);
   fill(c);
   rect(xPosition, yPosition, brickWidth, brickHeight);   
  }  
}

void soldier()
{
  image(soldier,d,e,f,f); 
  image(soldier,d+g,e,f,f); 
  image(soldier,d+2*g,e,f,f); 
  image(soldier,d+3*g,e,f,f); 
  image(soldier,d+4*g,e,f,f); 

}

Image:

Tagged:

Answers

Sign In or Register to comment.