Well here is some of the code, it should have enough to debug. The Boolean 'thrusts' is what makes the ship go forward or slowly stop. if its on it goes forward, if its off it stops. I change the boolean value within the Ship class, via method thrusts or noThrusts. In Java it works fine, JS it doesnt register the change in boolean variable i guess.
should I be using that redraw() that you have in your link?
/* @pjs preload="Splash_Image.PNG, nothrusters.png, thrusters.PNG, asteroid2.PNG, RedNebula.png, missles.PNG"; */
PImage splash_screen;
PImage ship_image; //initialize ship image
PImage ship_image_thrusts; //initialize ship thruster image
PImage nebula; //initialize Nebula backgroung
PImage rock_image; //initialize asteroid image
boolean thrusters = false; //set if thrusters on or off
ArrayList rockGroup; //initialize asteroid group
PImage missile_image;
ArrayList missileGroup;
ArrayList newlist;
boolean contact = false;
Ship my_ship;
ImageInfo ship_info;
ImageInfo rock_info;
ImageInfo missile_info;
int score = 0;
int lives = 3;
boolean game_started = false;
boolean collision;
void setup() {
textSize(20);
size(800,600);
smooth();
ship_info = new ImageInfo(-33, -33, 60, 0);
rock_info = new ImageInfo(-44, -45, 88, 0);
missile_info = new ImageInfo(-9, -8.5, 18, 0);
my_ship = new Ship(200, 200, 0, 0, 0, 60); //create a ship instance
rockGroup = new ArrayList(); //Create empty list
missileGroup = new ArrayList();
splash_screen = loadImage("Splash_Image.PNG");
ship_image = loadImage("nothrusters.png"); //initializing images
ship_image_thrusts = loadImage("thrusters.PNG"); //initializing images
rock_image = loadImage("asteroid2.PNG"); //initializing images
nebula = loadImage("RedNebula.png"); //initializing images
nebula.resize(width,height);
missile_image = loadImage("missles.PNG");
}
//ALL DRAWING STARTS HERE
void draw() {
background(nebula); //DRAWS THE BACKGROUND
my_ship.draw(); //DRAWS THE SHIP
rock_spawner(); // FUNCTION: ROCK SPAWNING FUNCTION
processing_sprite(missileGroup); //FUNCTION: DRAWS MISSILES
processing_sprite(rockGroup); //FUNCTION: DRAWS ROCKS
group_collision(rockGroup, my_ship,null); //FUNCTION: ROCK COLLISION WITH SHIP
group_group_collision(rockGroup, missileGroup); //FUNCTION: ROCK AND MISSILE COLLISION
text("Score: " + score, 25,25);
text("Lives: " + lives, width - 140,25);
if (game_started == false){ //IF GAME HASN'T STARTED YET
tint(255,0,0, 200);
image(splash_screen, width/2-199, height/2-151);
noTint();
if (mousePressed == true && mouseX > width/2-200 && mouseX < width/2+200) game_started = true;}
tint(255, 120);
fill(0, 255, 120);
rect(0, height-200, 50, 100);
rect(50, height-200, 50, 100);
ellipse(width-50, height-150, 50, 50);
rect(0, height-250, 100, 50);
noTint();
}
void rock_spawner() { //SPAWNS ROCKS AT RANDOM POSITION AND RANDOM VELOCITY.
for (int i=0;i<12;i++) {
float velx = random(-1.2, 1.2);
float vely = random(-1.2, 1.2);
Sprite a_rock = new Sprite(rock_image, random(width), random(height),velx, vely, 0, 0,80);
if (rockGroup.size() < 12 && rock_too_close(a_rock, my_ship) != true) rockGroup.add(a_rock);}}
void mousePressed() {
if (mouseY > height-270 && mouseY < height-200) my_ship.thrusters();
if (mouseX < 50 && mouseY > height-200) my_ship.decrement();
if (mouseX > 50 && mouseX < 100 && mouseY > height-200) my_ship.incre();
if (mouseX >= width-100 && mouseX <= width && mouseY > height-200 && mouseY < height) my_ship.shoot();
}
void mouseReleased() {
my_ship.noThrusters();
my_ship.halt();
}
class Ship {
float xpos, ypos, xvel, yvel, angle;
float angle_vel = 0;
float radius;
Ship(float _xpos, float _ypos, float _xvel, float _yvel, float _angle, float _radius) {
xpos = _xpos;
ypos = _ypos;
xvel = _xvel;
yvel = _yvel;
angle = _angle;
radius = _radius;
}
void update() {
xpos+=xvel;
ypos+=yvel;
if (xpos >= width) xpos = 6;
if (ypos >= height) ypos = 6;
if (xpos <= 5) xpos = width-6;
if (ypos <= 5) ypos = height-6;
angle+=angle_vel;
xvel*=.99;
yvel*=.99;
}
void thrusters() {
thrusters = true;
}
void noThrusters() {
thrusters = false;
}
void decrement() {
angle_vel=-.09;
}
void incre() {
angle_vel=.09;
}
void halt() {
angle_vel=0;
}
float get_X() {
return xpos;
}
float get_Y() {
return ypos;
}
float get_Xvel() {
return xvel;
}
float get_Yvel() {
return yvel;
}
float get_radius(){
return radius;
}
void draw() {
pushMatrix();
translate(xpos, ypos);
rotate(angle);
update();
if (thrusters==false) {
image(ship_image, -33,-33);
xvel *=.99;
yvel *=.99;
}
else {
image(ship_image_thrusts, -33,-33);
xvel += cos(angle) * .1;
yvel += sin(angle) * .1;
}
popMatrix();
}
void shoot() {
Sprite missile = new Sprite(missile_image, xpos+30, ypos+30, cos(angle)*6, sin(angle)*6, 0, 50, 12);
missileGroup.add(missile);
}
}