This commit is contained in:
Licht 2014-12-09 12:22:26 +01:00
commit 6610b5a509
21 changed files with 178 additions and 80 deletions

View File

@ -6,13 +6,6 @@ background:CloudBackground
spawn:EnemyBoss,1,1,50 spawn:EnemyBoss,1,1,50
[1-2] [1-2]
spawn:StoneOne,2,1,0 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:StoneOne,2,1,80
spawn:StoneThree,2,1,90 spawn:StoneThree,2,1,90
spawn:StoneThree,2,1,100 spawn:StoneThree,2,1,100

View File

@ -148,8 +148,8 @@ public class GameFrame extends JFrame {
bufferedGraphics.dispose(); bufferedGraphics.dispose();
} }
} while (this.bufferStrategy.contentsRestored()); //Redraw in case the VolatileImage was restored } 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 } 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. Toolkit.getDefaultToolkit().sync(); //Tell the OS to update its graphics of the window.
this.frameTime = System.nanoTime() - frameStart; //Update frameTime this.frameTime = System.nanoTime() - frameStart; //Update frameTime
} }

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.EnemyThree;
import de.teamteamteam.spacescooter.entity.enemy.EnemyTwo; import de.teamteamteam.spacescooter.entity.enemy.EnemyTwo;
import de.teamteamteam.spacescooter.entity.item.ItemNuke; import de.teamteamteam.spacescooter.entity.item.ItemNuke;
import de.teamteamteam.spacescooter.screen.GameScreen;
/** /**
* This is our main control input source. * This is our main control input source.
@ -126,6 +127,9 @@ public class Keyboard implements KeyListener {
if(e.getKeyCode() == KeyEvent.VK_0) { if(e.getKeyCode() == KeyEvent.VK_0) {
new EnemyBoss(400,400); new EnemyBoss(400,400);
} }
if(e.getKeyCode() == KeyEvent.VK_5) {
GameScreen.getPlayer().setCollide(!GameScreen.getPlayer().canCollide());
}
} }

View File

@ -1,5 +1,9 @@
package de.teamteamteam.spacescooter.entity; 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; import de.teamteamteam.spacescooter.entity.spi.Collidable;
/** /**
@ -22,6 +26,16 @@ public abstract class CollidableEntity extends Entity implements Collidable {
*/ */
private boolean damaging; private boolean damaging;
/**
* Height of the hitbox.
*/
private int hitboxHeight;
/**
* Width of the hitbox.
*/
private int hitboxWidth;
/** /**
* Default constructor. Initializes sane defaults. * Default constructor. Initializes sane defaults.
@ -32,6 +46,78 @@ public abstract class CollidableEntity extends Entity implements Collidable {
this.setDamaging(true); 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. * Handle collisions based on what the LivingEntity collided with.

View File

@ -53,12 +53,12 @@ public abstract class Entity implements Updateable, Paintable {
/** /**
* Entity width. * Entity width.
*/ */
private int width; private int imageWidth;
/** /**
* Entity height. * Entity height.
*/ */
private int height; private int imageHeight;
/** /**
* Whether or not the Entity is able to move using transpose. * 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. * Get the centered X-Position of the Entity.
*/ */
public int getCenteredX() { public int getCenteredX() {
return this.x + (this.width / 2); return this.x + (this.imageWidth / 2);
} }
/** /**
* Get the centered Y-Position of the Entity. * Get the centered Y-Position of the Entity.
*/ */
public int getCenteredY() { 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. * Get the Entities width.
*/ */
public int getWidth() { public int getImageWidth() {
return this.width; return this.imageWidth;
} }
/** /**
* Get the Entities height. * Get the Entities height.
*/ */
public int getHeight() { public int getImageHeight() {
return this.height; return this.imageHeight;
} }
/** /**
* Set the entities width and height. * Set the entities width and height.
*/ */
public void setDimensions(int width, int height) { public void setImageDimensions(int width, int height) {
this.width = width; this.imageWidth = width;
this.height = height; this.imageHeight = height;
} }
/** /**
@ -170,7 +170,7 @@ public abstract class Entity implements Updateable, Paintable {
public void setImage(String filename) { public void setImage(String filename) {
this.img = Loader.getBufferedImageByFilename(filename); this.img = Loader.getBufferedImageByFilename(filename);
//set the entities dimensions using the dimensions of the image. //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,11 +190,12 @@ public abstract class Entity implements Updateable, Paintable {
/** /**
* The default way to paint the Entity. * The default way to paint the Entity.
* Simply draw the Entities image on its current position. * Simply draw the Entities image on its current position.
* Debugging option: draw the image border in green.
*/ */
public void paint(Graphics2D g) { public void paint(Graphics2D g) {
if(GameConfig.DEBUG) { if(GameConfig.DEBUG) {
g.setColor(new Color(255,0,0)); g.setColor(new Color(0,255,0));
g.drawRect(this.x, this.y, this.width, this.height); g.drawRect(this.x, this.y, this.imageWidth, this.imageHeight);
} }
g.drawImage(this.img, this.x, this.y, null); g.drawImage(this.img, this.x, this.y, null);
} }

View File

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

View File

@ -128,7 +128,7 @@ public class Player extends ShootingEntity implements KeyboardListener {
public void paint(Graphics2D g) { public void paint(Graphics2D g) {
if(this.currentCollisionCooldown > 0) { if(this.currentCollisionCooldown > 0) {
g.setColor(Color.RED); 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); super.paint(g);
} }

View File

@ -42,7 +42,7 @@ public abstract class Enemy extends ShootingEntity {
super.update(); super.update();
// enemy has fully left the screen ..to the left! // enemy has fully left the screen ..to the left!
if(this.getX() + this.getWidth() < 0){ if(this.getX() + this.getImageWidth() < 0){
this.remove(); this.remove();
return; return;
} }

View File

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

View File

@ -17,7 +17,7 @@ public class ExplosionOne extends Animation {
"images/explosions/01/explosion7.png" "images/explosions/01/explosion7.png"
}; };
this.configure(images, 10); 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"); SoundSystem.playSound("sounds/bad_explosion1.wav");
} }
} }

