We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi im trying to make a car game where the car needs to do a zig zag course through other cars. I cant moove the image for some reason.
`Ship ship;
PImage img;
void setup() {
size(800, 800);
img = loadImage("Ecar.jpg");
ship = new Ship();
}
void draw() {
background(51);
ship.show();
ship.move();
}
void keyPressed() {
if (keyCode == RIGHT) {
ship.setDir(1);
} else if (keyCode == LEFT) {
ship.setDir(-1);
}
}`
`class Ship {
float x, xdir;
PShape car;
Ship() {
this.x = width/2-40;
this.xdir = 0;
noStroke();
fill(255,0,0);
car = createShape(RECT, this.x, height-300, 100, 200);
car.setTexture(img);
}
void show() {
fill(255);
rectMode(CENTER);
shape(car);
//rect(this.x, height-50, 20, 60);
}
void setDir(float dir) {
this.xdir = dir;
}
void move() {
this.x += this.xdir*5;
}
}`
Answers
https://forum.processing.org/two/discussion/15473/how-to-format-code-and-text
Please stop getting this wrong.
I think your Ship class's show() function is missing a closing bracket.
That your code has a syntax error like this in it is not promising. Start with code that runs. If you make any changes to it, make sure it still runs. If it breaks, revert those changes immediately (or fix it). Do this for even the smallest changes. In this manner you will always have code that, at the very least, runs.
Next, you are talking about cars and zig-zagging, but your code has a Ship class in it. What are the Ships even for? What even is a car? Is "Car" going to be an type of object? What kind of zig-zagging are you trying to get it to do?
some improvement on how to display a car / ship using shape() command: you need to use the position
x
here!ok so i found an exaple but every time i run it it says thet there is a nullPointerExpectation on this point
this is the code
Better instead of searching code that you didn’t write and don’t understand work with your own code or with my improved version of it.