Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import mayflower.*;
- import java.awt.*;
- public class MainStage extends Stage {
- private HealthDisplay healthDisplay;
- private Player player;
- private Block ground;
- private String[][][] map;
- private int currentScreen;
- private Text scoreText;
- public MainStage() {
- scoreText = new Text("SCORE: "+String.format("%03d", 0), Color.GRAY, 30, "Impact");
- addActor(scoreText, 650, 0);
- map = new String[][][]{
- {
- {"00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00",},
- {"00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00",},
- {"00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "05_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00",},
- {"00_00", "00_00", "03_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "04_03", "00_00", "00_00", "00_00", "00_00", "00_00",},
- {"00_00", "03_00", "00_00", "00_00", "00_00", "00_00", "03_00", "00_00", "00_00", "01_17", "01_18", "01_19", "00_00", "00_00", "00_00", "00_00",},
- {"00_00", "00_00", "00_00", "00_00", "00_00", "01_04", "01_18", "01_06", "00_00", "00_00", "00_00", "00_00", "00_00", "05_00", "00_00", "00_00",},
- {"00_00", "00_00", "00_00", "00_00", "02_01", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00",},
- {"00_00", "00_00", "00_00", "00_00", "02_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "01_17", "01_18", "01_18",},
- {"00_00", "00_00", "00_00", "00_00", "02_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00",},
- {"01_17", "01_18", "01_18", "01_18", "01_05", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00",},
- {"00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00",},
- {"00_00", "00_00", "00_00", "00_00", "01_17", "01_18", "01_18", "01_18", "01_18", "01_18", "01_18", "01_18", "01_18", "01_18", "01_19", "00_00",},
- },
- {
- {"00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00",},
- {"00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00",},
- {"00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00",},
- {"00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "07_04", "05_00", "00_00", "08_01",},
- {"00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "08_00",},
- {"00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "01_04", "01_18", "01_18", "01_18", "01_19",},
- {"00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "05_00", "00_00", "00_00", "02_01", "00_04", "00_00", "00_00", "00_00", "00_00",},
- {"01_18", "01_06", "06_00", "06_00", "01_04", "01_19", "00_00", "00_00", "00_00", "00_01", "02_00", "00_00", "00_00", "00_00", "00_00", "00_00",},
- {"00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "07_00", "00_00", "04_00", "00_00", "02_00", "00_00", "00_00", "00_00", "00_00", "00_00",},
- {"00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "01_17", "01_18", "01_18", "01_18", "01_19", "00_00", "00_00", "00_00", "00_00", "00_00",},
- {"00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00",},
- {"00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00",},
- }, {
- {"00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00",},
- {"00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00",},
- {"00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "05_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00",},
- {"00_00", "00_00", "03_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "04_03", "00_00", "00_00", "00_00", "00_00", "00_00",},
- {"00_00", "03_00", "00_00", "00_00", "00_00", "00_00", "03_00", "00_00", "00_00", "01_17", "01_18", "01_19", "00_00", "00_00", "00_00", "00_00",},
- {"00_00", "00_00", "00_00", "00_00", "00_00", "01_04", "01_18", "01_06", "00_00", "00_00", "00_00", "00_00", "00_00", "05_00", "00_00", "00_00",},
- {"00_00", "00_00", "00_00", "00_00", "02_01", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00",},
- {"00_00", "00_00", "00_00", "00_00", "02_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "01_17", "01_18", "01_18",},
- {"00_00", "00_00", "00_00", "00_00", "02_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00",},
- {"01_17", "01_18", "01_18", "01_18", "01_05", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00",},
- {"00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00", "00_00",},
- {"00_00", "00_00", "00_00", "00_00", "01_17", "01_18", "01_18", "01_18", "01_18", "01_18", "01_18", "01_18", "01_18", "01_18", "01_19", "00_00",},
- },
- };
- currentScreen = 0;
- generateMap();
- Picture bgPicture = new Picture("src/img/BG/main.png");
- setBackground(bgPicture);
- //setBackgroundColor(Color.ORANGE);
- player = new Player();
- addActor(player, 75, 100);
- //showBounds(true);
- HealthDisplay health = new HealthDisplay();
- addActor(health, 55, 15);
- }
- public void update() {
- Keyboard kb = getKeyboard();
- Actor[] actors = getActors();
- HealthDisplay localHealth = new HealthDisplay();
- Player localPlayer = new Player();
- for(Actor health : actors){
- if(health instanceof HealthDisplay){
- //((HealthDisplay) health).adjustHealth(-1);
- localHealth = (HealthDisplay) health;
- }
- }
- for(Actor player : actors){
- if(player instanceof Player){
- //((HealthDisplay) health).adjustHealth(-1);
- localPlayer = (Player) player;
- }
- }
- if (kb.isKeyPressed("r")) {
- localPlayer.setPosition(25, 50);
- localPlayer.setGravity(0.0);
- clearMap();
- generateMap();
- }
- if(localPlayer.getX() > 800){
- localPlayer.setPosition(0, localPlayer.getY());
- currentScreen ++;
- clearMap();
- generateMap();
- }
- if(1500 < localPlayer.getY()){
- localPlayer.setPosition(25, 50);
- localPlayer.setGravity(0.0);
- clearMap();
- generateMap();
- localHealth.adjustHealth(-1);
- }
- if(localHealth.getHealth() < 0){
- getMayflower().setStage(new GameOver());
- }
- scoreText.setText("SCORE: "+String.format("%03d", localPlayer.getScore()));
- }
- public void clearMap() {
- Actor[] actors = getActors();
- for(Actor actor : actors){
- if(!(actor instanceof Player || actor instanceof HealthDisplay || actor instanceof Text)){
- this.removeActor(actor);
- }
- }
- }
- public void generateMap(){
- String[][] world = map[currentScreen];
- for (int r = 0; r < world.length; r++) {
- for (int c = 0; c < world[0].length; c++) {
- int object = Integer.parseInt(world[r][c].split("_")[0]);
- int style = Integer.parseInt(world[r][c].split("_")[1]);
- int posX = c * 50 + 25;
- int posY = r * 50 + 25;
- switch (object) {
- case 1:
- Grass grass = new Grass(style);
- addActor(grass, posX, posY);
- break;
- case 2:
- Ladder ladder = new Ladder(style);
- addActor(ladder, posX, posY);
- break;
- case 3:
- Spike spike = new Spike();
- addActor(spike, posX, posY);
- break;
- case 4:
- Flag flag = new Flag(style);
- addActor(flag, posX, posY);
- break;
- case 5:
- Coin coin = new Coin();
- addActor(coin, posX, posY);
- break;
- case 6:
- Bridge bridge = new Bridge(style);
- addActor(bridge, posX, posY);
- break;
- case 7:
- Slime slime = new Slime(style);
- addActor(slime, posX, posY);
- break;
- case 8:
- Door door = new Door(style);
- addActor(door, posX, posY);
- break;
- }
- }
- }
- }
- public HealthDisplay getHealthDisplay(){
- return healthDisplay;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement