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.

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