Skip to content

Commit

Permalink
new background, fixed drop, player hp, monster bullet animation, several
Browse files Browse the repository at this point in the history
waves, waves counter, game end
  • Loading branch information
Totenfluch committed Apr 9, 2016
1 parent 5b3bda3 commit 1252d68
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 25 deletions.
Binary file modified Blockinvaders/res/background.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions Blockinvaders/src/me/game/pack/Drop.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ public void refresh(){
AllDrops.remove(this);
return;
}

for(int i = 0; i<Frame.Players.size(); i++){
Spieler Peter = Frame.Players.elementAt(i);
if(Peter.isDead())
break;
if(checkHit(Peter.getX(), Peter.getY(), Peter.getWidth(), Peter.getHeight())){
assign(Peter);
AllDrops.remove(this);
Expand Down
90 changes: 67 additions & 23 deletions Blockinvaders/src/me/game/pack/Frame.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ else if(i == 3)
for(int i = 0; i<Monsters.length; i++){
Monster Monti = Monsters[i];
if(Monti.isAlive()){
gc.setFill(Color.BROWN);
gc.setFill(Monti.getColor());
gc.fillRect(Monti.getPosX(), Monti.getPosY(), Monti.getWidth(), Monti.getLength());
if(Monti.getLeben() != Monti.getInitHp()){
double fragleben = (double)Monti.getLeben()/(double)Monti.getInitHp();
Expand All @@ -165,7 +165,12 @@ else if(i == 3)
}else{
gc.setFill(Color.RED);
}
gc.fillRect(Monti.getPosX()+Monti.getWidth()/10, Monti.getPosY()+Monti.getLength()/3, Monti.getWidth()*fragleben-Monti.getWidth()/10, Monti.getLength()-Monti.getLength()*0.8);
gc.fillRect(Monti.getPosX()+Monti.getWidth()/10, Monti.getPosY()+Monti.getLength()/2.5, Monti.getWidth()*fragleben-Monti.getWidth()/10, Monti.getLength()-Monti.getLength()*0.8);
}

Random r = new Random();
if(r.nextInt(1600-clearcount*50) == 1){
Monti.getWaffe().shoot(Monti.getPosX(), Monti.getPosY());
}
alives++;
}
Expand All @@ -176,6 +181,7 @@ else if(i == 3)
Monster Monti = Monsters[i];
Monti.setInitHp(Monster_HP+20*clearcount);
Monti.setLeben(Monster_HP+20*clearcount);
Monti.setWorth(Monti.getWorth()+1);
}
}

Expand All @@ -187,7 +193,10 @@ else if(i == 3)
StringBuffer sb = new StringBuffer();
for(int i = 0; i<Players.elementAt(0).getLeben(); i++)
sb.append("+ ");
gc.fillText(sb.toString(), 45, 75);
if(!Players.elementAt(0).isDead())
gc.fillText(sb.toString(), 45, 75);
else
gc.fillText("DEAD", 45, 80);

if(Players.size() > 1){
gc.setFont(new Font("Impact", 30));
Expand All @@ -197,7 +206,10 @@ else if(i == 3)
StringBuffer sb2 = new StringBuffer();
for(int i = 0; i<Players.elementAt(1).getLeben(); i++)
sb2.append("+ ");
gc.fillText(sb2.toString(), 45, 850);
if(!Players.elementAt(1).isDead())
gc.fillText(sb2.toString(), 45, 850);
else
gc.fillText("DEAD", 45, 855);
}


Expand All @@ -207,14 +219,22 @@ else if(i == 3)
gc.fillRect(draw.xPos, draw.yPos, draw.width, draw.height);
}
}

for(int i = 0; i<MonsterWaffe.ActiveWeapons.size(); i++){
for(int x = 0; x<MonsterWaffe.ActiveWeapons.elementAt(i).kugeln.size(); x++){
MonsterKugel draw = MonsterWaffe.ActiveWeapons.elementAt(i).kugeln.elementAt(x);
gc.fillRect(draw.xPos, draw.yPos, draw.width, draw.height);
}
}

gc.setFill(Color.GOLD);
for(int i = 0; i<Drop.AllDrops.size(); i++){
Drop p = Drop.AllDrops.elementAt(i);
gc.fillRect(p.xPos, p.yPos, Drop.DropSizeX, Drop.DropSizeY);
}



gc.setFont(new Font("Impact", 20));
gc.fillText("Wave: " + (clearcount+1), GAME_WIDTH/2-30, 40);
}
}));

