242 lines
7.4 KiB
Java
242 lines
7.4 KiB
Java
import processing.core.PApplet;
|
|
import processing.core.PFont;
|
|
import processing.sound.*;
|
|
|
|
import java.io.IOException;
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
* The window which holds all game information and draws.
|
|
*/
|
|
public class Fenster extends PApplet {
|
|
|
|
Score save;
|
|
FileHandleUtil savefile = FileHandleUtil.getInstance();
|
|
Player player;
|
|
Tiles tiles;
|
|
int translate_x = 0;
|
|
int translate_y = 0;
|
|
|
|
float tilewidth = 40.0f;
|
|
|
|
// STATES
|
|
StartScreen startScreen;
|
|
GameScreen gameScreen;
|
|
FightScreen fightScreen;
|
|
DeathScreen deathScreen;
|
|
SoundFile soundTrack;
|
|
SoundFile confirm;
|
|
SoundFile enemyDamage;
|
|
SoundFile playerDamage;
|
|
SoundFile healEffect;
|
|
SoundFile shrinkEffect;
|
|
SoundFile noHit;
|
|
SoundFile deathSound;
|
|
SoundFile restart;
|
|
|
|
boolean gametitel = true;
|
|
|
|
Fight myfight;
|
|
|
|
AuraFight auraFight;
|
|
int gametitel_gamma = 255;
|
|
boolean gametitel_fade = false;
|
|
|
|
UI ui = new UI(this);
|
|
|
|
public static void main(String[] args){
|
|
String[] processingArgs = {"auraworld"};
|
|
Fenster mySketch = new Fenster();
|
|
PApplet.runSketch(processingArgs, mySketch);
|
|
}
|
|
|
|
@Override
|
|
public void settings() {
|
|
size(800, 800);
|
|
|
|
setupPlayer();
|
|
|
|
tiles.settings();
|
|
|
|
|
|
//this.text("lol", 0, 0);
|
|
//this.rect(4.0f, 4.0f, 4.0f, 4.0f);
|
|
}
|
|
|
|
@Override
|
|
public void setup() {
|
|
PFont font = createFont("UbuntuMono Nerd Font Mono Bold", 18);
|
|
this.textFont(font);
|
|
this.textSize(20);
|
|
this.textAlign(CENTER, CENTER);
|
|
|
|
myfight = new Fight(this, player, (Enemy) tiles.get(10, 10));
|
|
|
|
startScreen.setup();
|
|
startScreen.isState = true;
|
|
|
|
soundTrack = new SoundFile(this, "./soundtrack.mp3");
|
|
soundTrack.loop(1, 0.2f);
|
|
confirm = new SoundFile(this, "./assets/Text 1.wav");
|
|
enemyDamage = new SoundFile(this, "./assets/Hit damage 1.wav");
|
|
playerDamage = new SoundFile(this, "./assets/Boss hit 1.wav");
|
|
healEffect = new SoundFile(this, "./assets/Big Egg collect 1.wav");
|
|
shrinkEffect = new SoundFile(this, "./assets/Balloon start riding 2.wav");
|
|
noHit = new SoundFile(this, "./assets/Bubble 1.wav");
|
|
deathSound = new SoundFile(this, "./assets/Block Break 1.wav");
|
|
restart = new SoundFile(this, "./assets/Cancel 1.wav");
|
|
}
|
|
|
|
@Override
|
|
public void draw() {
|
|
// System.out.println(frameRate);
|
|
pushMatrix();
|
|
translate(translate_x, translate_y);
|
|
if(player.pos.get().x > width) {
|
|
translate_x = -800;
|
|
System.out.println("translate: " + translate_x + " : " + translate_y);
|
|
} else {
|
|
translate_x = 0;
|
|
}
|
|
if(player.pos.get().y > height) {
|
|
translate_y = -800;
|
|
System.out.println("translate: " + translate_x + " : " + translate_y);
|
|
} else translate_y = 0;
|
|
|
|
if(!startScreen.draw()) {
|
|
if(!gameScreen.active() && !fightScreen.active()) {
|
|
gameScreen.isState = true;
|
|
}
|
|
}
|
|
|
|
gameScreen.draw();
|
|
fightScreen.draw();
|
|
deathScreen.draw();
|
|
|
|
|
|
popMatrix();
|
|
ui.draw();
|
|
if (gametitel) {
|
|
fill(color(49, 54, 63), gametitel_gamma);
|
|
rect(0, 0, 800, 800);
|
|
textSize(15);
|
|
fill(color(238, 238, 238), gametitel_gamma);
|
|
text(" ('-. _ .-') ('-. (`\\ .-') /` _ .-') _ .-') _ \n" +
|
|
" ( OO ).-. ( \\( -O ) ( OO ).-. `.( OO ),' ( \\( -O ) ( ( OO) ) \n" +
|
|
" / . --. / ,--. ,--. ,------. / . --. /,--./ .--. .-'),-----. ,------. ,--. \\ .'_ \n" +
|
|
" | \\-. \\ | | | | | /`. ' | \\-. \\ | | | ( OO' .-. '| /`. ' | |.-') ,`'--..._) \n" +
|
|
".-'-' | | | | | .-') | / | |.-'-' | || | | |, / | | | || / | | | | OO )| | \\ ' \n" +
|
|
" \\| |_.' | | |_|( OO )| |_.' | \\| |_.' || |.'.| |_)\\_) | |\\| || |_.' | | |`-' || | ' | \n" +
|
|
" | .-. | | | | `-' /| . '.' | .-. || | \\ | | | || . '.'(| '---.'| | / : \n" +
|
|
" | | | |(' '-'(_.-' | |\\ \\ | | | || ,'. | `' '-' '| |\\ \\ | | | '--' / \n" +
|
|
" `--' `--' `-----' `--' '--' `--' `--''--' '--' `-----' `--' '--' `------' `-------'", 400, 200);
|
|
if (gametitel_fade) {
|
|
gametitel_gamma = gametitel_gamma - 5;
|
|
}
|
|
if (gametitel_gamma < 1) {
|
|
gametitel = false;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//println(player.x + " " + player.y);
|
|
}
|
|
|
|
public void keyPressed(processing.event.KeyEvent event) {
|
|
if (gametitel) {
|
|
if (keyCode == 32) {
|
|
gametitel_fade = true;
|
|
}
|
|
}
|
|
switch(key) {
|
|
case 'w':
|
|
// code block
|
|
dead();
|
|
case 'u':
|
|
// code block
|
|
try {
|
|
closeGame();
|
|
} catch (IOException e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
exit();
|
|
}
|
|
startScreen.keyPressed();
|
|
gameScreen.keyPressed();
|
|
fightScreen.keyPressed();
|
|
|
|
|
|
}
|
|
|
|
public void mousePressed() {
|
|
fightScreen.mousePressed();
|
|
deathScreen.mousePressed();
|
|
}
|
|
|
|
void setupPlayer() {
|
|
try {
|
|
List<Score> allSaves = savefile.readLatestScores();
|
|
if (allSaves.size() == 0) {
|
|
player = new Player(this);
|
|
classSetup();
|
|
} else {
|
|
save = allSaves.getLast();
|
|
player = new Player(this, save.getScore(), save.getPosition(), save.getHealth());
|
|
System.out.println(save.getPosition().x + " : " + save.getPosition().y);
|
|
classSetupWithSave();
|
|
}
|
|
} catch (IOException e) {
|
|
player = new Player(this);
|
|
classSetup();
|
|
}
|
|
}
|
|
|
|
void closeGame() throws IOException {
|
|
Score score = new Score(1, player.experience, player.pos.get_grid(), player.health);
|
|
try {
|
|
savefile.addScore(score);
|
|
} catch (IOException e) {
|
|
savefile.createFile();
|
|
savefile.addScore(score);
|
|
}
|
|
}
|
|
|
|
void classSetup() {
|
|
tiles = new Tiles(this, 40.0f);
|
|
startScreen = new StartScreen(this);
|
|
gameScreen = new GameScreen(this);
|
|
fightScreen = new FightScreen(this);
|
|
deathScreen = new DeathScreen(this);
|
|
}
|
|
|
|
void classSetupWithSave() {
|
|
tiles = new Tiles(this, 40.0f);
|
|
startScreen = new StartScreen(this);
|
|
gameScreen = new GameScreen(this);
|
|
fightScreen = new FightScreen(this);
|
|
deathScreen = new DeathScreen(this);
|
|
startScreen.isState = false;
|
|
gameScreen.isState = true;
|
|
}
|
|
|
|
public void dead() {
|
|
soundTrack.stop();
|
|
deathSound.play();
|
|
gameScreen.isState = false;
|
|
fightScreen.isState = false;
|
|
deathScreen.isState = true;
|
|
}
|
|
|
|
public void reset() {
|
|
player = new Player(this);
|
|
classSetup();
|
|
soundTrack.play();
|
|
deathScreen.isState = false;
|
|
startScreen.setup();
|
|
tiles.settings();
|
|
startScreen.isState = true;
|
|
}
|
|
}
|