Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bgg 0002 #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/main/java/al/tonikolaba/audio/JukeBox.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package al.tonikolaba.audio;

import java.util.HashMap;
import java.util.Objects;
import java.util.logging.Level;

import javax.sound.sampled.AudioFormat;
Expand Down Expand Up @@ -32,13 +33,13 @@ public static void init() {
public static void load(String s, String n) {
// if (clips.get(s) != null)
// return;
Clip clip;
final Clip clip;
try {
AudioInputStream ais = AudioSystem.getAudioInputStream(JukeBox.class.getResourceAsStream(s));
AudioFormat baseFormat = ais.getFormat();
AudioFormat decodeFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), 16,
final AudioInputStream ais = AudioSystem.getAudioInputStream(Objects.requireNonNull(JukeBox.class.getResourceAsStream(s)));
final AudioFormat baseFormat = ais.getFormat();
final AudioFormat decodeFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), 16,
baseFormat.getChannels(), baseFormat.getChannels() * 2, baseFormat.getSampleRate(), false);
AudioInputStream dais = AudioSystem.getAudioInputStream(decodeFormat, ais);
final AudioInputStream dais = AudioSystem.getAudioInputStream(decodeFormat, ais);
clip = AudioSystem.getClip();
clip.open(dais);
clips.put(n, clip);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/al/tonikolaba/entity/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import javax.imageio.ImageIO;

import al.tonikolaba.audio.JukeBox;
import al.tonikolaba.entity.enemies.Enemy;
import al.tonikolaba.handlers.LoggingHelper;
import al.tonikolaba.tilemap.TileMap;