Expand Down Expand Up @@ -281,7 +301,8 @@ public static void switchSceneToGame(){
if(x%2 == 0)
sub = 50;

Monsters[i] = new Monster(Monster_HP, sub+600+ix*50, x*100, 30, 20, 1);
Monsters[i] = new Monster(null, Monster_HP, sub+600+ix*50, x*100, 30, 20, 1, Color.BROWN);
Monsters[i].giveWeapon(new MonsterStandardWaffe(Monsters[i]));
}
Players.add(P1);
if(Coop_enabled){
Expand Down Expand Up @@ -316,43 +337,66 @@ public static void Refresh(){
}

if(P1_inLeft){
Players.elementAt(0).moveLeft();
if(!Players.elementAt(0).isDead())
Players.elementAt(0).moveLeft();
}else if(P1_inRight){
Players.elementAt(0).moveRight();
if(!Players.elementAt(0).isDead())
Players.elementAt(0).moveRight();
}
if(P1_inShoot){
Players.elementAt(0).waffe.shoot(Players.elementAt(0).getX(), Players.elementAt(0).getY());
if(!Players.elementAt(0).isDead())
Players.elementAt(0).waffe.shoot(Players.elementAt(0).getX(), Players.elementAt(0).getY());
}

if(Coop_enabled){
if(P2_inLeft){
Players.elementAt(1).moveLeft();
if(!Players.elementAt(1).isDead())
Players.elementAt(1).moveLeft();
}else if(P2_inRight){
Players.elementAt(1).moveRight();
if(!Players.elementAt(1).isDead())
Players.elementAt(1).moveRight();
}
if(P2_inShoot){
Players.elementAt(1).waffe.shoot(Players.elementAt(1).getX(), Players.elementAt(1).getY());
if(!Players.elementAt(1).isDead())
Players.elementAt(1).waffe.shoot(Players.elementAt(1).getX(), Players.elementAt(1).getY());
}
}

for(int x =0;x<Players.size(); x++){
Players.elementAt(x).waffe.refresh();
}
for(int x = 0;x<Players.size(); x++){
if(!Players.elementAt(x).isDead())
Players.elementAt(x).waffe.refresh();
}

for(int i = 0; i<Waffen.ActiveWeapons.size(); i++){
for(int x = 0; x<Waffen.ActiveWeapons.elementAt(i).kugeln.size(); x++){
Kugel r = Waffen.ActiveWeapons.elementAt(i).kugeln.elementAt(x);
if(r.yPos <= 0 || r.yPos >= GAME_LENGTH || r.xPos <= 0 || r.xPos >= GAME_WIDTH)
Waffen.ActiveWeapons.elementAt(i).kugeln.remove(r);
}
Waffen.ActiveWeapons.elementAt(i).refresh();
}

for(int i = 0; i<Drop.AllDrops.size(); i++){
Drop p = Drop.AllDrops.elementAt(i);
p.refresh();
}


for(int i = 0; i<MonsterWaffe.ActiveWeapons.size(); i++){
MonsterWaffe.ActiveWeapons.elementAt(i).refresh();
}

int dead = 0;
for(int i = 0; i<Players.size(); i++){
if(Players.elementAt(i).isDead())
dead++;
if(dead == Players.size())
EndGame();
}
}

public static void EndGame(){
tf.stop();
gc.clearRect(0, 0, GAME_WIDTH, GAME_LENGTH);
gc.setFont(new Font("Futura", 140));
gc.setFill(Color.BLACK);
gc.fillRect(0, 0, GAME_WIDTH, GAME_LENGTH);
gc.setFill(Color.RED);
gc.fillText("You Lost", 500, GAME_LENGTH/2+200);
}

}
3 changes: 3 additions & 0 deletions Blockinvaders/src/me/game/pack/Kugel.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public int getDamage() {
}

public void refresh(){
if(yPos <= 0 || yPos >= Frame.GAME_LENGTH || xPos <= 0 || xPos >= Frame.GAME_WIDTH)
waffe.kugeln.remove(this);

for(int i = 0; i<Frame.Monsters.length; i++){
Monster Monti = Frame.Monsters[i];
if(checkHit(Monti.getPosX(), Monti.getPosY(), Monti.getWidth(), Monti.getLength())){
Expand Down
27 changes: 26 additions & 1 deletion Blockinvaders/src/me/game/pack/Monster.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Random;

import javafx.scene.paint.Color;
import me.game.pack.Drop.Drops;

import com.sun.javafx.geom.Rectangle;
Expand All @@ -15,8 +16,10 @@ public class Monster {
private int worth;
private boolean alive;
private int InitialHp;
private MonsterWaffe waffe;
private Color color;

public Monster(int Leben, double x, double y, double width, double length, int worth){
public Monster(MonsterWaffe waffe, int Leben, double x, double y, double width, double length, int worth, Color color){
this.Leben = Leben;
this.x = x;
this.y = y;
Expand All @@ -25,6 +28,28 @@ public Monster(int Leben, double x, double y, double width, double length, int w
this.worth = worth;
alive = true;
InitialHp = Leben;
this.waffe = waffe;
this.color = color;
}

public void setColor(Color c){
this.color = c;
}

public Color getColor(){
return color;
}

public void setWorth(int amount){
worth = amount;
}

public MonsterWaffe getWaffe(){
return waffe;
}

public void giveWeapon(MonsterWaffe waffe){
this.waffe = waffe;
}

public int getInitHp(){
Expand Down
9 changes: 8 additions & 1 deletion Blockinvaders/src/me/game/pack/MonsterKugel.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.game.pack;

import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;

public class MonsterKugel {
Expand Down Expand Up @@ -47,18 +48,24 @@ public int getDamage() {
}

public void refresh(){
if(yPos <= 0 || yPos >= Frame.GAME_LENGTH || xPos <= 0 || xPos >= Frame.GAME_WIDTH)
waffe.kugeln.remove(this);

for(int x =0;x<Frame.Players.size(); x++){
Spieler p = Frame.Players.elementAt(x);
if(checkHit(p.getX(), p.getY(), p.getWidth(), p.getHeight())){
if(!p.isDead()){
waffe.kugeln.remove(this);
p.removeLeben();
waffe.Besitzer.setInitHp(waffe.Besitzer.getInitHp()+300);
waffe.Besitzer.setLeben(waffe.Besitzer.getInitHp());
waffe.Besitzer.setColor(Color.DARKMAGENTA);
}
}
}

xPos += dx;
yPos -= dy;
yPos += dy;
}

public boolean checkHit(double ox, double oy, double owidth, double olength){
Expand Down

0 comments on commit 1252d68

Please sign in to comment.