HOW DO I MAKE THIS GAME 2 PLAYER WITH WASD? unexpected token void

edited December 2016 in Questions about Code

Everytime I try my "greencar.png" replaces the other car, and wasd doesnt work because it reads "unexpected token void" PImage one; int x=40; int y=520; float col; class TopDownRotater {

PImage image; PVector position; PVector direction; PVector velocity; float rotateSpeed; float speed; }

TopDownRotater car;

float left = 0; float right = 0; float down = 0; float up = 0; PImage image; class Bullet {

PVector position; PVector direction; PVector velocity; float speed; boolean dead; }

Bullet bullet;

void setup() { size(600, 601); one = loadImage("one.jpg"); car = new TopDownRotater();

car.image = loadImage("pinkcar.png"); car.image = loadImage("greencar.png");

car.position = new PVector(40, 520);

car.direction = new PVector(0, 1);

car.velocity = new PVector(0, 0);

car.speed = 3;

car.rotateSpeed = .1;

bullet = new Bullet(); bullet.dead = true; }

void draw() { background(one);

rotate2D(car.direction, car.rotateSpeed * (left + right));

car.velocity.x = car.direction.x * (car.speed * (up + down)); car.velocity.y = car.direction.y * (car.speed * (up + down));

car.position.add(car.velocity);

pushMatrix();

translate(car.position.x, car.position.y);

rotate(car.direction.heading2D());

imageMode(CENTER);

image(car.image, 0, 0, 1255/11, 600/11); col = red(get(x,y)); println(col); //fill(0); if(col>83){ x= 40; y=520; }

popMatrix(); if (bullet.dead == false) { fill(255, 0, 0); bullet.position.add(bullet.velocity); ellipse(bullet.position.x, bullet.position.y, 40, 40); } }

void rotate2D(PVector v, float theta) { float m = v.mag(); float a = v.heading2D(); a += theta; v.x = m * cos(a); v.y = m * sin(a);

}

void keyPressed() {

if (keyCode == RIGHT) { right = 1; } if (keyCode == LEFT) { left = -1; } if (keyCode == UP) { up = 1; } if (keyCode == DOWN) { down = -1;

 if (key == 's') {
down = -1;

} if (key == 'w') { up = 1; }
if (key == 'd') { left = -1; } if (key == 'a') { right = 1; } }

void keyReleased() { if (keyCode == RIGHT) { right = 0; } if (keyCode == LEFT) { left = 0; } if (keyCode == UP) { up = 0; } if (keyCode == DOWN)
{ down = 0; } if (key == ' ')
{ bullet = new Bullet(); bullet.speed = car.speed + 2; bullet.direction = new PVector(car.direction.x, car.direction.y); bullet.position = new PVector(car.position.x, car.position.y); bullet.velocity = new PVector(bullet.direction.x * bullet.speed, bullet.direction.y * bullet.speed); bullet.dead = false; } }

Answers

  • Edit post, highlight code, press Ctrl-o.

    You are missing a bracket somewhere, or have one too many. Use ctrl-t in the processing editor to help you find it.

Sign In or Register to comment.