View File

@ -26,7 +26,7 @@ public class ExplosionTwo extends Animation {
"images/explosions/02/explosion2_16.png" "images/explosions/02/explosion2_16.png"
}; };
this.configure(images, 10); 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"); SoundSystem.playSound("sounds/bad_explosion2.wav");
} }

View File

@ -38,7 +38,7 @@ public abstract class Item extends CollidableEntity {
*/ */
public void update(){ public void update(){
this.transpose(-1, 0); this.transpose(-1, 0);
if(this.getX() < this.getWidth()) { if(this.getX() < this.getImageWidth()) {
this.remove(); this.remove();
} }
} }

View File

@ -9,6 +9,7 @@ public class StoneOne extends MovingObstacle {
super(x, y); super(x, y);
this.setImage("images/stones/stone01.png"); this.setImage("images/stones/stone01.png");
this.setCollisionDamage(9001); 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); super(x, y);
this.setImage("images/stones/stone03.png"); this.setImage("images/stones/stone03.png");
this.setCollisionDamage(9001); 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); super(x, y);
this.setImage("images/stones/stone02.png"); this.setImage("images/stones/stone02.png");
this.setCollisionDamage(9001); 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"); this.setImage("images/shots/beam.png");
} }
@Override
public void update() { public void update() {
this.lifetime++; this.lifetime++;
if(this.lifetime>30){ if(this.lifetime>30){

View File

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

View File

@ -8,22 +8,32 @@ public interface Collidable {
/** /**
* Get X-Position of the Collidable. * Get X-Position of the Collidable.
*/ */
public int getX(); public int getHitboxX();
/** /**
* Get Y-Position of the Collidable. * Get Y-Position of the Collidable.
*/ */
public int getY(); public int getHitboxY();
/** /**
* Get the width of the Collidable. * 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. * 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. * Notify the Collidable that a collision happened.

View File

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

View File

@ -84,37 +84,40 @@ public final class Level {
public void handleUpdateTick() { public void handleUpdateTick() {
//Check whether the current interval is configured //Check whether the current interval is configured
int currentIntervalIndex = this.config.getIntervalIndexByCurrentTime(this.levelClock); int currentIntervalIndex = this.config.getIntervalIndexByCurrentTime(this.levelClock);
if(currentIntervalIndex == -1) return; //Nothing to do
//Fetch the current interval //If there are still configured intervals, take care of the rules
int[] currentInterval = this.config.intervalList.get(currentIntervalIndex); if(currentIntervalIndex != -1) {
int relativeTimeWithinCurrentInterval = this.levelClock - currentInterval[0]; //Fetch the current interval
int intervalLength = currentInterval[1] - currentInterval[0]; int[] currentInterval = this.config.intervalList.get(currentIntervalIndex);
/* int relativeTimeWithinCurrentInterval = this.levelClock - currentInterval[0];
* @see <LevelConfig> int intervalLength = currentInterval[1] - currentInterval[0];
* Get all the spawnrules for the current interval. /*
* - 0: Interval this rule belongs to * @see <LevelConfig>
* - 1: EntityNumber - This helps to find out what Entity to actually spawn. * Get all the spawnrules for the current interval.
* - 2: Amount - The amount of Entities to spawn at a time. * - 0: Interval this rule belongs to
* - 3: SpawnRate - The rate at which the Entities are supposed to be spawned. * - 1: EntityNumber - This helps to find out what Entity to actually spawn.
* - 4: SpawnPosition - percentage of GameConfig.windowHeight - Where the Enemy shall 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.
for(int[] spawnRule : this.config.spawnRuleList) { * - 4: SpawnPosition - percentage of GameConfig.windowHeight - Where the Enemy shall spawn.
//Skip spawn rules that are not in the current spawn interval. */
if(spawnRule[0] != currentIntervalIndex) continue; for(int[] spawnRule : this.config.spawnRuleList) {
//Divide the current interval by spawnrate //Skip spawn rules that are not in the current spawn interval.
int intervalModulus = intervalLength / spawnRule[3]; if(spawnRule[0] != currentIntervalIndex) continue;
//Check whether the spawn rate strikes right now. //Divide the current interval by spawnrate
if(relativeTimeWithinCurrentInterval % Math.max(1,intervalModulus) == 0) { int intervalModulus = intervalLength / spawnRule[3];
//If the rule matches the current time, spawn the configured Entity in the configured amount: //Check whether the spawn rate strikes right now.
for(int i=0; i<spawnRule[2]; i++) { if(relativeTimeWithinCurrentInterval % Math.max(1,intervalModulus) == 0) {
//Minus one because the upper border is _excluded_ from the range! //If the rule matches the current time, spawn the configured Entity in the configured amount:
int x = GameConfig.gameScreenWidth + GameConfig.gameScreenXOffset - 1; for(int i=0; i<spawnRule[2]; i++) {
//Minus one because the upper border is _excluded_ from the range! //Minus one because the upper border is _excluded_ from the range!
int y = Math.round((GameConfig.gameScreenHeight * spawnRule[4]) / 100) + GameConfig.gameScreenYOffset - 1; int x = GameConfig.gameScreenWidth + GameConfig.gameScreenXOffset - 1;
this.spawnEntityByAvailableName(Entity.availableNames.values()[spawnRule[1]], x, y); //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);
}
} }
} }
} } //end if still intervals configured
//Check for GameOver things. //Check for GameOver things.
this.checkGameOverCondition(); this.checkGameOverCondition();

View File

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