Conflicts:
	src/de/teamteamteam/spacescooter/screen/GameOverScreen.java
	src/de/teamteamteam/spacescooter/screen/ShopScreen.java
This commit is contained in:
Sosch 2014-12-09 22:59:20 +01:00
commit 33a72d9268
53 changed files with 787 additions and 198 deletions

BIN
res/images/BossBobaFett.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

22
res/levels/second.level Normal file
View File

@ -0,0 +1,22 @@
name:Level Zwai! :D
backgroundMusic:music/ScooterFriendsTurbo8Bit.wav
background:EarthBackground
nextLevel:
-
[0-1]
spawn:EnemyBoss,1,1,50
[1-2]
spawn:StoneOne,2,1,0
spawn:StoneOne,2,1,80
spawn:StoneThree,2,1,90
spawn:StoneThree,2,1,100
[2-4]
spawn:EnemyOne,1,5,20
spawn:StoneOne,4,5,50
[4-10]
spawn:EnemyTwo,1,10,60
[10-25]
spawn:EnemyThree,2,4,33
spawn:EnemyTwo,5,6,10
[25-30]
spawn:EnemyBoss,1,1,50

View File

@ -1,28 +1,85 @@
name:Testlevel \o/
backgroundMusic:music/ScooterFriendsTurbo8Bit.wav
background:CloudBackground
nextLevel:levels/second.level
-
[0-1]
spawn:EnemyBoss,1,1,50
spawn:EnemyTwo,1,4,5
spawn:EnemyTwo,1,4,25
spawn:EnemyTwo,1,4,45
spawn:EnemyTwo,1,4,65
spawn:EnemyTwo,1,4,85
spawn:EnemyTwo,1,4,100
[1-2]
spawn:EnemyTwo,1,6,15
spawn:EnemyTwo,1,6,35
spawn:EnemyTwo,1,6,55
spawn:EnemyTwo,1,6,75
spawn:EnemyTwo,1,6,95
[2-3]
spawn:EnemyTwo,1,4,5
spawn:EnemyTwo,1,4,25
spawn:EnemyTwo,1,4,45
spawn:EnemyTwo,1,4,65
spawn:EnemyTwo,1,4,85
spawn:EnemyTwo,1,4,100
[3-4]
spawn:EnemyTwo,1,6,15
spawn:EnemyTwo,1,6,35
spawn:EnemyTwo,1,6,55
spawn:EnemyTwo,1,6,75
spawn:EnemyTwo,1,6,95
[4-5]
spawn:EnemyTwo,1,4,5
spawn:EnemyTwo,1,4,25
spawn:EnemyTwo,1,4,45
spawn:EnemyTwo,1,4,65
spawn:EnemyTwo,1,4,85
spawn:EnemyTwo,1,4,100
[5-6]
spawn:EnemyTwo,1,6,15
spawn:EnemyTwo,1,6,35
spawn:EnemyTwo,1,6,55
spawn:EnemyTwo,1,6,75
spawn:EnemyTwo,1,6,95
[6-7]
spawn:EnemyTwo,1,4,5
spawn:EnemyTwo,1,4,25
spawn:EnemyTwo,1,4,45
spawn:EnemyTwo,1,4,65
spawn:EnemyTwo,1,4,85
spawn:EnemyTwo,1,4,100
[7-8]
spawn:EnemyTwo,1,6,15
spawn:EnemyTwo,1,6,35
spawn:EnemyTwo,1,6,55
spawn:EnemyTwo,1,6,75
spawn:EnemyTwo,1,6,95
[8-9]
spawn:EnemyTwo,1,4,5
spawn:EnemyTwo,1,4,25
spawn:EnemyTwo,1,4,45
spawn:EnemyTwo,1,4,65
spawn:EnemyTwo,1,4,85
spawn:EnemyTwo,1,4,100
[9-10]
spawn:EnemyTwo,1,6,15
spawn:EnemyTwo,1,6,35
spawn:EnemyTwo,1,6,55
spawn:EnemyTwo,1,6,75
spawn:EnemyTwo,1,6,95
[10-12]
spawn:StoneOne,2,1,0
spawn:StoneOne,2,1,10
spawn:StoneTwo,2,1,20
spawn:StoneOne,2,1,30
spawn:StoneTwo,2,1,40
spawn:EnemyOne,2,1,50
spawn:StoneOne,2,1,60
spawn:StoneThree,2,1,70
spawn:StoneOne,2,1,80
spawn:StoneThree,2,1,90
spawn:StoneThree,2,1,100
[2-4]
[12-14]
spawn:EnemyOne,1,5,20
spawn:StoneOne,4,5,50
[4-10]
[14-20]
spawn:EnemyTwo,1,10,60
[10-25]
[20-35]
spawn:EnemyThree,2,4,33
spawn:EnemyTwo,5,6,10
[25-30]
[35-40]
spawn:EnemyBoss,1,1,50

View File

@ -148,8 +148,8 @@ public class GameFrame extends JFrame {
bufferedGraphics.dispose();
}
} while (this.bufferStrategy.contentsRestored()); //Redraw in case the VolatileImage was restored
this.bufferStrategy.show(); //Show the drawn image
} while (this.bufferStrategy.contentsLost()); //Redraw in case the VolatileImage got lost
this.bufferStrategy.show(); //Show the drawn image
Toolkit.getDefaultToolkit().sync(); //Tell the OS to update its graphics of the window.
this.frameTime = System.nanoTime() - frameStart; //Update frameTime
}

View File

@ -0,0 +1,38 @@
package de.teamteamteam.spacescooter.background;
import java.awt.Graphics2D;
import de.teamteamteam.spacescooter.brain.GameConfig;
public class FuckedUpCloudBackground extends ScrollingBackground {
private double x;
private double x_delta;
private int percentage;
private int timer;
public FuckedUpCloudBackground(int x, int y) {
super(x, y);
this.setImage("images/cloudbackground.png");
this.setScrollingSpeed(-1);
}
public void paint(Graphics2D g) {
g.fillRect(0, 0, GameConfig.windowWidth, GameConfig.windowHeight);
/*if(this.timer == 0 && this.percentage < 100) {
this.percentage++;
} else if (timer > 500 && this.percentage > 0) {
this.percentage--;
} else if (this.percentage == 100){
this.timer++;
} else if (this.percentage == 0) {
this.timer--;
}*/
this.x += 0.005;
g.rotate(this.x, GameConfig.windowWidth/2, GameConfig.windowHeight/2);
super.paint(g);
}
}

View File

