Add rocket (fire button: y), add ItemRocket (increase rocket amount), add some comments
This commit is contained in:
parent
841875c09c
commit
7437a5c18d
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
After Width: | Height: | Size: 307 B |
Binary file not shown.
After Width: | Height: | Size: 373 B |
|
@ -15,6 +15,7 @@ public class Player extends ShootingEntity implements KeyboardListener {
|
|||
private Keyboard keyboard = null;
|
||||
private double healthPercent = 0;
|
||||
private double shieldPercent = 0;
|
||||
private int rocketAmount = 1;
|
||||
|
||||
public Player(int x, int y) {
|
||||
super(x, y);
|
||||
|
@ -62,6 +63,11 @@ public class Player extends ShootingEntity implements KeyboardListener {
|
|||
if(Keyboard.isKeyDown(KeyEvent.VK_SPACE)) {
|
||||
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--;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package de.teamteamteam.spacescooter.entity;
|
||||
|
||||
import de.teamteamteam.spacescooter.entity.shot.Rocket;
|
||||
import de.teamteamteam.spacescooter.entity.shot.Shot;
|
||||
import de.teamteamteam.spacescooter.screen.GameScreen;
|
||||
|
||||
/**
|
||||
* The ShootingEntity is a LivingEntity that is able to fire Shots.
|
||||
|
@ -26,6 +28,12 @@ public abstract class ShootingEntity extends LivingEntity {
|
|||
*/
|
||||
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
|
||||
* right position relative to the ShootingEntity.
|
||||
|
@ -74,6 +82,7 @@ public abstract class ShootingEntity extends LivingEntity {
|
|||
*/
|
||||
public void update() {
|
||||
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.
|
||||
|
@ -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!!!
|
||||
*/
|
||||
|
@ -190,4 +220,5 @@ public abstract class ShootingEntity extends LivingEntity {
|
|||
filename
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,8 +30,17 @@ public abstract class Item extends CollidableEntity {
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Item property.
|
||||
* What happens when item is collected.
|
||||
*/
|
||||
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){
|
||||
int auswahl = ItemChance.choose();
|
||||
switch (auswahl) {
|
||||
|
@ -48,7 +57,7 @@ public abstract class Item extends CollidableEntity {
|
|||
new ItemShield(x, y);
|
||||
break;
|
||||
case 4:
|
||||
new TestItem1(x, y);
|
||||
new ItemRocket(x, y);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,12 +7,21 @@ public class ItemChance {
|
|||
private static int summe = 0;
|
||||
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() {
|
||||
ItemChance.items = new int[4];
|
||||
items[0] = 4;
|
||||
items[1] = 3;
|
||||
items[2] = 2;
|
||||
items[3] = 1;
|
||||
ItemChance.items = new int[6];
|
||||
items[0] = 1; //ItemNuke
|
||||
items[2] = 2; //ItemHeal
|
||||
items[3] = 2; //ItemShield
|
||||
items[4] = 2; //ItemRocket
|
||||
items[1] = 4; //ItemCredit
|
||||
items[5] = 3; //ItemIncreaseDamage
|
||||
|
||||
for(int i=0; i<ItemChance.items.length; i++) {
|
||||
ItemChance.summe += ItemChance.items[i];
|
||||
|
@ -20,7 +29,6 @@ public class ItemChance {
|
|||
}
|
||||
|
||||
public static int choose() {
|
||||
//dauerhaft
|
||||
int r = Random.nextInt(ItemChance.summe - 1) + 1;
|
||||
|
||||
for(int i=0; i<ItemChance.items.length; i++) {
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
package de.teamteamteam.spacescooter.entity.item;
|
||||
|
||||
import de.teamteamteam.spacescooter.entity.Player;
|
||||
import de.teamteamteam.spacescooter.gui.Credits;
|
||||
|
||||
public class ItemCredit extends Item {
|
||||
|
||||
public static int chance = 2;
|
||||
|
||||
public ItemCredit(int x, int y) {
|
||||
super(x, y);
|
||||
this.setImage("images/items/itemCredit.png");
|
||||
|
@ -13,6 +12,6 @@ public class ItemCredit extends Item {
|
|||
|
||||
@Override
|
||||
public void itemCollected(Player player) {
|
||||
player.setShootDamage(player.getShootDamage()+5);
|
||||
Credits.add(10);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,6 @@ import de.teamteamteam.spacescooter.entity.Player;
|
|||
|
||||
public class ItemHeal extends Item {
|
||||
|
||||
public static int chance = 3;
|
||||
|
||||
public ItemHeal(int x, int y) {
|
||||
super(x, y);
|
||||
this.setImage("images/items/itemHeal.png");
|
||||
|
|
|
@ -2,10 +2,11 @@ package de.teamteamteam.spacescooter.entity.item;
|
|||
|
||||
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);
|
||||
//TODO: Chane Image
|
||||
this.setImage("images/items/item.png");
|
||||
}
|
||||
|
|
@ -4,8 +4,6 @@ import de.teamteamteam.spacescooter.entity.Player;
|
|||
|
||||
public class ItemNuke extends Item {
|
||||
|
||||
public static int chance = 2;
|
||||
|
||||
public ItemNuke(int x, int y) {
|
||||
super(x, y);
|
||||
this.setImage("images/items/itemNuke.png");
|
||||
|
|
|
@ -3,8 +3,6 @@ package de.teamteamteam.spacescooter.entity.item;
|
|||
import de.teamteamteam.spacescooter.entity.Player;
|
||||
|
||||
public class ItemOneUp extends Item {
|
||||
|
||||
public static int chance = 4;
|
||||
|
||||
public ItemOneUp(int x, int y) {
|
||||
super(x, y);
|
||||
|
@ -13,6 +11,6 @@ public static int chance = 4;
|
|||
|
||||
@Override
|
||||
public void itemCollected(Player player) {
|
||||
player.setShieldPoints(player.getShieldPoints() + 5);
|
||||
System.out.println("1 UP");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -4,8 +4,6 @@ import de.teamteamteam.spacescooter.entity.Player;
|
|||
|
||||
public class ItemShield extends Item {
|
||||
|
||||
public static int chance = 4;
|
||||
|
||||
public ItemShield(int x, int y) {
|
||||
super(x, y);
|
||||
this.setImage("images/items/itemShield.png");
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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) {
|
||||
}
|
||||
}
|
|
@ -76,6 +76,13 @@ public class Shot extends CollidableEntity {
|
|||
this.damageValue = dmg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the shot speed.
|
||||
*/
|
||||
public int getSpeed(){
|
||||
return speed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the shot travel in the right direction.
|
||||
* Remove the shot once out of the visible area.
|
||||
|
|
|
@ -8,7 +8,7 @@ public class Credits {
|
|||
/**
|
||||
* Credit points for the shop
|
||||
*/
|
||||
private static int credits = 1000;
|
||||
private static int credits = 0;
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,6 +26,9 @@ import de.teamteamteam.spacescooter.utility.CollisionHandler;
|
|||
*/
|
||||
public class GameScreen extends Screen {
|
||||
|
||||
/**
|
||||
* Road points for EnemyFour
|
||||
*/
|
||||
private ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
private static Player player;
|
||||
|
|
Loading…
Reference in New Issue