You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

456 lines
13 KiB
Java

package Main;
import org.newdawn.slick.Animation;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;
public class Level{
private Image cyberg,title,paused,instructionScreen,missionScreen,alert,clearedLevel;
private Invader invader;
private Player protector;
private UserInterface ui;
private State state;
//Levelbezeichnungen
private String[] level = {"-1- First Contact |", "-2- Two Paths to Core |", "-3- Cyberlabyrinth", "-4-", " -5- Final Fight |"};
//Game Over Screen Erstellung
private Image game_over_screen0,game_over_screen1,game_over_screen2,game_over_screen3,game_over_screen4,game_over_screen5,game_over_screen6,game_over_screen7,game_over_screen8;
Image[] game_over_screens = { game_over_screen0,
game_over_screen1,
game_over_screen2,
game_over_screen3,
game_over_screen4,
game_over_screen5,
game_over_screen6,
game_over_screen7,
game_over_screen8};
int selectedString,currentLevel;
SpriteSheet shock,arrows_sheet,walk_demo_sheet,virus_demo_sheet,rider_demo_sheet,shock_demo_sheet;
Animation selected,arrows,walk_demo,game_over,virus_demo,rider_demo,shock_demo;
Panel panel;
float waiter;//Ingame Zeit
boolean changedDirection = false;//Indikator für Richtungswechsel
public void init(GameContainer gc, Invader invader, Player player, UserInterface ui, State gameState, Panel panel, float waiter) throws SlickException{
game_over_screen0 = new Image("Main/cybergrid.png");
game_over_screen1 = new Image("Main/game_Over1.png");
game_over_screen2 = new Image("Main/game_Over2.png");
game_over_screen3 = new Image("Main/game_Over3.png");
game_over_screen4 = new Image("Main/game_Over4.png");
game_over_screen5 = new Image("Main/game_Over5.png");
game_over_screen6 = new Image("Main/game_Over6.png");
game_over_screen7 = new Image("Main/game_Over7.png");
game_over_screen8 = new Image("Main/game_Over8.png");
this.waiter = waiter;
this.panel = panel;
this.state = gameState;
this.invader = invader;
this.protector = player;
this.ui = ui;
alert = new Image("Main/Hack_Alert.png");
clearedLevel = new Image("Main/level_cleared_screen.png");
instructionScreen = new Image("Main/key_instructions.png");
missionScreen = new Image("Main/mission.png");
arrows_sheet = new SpriteSheet("Main/arrows_sheet.png" ,101, 101);
walk_demo_sheet = new SpriteSheet("Main/robot_sheet_good.png",50,100);
virus_demo_sheet = new SpriteSheet("Main/Virus_sheet.png",72,72);
rider_demo_sheet = new SpriteSheet("Main/rider.png",75,75);
shock_demo_sheet = new SpriteSheet("Main/shock.png",75,45);
arrows = new Animation(arrows_sheet,0,0,3,2,true,200, true);
walk_demo = new Animation(walk_demo_sheet,0,0,5,2,true,200,true);
virus_demo = new Animation(virus_demo_sheet,2,1,3,4,true,200,true);
rider_demo = new Animation(rider_demo_sheet,0,0,2,0,true,200,true);
shock_demo = new Animation(shock_demo_sheet,0,0,3,0,true,200,true);
selectedString = 0;//Default Auswahl im Menu
currentLevel = 1;//Initial Level zu Begin
cyberg = new Image("Main/cybergrid.png");
title = new Image("Main/titel.png");
paused = new Image("Main/paused_menu.png");
shock = new SpriteSheet("Main/shock.png", 75, 45);
selected = new Animation(shock,0,0,3,0,true,250,true);
protector.init(gc,gameState,100);//Roboter Initialisierung an YPosition 100
invader.init(gc,gameState);
}
public void render (GameContainer gc, Graphics g)throws SlickException{
//Rendering abhängig von State
switch(state.currentState){
case "win" ://Sieges Screen
g.drawImage(clearedLevel, 0, 0);
g.setColor(Color.cyan);
g.drawLine(0, 100, 800, 100);
break;
//game over Pseudo-Animation
case "gameOver":
if(waiter > 5)
g.drawImage(game_over_screen8, 0, 0);
else if ( waiter > 4.2)
g.drawImage(game_over_screen7, 0, 0);
else if(waiter > 3.8)
g.drawImage(game_over_screen6, 0, 0);
else if(waiter > 3.2)
g.drawImage(game_over_screen5, 0, 0);
else if(waiter > 2.8)
g.drawImage(game_over_screen4, 0, 0);
else if(waiter > 2.2)
g.drawImage(game_over_screen3, 0, 0);
else if(waiter > 1.8)
g.drawImage(game_over_screen2, 0, 0);
else if(waiter > 1.2)
g.drawImage(game_over_screen1, 0, 0);
else
g.drawImage(game_over_screen0, 0, 0);
break;
//Steuerungs Screens
case "controlInstructions":
if(waiter < 5){
g.drawImage(instructionScreen, 0, 0);
arrows.draw(150, 200);
walk_demo.draw(550, 200);
}
else if(waiter >6){//"Missions screen"
g.drawImage(missionScreen, 0, 0);
walk_demo.draw(550, 200);
virus_demo.draw(550, 300);
rider_demo.draw(550, 430);
shock_demo.draw(550, 460);
}
break;
case "level_intro":
//Level intro je nach currentLevel
switch(currentLevel){
case 1:alert.draw(0, 0);
g.setColor(Color.red);
g.drawLine(0, 200, 800, 200);
g.drawLine(0, 400, 800, 400);
g.setColor(Color.white);
g.drawString("1", 300, 330);
g.drawString("-First Contact-", 330, 330);
break;
case 2:alert.draw(0, 0);
g.setColor(Color.red);
g.drawLine(0, 200, 800, 200);
g.drawLine(0, 400, 800, 400);
g.setColor(Color.white);
g.drawString("2", 300, 330);
g.drawString("-Two Paths to the Core-", 330, 330);
break;
case 3:alert.draw(0, 0);
g.setColor(Color.red);
g.drawLine(0, 200, 800, 200);
g.drawLine(0, 400, 800, 400);
g.setColor(Color.white);
g.drawString("3", 300, 330);
g.drawString("-The Cyberlabyrinth-", 330, 330);
break;
case 4:alert.draw(0, 0);
g.setColor(Color.red);
g.drawLine(0, 200, 800, 200);
g.drawLine(0, 400, 800, 400);
g.setColor(Color.white);
g.drawString("4", 300, 330);
g.drawString("-The prelast level-", 330, 330);
break;
case 5:alert.draw(0, 0);
g.setColor(Color.red);
g.drawLine(0, 200, 800, 200);
g.drawLine(0, 400, 800, 400);
g.setColor(Color.white);
g.drawString("5", 300, 330);
g.drawString("-Final Fight-", 330, 330);
break;
}
break;
case "titel":
g.drawImage(title, 0, 0);break;
case"paused":
cyberg.draw(0, 0, 800, 600);
panel.render(gc,g);
protector.render(gc, g);
invader.render(gc, g);
g.setColor(Color.magenta);
//Pause Menü Tags
paused.draw(225, 250);
g.drawString("Resume Game", 425, 290);
g.drawString("Options(Not Implemented)", 425, 320);
g.drawString("Exit Game", 425, 350);
//Name des Levels in der UI
switch(currentLevel){
case 1:g.drawString(level[0], 30, 555);break;
case 2:g.drawString(level[1], 30, 555);break;
case 3:g.drawString(level[2], 30, 555);break;
case 4:g.drawString(level[3], 30, 555);break;
case 5:g.drawString(level[4], 30, 555);break;
}
switch(selectedString){
case 0: selected.draw(325, 280);break;
case 1: selected.draw(325, 310);break;
case 2: selected.draw(325, 340);break;
}
break;
case"start":
cyberg.draw(0, 0, 800, 600);
panel.render(gc,g);
protector.render(gc, g);
invader.render(gc, g);
g.setColor(Color.red);
g.drawLine(0, gc.getHeight()-50, 800, gc.getHeight()-50);//Systemlebenslinie
g.setColor(Color.magenta);
switch(currentLevel){
case 1:g.drawString(level[0], 30, 555);break;
case 2:g.drawString(level[1], 30, 555);break;
case 3:g.drawString(level[2], 30, 555);break;
case 4:g.drawString(level[3], 30, 555);break;
case 5:g.drawString(level[4], 30, 555);break;
}
break;
}
}
public void update (GameContainer gc,float _delta)throws SlickException{
this.waiter += _delta;//Ingame Zeit
switch(state.currentState){
case "paused":
//Kontrolle im Menü
if(gc.getInput().isKeyPressed(Input.KEY_UP)&& selectedString >0)
selectedString--;
if(gc.getInput().isKeyPressed(Input.KEY_DOWN)&& selectedString <2)
selectedString++;
break;
case "start":
protector.update(gc, _delta);
invader.update(gc, _delta);
if(!invader.isParalized&& invader.para_timer >=5 && currentLevel == 5){
//invader movement in final level//
if(invader.riderX+75 > panel.xPos+panel.xSize*15 && changedDirection == false){
invader.flightSpdX *= -1;
invader.fly_right = false;
changedDirection = true;
}
if(invader.riderX -75 < panel.xPos+panel.xSize*1 && changedDirection == false){
invader.flightSpdX *= -1;
invader.fly_right = true;
changedDirection = true;
}
if(invader.riderX < panel.xPos+panel.xSize*9 &&
invader.riderX > panel.xPos+panel.xSize*6 && changedDirection == true)
changedDirection = false;
//Ball Bewegung im letzten level
if(invader.ball.xPos-36 > panel.xPos+panel.xSize*15)
invader.ball.collisionManager("x_inverted");
if(invader.ball.xPos+36 < panel.xPos+panel.xSize*1)
invader.ball.collisionManager("x_inverted");
}
//Level ende und wechsel zum nächsten Level
if(panel.xPos <= -4350 && protector.isLanded){
currentLevel++;
waiter = 0;
state.stateId = 5;
panel.init(gc, state, currentLevel);
protector.init(gc, state, -100);
invader.init(gc, state);
ui.sbar_width = 0;
invader.isParalized = false;
panel.xPos = 350;
}
//Roboter - Panel kollision
for(int i = 1; i< panel.collisionarea.length;i++){
if(panel.collisionarea[i].intersects(protector.getCollisionarea())&&!protector.hasFloorContact){
protector.ySpd = 0;
protector.setFloorContact(true);
protector.isLanded = true;
} else
protector.hasFloorContact = false;
//einsetzen der "Gravitation"
if(panel.collisionarea[i].intersects(protector.getCollisionarea())&& !protector.hasFloorContact){
protector.ySpd *=0;
}
}
//Roboter Sprung
if(gc.getInput().isKeyDown(Input.KEY_UP)&& protector.isLanded)
{
if(protector.isRunningRight){
protector.move = 3;
}
else
if(protector.isRunningLeft){
protector.move = 4;
}
else
protector.move = 0;
protector.hasFloorContact = false;
protector.ySpd = -400;
protector.isLanded = false;
}
//Ball fliegt oben aus dem Screen
if(invader.ball.yPos < 0&& !invader.ball.ballIsKilled){
invader.ball.killBall(gc);
protector.ballhit =false;
}
//Kollision Ball - Hacker
if(invader.ball.yPos < invader.riderY + 75 &&
invader.ball.yPos > invader.riderY &&
invader.ball.xPos < invader.riderX + 75 &&
invader.ball.xPos > invader.riderX ){
invader.ball.killBall(gc);
ui.sbar_width += 20;
protector.ballhit=false;
}
//Disconnected Erzeugung
if(ui.sbar_width >= 100 && !invader.isParalized){
invader.isParalized = true;
invader.paralized();
}
//ReConect des Hackers
if(invader.para_timer >= 5 && ui.sbar_width >= 100){
ui.sbar_width -=100;
invader.isParalized = false;
}
// Ball Kollidiert mit Systemlebenslinie
if( (invader.ball.yPos >= gc.getHeight()-50)){
invader.ball.killBall(gc);
protector.ballhit=false;
if(ui.dbar_width >0)
ui.dbar_width -= 20;
}
//Ball - Roboter Kollision
if(invader.ball.yPos >= protector.yPos -50 &&
invader.ball.xPos >= protector.xPos -25&&
invader.ball.xPos <= protector.xPos + 25&&
invader.ball.yPos <= protector.yPos +50&&
!protector.ballhit){
invader.ball.collisionManager("y_inverted");
protector.ballhit= true;
}
//roboter rechtsbewegung
if(gc.getInput().isKeyDown(Input.KEY_RIGHT)){
if(protector.isLanded)protector.move = 1;
else
protector.move = 3;
panel.xSpd=-200;
invader.ball.xPos-=3;
if(!invader.isParalized)
invader.riderX -=3;
}
else
//roboter Linksbewegung
if(gc.getInput().isKeyDown(Input.KEY_LEFT)){
if(protector.isLanded)protector.move = 2;
else
protector.move = 4;
panel.xSpd=200;
invader.ball.xPos+=3;
if(!invader.isParalized)
invader.riderX +=3;
}
else
{//roboter stand bewegung
protector.move = 0;
panel.xSpd=0;
}
//roboter fliegt unten durch den Screen
if(protector.yPos > 800){
protector.init(gc, state,-100 );
panel.xPos = 350;
invader.init(gc, state);
invader.ball.killBall(gc);
ui.sbar_width = 0;
ui.dbar_width -=20 ;
invader.isParalized = false;
}
break;
}
}
}