package Main; import org.newdawn.slick.Animation; import org.newdawn.slick.GameContainer; import org.newdawn.slick.Graphics; import org.newdawn.slick.SlickException; import org.newdawn.slick.SpriteSheet; public class Invader { int riderX, riderY,flightSpdX,flightSpdY; SpriteSheet rider,shocking; Animation flight_left, flight_right,shock; String flight_direction;//Flugrichtung float countDown,para_timer; boolean readyToFire,//Check für die Abschuss automatik ball_shoot,//Check ob Ball abgefeuert wurde fly_right,//Check ob Flugrichtung rechts isParalized;//Disconnected check Ball ball;//Definierung eines Ball objektes private State state; void init(GameContainer gc, State gameState) throws SlickException{ this.state = gameState; riderX = 450; riderY = 30; flightSpdX = 1; flightSpdY = 1; flight_direction = "right"; fly_right = true; ball_shoot= false; isParalized = false; rider = new SpriteSheet("Main/rider.png", 75, 75); shocking = new SpriteSheet("Main/shock.png", 75, 45); flight_left = new Animation(rider,0,1,2,1,true,250,true); flight_right = new Animation(rider,0,0,2,0,true,250,true); shock = new Animation(shocking,0,0,3,0,true,250,true); countDown = 3.1f; para_timer = 5.1f; readyToFire = false; ball = new Ball();//erstellung des Ballobjektes } void render(GameContainer gc, Graphics g) throws SlickException{ switch(state.currentState){ case "titel":break; case "start": case "paused": if(fly_right)//rechtsflug animation flight_right.draw(riderX, riderY); else//linksflug animation flight_left.draw(riderX, riderY); //ball wird nur gerendert falls er abgeschossen wurde if(ball_shoot){ ball.render(gc, g); } //shock animation des Disconnected Status if(para_timer < 5){ shock.draw(riderX, riderY+20); } break; } } void update(GameContainer gc, float _delta) throws SlickException{ switch(state.currentState){ case "paused":break; case "start" : countDown += _delta; para_timer += _delta; //flug nur bei Connected Status if(!isParalized&& para_timer >=5 ){ riderX += flightSpdX; //Abschuss automatik if(readyToFire == true && countDown > 3 ){ ball.init(gc, riderX+37, riderY+80, flightSpdX); ball_shoot = true; readyToFire= false; } } //ball bewegung if(ball_shoot&&!ball.ballIsKilled) ball.update(gc, _delta ); //ball wird bei zerstörung für den schuss vorbereitet if(ball.ballIsKilled){ prepareToFire(); ball.ballIsKilled =false; } gc.getInput().clearKeyPressedRecord();//Tastendruck löschung zur Sicherheit break; } } //Abschussmethode void prepareToFire(){ countDown = 0; readyToFire = true; ball_shoot = false; } //Disconnected Methode void paralized(){ para_timer = 0; } }