class Lander{ PImage piMe, piExplode, piThrust; PVector position, velocity; int radius; float thrustFactor = 0.1; float maxVelocity = -1; float maxSafeLandingVelocity = 2; int[][] aMeOffset = { null, {-50,-50}, {-50,-30} }; //x,ys - indexed by game type int[][] aThrustOffset = { null, {-25,20}, {-50,-30} }; //x,ys - indexed by game type int[][] aCrashOffset = { null, {-80,-80}, {-50,-30} }; //x,ys - indexed by game type Lander(){ ellipseMode(CENTER); radius = 55; position = new PVector(0, 0); velocity = new PVector(0.5, 0); piMe = loadImage("images/lander"+iGameSkin+".png"); piThrust = loadImage("images/thrust"+iGameSkin+".png"); piExplode = loadImage("images/explosion"+iGameSkin+".png"); } void draw(){ // update position velocity.y += gravity; position.x += velocity.x; position.y += velocity.y; image(piMe, position.x+aMeOffset[iGameSkin][0], position.y+aMeOffset[iGameSkin][1]); /* // the ball detection zone fill(0); ellipse(position.x, position.y, radius * 2, radius * 2);//*/ // stage collision check checkStageBounds(); } void Land(){ if(velocity.y > maxSafeLandingVelocity){ Crash("You landed too fast!"); } else { image(piMe, position.x+aMeOffset[iGameSkin][0], position.y+aMeOffset[iGameSkin][1]); StopGame(true, "You landed safely!"); } } void Crash(String sMessage){ image(piExplode, position.x+aCrashOffset[iGameSkin][0], position.y+aCrashOffset[iGameSkin][1]); StopGame(false, sMessage); } // STANDARD STAGE COLLISION DECTECTION void checkStageBounds() { if (position.x + radius > width) { position.x = width - radius; velocity.x *= -1; } else if (position.x - radius < 0) { position.x = radius; velocity.x *= -1; } if (position.y + radius > height) { position.y = height - radius; velocity.y *= -1; } else if (position.y - radius < 0) { position.y = radius; velocity.y *= -1; } } void thrust(){ if(velocity.y > maxVelocity) velocity.y -= thrustFactor; image(piThrust, position.x+aThrustOffset[iGameSkin][0], position.y+aThrustOffset[iGameSkin][1]); } }