Itemchance, 4 Test Items und schuss speed

This commit is contained in:
Sosch 2014-11-04 13:34:17 +01:00
parent f67a2573a9
commit 9f7773ef5e
18 changed files with 171 additions and 14 deletions

BIN
res/images/Item.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 318 B

BIN
res/images/Item2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 308 B

BIN
res/images/Item3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 310 B

BIN
res/images/Item4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 310 B

View File

@ -52,9 +52,7 @@ public class EnemyFour extends Enemy{
nextPoint = points.get(index);
index++;
neuerVektor();
System.out.println("neuer point");
}catch(IndexOutOfBoundsException e){
System.out.println("ich bin dann mal weg!!");
this.remove();
}
}

View File

@ -11,15 +11,16 @@ public class EnemyThree extends Enemy{
private double newY;
private double ySpeed = 0.4;
private Random random;
public EnemyThree(int x, int y) {
super(x, y);
Random random = new Random();
random = new Random();
this.setImage("images/nyancat.png");
this.setShootSpeed(4);
this.setShootDelay(42);
this.setShootSpawn(-10, 10);
this.setHealthPoints(5);
this.setHealthPoints(15);
this.setPosition(GameConfig.windowWidth, random.nextInt(GameConfig.windowHeight - this.getHeight()));
this.newY = this.getY();
}
@ -33,6 +34,7 @@ public class EnemyThree extends Enemy{
Screen.currentScreen.addEntity(new EnemyThree(0, 0));
}
if(!this.isAlive()){
if(random.nextInt(10) < 5) Items.create(getX(), getY());
Screen.currentScreen.addEntity(new EnemyThree(0, 0));
}
LinkedList<Entity> list = Screen.currentScreen.getEntities();

View File

@ -0,0 +1,35 @@
package de.teamteamteam.spacescooter.entity;
import java.util.Random;
public class ItemChance {
private static int summe = 0;
private static int[] items;
public ItemChance() {
ItemChance.items = new int[4];
items[0] = 4;
items[1] = 3;
items[2] = 2;
items[3] = 1;
for(int i=0; i<ItemChance.items.length; i++) {
ItemChance.summe += ItemChance.items[i];
}
}
public static int choose() {
//dauerhaft
Random random = new Random();
int r = random.nextInt(ItemChance.summe - 1) + 1;
for(int i=0; i<ItemChance.items.length; i++) {
r -= ItemChance.items[i];
if(r <= 0) {
return i;
}
}
return -1;
}
}

View File

@ -0,0 +1,47 @@
package de.teamteamteam.spacescooter.entity;
import java.util.LinkedList;
import de.teamteamteam.spacescooter.screen.Screen;
public abstract class Items extends LivingEntity{
public Items(int x, int y) {
super(x, y);
this.setHealthPoints(1);
}
public void update(){
this.setPosition(getX()-1, getY());
if(this.getX() < 0-getWidth()){
this.remove();
};
if(!this.isAlive()){
LinkedList<Entity> entities = Screen.currentScreen.getEntities();
for (Entity e : entities) {
if(e instanceof Player){
itemCollected((Player) e);
}
}
}
}
public abstract void itemCollected(Player player);
public static void create(int x, int y){
int auswahl = ItemChance.choose();
switch (auswahl) {
case 0:
Screen.currentScreen.addEntity(new TestItem1(x, y));
break;
case 1:
Screen.currentScreen.addEntity(new TestItem2(x, y));
break;
case 2:
Screen.currentScreen.addEntity(new TestItem3(x, y));
break;
case 3:
Screen.currentScreen.addEntity(new TestItem4(x, y));;
break;
}
}
}

View File

@ -55,6 +55,11 @@ public abstract class LivingEntity extends Entity implements Collidable {
enemy.takeDamage(this.getCollisionDamage());
this.takeDamage(enemy.getCollisionDamage());
}
if(this instanceof Player && entity instanceof Items){
Items item = (Items) entity;
item.setHealthPoints(0);
item.remove();
}
}
public void setCollisionDamage(int d) {

View File

@ -9,13 +9,14 @@ public class Player extends ShootingEntity {
protected boolean shoot = false;
private boolean canMove = true;
public Player(int x, int y) {
super(x, y);
this.setImage("images/ship.png");
this.setShootDelay(5);
this.setShootSpawn(50, 16);
this.setShootDirection(Shot.RIGHT);
this.setShootSpeed(4);
this.setShootSpeed(10);
this.setHealthPoints(100);
}

View File

@ -9,6 +9,7 @@ public abstract class ShootingEntity extends LivingEntity {
private int shootSpawnX;
private int shootSpawnY;
private int shootDirection;
private int damageValue = 5;
private int shootSpeed;
public ShootingEntity(int x, int y) {
@ -23,7 +24,7 @@ public abstract class ShootingEntity extends LivingEntity {
protected void shoot() {
if(this.currentShootDelay == 0) {
Screen.currentScreen.addEntity(new SingleShot(this.x + this.shootSpawnX, this.y + this.shootSpawnY, this.shootDirection, this.shootSpeed));
Screen.currentScreen.addEntity(new SingleShot(this.x + this.shootSpawnX, this.y + this.shootSpawnY, this.shootDirection, this.shootSpeed, this.damageValue));
this.currentShootDelay = this.shootDelay;
}
}
@ -44,4 +45,12 @@ public abstract class ShootingEntity extends LivingEntity {
this.shootSpawnX = x;
this.shootSpawnY = y;
}
public void setDamageValue(int damageValue){
this.damageValue = damageValue;
}
public int getDamageValue(){
return this.damageValue;
}
}

View File

@ -13,11 +13,12 @@ public abstract class Shot extends LivingEntity {
private int speed;
private int direction;
public Shot(int x, int y, int shootDirection, int shootSpeed) {
public Shot(int x, int y, int shootDirection, int shootSpeed, int damageValue) {
super(x, y);
this.direction = shootDirection;
this.speed = shootSpeed;
this.collisionCount = 1;
this.damageValue = damageValue;
}
public void setImage(String filename) {

View File

@ -2,10 +2,8 @@ package de.teamteamteam.spacescooter.entity;
public class SingleShot extends Shot {
public SingleShot(int x, int y, int shootDirection, int shootSpeed) {
super(x, y, shootDirection, shootSpeed);
public SingleShot(int x, int y, int shootDirection, int shootSpeed, int damageValue) {
super(x, y, shootDirection, shootSpeed, damageValue);
this.setImage("images/shot.png");
this.setDamageValue(5);
}
}

View File

@ -0,0 +1,14 @@
package de.teamteamteam.spacescooter.entity;
public class TestItem1 extends Items{
public TestItem1(int x, int y) {
super(x, y);
this.setImage("images/Item.png");
}
@Override
public void itemCollected(Player player) {
player.setDamageValue(player.getDamageValue()+5);
}
}

View File

@ -0,0 +1,16 @@
package de.teamteamteam.spacescooter.entity;
public class TestItem2 extends Items{
public static int chance = 2;
public TestItem2(int x, int y) {
super(x, y);
this.setImage("images/Item2.png");
}
@Override
public void itemCollected(Player player) {
player.setDamageValue(player.getDamageValue()+5);
}
}

View File

@ -0,0 +1,16 @@
package de.teamteamteam.spacescooter.entity;
public class TestItem3 extends Items{
public static int chance = 3;
public TestItem3(int x, int y) {
super(x, y);
this.setImage("images/Item3.png");
}
@Override
public void itemCollected(Player player) {
player.setDamageValue(player.getDamageValue()+5);
}
}

View File

@ -0,0 +1,16 @@
package de.teamteamteam.spacescooter.entity;
public class TestItem4 extends Items{
public static int chance = 4;
public TestItem4(int x, int y) {
super(x, y);
this.setImage("images/Item4.png");
}
@Override
public void itemCollected(Player player) {
player.setDamageValue(player.getDamageValue()+5);
}
}

View File

@ -11,8 +11,8 @@ import de.teamteamteam.spacescooter.background.StarBackground;
import de.teamteamteam.spacescooter.control.Keyboard;
import de.teamteamteam.spacescooter.entity.EnemyFour;
import de.teamteamteam.spacescooter.entity.EnemyThree;
import de.teamteamteam.spacescooter.entity.EnemyTwo;
import de.teamteamteam.spacescooter.entity.Entity;
import de.teamteamteam.spacescooter.entity.ItemChance;
import de.teamteamteam.spacescooter.entity.Player;
public class GameScreen extends Screen {
@ -21,6 +21,7 @@ public class GameScreen extends Screen {
public GameScreen(Screen parent) {
super(parent);
new ItemChance();
points.add(new Point(300,300));
points.add(new Point(600,100));
points.add(new Point(0,500));
@ -29,8 +30,6 @@ public class GameScreen extends Screen {
this.entities.add(new EnemyFour(800, 400, points));
this.entities.add(new EnemyThree(650, 300));
this.entities.add(new EnemyThree(450, 100));
this.entities.add(new EnemyTwo(750, 550));
this.entities.add(new EnemyTwo(150, 250));
}
@Override