Expand Down Expand Up @@ -105,8 +106,8 @@ public Player(TileMap tm) {

facingRight = true;

lives = 3;
health = maxHealth = 5;
lives = PlayerSave.getLives();
health = maxHealth = PlayerSave.getHeath();

// load sprites
try {
Expand Down
33 changes: 18 additions & 15 deletions src/main/java/al/tonikolaba/entity/PlayerSave.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,45 @@

public class PlayerSave {

private static int lives = 3;
private static int health = 5;
private static long time = 0;
private static int lives;
private static int heath;
private static long time;

public PlayerSave() {
// throw new IllegalStateException("Utility Class");
}

public static void init() {
lives = 3;
health = 5;
heath = 20;
time = 0;
}

// public static void init() {
// LIVES = 3;
// HEATH = 20;
// TIME = 0;
// }

public static int getLives() {
return lives;
}

public static void setLives(int i) {
lives = i;
public static void setLives(int lives) {
PlayerSave.lives = lives;
}

public static int getHealth() {
return health;
public static int getHeath() {
return heath;
}

public static void setHealth(int i) {
health = i;
public static void setHeath(int heath) {
PlayerSave.heath = heath;
}

public static long getTime() {
return time;
}

public static void setTime(long t) {
time = t;
public static void setTime(long time) {
PlayerSave.time = time;
}

}
3 changes: 2 additions & 1 deletion src/main/java/al/tonikolaba/entity/Teleport.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.util.Objects;
import java.util.logging.Level;

/**
Expand All @@ -22,7 +23,7 @@ public Teleport(TileMap tm) {
cwidth = 20;
cheight = 40;
try {
BufferedImage spritesheet = ImageIO.read(getClass().getResourceAsStream("/Sprites/Player/Teleport.gif"));
BufferedImage spritesheet = ImageIO.read(Objects.requireNonNull(getClass().getResourceAsStream("/Sprites/Player/Teleport.gif")));
sprites = new BufferedImage[9];
for (int i = 0; i < sprites.length; i++) {
sprites[i] = spritesheet.getSubimage(i * width, 0, width, height);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package al.tonikolaba.entity;
package al.tonikolaba.entity.enemies;

import al.tonikolaba.audio.JukeBox;
import al.tonikolaba.entity.MapObject;
import al.tonikolaba.tilemap.TileMap;

/**
Expand Down
1 change: 0 additions & 1 deletion src/main/java/al/tonikolaba/entity/enemies/Flyer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package al.tonikolaba.entity.enemies;

import al.tonikolaba.entity.Enemy;
import al.tonikolaba.tilemap.TileMap;

/**
Expand Down
1 change: 0 additions & 1 deletion src/main/java/al/tonikolaba/entity/enemies/RedEnergy.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package al.tonikolaba.entity.enemies;

import al.tonikolaba.entity.Enemy;
import al.tonikolaba.handlers.Content;
import al.tonikolaba.tilemap.TileMap;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package al.tonikolaba.entity;
package al.tonikolaba.entity.enemies;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import al.tonikolaba.entity.Explosion;
import al.tonikolaba.entity.Player;
import al.tonikolaba.tilemap.TileMap;

import javax.imageio.ImageIO;

import al.tonikolaba.entity.enemies.RedEnergy;
import al.tonikolaba.tilemap.TileMap;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.ArrayList;

/**
* @author N. Kolaba
Expand Down
1 change: 0 additions & 1 deletion src/main/java/al/tonikolaba/entity/enemies/Ufo.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package al.tonikolaba.entity.enemies;

import al.tonikolaba.entity.Enemy;
import al.tonikolaba.entity.Player;
import al.tonikolaba.handlers.Content;
import al.tonikolaba.tilemap.TileMap;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/al/tonikolaba/entity/enemies/Zogu.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package al.tonikolaba.entity.enemies;

import al.tonikolaba.entity.Enemy;
import al.tonikolaba.handlers.Content;
import al.tonikolaba.tilemap.TileMap;

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/al/tonikolaba/gamestate/BasicState.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.util.Objects;
import java.util.logging.Level;

import javax.imageio.ImageIO;
Expand Down Expand Up @@ -40,11 +41,11 @@ public BasicState(GameStateManager gsm) {
this.gsm = gsm;
try {

bg = ImageIO.read(getClass().getResourceAsStream("/Backgrounds/sfondi1.gif")).getSubimage(0, 0,
bg = ImageIO.read(Objects.requireNonNull(getClass().getResourceAsStream("/Backgrounds/sfondi1.gif"))).getSubimage(0, 0,
GamePanel.WIDTH, GamePanel.HEIGHT);

// load floating head
head = ImageIO.read(getClass().getResourceAsStream("/HUD/Hud.gif")).getSubimage(0, 12, 12, 11);
head = ImageIO.read(Objects.requireNonNull(getClass().getResourceAsStream("/HUD/Hud.gif"))).getSubimage(0, 12, 12, 11);

// titles and fonts
fontMenu = new Font("Arial", Font.BOLD, 18);
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/al/tonikolaba/gamestate/GameState.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
import javax.imageio.ImageIO;

import al.tonikolaba.audio.JukeBox;
import al.tonikolaba.entity.Enemy;
import al.tonikolaba.entity.Enemy.EnemyType;
import al.tonikolaba.entity.enemies.Enemy;
import al.tonikolaba.entity.enemies.Enemy.EnemyType;
import al.tonikolaba.entity.EnemyProjectile;
import al.tonikolaba.entity.EnergyParticle;
import al.tonikolaba.entity.Explosion;
import al.tonikolaba.entity.HUD;
import al.tonikolaba.entity.Player;
import al.tonikolaba.entity.PlayerSave;
import al.tonikolaba.entity.Portal;
import al.tonikolaba.entity.Spirit;
import al.tonikolaba.entity.enemies.Spirit;
import al.tonikolaba.entity.Teleport;
import al.tonikolaba.entity.Title;
import al.tonikolaba.entity.enemies.RedEnergy;
Expand Down Expand Up @@ -156,7 +156,7 @@ protected void setupGameObjects(int playerX, int playerY, int goalX, int goalY,
playerYStart = playerY;
player = new Player(tileMap);
player.setPosition(playerX, playerY);
player.setHealth(PlayerSave.getHealth());
player.setHealth(PlayerSave.getHeath());
player.setLives(PlayerSave.getLives());
player.setTime(PlayerSave.getTime());

Expand Down Expand Up @@ -453,7 +453,7 @@ protected void eventFinishFunc() {
JukeBox.stop(TELEPORT_MUSIC_NAME);
}
if (eventCount == 180) {
PlayerSave.setHealth(player.getHealth());
PlayerSave.setHeath(player.getHealth());
PlayerSave.setLives(player.getLives());
PlayerSave.setTime(player.getTime());
gsm.setState(nextLevelState);
Expand Down
49 changes: 30 additions & 19 deletions src/main/java/al/tonikolaba/gamestate/GameStateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class GameStateManager {
public static final int LEVEL2STATE = 3;
public static final int LEVEL3STATE = 4;
public static final int LEVEL4STATE = 5;
// public static final int LEVELTEST = 6;
// public static final int LEVELTEST = 6;
public static final int HOWTOPLAY = 7;
public static final int ACIDSTATE = 15;
public BasicState[] gameStates;
Expand All @@ -39,24 +39,35 @@ public GameStateManager() {
}

public void loadState(int state) {
if (state == MENUSTATE)
gameStates[state] = new MenuState(this);
else if (state == OPTIONSSTATE)
gameStates[state] = new OptionsState(this);
else if (state == HOWTOPLAY)
gameStates[state] = new HowtoPlay(this);
else if (state == LEVEL1STATE)
gameStates[state] = new Level1State(this);
else if (state == LEVEL2STATE)
gameStates[state] = new Level2State(this);
else if (state == LEVEL3STATE)
gameStates[state] = new Level3State(this);
else if (state == LEVEL4STATE)
gameStates[state] = new Level4State(this);
// else if (state == LEVELTEST)
// gameStates[state] = new LevelTest(this);
else if (state == ACIDSTATE)
gameStates[state] = new AcidState(this);
switch (state) {
case (MENUSTATE):
gameStates[state] = new MenuState(this);
break;
case (OPTIONSSTATE):
gameStates[state] = new OptionsState(this);
break;
case(HOWTOPLAY):
gameStates[state] = new HowtoPlay(this);
break;
case (LEVEL1STATE):
gameStates[state] = new Level1State(this);
break;
case (LEVEL2STATE):
gameStates[state] = new Level2State(this);
break;
case (LEVEL3STATE):
gameStates[state] = new Level3State(this);
break;
case(LEVEL4STATE):
gameStates[state] = new Level4State(this);
break;
// case(LEVELTEST):
// gameStates[state] = new LevelTest(this);
// break;
case(ACIDSTATE):
gameStates[state] = new AcidState(this);
break;
}
}

private void unloadState(int state) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/al/tonikolaba/gamestate/HowtoPlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public void draw(Graphics2D h) {
h.fillRect(200, 160, 280, 200); // Fills a square
h.drawRoundRect(190, 150, 300, 220, 50, 50);
h.setColor(Color.RED);
h.drawString("< > - MOVE LEFT OR RIGHT", 230, 200);
h.drawString("W+R - JUMP AND HIT ", 230, 220);
h.drawString("R - SINGLE HIT ", 230, 240);
h.drawString("<- -> - MOVE LEFT OR RIGHT", 230, 200);
h.drawString("LEFT SHIFT - RUN", 230, 220);
h.drawString("D - SINGLE HIT ", 230, 240);
h.drawString("F - BIG HIT ", 230, 260);
h.drawString("W - JUMP UP ", 230, 280);
h.drawString("SPACE - JUMP UP ", 230, 280);
h.drawString("ESC - PAUSE ", 230, 300);
h.setFont(font);
h.drawString(" * Press any key to go Back ", 240, 330);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/al/tonikolaba/gamestate/Level1State.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package al.tonikolaba.gamestate;

import al.tonikolaba.entity.Enemy.EnemyType;
import al.tonikolaba.entity.enemies.Enemy.EnemyType;
import al.tonikolaba.tilemap.Background;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/al/tonikolaba/gamestate/Level2State.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package al.tonikolaba.gamestate;

import al.tonikolaba.entity.Enemy.EnemyType;
import al.tonikolaba.entity.enemies.Enemy.EnemyType;
import al.tonikolaba.tilemap.Background;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/al/tonikolaba/gamestate/Level3State.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

package al.tonikolaba.gamestate;

import al.tonikolaba.entity.Enemy.EnemyType;
import al.tonikolaba.entity.enemies.Enemy.EnemyType;
import al.tonikolaba.entity.Player;
import al.tonikolaba.tilemap.Background;

Expand Down
18 changes: 9 additions & 9 deletions src/main/java/al/tonikolaba/gamestate/Level4State.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import java.util.ArrayList;

import al.tonikolaba.audio.JukeBox;
import al.tonikolaba.entity.Enemy;
import al.tonikolaba.entity.enemies.Enemy;
import al.tonikolaba.entity.EnergyParticle;
import al.tonikolaba.entity.Explosion;
import al.tonikolaba.entity.HUD;
import al.tonikolaba.entity.Player;
import al.tonikolaba.entity.PlayerSave;
import al.tonikolaba.entity.Portal;
import al.tonikolaba.entity.Spirit;
import al.tonikolaba.entity.enemies.Spirit;
import al.tonikolaba.entity.Teleport;
import al.tonikolaba.entity.batbat.Piece;
import al.tonikolaba.entity.enemies.RedEnergy;
Expand Down Expand Up @@ -68,16 +68,16 @@ public void init(int nextLevel) {
// player
player = new Player(tileMap);
player.setPosition(50, 190);
player.setHealth(PlayerSave.getHealth());
player.setHealth(PlayerSave.getHeath());
player.setLives(PlayerSave.getLives());
player.setTime(PlayerSave.getTime());

// player
player = new Player(tileMap);
player.setPosition(50, 190);
player.setHealth(PlayerSave.getHealth());
player.setLives(PlayerSave.getLives());
player.setTime(PlayerSave.getTime());
// player = new Player(tileMap);
// player.setPosition(50, 190);
// player.setHealth(PlayerSave.getHealth());
// player.setLives(PlayerSave.getLives());
// player.setTime(PlayerSave.getTime());

// explosions
explosions = new ArrayList<Explosion>();
Expand Down Expand Up @@ -341,7 +341,7 @@ private void eventFinish() {
tb.get(0).height += 8;
}
if (eventCount == 60) {
PlayerSave.setHealth(player.getHealth());
PlayerSave.setHeath(player.getHealth());
PlayerSave.setLives(player.getLives());
PlayerSave.setTime(player.getTime());
gsm.setState(GameStateManager.ACIDSTATE);
Expand Down
Loading