Add damagable/vulnerable logic.
Also, add the other Backgrounds to spawnable Entities and stuff.
This commit is contained in:
parent
db0ecc13c0
commit
de685366ee
@ -1,11 +1,12 @@
|
||||
|
||||
name:Testlevel \o/
|
||||
backgroundMusic:music/ScooterFriendsTurbo8Bit.wav
|
||||
background:StarBackground
|
||||
background:CloudBackground
|
||||
-
|
||||
[0-4]
|
||||
spawn:EnemyOne,1,1
|
||||
spawn:EnemyOne,1,5
|
||||
[4-10]
|
||||
spawn:EnemyTwo,2,10
|
||||
spawn:EnemyTwo,1,10
|
||||
[10-25]
|
||||
spawn:EnemyThree,2,4
|
||||
spawn:EnemyTwo,5,6
|
||||
|
@ -17,13 +17,19 @@ public abstract class CollidableEntity extends Entity implements Collidable {
|
||||
*/
|
||||
private boolean canCollide;
|
||||
|
||||
/**
|
||||
* Whether this CollidableEntity will damage things it collides with.
|
||||
*/
|
||||
private boolean damaging;
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
* Default constructor. Initializes sane defaults.
|
||||
*/
|
||||
public CollidableEntity(int x, int y) {
|
||||
super(x, y);
|
||||
this.setCollide(true);
|
||||
this.setDamaging(true);
|
||||
}
|
||||
|
||||
|
||||
@ -60,7 +66,24 @@ public abstract class CollidableEntity extends Entity implements Collidable {
|
||||
* Get the current collision damage of the Entity.
|
||||
*/
|
||||
public int getCollisionDamage() {
|
||||
if(!this.getDamaging()) return 0;
|
||||
return this.collisionDamage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether the Collidable will damage things it hits.
|
||||
* This defaults to true on construction and will only be changed manually.
|
||||
*/
|
||||
public void setDamaging(boolean damaging) {
|
||||
this.damaging = damaging;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell whether the Collidable will damage things it hits.
|
||||
* This defaults to true on construction and will only be changed manually.
|
||||
*/
|
||||
public boolean getDamaging(){
|
||||
return this.damaging;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public abstract class Entity implements Updateable, Paintable {
|
||||
*/
|
||||
public static enum availableNames {
|
||||
/* Backgrounds */
|
||||
StarBackground,
|
||||
StarBackground, CloudBackground, EarthBackground,
|
||||
/* Enemies */
|
||||
EnemyOne, EnemyTwo, EnemyThree, EnemyFour,
|
||||
/* Boss Enemies and belongings */
|
||||
|
@ -41,12 +41,18 @@ public abstract class LivingEntity extends CollidableEntity implements Hittable
|
||||
*/
|
||||
private int scorePoints;
|
||||
|
||||
/**
|
||||
* Whether the LivingEntity will take damage.
|
||||
*/
|
||||
private boolean damagable;
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
* Default constructor. Initializes sane defaults.
|
||||
*/
|
||||
public LivingEntity(int x, int y) {
|
||||
super(x, y);
|
||||
this.setDamagable(true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -85,6 +91,9 @@ public abstract class LivingEntity extends CollidableEntity implements Hittable
|
||||
* points. Triggers die() method on death.
|
||||
*/
|
||||
public void takeDamage(int damage) {
|
||||
//Skip taking damage if not vulnerable.
|
||||
if(!this.getVulnerable())
|
||||
return;
|
||||
// Skip everything if already dead.
|
||||
if (this.isAlive() == false)
|
||||
return;
|
||||
@ -228,4 +237,20 @@ public abstract class LivingEntity extends CollidableEntity implements Hittable
|
||||
this.scorePoints = s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether the LivingEntity is damagable.
|
||||
* This defaults to true on construction and will only be changed manually.
|
||||
*/
|
||||
public void setDamagable(boolean damagable) {
|
||||
this.damagable = damagable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the LivingEntity is damagable.
|
||||
* This defaults to true on construction and will only be changed manually.
|
||||
*/
|
||||
public boolean getVulnerable() {
|
||||
return this.damagable;
|
||||
}
|
||||
|
||||
}
|
||||
|
25
src/de/teamteamteam/spacescooter/entity/Obstacle.java
Normal file
25
src/de/teamteamteam/spacescooter/entity/Obstacle.java
Normal file
@ -0,0 +1,25 @@
|
||||
package de.teamteamteam.spacescooter.entity;
|
||||
|
||||
import de.teamteamteam.spacescooter.entity.spi.Collidable;
|
||||
|
||||
/**
|
||||
* Obstacles are static or floating things that do damage on collision.
|
||||
*/
|
||||
public abstract class Obstacle extends CollidableEntity {
|
||||
|
||||
public Obstacle(int x, int y) {
|
||||
super(x, y);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void collideWith(Collidable entity) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -8,6 +8,7 @@ import de.teamteamteam.spacescooter.brain.GameConfig;
|
||||
import de.teamteamteam.spacescooter.brain.PlayerSession;
|
||||
import de.teamteamteam.spacescooter.control.Keyboard;
|
||||
import de.teamteamteam.spacescooter.control.KeyboardListener;
|
||||
import de.teamteamteam.spacescooter.entity.enemy.Enemy;
|
||||
import de.teamteamteam.spacescooter.entity.shot.Shot;
|
||||
import de.teamteamteam.spacescooter.entity.spi.Collidable;
|
||||
import de.teamteamteam.spacescooter.sound.SoundSystem;
|
||||
@ -88,9 +89,9 @@ public class Player extends ShootingEntity implements KeyboardListener {
|
||||
//Collision cooldown handling
|
||||
if(this.currentCollisionCooldown > 0) {
|
||||
this.currentCollisionCooldown--;
|
||||
if(this.currentCollisionCooldown == 0) {
|
||||
this.setCollide(true);
|
||||
}
|
||||
} else {
|
||||
this.setDamagable(true);
|
||||
this.setDamaging(true);
|
||||
}
|
||||
int offset = 3;
|
||||
if(Keyboard.isKeyDown(KeyEvent.VK_UP) && this.getY() > 51) {
|
||||
@ -130,13 +131,16 @@ public class Player extends ShootingEntity implements KeyboardListener {
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine what will happen if a Player collides with an Item.
|
||||
* Implement damage immunity logic after collisions with Enemy or Obstacle Entities.
|
||||
*/
|
||||
@Override
|
||||
public void collideWith(Collidable entity) {
|
||||
super.collideWith(entity);
|
||||
this.setCollide(false);
|
||||
if(this.currentCollisionCooldown == 0 && (entity instanceof Enemy || entity instanceof Obstacle)) {
|
||||
this.currentCollisionCooldown = this.collisionCooldown;
|
||||
this.setDamagable(false);
|
||||
this.setDamaging(false);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,5 @@
|
||||
package de.teamteamteam.spacescooter.entity.enemy;
|
||||
|
||||
import de.teamteamteam.spacescooter.brain.GameConfig;
|
||||
import de.teamteamteam.spacescooter.entity.explosion.MultiExplosion;
|
||||
import de.teamteamteam.spacescooter.gui.BossHealthBar;
|
||||
import de.teamteamteam.spacescooter.utility.Random;
|
||||
|
@ -30,7 +30,6 @@ public class EnemyFour extends Enemy{
|
||||
this.points = points;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.setCollisionDamage(this.getHealthPoints());
|
||||
getNextPoint();
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,6 @@ public class EnemyOne extends Enemy {
|
||||
this.setShootDamage(5);
|
||||
this.setCollisionDamage(5);
|
||||
this.setHealthPoints(5);
|
||||
this.setCollisionDamage(this.getHealthPoints());
|
||||
this.setScore(10);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package de.teamteamteam.spacescooter.entity.enemy;
|
||||
|
||||
import de.teamteamteam.spacescooter.brain.GameConfig;
|
||||
import de.teamteamteam.spacescooter.entity.Player;
|
||||
import de.teamteamteam.spacescooter.entity.explosion.MultiExplosion;
|
||||
import de.teamteamteam.spacescooter.entity.item.Item;
|
||||
|
@ -1,8 +1,6 @@
|
||||
package de.teamteamteam.spacescooter.entity.enemy;
|
||||
|
||||
import de.teamteamteam.spacescooter.brain.GameConfig;
|
||||
import de.teamteamteam.spacescooter.entity.explosion.ExplosionTwo;
|
||||
import de.teamteamteam.spacescooter.utility.Random;
|
||||
|
||||
public class EnemyTwo extends Enemy{
|
||||
|
||||
@ -17,7 +15,6 @@ public class EnemyTwo extends Enemy{
|
||||
this.setCollisionDamage(5);
|
||||
this.setHealthPoints(5);
|
||||
this.setScore(20);
|
||||
this.setCollisionDamage(this.getHealthPoints());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -40,4 +40,14 @@ public interface Collidable {
|
||||
* Set whether the Collidable is currently active.
|
||||
*/
|
||||
public void setCollide(boolean canCollide);
|
||||
|
||||
/**
|
||||
* Set whether the Collidable will damage things it hits.
|
||||
*/
|
||||
public void setDamaging(boolean damaging);
|
||||
|
||||
/**
|
||||
* Tell whether the Collidable will damage things it hits.
|
||||
*/
|
||||
public boolean getDamaging();
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package de.teamteamteam.spacescooter.level;
|
||||
|
||||
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.entity.Entity;
|
||||
@ -117,6 +119,12 @@ public final class Level {
|
||||
case StarBackground:
|
||||
new StarBackground(x, y);
|
||||
break;
|
||||
case CloudBackground:
|
||||
new CloudBackground(x, y);
|
||||
break;
|
||||
case EarthBackground:
|
||||
new EarthBackground(x, y);
|
||||
break;
|
||||
case EnemyOne:
|
||||
new EnemyOne(x, y);
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user