Add rocket (fire button: y), add ItemRocket (increase rocket amount), add some comments

This commit is contained in:
Sosch 2014-11-24 23:33:56 +01:00
parent 841875c09c
commit 7437a5c18d
19 changed files with 162 additions and 22 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
res/images/shots/rocket.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 307 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 373 B

View File

@ -15,6 +15,7 @@ public class Player extends ShootingEntity implements KeyboardListener {
private Keyboard keyboard = null; private Keyboard keyboard = null;
private double healthPercent = 0; private double healthPercent = 0;
private double shieldPercent = 0; private double shieldPercent = 0;
private int rocketAmount = 1;
public Player(int x, int y) { public Player(int x, int y) {
super(x, y); super(x, y);
@ -62,6 +63,11 @@ public class Player extends ShootingEntity implements KeyboardListener {
if(Keyboard.isKeyDown(KeyEvent.VK_SPACE)) { if(Keyboard.isKeyDown(KeyEvent.VK_SPACE)) {
this.shoot(); this.shoot();
} }
if(Keyboard.isKeyDown(KeyEvent.VK_Y)) {
if(rocketAmount > 0){
this.shootRocket();
}
}
} }
} }
@ -133,4 +139,25 @@ public class Player extends ShootingEntity implements KeyboardListener {
} }
} }
/**
* Get the current rocket amount.
*/
public int getRocketAmount(){
return rocketAmount;
}
/**
* Add one rocket.
*/
public void addRocketAmount(){
rocketAmount++;
}
/**
* Remove one rocket.
*/
public void removeRocketAmount(){
rocketAmount--;
}
} }

View File

@ -1,6 +1,8 @@
package de.teamteamteam.spacescooter.entity; package de.teamteamteam.spacescooter.entity;
import de.teamteamteam.spacescooter.entity.shot.Rocket;
import de.teamteamteam.spacescooter.entity.shot.Shot; import de.teamteamteam.spacescooter.entity.shot.Shot;
import de.teamteamteam.spacescooter.screen.GameScreen;
/** /**
* The ShootingEntity is a LivingEntity that is able to fire Shots. * The ShootingEntity is a LivingEntity that is able to fire Shots.
@ -26,6 +28,12 @@ public abstract class ShootingEntity extends LivingEntity {
*/ */
private int currentShootDelay; private int currentShootDelay;
/**
* The current tick delay to wait until the next Rocket can be fired.
* This value is used to enforce the actual delay defined in shootDelay.
*/
private int currentRocketDelay;
/** /**
* The X delta to pass to the Shot, so it spawns at the * The X delta to pass to the Shot, so it spawns at the
* right position relative to the ShootingEntity. * right position relative to the ShootingEntity.
@ -74,6 +82,7 @@ public abstract class ShootingEntity extends LivingEntity {
*/ */
public void update() { public void update() {
if(this.currentShootDelay > 0) this.currentShootDelay--; if(this.currentShootDelay > 0) this.currentShootDelay--;
if(this.currentRocketDelay > 0) this.currentRocketDelay--;
} }
/** /**
@ -88,6 +97,16 @@ public abstract class ShootingEntity extends LivingEntity {
} }
} }
} }
public void shootRocket() {
if(this.canShoot == true) {
if(this.currentRocketDelay == 0) {
this.createRocket();
GameScreen.getPlayer().removeRocketAmount();
this.currentRocketDelay = this.shootDelay*3;
}
}
}
/** /**
* Enable or disable the ShootingEntitys fire ability. * Enable or disable the ShootingEntitys fire ability.
@ -177,6 +196,17 @@ public abstract class ShootingEntity extends LivingEntity {
); );
} }
public void createRocket() {
new Rocket(
this.getX() + this.shootSpawnX,
this.getY() + this.shootSpawnY,
this.shootDirection,
this.shootSpeed,
(int)(this.shootDamage*1.5),
this.primaryShotImage
);
}
/** /**
* Custom Shoot for Custom Action!!! * Custom Shoot for Custom Action!!!
*/ */
@ -190,4 +220,5 @@ public abstract class ShootingEntity extends LivingEntity {
filename filename
); );
} }
} }