@ -78,6 +78,11 @@ public final class GameConfig {
*/
public static final int initialPlayerShotDamage = 10;
/**
* The first level the game will start with.
*/
public static final String firstLevel = "levels/test.level";
/**
* Private constructor, this class will never be instantiated.
*/

View File

@ -21,34 +21,34 @@ public class PlayerSession {
* Damage value of the normal Shots the ship fires.
* This can be changed by upgrades in the shop.
*/
private static int shipShotDamage;
private static int baseShotDamage;
/**
* The ships default maximum shield points.
* This can be changed by upgrades in the shop.
*/
private static int shipShieldPoints;
private static int baseShieldPoints;
/**
* The ships default maximum health points.
* This can be changed by upgrades in the shop.
*/
private static int shipHealthPoints;
private static int baseHealthPoints;
/**
* The number of health upgrades the player bought for the ship.
*/
private static int shipHealthUpgadesBought;
private static int baseHealthUpgadesBought;
/**
* The number of shield upgrades the player bought for the ship.
*/
private static int shipShieldUpgadesBought;
private static int baseShieldUpgadesBought;
/**
* The number of shot damage upgrades the player bought for the ship.
*/
private static int shipShotUpgadesBought;
private static int baseShotUpgadesBought;
/**
* The secondary weapon of the ship.
@ -57,6 +57,11 @@ public class PlayerSession {
*/
private static int secondaryWeapon;
/**
* The next level to load for the player.
*/
private static String nextLevel;
/**
* Private constructor, this class will never be instantiated.
@ -121,106 +126,106 @@ public class PlayerSession {
/**
* Get the ships maximum health points.
*/
public static int getShipHealthPoints() {
return PlayerSession.shipHealthPoints;
public static int getBaseHealthPoints() {
return PlayerSession.baseHealthPoints;
}
/**
* Set the ships maximum health points.
*/
public static void setShipHealthPoints(int shipHealthPoints) {
PlayerSession.shipHealthPoints = shipHealthPoints;
public static void setBaseHealthPoints(int baseHealthPoints) {
PlayerSession.baseHealthPoints = baseHealthPoints;
}
/**
* Add to the ships maximum health points.
*/
public static void addShipHealthPoints(int shipHealthPoints) {
PlayerSession.shipHealthPoints += shipHealthPoints;
public static void addBaseHealthPoints(int baseHealthPoints) {
PlayerSession.baseHealthPoints += baseHealthPoints;
}
/**
* Get the ships maximum shield points.
*/
public static int getShipShieldPoints() {
return PlayerSession.shipShieldPoints;
public static int getBaseShieldPoints() {
return PlayerSession.baseShieldPoints;
}
/**
* Set the ships maximum shield points.
*/
public static void setShipShieldPoints(int shipShieldPoints) {
PlayerSession.shipShieldPoints = shipShieldPoints;
public static void setBaseShieldPoints(int baseShieldPoints) {
PlayerSession.baseShieldPoints = baseShieldPoints;
}
/**
* Add to the ships maximum shield points.
*/
public static void addShipShieldPoints(int shipShieldPoints) {
PlayerSession.shipShieldPoints += shipShieldPoints;
public static void addBaseShieldPoints(int baseShieldPoints) {
PlayerSession.baseShieldPoints += baseShieldPoints;
}
/**
* Get the ships shot damage value.
*/
public static int getShipShotDamage() {
return PlayerSession.shipShotDamage;
public static int getBaseShotDamage() {
return PlayerSession.baseShotDamage;
}
/**
* Set the ships shot damage value.
*/
public static void setShipShotDamage(int shipShotDamage) {
PlayerSession.shipShotDamage = shipShotDamage;
public static void setBaseShotDamage(int baseShotDamage) {
PlayerSession.baseShotDamage = baseShotDamage;
}
/**
* Add to the ships shot damage value.
*/
public static void addShipShotDamage(int shipShotDamage) {
PlayerSession.shipShotDamage += shipShotDamage;
public static void addBaseShotDamage(int shipShotDamage) {
PlayerSession.baseShotDamage += shipShotDamage;
}
/**
* Get the number of ship health upgrades the player bought in the shop.
*/
public static int getShipHealthUpgradesBought() {
return PlayerSession.shipHealthUpgadesBought;
public static int getBaseHealthUpgradesBought() {
return PlayerSession.baseHealthUpgadesBought;
}
/**
* Increment the number of ship health upgrades the player bought.
*/
public static void incrementShipHealthUpgradesBought() {
PlayerSession.shipHealthUpgadesBought++;
public static void incrementBaseHealthUpgradesBought() {
PlayerSession.baseHealthUpgadesBought++;
}
/**
* Get the number of ship shield upgrades the player bought in the shop.
*/
public static int getShipShieldUpgradesBought() {
return PlayerSession.shipShieldUpgadesBought;
public static int getBaseShieldUpgradesBought() {
return PlayerSession.baseShieldUpgadesBought;
}
/**
* Increment the number of ship shield upgrades the player bought.
*/
public static void incrementShipShieldUpgradesBought() {
PlayerSession.shipShieldUpgadesBought++;
public static void incrementBaseShieldUpgradesBought() {
PlayerSession.baseShieldUpgadesBought++;
}
/**
* Get the number of ship shot upgrades the player bought in the shop.
*/
public static int getShipShotUpgradesBought() {
return PlayerSession.shipShotUpgadesBought;
public static int getBaseShotUpgradesBought() {
return PlayerSession.baseShotUpgadesBought;
}
/**
* Increment the number of ship shot upgrades the player bought.
*/
public static void incrementShipShotUpgradesBought() {
PlayerSession.shipShotUpgadesBought++;
public static void incrementBaseShotUpgradesBought() {
PlayerSession.baseShotUpgadesBought++;
}
/**
@ -237,6 +242,19 @@ public class PlayerSession {
PlayerSession.secondaryWeapon = secondaryWeapon;
}
/**
* Get the next Level the player will play.
*/
public static String getNextLevel() {
return PlayerSession.nextLevel;
}
/**
* Set the next Level the player will play.
*/
public static void setNextLevel(String nextLevel) {
PlayerSession.nextLevel = nextLevel;
}
/**
* This will reset all data from the players session.
@ -245,14 +263,16 @@ public class PlayerSession {
* (So the next player can start a fresh session.)
*/
public static void reset() {
PlayerSession.nextLevel = GameConfig.firstLevel;
PlayerSession.score = 0;
PlayerSession.secondaryWeapon = 1;
PlayerSession.credits = 0;
PlayerSession.shipHealthPoints = GameConfig.initialPlayerHealthPoints;
PlayerSession.shipShieldPoints = GameConfig.initialPlayerShieldPoints;
PlayerSession.shipShotDamage = GameConfig.initialPlayerShotDamage;
PlayerSession.shipHealthUpgadesBought = 0;
PlayerSession.shipShieldUpgadesBought = 0;
PlayerSession.shipShotUpgadesBought = 0;
PlayerSession.baseHealthPoints = GameConfig.initialPlayerHealthPoints;
PlayerSession.baseShieldPoints = GameConfig.initialPlayerShieldPoints;
PlayerSession.baseShotDamage = GameConfig.initialPlayerShotDamage;
PlayerSession.baseHealthUpgadesBought = 0;
PlayerSession.baseShieldUpgadesBought = 0;
PlayerSession.baseShotUpgadesBought = 0;
}
}

View File

@ -11,6 +11,7 @@ import de.teamteamteam.spacescooter.entity.enemy.EnemyOne;
import de.teamteamteam.spacescooter.entity.enemy.EnemyThree;
import de.teamteamteam.spacescooter.entity.enemy.EnemyTwo;
import de.teamteamteam.spacescooter.entity.item.ItemNuke;
import de.teamteamteam.spacescooter.screen.GameScreen;
/**
* This is our main control input source.
@ -116,7 +117,7 @@ public class Keyboard implements KeyListener {
}
if(e.getKeyCode() == KeyEvent.VK_4) {
ArrayList<Point> points = new ArrayList<Point>();
points.add(new Point(398,306));;
points.add(new Point(398,306));
points.add(new Point(10,300));
new EnemyFour(700,51,points);
}
@ -126,6 +127,9 @@ public class Keyboard implements KeyListener {
if(e.getKeyCode() == KeyEvent.VK_0) {
new EnemyBoss(400,400);
}
if(e.getKeyCode() == KeyEvent.VK_5) {
GameScreen.getPlayer().setCollide(!GameScreen.getPlayer().canCollide());
}
}

View File

@ -47,7 +47,7 @@ public class ConcurrentLinkedList<T> {
while(element.equals(currentNode.getValue()) == false && currentNode.hasNext()) {
currentNode = currentNode.next();
}
if(currentNode.getValue().equals(element)) {
if(currentNode.getValue() != null && currentNode.getValue().equals(element)) {
currentNode.setValue(null);
return;
}

View File

@ -1,5 +1,9 @@
package de.teamteamteam.spacescooter.entity;
import java.awt.Color;
import java.awt.Graphics2D;
import de.teamteamteam.spacescooter.brain.GameConfig;
import de.teamteamteam.spacescooter.entity.spi.Collidable;
/**
@ -22,6 +26,16 @@ public abstract class CollidableEntity extends Entity implements Collidable {
*/
private boolean damaging;
/**
* Height of the hitbox.
*/
private int hitboxHeight;
/**
* Width of the hitbox.
*/
private int hitboxWidth;
/**
* Default constructor. Initializes sane defaults.
@ -32,6 +46,78 @@ public abstract class CollidableEntity extends Entity implements Collidable {
this.setDamaging(true);
}
/**
* Get X-Position of the Collidable.
*/
public int getHitboxX() {
return this.getCenteredX() - (this.hitboxWidth / 2);
}
/**
* Get Y-Position of the Collidable.
*/
public int getHitboxY() {
return this.getCenteredY() - (this.hitboxHeight / 2);
}
/**
* Get the width of the Collidable.
*/
public int getHitboxWidth() {
return this.hitboxWidth;
}
/**
* Set the width of the Collidable.
*/
public void setHitboxWidth(int hitboxWidth) {
this.hitboxWidth = hitboxWidth;
}
/**
* Get the height of the Collidable.
*/
public int getHitboxHeight() {
return this.hitboxHeight;
}
/**
* Set the height of the Collidable.
*/
public void setHitboxHeight(int hitboxHeight) {
this.hitboxHeight = hitboxHeight;
}
/**
* Set the dimensions of the CollidableEntities hitbox.
*/
public void setHitboxDimenstions(int width, int height) {
this.hitboxWidth = width;
this.hitboxHeight = height;
}
/**
* Overriding the Entities setImageDimension to (ab)use their width/height
* for reuse in the hitbox.
*/
@Override
public void setImageDimensions(int width, int height) {
super.setImageDimensions(width, height);
this.hitboxWidth = this.getImageWidth();
this.hitboxHeight = this.getImageHeight();
}
/**
* Adding a debugging option to draw the hitbox in red.
*/
@Override
public void paint(Graphics2D g) {
super.paint(g);
if(GameConfig.DEBUG) {
g.setColor(new Color(255,0,0));
g.drawRect(this.getHitboxX(), this.getHitboxY(), this.hitboxWidth, this.hitboxHeight);
}
}
/**
* Handle collisions based on what the LivingEntity collided with.

View File

@ -53,12 +53,12 @@ public abstract class Entity implements Updateable, Paintable {
/**
* Entity width.
*/
private int width;
private int imageWidth;
/**
* Entity height.
*/
private int height;
private int imageHeight;
/**
* Whether or not the Entity is able to move using transpose.
@ -106,14 +106,14 @@ public abstract class Entity implements Updateable, Paintable {
* Get the centered X-Position of the Entity.
*/
public int getCenteredX() {
return this.x + (this.width / 2);
return this.x + (this.imageWidth / 2);
}
/**
* Get the centered Y-Position of the Entity.
*/
public int getCenteredY() {
return this.y + (this.height / 2);
return this.y + (this.imageHeight / 2);
}
/**
@ -138,23 +138,23 @@ public abstract class Entity implements Updateable, Paintable {
/**
* Get the Entities width.
*/
public int getWidth() {
return this.width;
public int getImageWidth() {
return this.imageWidth;
}
/**
* Get the Entities height.
*/
public int getHeight() {
return this.height;
public int getImageHeight() {
return this.imageHeight;
}
/**
* Set the entities width and height.
*/
public void setDimensions(int width, int height) {
this.width = width;
this.height = height;
public void setImageDimensions(int width, int height) {
this.imageWidth = width;
this.imageHeight = height;
}
/**
@ -170,7 +170,7 @@ public abstract class Entity implements Updateable, Paintable {
public void setImage(String filename) {
this.img = Loader.getBufferedImageByFilename(filename);
//set the entities dimensions using the dimensions of the image.
this.setDimensions(this.img.getWidth(), this.img.getHeight());
this.setImageDimensions(this.img.getWidth(), this.img.getHeight());
}
/**
@ -190,15 +190,25 @@ public abstract class Entity implements Updateable, Paintable {
/**
* The default way to paint the Entity.
* Simply draw the Entities image on its current position.
* Debugging option: draw the image border in green.
*/
public void paint(Graphics2D g) {
if(GameConfig.DEBUG) {
g.setColor(new Color(255,0,0));
g.drawRect(this.x, this.y, this.width, this.height);
g.setColor(new Color(0,255,0));
g.drawRect(this.x, this.y, this.imageWidth, this.imageHeight);
}
g.drawImage(this.img, this.x, this.y, null);
}
/**
* Make sure an Entity removes itself when off-screen.
*/
public void update() {
if(this.getX() + this.getImageWidth() < 0) {
this.remove();
}
}
/**
* Removes entity from the game by telling the current Screen
* to remove it from its list.

View File

@ -104,7 +104,7 @@ public abstract class LivingEntity extends CollidableEntity implements Hittable
return;
if (this.shieldPoints > 0) {
if (this.shieldPoints < damage) {
this.healthPoints = (damage - this.shieldPoints);
this.healthPoints -= (damage - this.shieldPoints);
this.shieldPoints = 0;
} else {
this.shieldPoints -= damage;

View File

@ -60,11 +60,11 @@ public class Player extends ShootingEntity implements KeyboardListener {
this.setShootSpeed(10);
this.setCollisionDamage(5);
this.setScore(0);
this.setHealthPoints(PlayerSession.getShipHealthPoints());
this.setMaximumHealthPoints(PlayerSession.getShipHealthPoints());
this.setShieldPoints(PlayerSession.getShipShieldPoints());
this.setMaximumShieldPoints(PlayerSession.getShipShieldPoints());
this.setShootDamage((PlayerSession.getShipShotDamage())/2);
this.setHealthPoints(PlayerSession.getBaseHealthPoints());
this.setMaximumHealthPoints(PlayerSession.getBaseHealthPoints());
this.setShieldPoints(PlayerSession.getBaseShieldPoints());
this.setMaximumShieldPoints(PlayerSession.getBaseShieldPoints());
this.setShootDamage(PlayerSession.getBaseShotDamage());
this.registerOnKeyboard(Keyboard.getInstance());
}
@ -124,7 +124,7 @@ public class Player extends ShootingEntity implements KeyboardListener {
public void paint(Graphics2D g) {
if(this.currentCollisionCooldown > 0) {
g.setColor(Color.RED);
g.drawRect(this.getX(), this.getY(), this.getWidth(), this.getHeight());
g.drawRect(this.getX(), this.getY(), this.getImageWidth(), this.getImageHeight());
}
super.paint(g);
}
@ -171,7 +171,7 @@ public class Player extends ShootingEntity implements KeyboardListener {
}
super.remove();
}
/**
* keyPressed method, comes in handy when a key on the keyboard is pressed
*/

View File

@ -87,6 +87,7 @@ public abstract class ShootingEntity extends LivingEntity {
* Update logic making sure that the currentShootDelay is updated.
*/
public void update() {
super.update();
if(this.currentShootDelay > 0) this.currentShootDelay--;
if(this.currentRocketDelay > 0) this.currentRocketDelay--;
if(this.currentBeamDelay > 0) this.currentBeamDelay--;
@ -251,7 +252,7 @@ public abstract class ShootingEntity extends LivingEntity {
this.getY() + this.shootSpawnY,
this.shootDirection,
this.shootSpeed,
(int) (this.shootDamage*1.2),
(int) (this.shootDamage*5),
this. primaryShotImage
);
}

View File

@ -40,13 +40,6 @@ public abstract class Enemy extends ShootingEntity {
*/
public void update() {
super.update();
// enemy has fully left the screen ..to the left!
if(this.getX() + this.getWidth() < 0){
this.remove();
return;
}
if(willShoot == true){
this.shoot();
}

View File

@ -44,7 +44,7 @@ public class EnemyBoss extends Enemy{
public void update() {
super.update();
//Move into the Screen until it fits on X-Axis
if(this.getX() > GameConfig.gameScreenWidth+GameConfig.gameScreenXOffset-this.getWidth()) {
if(this.getX() > GameConfig.gameScreenWidth+GameConfig.gameScreenXOffset-this.getImageWidth()) {
this.transpose(-1, 0);
}
//Move up or down within the GameScreen.
@ -52,12 +52,12 @@ public class EnemyBoss extends Enemy{
if(this.getY() == GameConfig.gameScreenYOffset){
move = 1;
}
if(this.getY() == GameConfig.gameScreenHeight + GameConfig.gameScreenYOffset - this.getHeight()){
if(this.getY() == GameConfig.gameScreenHeight + GameConfig.gameScreenYOffset - this.getImageHeight()){
move = -1;
}
//Randomly spawn minions.
if(Random.nextInt(1000) < 5) {
new EnemyBossMinion(GameConfig.gameScreenWidth +GameConfig.gameScreenXOffset - this.getWidth(), this.getY());
new EnemyBossMinion(GameConfig.gameScreenWidth +GameConfig.gameScreenXOffset - this.getImageWidth(), this.getY());
}
//Randomly fire doubleshots.
if(Random.nextInt(1000) < 50) {

View File

@ -16,7 +16,7 @@ public class EnemyBossMinion extends Enemy{
this.setImage("images/enemybossminion.png");
this.setPrimaryShotImage("images/shots/laser_green.png");
this.setShootSpeed(4);
this.setShootDelay(42);
this.setShootDelay(30);
this.setShootSpawn(-10, 10);
this.setShootDamage(5);
this.setHealthPoints(15);

View File

@ -4,6 +4,8 @@ import java.awt.Point;
import java.util.ArrayList;
import de.teamteamteam.spacescooter.entity.explosion.ExplosionOne;
import de.teamteamteam.spacescooter.entity.item.Item;
import de.teamteamteam.spacescooter.utility.Random;
public class EnemyFour extends Enemy{
@ -21,7 +23,8 @@ public class EnemyFour extends Enemy{
this.setImage("images/enemy01.png");
this.setPrimaryShotImage("images/shots/laser_yellow.png");
this.setShootSpeed(4);
this.setShootDelay(42);
this.setShootDelay(60);
this.setCanShoot(false);
this.setShootSpawn(-10, 10);
this.setShootDamage(5);
this.setCollisionDamage(5);
@ -70,4 +73,13 @@ public class EnemyFour extends Enemy{
new ExplosionOne(this.getCenteredX(), this.getCenteredY());
}
/**
* This enemy spawns an Item on its death and causes another enemy to appear.
*/
@Override
public void die() {
if(Random.nextInt(100) < 5) Item.create(getX(), getY());
super.die();
}
}

View File

@ -9,7 +9,7 @@ public class EnemyOne extends Enemy {
this.setImage("images/nyancat.png");
this.setPrimaryShotImage("images/shots/laser_red.png");
this.setShootSpeed(2);
this.setShootDelay(42);
this.setShootDelay(62);
this.setShootSpawn(-8, 10);
this.setShootDamage(5);
this.setCollisionDamage(5);

View File

@ -16,7 +16,7 @@ public class EnemyThree extends Enemy{
this.setImage("images/enemy03.png");
this.setPrimaryShotImage("images/shots/laser_red.png");
this.setShootSpeed(4);
this.setShootDelay(42);
this.setShootDelay(62);
this.setShootSpawn(-10, 10);
this.setShootDamage(5);
this.setHealthPoints(15);

View File

@ -9,7 +9,7 @@ public class EnemyTwo extends Enemy{
this.setImage("images/enemy02.png");
this.setPrimaryShotImage("images/shots/laser_green.png");
this.setShootSpeed(4);
this.setShootDelay(42);
this.setShootDelay(120);
this.setShootSpawn(-10, 10);
this.setShootDamage(5);
this.setCollisionDamage(5);

View File

@ -17,7 +17,7 @@ public class ExplosionOne extends Animation {
"images/explosions/01/explosion7.png"
};
this.configure(images, 10);
this.setPosition(x - (this.getWidth()/2), y - (this.getHeight()/2));
this.setPosition(x - (this.getImageWidth()/2), y - (this.getImageHeight()/2));
SoundSystem.playSound("sounds/bad_explosion1.wav");
}
}

View File

@ -26,7 +26,7 @@ public class ExplosionTwo extends Animation {
"images/explosions/02/explosion2_16.png"
};
this.configure(images, 10);
this.setPosition(x - (this.getWidth()/2), y - (this.getHeight()/2));
this.setPosition(x - (this.getImageWidth()/2), y - (this.getImageHeight()/2));
SoundSystem.playSound("sounds/bad_explosion2.wav");
}

View File

@ -38,9 +38,6 @@ public abstract class Item extends CollidableEntity {
*/
public void update(){
this.transpose(-1, 0);
if(this.getX() < this.getWidth()) {
this.remove();
}
}
/**
@ -60,7 +57,7 @@ public abstract class Item extends CollidableEntity {
int[] items = new int[6];
items[0] = 1; //ItemNuke
items[1] = 4; //ItemCredit
items[2] = 2; //ItemHeal
items[2] = 3; //ItemHeal
items[3] = 2; //ItemShield
items[4] = 2; //ItemRocket or ItemBeam
items[5] = 3; //ItemIncreaseDamage

View File

@ -11,6 +11,6 @@ public class ItemHeal extends Item {
@Override
public void itemCollected(Player player) {
player.addHealthPoints(15);
player.addHealthPoints(20);
}
}

View File

@ -6,13 +6,19 @@ public class ItemIncreaseDamage extends Item {
public ItemIncreaseDamage(int x, int y) {
super(x, y);
//TODO: Change Image
this.setImage("images/items/item.png");
this.setImage("images/items/itemShotPowerUp.png");
}
/**
* Increase shoot damage of Player if not above 25.
*/
@Override
public void itemCollected(Player player) {
player.setShootDamage(player.getShootDamage()+5);
if(player.getShootDamage() > 25) {
return;
} else {
player.setShootDamage(player.getShootDamage()+5);
}
}
}

View File

@ -27,6 +27,7 @@ public abstract class MovingObstacle extends Obstacle {
* Make the Obstacle move at its defined X- and Y-Delta.
*/
public void update() {
super.update();
this.transpose(this.xDelta, this.yDelta);
}

View File

@ -20,5 +20,13 @@ public abstract class Obstacle extends CollidableEntity {
public void collideWith(Collidable entity) {
}
/**
* Patch through the update() call.
*/
@Override
public void update() {
super.update();
}
}

View File

@ -9,6 +9,7 @@ public class StoneOne extends MovingObstacle {
super(x, y);
this.setImage("images/stones/stone01.png");
this.setCollisionDamage(9001);
this.setHitboxDimenstions(this.getImageWidth() - 5, this.getImageHeight() - 5);
}
}

View File

@ -9,6 +9,7 @@ public class StoneThree extends MovingObstacle {
super(x, y);
this.setImage("images/stones/stone03.png");
this.setCollisionDamage(9001);
this.setHitboxDimenstions(this.getImageWidth() - 5, this.getImageHeight() - 5);
}
}

View File

@ -9,6 +9,7 @@ public class StoneTwo extends MovingObstacle {
super(x, y);
this.setImage("images/stones/stone02.png");
this.setCollisionDamage(9001);
this.setHitboxDimenstions(this.getImageWidth() - 5, this.getImageHeight() - 5);
}
}

View File

@ -15,7 +15,6 @@ public class BeamImage extends Entity {
this.setImage("images/shots/beam.png");
}
@Override
public void update() {
this.lifetime++;
if(this.lifetime>30){

View File

@ -90,8 +90,8 @@ public class Shot extends CollidableEntity {
public void update() {
this.transpose(this.direction * this.speed, 0);
//remove the shot in case it is out of the game window.
if ((this.getX() + this.getWidth()) < 0 || this.getX() > GameConfig.windowWidth
|| (this.getY() + this.getHeight()) < 0
if ((this.getX() + this.getImageWidth()) < 0 || this.getX() > GameConfig.windowWidth
|| (this.getY() + this.getImageHeight()) < 0
|| this.getY() > GameConfig.windowHeight) {
this.remove();
}

View File

@ -8,22 +8,32 @@ public interface Collidable {
/**
* Get X-Position of the Collidable.
*/
public int getX();
public int getHitboxX();
/**
* Get Y-Position of the Collidable.
*/
public int getY();
public int getHitboxY();
/**
* Get the width of the Collidable.
*/
public int getWidth();
public int getHitboxWidth();
/**
* Set the width of the Collidable.
*/
public void setHitboxWidth(int hitboxWidth);
/**
* Get the height of the Collidable.
*/
public int getHeight();
public int getHitboxHeight();
/**
* Set the height of the Collidable.
*/
public void setHitboxHeight(int hitboxHeight);
/**
* Notify the Collidable that a collision happened.

View File

@ -0,0 +1,56 @@
package de.teamteamteam.spacescooter.gui;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import de.teamteamteam.spacescooter.brain.GameConfig;
import de.teamteamteam.spacescooter.entity.Entity;
/**
* A headline that is being displayed at the beginning of each level,
* disappearing by fading out after 1-2 seconds.
*/
public class LevelHeadline extends Entity {
private int lifeTime;
private int lifeTimeCounter;
private String text;
public LevelHeadline(int x, int y, String text) {
super(x, y);
this.text = text;
this.lifeTime = 150;
this.lifeTimeCounter = this.lifeTime;
}
/**
* Make the headline stay for a while, then let it disappear.
*/
@Override
public void update() {
if(this.lifeTimeCounter > 0) {
this.lifeTimeCounter--;
}
if(lifeTime == 0) {
this.remove();
}
}
/**
* Draw the Headline
*/
public void paint(Graphics2D g) {
g.setFont(new Font("Monospace", 0, 60));
float alpha = (float) (this.lifeTimeCounter / (this.lifeTime * 1.0));
int textWidth = g.getFontMetrics().stringWidth(this.text);
int textHeight = g.getFontMetrics().getHeight();
int x = (GameConfig.gameScreenWidth/2 - textWidth/2);
int y = (int) (GameConfig.gameScreenHeight/2 - textHeight);
g.setColor(new Color(1.0F, 1.0F, 1.0F, alpha));
g.drawString(this.text, x, y);
}
}

View File

@ -30,7 +30,6 @@ public class SecondaryWeaponAmount extends Entity{
}
@Override
public void update() {}
}

View File

@ -1,19 +1,29 @@
package de.teamteamteam.spacescooter.level;
import java.awt.Point;
import java.util.ArrayList;
import de.teamteamteam.spacescooter.background.CloudBackground;
import de.teamteamteam.spacescooter.background.EarthBackground;
import de.teamteamteam.spacescooter.background.StarBackground;
import de.teamteamteam.spacescooter.brain.GameConfig;
import de.teamteamteam.spacescooter.brain.PlayerSession;
import de.teamteamteam.spacescooter.datastructure.ConcurrentIterator;
import de.teamteamteam.spacescooter.entity.Entity;
import de.teamteamteam.spacescooter.entity.Player;
import de.teamteamteam.spacescooter.entity.enemy.Enemy;
import de.teamteamteam.spacescooter.entity.enemy.EnemyBoss;
import de.teamteamteam.spacescooter.entity.enemy.EnemyFour;
import de.teamteamteam.spacescooter.entity.enemy.EnemyOne;
import de.teamteamteam.spacescooter.entity.enemy.EnemyThree;
import de.teamteamteam.spacescooter.entity.enemy.EnemyTwo;
import de.teamteamteam.spacescooter.entity.obstacle.Obstacle;
import de.teamteamteam.spacescooter.entity.obstacle.StoneOne;
import de.teamteamteam.spacescooter.entity.obstacle.StoneThree;
import de.teamteamteam.spacescooter.entity.obstacle.StoneTwo;
import de.teamteamteam.spacescooter.gui.LevelHeadline;
import de.teamteamteam.spacescooter.screen.GameScreen;
import de.teamteamteam.spacescooter.screen.Screen;
import de.teamteamteam.spacescooter.sound.SoundSystem;
import de.teamteamteam.spacescooter.utility.Loader;
@ -54,24 +64,38 @@ public final class Level {
*/
private int gameOverDelay;
/**
* Tells how the game over has to be interpreted.
* True - player won, False - player lost.
*/
private boolean playerWon;
/**
* EntityIterator to evaluate the state of all the existing Entities.
*/
private ConcurrentIterator<Entity> entityIterator;
/**
* Constructor creating a LevelConfig based on a given config file.
*/
public Level(String levelConfig) {
this.levelClock = 0;
this.isGameOver = false;
this.playerWon = false;
this.gameOverDelay = 3;
this.config = Loader.getLevelConfigByFilename(levelConfig);
this.entityIterator = Screen.currentScreen.createEntityIterator();
}
/**
* Initialize the level based on the LevelConfig attributes.
* Initialize the level based on the LevelConfig attributes,
* show the level name in a LevelHeadline.
*/
public void doBuildUp() {
this.spawnEntityByAvailableName(Entity.availableNames.valueOf(this.config.background), 0, 50);
this.spawnEntityByAvailableName(Entity.availableNames.valueOf(this.config.background), 0, 50, null);
GameScreen.setPlayer(new Player(200, 300));
this.backgroundMusic = SoundSystem.playSound(this.config.backgroundMusic);
new LevelHeadline(100,100, this.config.name);
}
/**
@ -84,37 +108,49 @@ public final class Level {
public void handleUpdateTick() {
//Check whether the current interval is configured
int currentIntervalIndex = this.config.getIntervalIndexByCurrentTime(this.levelClock);
if(currentIntervalIndex == -1) return; //Nothing to do
//Fetch the current interval
int[] currentInterval = this.config.intervalList.get(currentIntervalIndex);
int relativeTimeWithinCurrentInterval = this.levelClock - currentInterval[0];
int intervalLength = currentInterval[1] - currentInterval[0];
/*
* @see <LevelConfig>
* Get all the spawnrules for the current interval.
* - 0: Interval this rule belongs to
* - 1: EntityNumber - This helps to find out what Entity to actually spawn.
* - 2: Amount - The amount of Entities to spawn at a time.
* - 3: SpawnRate - The rate at which the Entities are supposed to be spawned.
* - 4: SpawnPosition - percentage of GameConfig.windowHeight - Where the Enemy shall spawn.
*/
for(int[] spawnRule : this.config.spawnRuleList) {
//Skip spawn rules that are not in the current spawn interval.
if(spawnRule[0] != currentIntervalIndex) continue;
//Divide the current interval by spawnrate
int intervalModulus = intervalLength / spawnRule[3];
//Check whether the spawn rate strikes right now.
if(relativeTimeWithinCurrentInterval % Math.max(1,intervalModulus) == 0) {
//If the rule matches the current time, spawn the configured Entity in the configured amount:
for(int i=0; i<spawnRule[2]; i++) {
//Minus one because the upper border is _excluded_ from the range!
int x = GameConfig.gameScreenWidth + GameConfig.gameScreenXOffset - 1;
//Minus one because the upper border is _excluded_ from the range!
int y = Math.round((GameConfig.gameScreenHeight * spawnRule[4]) / 100) + GameConfig.gameScreenYOffset - 1;
this.spawnEntityByAvailableName(Entity.availableNames.values()[spawnRule[1]], x, y);
//If there are still configured intervals, take care of the rules
if(currentIntervalIndex != -1) {
//Fetch the current interval
int[] currentInterval = this.config.intervalList.get(currentIntervalIndex);
int relativeTimeWithinCurrentInterval = this.levelClock - currentInterval[0];
int intervalLength = currentInterval[1] - currentInterval[0];
/*
* @see <LevelConfig>
* Get all the spawnrules for the current interval.
* - 0: Interval this rule belongs to
* - 1: EntityNumber - This helps to find out what Entity to actually spawn.
* - 2: Amount - The amount of Entities to spawn at a time.
* - 3: SpawnRate - The rate at which the Entities are supposed to be spawned.
* - 4: SpawnPosition - percentage of GameConfig.windowHeight - Where the Enemy shall spawn.
* - 5: Points - points for EnemyFour
*/
for(String[] spawnRule : this.config.spawnRuleList) {
//Skip spawn rules that are not in the current spawn interval.
if(Integer.parseInt(spawnRule[0]) != currentIntervalIndex) continue;
//Divide the current interval by spawnrate
int intervalModulus = intervalLength / Integer.parseInt(spawnRule[3]);
//Check whether the spawn rate strikes right now.
if(relativeTimeWithinCurrentInterval % Math.max(1,intervalModulus) == 0) {
//If the rule matches the current time, spawn the configured Entity in the configured amount:
for(int i=0; i<Integer.parseInt(spawnRule[2]); i++) {
ArrayList<Point> points = null;
//Minus one because the upper border is _excluded_ from the range!
int x = GameConfig.gameScreenWidth + GameConfig.gameScreenXOffset - 1;
if (!spawnRule[5].equals("")) {
points = new ArrayList<Point>();
String [] lol = spawnRule[5].split(";");
for(int run = 0; run < lol.length; run = run+2) {
points.add(new Point(Integer.parseInt(lol[run]),Integer.parseInt(lol[run+1])));
}
}
//Minus one because the upper border is _excluded_ from the range!
int y = Math.round((GameConfig.gameScreenHeight * Integer.parseInt(spawnRule[4])) / 100) + GameConfig.gameScreenYOffset - 1;
this.spawnEntityByAvailableName(Entity.availableNames.values()[Integer.parseInt(spawnRule[1])], x, y, points);
}
}
}
}
} //end if still intervals configured
//Check for GameOver things.
this.checkGameOverCondition();
@ -131,10 +167,29 @@ public final class Level {
/**
* Evaluates things like whether the Player is alive or
* - if there is a bossfight - if the boss is dead.
* Also checks whether the player has survived everything (won)
*/
private void checkGameOverCondition() {
if(!GameScreen.getPlayer().isAlive()) {
this.isGameOver = true;
this.playerWon = false;
}
int enemyCounter = 0;
int obstacleCounter = 0;
this.entityIterator.reset();
while(this.entityIterator.hasNext()) {
Entity e = this.entityIterator.next();
if(e instanceof Enemy) enemyCounter++;
if(e instanceof Obstacle) obstacleCounter++;
}
//use the currentIntervalIndex to determine whether there are things scheduled to spawn.
int currentIntervalIndex = this.config.getIntervalIndexByCurrentTime(this.levelClock);
if(enemyCounter == 0 && obstacleCounter == 0 && GameScreen.getPlayer().isAlive() && currentIntervalIndex == -1) {
this.isGameOver = true;
this.playerWon = true;
//Update the next Level
PlayerSession.setNextLevel(this.config.nextLevel);
}
}
@ -146,6 +201,12 @@ public final class Level {
return (this.gameOverDelay == 0);
}
/**
* Tell whether the player won the game.
*/
public boolean playerHasWon() {
return this.playerWon;
}
/**
* Clean up before the Level is torn down.
@ -162,7 +223,7 @@ public final class Level {
* Spawn an Entity by name on the given position.
* Uses Entity.availableNames to determine the actual Entity to spawn.
*/
private void spawnEntityByAvailableName(Entity.availableNames entity, int x, int y) {
private void spawnEntityByAvailableName(Entity.availableNames entity, int x, int y, ArrayList<Point> points) {
switch(entity) {
case StarBackground:
new StarBackground(x, y);
@ -183,7 +244,7 @@ public final class Level {
new EnemyThree(x, y);
break;
case EnemyFour:
//TODO: FIX CONSTRUCTOR new EnemyFour(x, y);
new EnemyFour(x, y, points);
break;
case EnemyBoss:
new EnemyBoss(x, y);
@ -202,5 +263,4 @@ public final class Level {
break;
}
}
}

View File

@ -28,6 +28,11 @@ public class LevelConfig {
*/
public String backgroundMusic;
/**
* The name of the level that will come after this one.
*/
public String nextLevel;
/**
* Intervals have a start and an end.
* They are put within this list in a sorted manner, ascending in values.
@ -45,12 +50,12 @@ public class LevelConfig {
* - 3: SpawnRate - The rate at which the Entities are supposed to be spawned.
* - 4: SpawnPosition - percentage of GameConfig.windowHeight - Where the Enemy shall spawn.
*/
public List<int[]> spawnRuleList;
public List<String[]> spawnRuleList;
public LevelConfig() {
this.intervalList = new ArrayList<int[]>();
this.spawnRuleList = new ArrayList<int[]>();
this.spawnRuleList = new ArrayList<String[]>();
}
public String toString() {
@ -62,8 +67,10 @@ public class LevelConfig {
sb.append(this.background);
sb.append(" backgroundMusic=");
sb.append(this.backgroundMusic);
sb.append(" nextLevelName=");
sb.append(this.nextLevel);
sb.append("\\\n\tRules:\n");
for(int[] rule : this.spawnRuleList) {
for(String[] rule : this.spawnRuleList) {
sb.append("\t");
sb.append(rule);
sb.append("\n");
@ -119,17 +126,19 @@ public class LevelConfig {
/**
* Add a given EntitySpawnRule to the ruleList.
* @param wayPoints
* @param enemyWayPoints
*/
public void addEntitySpawnRule(int intervalStart, int intervalEnd, String entityName, int amount, int spawnRate, int spawnPositionPercentage) {
public void addEntitySpawnRule(int intervalStart, int intervalEnd, String entityName, String amount, String spawnRate, String spawnPositionPercentage, String wayPoints) {
int intervalIndex = this.getIntervalIndexByBorders(intervalStart, intervalEnd);
if(intervalIndex == -1) {
throw new LevelConfigException("No Interval for rule found!\nRule: " + intervalStart + " to " + intervalEnd + ": " + entityName + ", " + amount + ", " + spawnRate + ", " + spawnPositionPercentage);
} else {
int enemyNumber = Entity.availableNames.valueOf(entityName).ordinal();
if(spawnPositionPercentage < 0 || spawnPositionPercentage > 100) {
if(Integer.parseInt(spawnPositionPercentage) < 0 || Integer.parseInt(spawnPositionPercentage) > 100) {
throw new LevelConfigException("Invalid spawnPosition percentage!\nRule: " + intervalStart + " to " + intervalEnd + ": " + entityName + ", " + amount + ", " + spawnRate + ", " + spawnPositionPercentage);
}
int[] newRule = {intervalIndex, enemyNumber, amount, spawnRate, spawnPositionPercentage};
String[] newRule = {""+intervalIndex, ""+enemyNumber, ""+amount, ""+spawnRate, ""+spawnPositionPercentage, wayPoints};
this.spawnRuleList.add(newRule);
}
}

View File

@ -31,6 +31,11 @@ public class LevelConfigParser {
*/
private int currentIntervalStart;
/**
* The start of the last read interval.
*/
private String wayPoints;
/**
* The end of the last read interval.
*/
@ -70,6 +75,8 @@ public class LevelConfigParser {
this.levelConfig.background = linePieces[1];
} else if (linePieces[0].equals("backgroundMusic")) {
this.levelConfig.backgroundMusic = linePieces[1];
} else if (linePieces[0].equals("nextLevel")) {
this.levelConfig.nextLevel = linePieces[1];
} else {
throw new LevelConfigException("[LevelConfigParser] Unknown attribute in line: '" + line + "'");
}
@ -86,14 +93,20 @@ public class LevelConfigParser {
} else {
String[] rule = line.split(":", 2);
if(rule[0].equals("spawn")) {
String[] entitySpawnRule = rule[1].split(",", 4);
String[] entitySpawnRule = rule[1].split(",", 5);
if (entitySpawnRule.length <= 4) {
wayPoints = "";
} else {
wayPoints = entitySpawnRule[4];
}
this.levelConfig.addEntitySpawnRule(
this.currentIntervalStart,
this.currentIntervalEnd,
entitySpawnRule[0],
Integer.parseInt(entitySpawnRule[1]),
Integer.parseInt(entitySpawnRule[2]),
Integer.parseInt(entitySpawnRule[3])
entitySpawnRule[1],
entitySpawnRule[2],
entitySpawnRule[3],
wayPoints
);
} else {
throw new LevelConfigException("Unknown rule type: '"+rule[0]+"' : '"+line+"'");
@ -104,6 +117,12 @@ public class LevelConfigParser {
throw new LevelConfigException("[LevelConfigParser] Where am i?!");
}
}
//Set the nextLevel to null explicitly, so it is easy to detect.
if(this.levelConfig.nextLevel.equals("")) {
this.levelConfig.nextLevel = null;
}
return this.levelConfig;
}

View File

@ -0,0 +1,47 @@
package de.teamteamteam.spacescooter.screen;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import de.teamteamteam.spacescooter.brain.GameConfig;
import de.teamteamteam.spacescooter.control.Keyboard;
import de.teamteamteam.spacescooter.entity.enemy.EnemyOne;
/**
* This is the Screen where you can look at all those awesome guys who created this game. :D
*/
public class CreditsScreen extends Screen {
/**
* Default Constructor
*/
public CreditsScreen(Screen parent) {
super(parent);
}
/**
* Draw the Credits :)
*/
@Override
protected void paint(Graphics2D g) {
g.setColor(new Color(0,0,120));
g.fillRect(0, 0, GameConfig.windowWidth, GameConfig.windowHeight);
g.setColor(Color.WHITE);
g.setFont(new Font("Monospace", 0, 50));
String text = "#yolo";
g.drawString(text, (GameConfig.windowWidth - g.getFontMetrics().stringWidth(text))/2, 150);
}
/**
* In case the Loader is done, immediately fire up the MainMenuScreen.
*/
@Override
protected void update() {
if(Keyboard.isKeyDown(KeyEvent.VK_ENTER) || Keyboard.isKeyDown(KeyEvent.VK_SPACE)) {
this.parent.setOverlay(new MainMenuScreen(this.parent));
}
}
}

View File

@ -230,7 +230,7 @@ public class GameOverScreen extends Screen {
}else{
switch (this.menuPoint) {
case 0:
this.parent.setOverlay(new GameScreen(this.parent, "levels/test.level"));
this.parent.setOverlay(new GameScreen(this.parent));
break;
case 1:
this.parent.setOverlay(new MainMenuScreen(this.parent));

View File

@ -3,6 +3,7 @@ package de.teamteamteam.spacescooter.screen;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import de.teamteamteam.spacescooter.brain.PlayerSession;
import de.teamteamteam.spacescooter.control.Keyboard;
import de.teamteamteam.spacescooter.entity.Player;
import de.teamteamteam.spacescooter.gui.HealthBar;
@ -37,9 +38,9 @@ public class GameScreen extends Screen {
* GameScreen Constructor.
* Takes the level as its second parameter.
*/
public GameScreen(Screen parent, String levelConfigName) {
public GameScreen(Screen parent) {
super(parent);
this.level = new Level(levelConfigName);
this.level = new Level(PlayerSession.getNextLevel());
this.level.doBuildUp(); //Have the level build up the whole setting.
this.gameClockTrigger = 0;
@ -89,9 +90,19 @@ public class GameScreen extends Screen {
this.setOverlay(new GamePausedScreen(this), false);
}
//Go to GameOverScreen if the game is actually over.
//React if the game is actually over.
if (this.level.isGameOver()) {
this.parent.setOverlay(new GameOverScreen(this.parent));
if(this.level.playerHasWon()) {
if(PlayerSession.getNextLevel() == null) {
this.parent.setOverlay(new HighscoreScreen(this.parent));
} else {
//Go to the I don't know yet Screen if the game is over and the player WON.
this.parent.setOverlay(new GameWonScreen(this.parent));
}
} else {
//Go to GameOverScreen if the game is over - the player died and lost the game.
this.parent.setOverlay(new GameOverScreen(this.parent));
}
}
}

View File

@ -0,0 +1,100 @@
package de.teamteamteam.spacescooter.screen;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import de.teamteamteam.spacescooter.brain.GameConfig;
import de.teamteamteam.spacescooter.control.Keyboard;
import de.teamteamteam.spacescooter.entity.Player;
import de.teamteamteam.spacescooter.gui.Button;
import de.teamteamteam.spacescooter.utility.Loader;
/**
* This Screen is shown after the player has beaten a level, so he can enter the shop
* and do some various things before entering the next level.
*/
public class GameWonScreen extends Screen {
private BufferedImage img;
private Player player;
private float playerMoveSpeed = 0;
private int colorValue = 0;
private boolean colorValueIncrease = true;
private int menuPoint = 0;
private int animationStatus = 0; //0 = Noch nicht gestartet, 1 = Animation läuft, 2 = Animation beendet
public GameWonScreen(Screen parent) {
super(parent);
this.img = Loader.getBufferedImageByFilename("images/pausebackground.png");
new Button(GameConfig.windowWidth/2-125, 300);
new Button(GameConfig.windowWidth/2-125, 400);
player = new Player(GameConfig.windowWidth/2-170, 309);
player.setCanMove(false);
player.setCanShoot(false);
}
@Override
protected void paint(Graphics2D g) {
g.drawImage(this.img, 0, 0, null);
this.entityPaintIterator.reset();
while (this.entityPaintIterator.hasNext()) {
this.entityPaintIterator.next().paint(g);
}
g.setFont(new Font("Monospace", 0, 100));
g.setColor(new Color(75 + colorValue, 175 + colorValue, 175 + colorValue));
g.drawString("You win!", GameConfig.windowWidth/2-210, 200);
g.setFont(new Font("Monospace", 0, 20));
g.setColor(new Color(0, 0, 0));
g.drawString("Weiter", GameConfig.windowWidth/2-70, 332);
g.drawString("Hauptmen\u00fc", GameConfig.windowWidth/2-60, 432);
}
@Override
protected void update() {
this.entityUpdateIterator.reset();
while (this.entityUpdateIterator.hasNext()) {
this.entityUpdateIterator.next().update();
}
if(this.colorValueIncrease) {
this.colorValue += 2;
if(this.colorValue > 70) this.colorValueIncrease = false;
} else {
this.colorValue -= 2;
if(this.colorValue < -70) this.colorValueIncrease = true;
}
if(Keyboard.isKeyDown(KeyEvent.VK_DOWN) && this.animationStatus == 0){
this.menuPoint = 1;
player.setPosition(player.getX(), 409);
}
if(Keyboard.isKeyDown(KeyEvent.VK_UP) && this.animationStatus == 0){
this.menuPoint = 0;
player.setPosition(player.getX(), 309);
}
// make a selection
if(Keyboard.isKeyDown(KeyEvent.VK_ENTER) || Keyboard.isKeyDown(KeyEvent.VK_SPACE)) {
this.animationStatus = 1;
}
if(this.animationStatus == 1) {
if(player.getX() <= GameConfig.windowWidth) {
player.setPosition(player.getX() + (int) playerMoveSpeed, player.getY());
playerMoveSpeed += 0.1;
} else this.animationStatus = 2;
} else if(this.animationStatus == 2) {
switch (this.menuPoint) {
case 0:
this.parent.setOverlay(new ShopScreen(this.parent));
break;
case 1:
this.parent.setOverlay(new MainMenuScreen(this.parent));
break;
}
}
}
}

View File

@ -5,6 +5,7 @@ import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import de.teamteamteam.spacescooter.brain.GameConfig;
import de.teamteamteam.spacescooter.brain.PlayerSession;
import de.teamteamteam.spacescooter.control.Keyboard;
import de.teamteamteam.spacescooter.gui.Button;
import de.teamteamteam.spacescooter.gui.ImageEntity;
@ -55,6 +56,7 @@ public class HighscoreScreen extends Screen{
this.cursorMoveSpeed += 0.1;
} else this.animationStatus = 2;
} else if(this.animationStatus == 2) {
PlayerSession.reset(); //The player now entered his highscore, reset the PlayerSession now.
this.parent.setOverlay(new MainMenuScreen(this.parent));
}
}

View File

@ -74,8 +74,18 @@ public class LoadingScreen extends Screen {
g.fillRect(0, 0, GameConfig.windowWidth, GameConfig.windowHeight);
g.setColor(Color.WHITE);
g.setFont(new Font("Monospace", 0, 50));
g.drawString("Loading ...", 100, 100);
g.drawString("Progress: " + this.getProgress() + "%", 200, 500);
String text = "Loading ...";
g.drawString(text, (GameConfig.windowWidth - g.getFontMetrics().stringWidth(text))/2, 150);
text = this.getProgress() + "%";
g.drawString(text, (GameConfig.windowWidth - g.getFontMetrics().stringWidth(text))/2, GameConfig.windowHeight - 175);
int height = 75;
int width = GameConfig.windowWidth - 100;
int x = (GameConfig.windowWidth - width) / 2;
int y = GameConfig.windowHeight - 150;
int padding = 5;
g.drawRect(x - padding , y - padding, width + 2*padding, height + 2*padding);
g.setColor(Color.YELLOW);
g.fillRect(x, y, (int) (width * (this.getProgress() / 100.0)), height);
}
/**

View File

@ -98,7 +98,7 @@ public class MainMenuScreen extends Screen {
} else if(animationStatus == 2) {
switch (menuPoint) {
case 0:
this.parent.setOverlay(new GameScreen(this.parent, "levels/test.level"));
this.parent.setOverlay(new GameScreen(this.parent));
break;
case 1:
this.parent.setOverlay(new ShopScreen(this.parent));
@ -107,6 +107,7 @@ public class MainMenuScreen extends Screen {
this.parent.setOverlay(new HighscoreScreen(this.parent));
break;
case 3:
this.parent.setOverlay(new CreditsScreen(this.parent));
break;
case 4:
System.exit(0);

View File

@ -241,6 +241,8 @@ public abstract class Screen {
if(this.processSetOverlayCall) {
if(this.overlay != null) {
this.overlay.cleanup();
} else {
this.cleanup();
}
if(this.newOverlay == null) {
Screen.currentScreen = this;

View File

@ -30,9 +30,9 @@ public class ShopScreen extends Screen {
super(parent);
new ImageEntity(0, 0, "images/shopbackground.png");
new Button(GameConfig.windowWidth/2-125, 500);
this.damage = new ShopOffer(100, 150, 15, PlayerSession.getShipShotUpgradesBought(), "Schaden 5C");
this.shield = new ShopOffer(100, 225, 15, PlayerSession.getShipShieldUpgradesBought(), "Schild 10C");
this.life = new ShopOffer(100, 300, 15, PlayerSession.getShipHealthUpgradesBought(), "Leben 10C");
damage = new ShopOffer(100, 150, 15, PlayerSession.getBaseShotUpgradesBought(), "Schaden 5C");
shield = new ShopOffer(100, 225, 15, PlayerSession.getBaseShieldUpgradesBought(), "Schild 10C");
life = new ShopOffer(100, 300, 15, PlayerSession.getBaseHealthUpgradesBought(), "Leben 10C");
new ImageEntity(GameConfig.windowWidth / 2 - 120, 365, "images/shop/shoprocket.png");
new ImageEntity(GameConfig.windowWidth / 2 + 30, 365, "images/shop/shopbeam.png");
if(PlayerSession.getSecondsecondaryWeapon() == 1){
@ -57,7 +57,7 @@ public class ShopScreen extends Screen {
g.drawString("Rocket", GameConfig.windowWidth / 2 - 110, 390);
g.drawString("Beam", GameConfig.windowWidth / 2 + 45, 390);
g.setColor(new Color(0, 0, 0));
g.drawString("Hauptmen\u00fc", GameConfig.windowWidth/2-55, 533);
g.drawString("Weiter", GameConfig.windowWidth/2-55, 533);
}
@Override
@ -98,24 +98,24 @@ public class ShopScreen extends Screen {
case 0:
if(PlayerSession.getCredits() >= 5 && damage.getBought() < damage.getMax()){
damage.buy();
PlayerSession.addShipShotDamage(5);
PlayerSession.incrementShipShotUpgradesBought();
PlayerSession.addBaseShotDamage(5);
PlayerSession.incrementBaseShotUpgradesBought();
PlayerSession.removeCredits(5);
}
break;
case 1:
if(PlayerSession.getCredits() >= 10 && shield.getBought() < shield.getMax()){
shield.buy();
PlayerSession.addShipShieldPoints(10);
PlayerSession.incrementShipShieldUpgradesBought();
PlayerSession.addBaseShieldPoints(10);
PlayerSession.incrementBaseShieldUpgradesBought();
PlayerSession.removeCredits(10);
}
break;
case 2:
if(PlayerSession.getCredits() >= 10 && life.getBought() < life.getMax()){
life.buy();
PlayerSession.addShipHealthPoints(10);
PlayerSession.incrementShipHealthUpgradesBought();
PlayerSession.addBaseHealthPoints(10);
PlayerSession.incrementBaseHealthUpgradesBought();
PlayerSession.removeCredits(10);
}
break;
@ -146,7 +146,7 @@ public class ShopScreen extends Screen {
this.cursorMoveSpeed += 0.1;
} else this.animationStatus = 2;
} else if(this.animationStatus == 2) {
this.parent.setOverlay(new MainMenuScreen(this.parent));
this.parent.setOverlay(new GameScreen(this.parent));
}
}

View File

@ -1,5 +1,7 @@
package de.teamteamteam.spacescooter.thread;
import de.teamteamteam.spacescooter.brain.GameConfig;
/**
* Since things like drawing the next image or triggering the next game tick
* need to happen in time, this TimedThread allows more precise timing
@ -18,11 +20,6 @@ public abstract class TimedThread extends Thread {
*/
private long workTime;
/**
* This is a quick hack :)
*/
private long runloops;
/**
* This method sets the actual working interval based on hz.
*
@ -37,7 +34,6 @@ public abstract class TimedThread extends Thread {
*/
public final void run() {
while (true) {
this.runloops++;
long workStart = System.nanoTime();
// do the actual work
this.work();
@ -47,9 +43,8 @@ public abstract class TimedThread extends Thread {
long timeToWait = this.workInterval - workTime;
//in case we are already running late, just print a warning and carry on!
if(timeToWait < 0 && this.runloops > 50) { // runloops for filtering out game start delays
System.err.println("[" + this.getName() + "] workTime exceeds workInterval!:" + this.workTime + " > " + this.workInterval);
runloops = 100; // overflow protect
if(timeToWait < 0) {
if(GameConfig.DEBUG) System.err.println("[" + this.getName() + "] workTime exceeds workInterval!:" + this.workTime + " > " + this.workInterval);
continue;
}
long msToWait = timeToWait / 1000000;

View File

@ -70,18 +70,18 @@ public class CollisionHandler {
* Check if two Collidables actually collided.
*/
private static boolean doCollide(Collidable cOne, Collidable cTwo) {
int x1 = cOne.getX();
int x2 = cOne.getX() + cOne.getWidth();
int x3 = cTwo.getX();
int x4 = cTwo.getX() + cTwo.getWidth();
int total_width = cOne.getWidth() + cTwo.getWidth();
int x1 = cOne.getHitboxX();
int x2 = cOne.getHitboxX() + cOne.getHitboxWidth();
int x3 = cTwo.getHitboxX();
int x4 = cTwo.getHitboxX() + cTwo.getHitboxWidth();
int total_width = cOne.getHitboxWidth() + cTwo.getHitboxWidth();
boolean x_overlap = total_width > Math.abs(Math.max(x2, x4) - Math.min(x1, x3));
int y1 = cOne.getY();
int y2 = cOne.getY() + cOne.getHeight();
int y3 = cTwo.getY();
int y4 = cTwo.getY() + cTwo.getHeight();
int total_height = cOne.getHeight() + cTwo.getHeight();
int y1 = cOne.getHitboxY();
int y2 = cOne.getHitboxY() + cOne.getHitboxHeight();
int y3 = cTwo.getHitboxY();
int y4 = cTwo.getHitboxY() + cTwo.getHitboxHeight();
int total_height = cOne.getHitboxHeight() + cTwo.getHitboxHeight();
boolean y_overlap = total_height > Math.abs(Math.max(y2, y4) - Math.min(y1, y3));
return x_overlap && y_overlap;

View File

@ -135,6 +135,12 @@ public class Loader {
Loader.addLevelByFilename(e);
}
loadingScreen.increaseCurrentProcessed();
//For the retro :D
try {
Thread.sleep(Random.nextInt(15));
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}