hey i got this game in processing and i have an error that reads........... "unexpected token: int"
in
Programming Questions
•
11 months ago
error says "unexpected token: int" the line of code that it highlights is "int c = mask.get(position.x, position.y;" what can i do to fix this? here's my code thus far.
PFont font;
PImage img; // Image variable here
int state = 1; // Start with the car on the track
int timer=25;
int timeLast = 0;
PVector position, velocity;
float angle, steerAngle;
boolean[] keys = new boolean[256];
//
void setup() {
//
size(690, 645);
smooth();
timeLast=second();
font = loadFont("ARDESTINE-48.vlw");
textFont(font, 48);
// load images in setup
img = loadImage("racecartrack.jpg");
img = loadImage("racecartrackcopy.jp");
//
velocity = new PVector();
position = new PVector(width * 10.5, height * 10.5);
//
angle = 0.0;
steerAngle = 0.0;
}
//
void draw() {
if (timer>0) {
game();
}
else {
state = 4; // out of time
}
}
void game() {
if (second()!=timeLast) {
timeLast=second();
timer-=1;
}
//
background(img);
fill(0);
text("Timer: "+timer, 320, 35);
//
switch(state){
case 0:
text("Crashed - you loose", 320, 70);
break;
case 2:
text("Finished - you win", 320, 70);
break;
case 4:
text("Out of time - you loose", 320, 70);
break;
}
PVector force = new PVector();
//
PVector vector1 = new PVector(sin(angle), cos(angle));
PVector vector2 = new PVector(vector1.y, - vector1.x);
//
float forwardVelocity = vector1.dot(velocity);
float sidewaysVelocity = vector2.dot(velocity);
//
steerAngle = 0.0;
float factor = constrain(forwardVelocity * 1.0, -2.5, 2.5);
if (keys[37]) {
angle += 0.025 * factor;
steerAngle = - PI * 0.75;
}
if (keys[39]) {
angle -= 0.025 * factor;
steerAngle = PI * 0.75;
}
//
force.add(PVector.mult(vector1, -forwardVelocity * 0.3));
if (keys[38]) {
force.add(PVector.mult(vector1, 3.0));
}
if (keys[40]) {
force.add(PVector.mult(vector1, -3.0));
}
//
float sidewaysFriction = - constrain(sidewaysVelocity * 5.0, -10.0, 10.0);
force.add(PVector.mult(vector2, sidewaysFriction));
//
force.div(15.0);
velocity.add(force);
position.add(velocity);
//
position.x = (position.x + width) % width;
position.y = (position.y + height) % height;
// get the color from the mask image
int c = mask.get(position.x, position.y;
// Now test c for the color
if(c == color(255,0,0) { // red
state = 0;
}
else if (c == color(0,255,0) { // green
state = 1;
}
else if (c == color(0,0,255) { // blue
state = 2;
}
fill(0, 210);
noStroke();
rectMode(CENTER);
//
pushMatrix();
translate(position.x, position.y);
rotate(-angle);
rect(0, 0, 35, 75);
pushMatrix();
translate(10, 17);
rotate(steerAngle);
rect(0, 5, 5, 10);
popMatrix();
pushMatrix();
translate(-10, 17);
rotate(steerAngle);
rect(0, 5, 5, 10);
popMatrix();
pushMatrix();
translate(-10, -17);
rect(0, -5, 5, 10);
popMatrix();
pushMatrix();
translate(10, -17);
rect(0, -5, 5, 10);
popMatrix();
popMatrix();
}
//
void keyPressed() {
keys[keyCode] = true;
}
void keyReleased() {
keys[keyCode] = false;
}
PFont font;
PImage img; // Image variable here
int state = 1; // Start with the car on the track
int timer=25;
int timeLast = 0;
PVector position, velocity;
float angle, steerAngle;
boolean[] keys = new boolean[256];
//
void setup() {
//
size(690, 645);
smooth();
timeLast=second();
font = loadFont("ARDESTINE-48.vlw");
textFont(font, 48);
// load images in setup
img = loadImage("racecartrack.jpg");
img = loadImage("racecartrackcopy.jp");
//
velocity = new PVector();
position = new PVector(width * 10.5, height * 10.5);
//
angle = 0.0;
steerAngle = 0.0;
}
//
void draw() {
if (timer>0) {
game();
}
else {
state = 4; // out of time
}
}
void game() {
if (second()!=timeLast) {
timeLast=second();
timer-=1;
}
//
background(img);
fill(0);
text("Timer: "+timer, 320, 35);
//
switch(state){
case 0:
text("Crashed - you loose", 320, 70);
break;
case 2:
text("Finished - you win", 320, 70);
break;
case 4:
text("Out of time - you loose", 320, 70);
break;
}
PVector force = new PVector();
//
PVector vector1 = new PVector(sin(angle), cos(angle));
PVector vector2 = new PVector(vector1.y, - vector1.x);
//
float forwardVelocity = vector1.dot(velocity);
float sidewaysVelocity = vector2.dot(velocity);
//
steerAngle = 0.0;
float factor = constrain(forwardVelocity * 1.0, -2.5, 2.5);
if (keys[37]) {
angle += 0.025 * factor;
steerAngle = - PI * 0.75;
}
if (keys[39]) {
angle -= 0.025 * factor;
steerAngle = PI * 0.75;
}
//
force.add(PVector.mult(vector1, -forwardVelocity * 0.3));
if (keys[38]) {
force.add(PVector.mult(vector1, 3.0));
}
if (keys[40]) {
force.add(PVector.mult(vector1, -3.0));
}
//
float sidewaysFriction = - constrain(sidewaysVelocity * 5.0, -10.0, 10.0);
force.add(PVector.mult(vector2, sidewaysFriction));
//
force.div(15.0);
velocity.add(force);
position.add(velocity);
//
position.x = (position.x + width) % width;
position.y = (position.y + height) % height;
// get the color from the mask image
int c = mask.get(position.x, position.y;
// Now test c for the color
if(c == color(255,0,0) { // red
state = 0;
}
else if (c == color(0,255,0) { // green
state = 1;
}
else if (c == color(0,0,255) { // blue
state = 2;
}
fill(0, 210);
noStroke();
rectMode(CENTER);
//
pushMatrix();
translate(position.x, position.y);
rotate(-angle);
rect(0, 0, 35, 75);
pushMatrix();
translate(10, 17);
rotate(steerAngle);
rect(0, 5, 5, 10);
popMatrix();
pushMatrix();
translate(-10, 17);
rotate(steerAngle);
rect(0, 5, 5, 10);
popMatrix();
pushMatrix();
translate(-10, -17);
rect(0, -5, 5, 10);
popMatrix();
pushMatrix();
translate(10, -17);
rect(0, -5, 5, 10);
popMatrix();
popMatrix();
}
//
void keyPressed() {
keys[keyCode] = true;
}
void keyReleased() {
keys[keyCode] = false;
}
1