View File

@ -30,8 +30,17 @@ public abstract class Item extends CollidableEntity {
}; };
} }
/**
* Item property.
* What happens when item is collected.
*/
public abstract void itemCollected(Player player); public abstract void itemCollected(Player player);
/**
* Selects which item spawns.
*
* (If you add a new item, you must also add it in ItemChance.java)
*/
public static void create(int x, int y){ public static void create(int x, int y){
int auswahl = ItemChance.choose(); int auswahl = ItemChance.choose();
switch (auswahl) { switch (auswahl) {
@ -48,7 +57,7 @@ public abstract class Item extends CollidableEntity {
new ItemShield(x, y); new ItemShield(x, y);
break; break;
case 4: case 4:
new TestItem1(x, y); new ItemRocket(x, y);
break; break;
} }
} }

View File

@ -7,12 +7,21 @@ public class ItemChance {
private static int summe = 0; private static int summe = 0;
private static int[] items; private static int[] items;
/**
* Item spawn probability,
* higher number, higher spawn rate,
* same number, same spawn rate.
*
* New items must be registered here!!
*/
public ItemChance() { public ItemChance() {
ItemChance.items = new int[4]; ItemChance.items = new int[6];
items[0] = 4; items[0] = 1; //ItemNuke
items[1] = 3; items[2] = 2; //ItemHeal
items[2] = 2; items[3] = 2; //ItemShield
items[3] = 1; items[4] = 2; //ItemRocket
items[1] = 4; //ItemCredit
items[5] = 3; //ItemIncreaseDamage
for(int i=0; i<ItemChance.items.length; i++) { for(int i=0; i<ItemChance.items.length; i++) {
ItemChance.summe += ItemChance.items[i]; ItemChance.summe += ItemChance.items[i];
@ -20,7 +29,6 @@ public class ItemChance {
} }
public static int choose() { public static int choose() {
//dauerhaft
int r = Random.nextInt(ItemChance.summe - 1) + 1; int r = Random.nextInt(ItemChance.summe - 1) + 1;
for(int i=0; i<ItemChance.items.length; i++) { for(int i=0; i<ItemChance.items.length; i++) {

View File

@ -1,11 +1,10 @@
package de.teamteamteam.spacescooter.entity.item; package de.teamteamteam.spacescooter.entity.item;
import de.teamteamteam.spacescooter.entity.Player; import de.teamteamteam.spacescooter.entity.Player;
import de.teamteamteam.spacescooter.gui.Credits;
public class ItemCredit extends Item { public class ItemCredit extends Item {
public static int chance = 2;
public ItemCredit(int x, int y) { public ItemCredit(int x, int y) {
super(x, y); super(x, y);
this.setImage("images/items/itemCredit.png"); this.setImage("images/items/itemCredit.png");
@ -13,6 +12,6 @@ public class ItemCredit extends Item {
@Override @Override
public void itemCollected(Player player) { public void itemCollected(Player player) {
player.setShootDamage(player.getShootDamage()+5); Credits.add(10);
} }
} }

View File

@ -4,8 +4,6 @@ import de.teamteamteam.spacescooter.entity.Player;
public class ItemHeal extends Item { public class ItemHeal extends Item {
public static int chance = 3;
public ItemHeal(int x, int y) { public ItemHeal(int x, int y) {
super(x, y); super(x, y);
this.setImage("images/items/itemHeal.png"); this.setImage("images/items/itemHeal.png");

View File

@ -2,10 +2,11 @@ package de.teamteamteam.spacescooter.entity.item;
import de.teamteamteam.spacescooter.entity.Player; import de.teamteamteam.spacescooter.entity.Player;
public class TestItem1 extends Item { public class ItemIncreaseDamage extends Item {
public TestItem1(int x, int y) { public ItemIncreaseDamage(int x, int y) {
super(x, y); super(x, y);
//TODO: Chane Image
this.setImage("images/items/item.png"); this.setImage("images/items/item.png");
} }

View File

@ -4,8 +4,6 @@ import de.teamteamteam.spacescooter.entity.Player;
public class ItemNuke extends Item { public class ItemNuke extends Item {
public static int chance = 2;
public ItemNuke(int x, int y) { public ItemNuke(int x, int y) {
super(x, y); super(x, y);
this.setImage("images/items/itemNuke.png"); this.setImage("images/items/itemNuke.png");

View File

@ -3,8 +3,6 @@ package de.teamteamteam.spacescooter.entity.item;
import de.teamteamteam.spacescooter.entity.Player; import de.teamteamteam.spacescooter.entity.Player;
public class ItemOneUp extends Item { public class ItemOneUp extends Item {
public static int chance = 4;
public ItemOneUp(int x, int y) { public ItemOneUp(int x, int y) {
super(x, y); super(x, y);
@ -13,6 +11,6 @@ public static int chance = 4;
@Override @Override
public void itemCollected(Player player) { public void itemCollected(Player player) {
player.setShieldPoints(player.getShieldPoints() + 5); System.out.println("1 UP");
} }
} }

View File

@ -0,0 +1,17 @@
package de.teamteamteam.spacescooter.entity.item;
import de.teamteamteam.spacescooter.entity.Player;
public class ItemRocket extends Item {
public ItemRocket(int x, int y) {
super(x, y);
this.setImage("images/items/itemRocket.png");
}
@Override
public void itemCollected(Player player) {
player.addRocketAmount();
}
}

View File

@ -4,8 +4,6 @@ import de.teamteamteam.spacescooter.entity.Player;
public class ItemShield extends Item { public class ItemShield extends Item {
public static int chance = 4;
public ItemShield(int x, int y) { public ItemShield(int x, int y) {
super(x, y); super(x, y);
this.setImage("images/items/itemShield.png"); this.setImage("images/items/itemShield.png");

View File

@ -0,0 +1,20 @@
package de.teamteamteam.spacescooter.entity.shot;
import de.teamteamteam.spacescooter.entity.spi.Collidable;
public class Rocket extends Shot{
public Rocket(int x, int y, int shootDirection, int shootSpeed, int damageValue, String filename) {
super(x, y, shootDirection, shootSpeed, damageValue, filename);
setImage("images/shots/rocket.png");
}
/**
* If the rocket collide with an enemy, the rocket create a big damage range
*/
@Override
public void collideWith(Collidable entity) {
new RocketExplosionRange(this.getX(), this.getY(), this.getDirection(), this.getSpeed(), this.getDamageValue(), "images/shots/rocket_explosion.png");
super.collideWith(entity);
}
}

View File

@ -0,0 +1,26 @@
package de.teamteamteam.spacescooter.entity.shot;
import de.teamteamteam.spacescooter.entity.spi.Collidable;
public class RocketExplosionRange extends Shot{
int i = 0;
public RocketExplosionRange(int x, int y, int shootDirection, int shootSpeed, int damageValue, String filename) {
super(x, y, shootDirection, shootSpeed, damageValue, filename);
}
/**
* Lifetime of the rocket explosion range.
*/
public void update() {
i++;
if(i>10){
this.remove();
}
}
@Override
public void collideWith(Collidable entity) {
}
}

View File

@ -76,6 +76,13 @@ public class Shot extends CollidableEntity {
this.damageValue = dmg; this.damageValue = dmg;
} }
/**
* Returns the shot speed.
*/
public int getSpeed(){
return speed;
}
/** /**
* Make the shot travel in the right direction. * Make the shot travel in the right direction.
* Remove the shot once out of the visible area. * Remove the shot once out of the visible area.

View File

@ -8,7 +8,7 @@ public class Credits {
/** /**
* Credit points for the shop * Credit points for the shop
*/ */
private static int credits = 1000; private static int credits = 0;
/** /**

View File

@ -26,6 +26,9 @@ import de.teamteamteam.spacescooter.utility.CollisionHandler;
*/ */
public class GameScreen extends Screen { public class GameScreen extends Screen {
/**
* Road points for EnemyFour
*/
private ArrayList<Point> points = new ArrayList<Point>(); private ArrayList<Point> points = new ArrayList<Point>();
private static Player player; private static Player player;