Skip to content
Permalink
Browse files

Fixed the errors and tweaked the spawning system, hopefully it should

work better now
  • Loading branch information
jdm13003 committed Apr 20, 2016
1 parent 4ad74b6 commit 3e1e64ee74750d08b7397a39ee82064bafc37060
@@ -34,6 +34,11 @@ public void createEnemy(int enemy_count){

}
}
public void createSD(int SDcount){
for(int n = 0; n < SDcount; n++){
addEntity(new StarDestroyer(810, r.nextInt(400), skin, this, game));
}
}
public void createStarDestroyer(int SDcount){
for(int i = 0; i < SDcount; i++){
addEntity(new StarDestroyer(810, r.nextInt(400), skin, this, game));
@@ -14,6 +14,7 @@
private Game game;
private Controller controller;
private double speed = 0.3 + 3 * r.nextDouble() ;
public double is_shooting = r.nextInt(60);

public EnemyFighter(double x, double y, Skins skin, Controller c, Game game){
super(x,y);
@@ -24,9 +25,23 @@ public EnemyFighter(double x, double y, Skins skin, Controller c, Game game){
public double getX(){
return x;
}
public void shoot(){
if(is_shooting == 0){
controller.addEntity(new EnemyLaser(x, y, skin, game));
is_shooting++;
}
else if(is_shooting == 190){
is_shooting = 0;
}
else{
is_shooting++;
}
}


public void tick(){
x -= speed;
shoot();
for(int n = 0; n < game.ea.size(); n++){
EntityTypeA tempa = game.ea.get(n);
if(GamePhysics.Collision(this, tempa)){
@@ -71,16 +71,17 @@ public void init()
}
addKeyListener(new KeyboardInput(this));
tp = new Skins(this);
p = new Player(200, 200, tp, this);
c = new Controller(tp, this);

if(numberOfPlayers == 2){
p2 = new Player2(300, 300, tp, this);
p2 = new Player2(300, 300, tp, this, c);
}
c = new Controller(tp, this);
p = new Player(200, 200, tp, this, c);

ea = c.getEntityA();
eb = c.getEntityB();
ec = c.getEntityC();
ed = c.getEntityD();
c.createStarDestroyer(1);
c.createEnemy(enemy_count);
}

@@ -164,10 +165,17 @@ private void tick() {
p2.tick();
}
if(kills >= enemy_count){
if (enemy_count == 10){
c.createSD(SDcount);
enemy_count = 2;
SDcount++;
c.createEnemy(enemy_count);
}
enemy_count +=1;
kills = 0;
c.createEnemy(enemy_count);
}

}
private void render(){
BufferStrategy bufferstrat = this.getBufferStrategy();
@@ -193,14 +201,14 @@ private void render(){
public void keyPressed(KeyEvent e){
int key = e.getKeyCode();
if(key == KeyEvent.VK_RIGHT){
p.setVelX(5);
p.setVelX(6);

} else if(key == KeyEvent.VK_LEFT){
p.setVelX(-5);
p.setVelX(-6);
} else if(key == KeyEvent.VK_DOWN){
p.setVelY(5);
p.setVelY(6);
} else if(key == KeyEvent.VK_UP){
p.setVelY(-5);
p.setVelY(-6);
} else if(key == KeyEvent.VK_L ){
if(is_shooting == 3){
is_shooting = 0;
@@ -209,15 +217,15 @@ public void keyPressed(KeyEvent e){
c.addEntity(new Laser(p.getX(),p.getY(), tp, this));}
is_shooting++;
} else if(key == KeyEvent.VK_A){
p2.setVelX(-5);
p2.setVelX(-4);
} else if(key == KeyEvent.VK_D){
p2.setVelX(5);
p2.setVelX(4);
}else if(key == KeyEvent.VK_S){
p2.setVelY(5);
p2.setVelY(4);
}else if(key == KeyEvent.VK_W){
p2.setVelY(-5);
p2.setVelY(-4);
}else if(key == KeyEvent.VK_SPACE ){
if(is_shooting2 == 3){
if(is_shooting2 == 4){
is_shooting2 = 0;
}
if(is_shooting2 == 0){
@@ -1,10 +1,10 @@
package main;

import java.util.LinkedList;

import entity.EntityTypeA;
import entity.EntityTypeB;
import entity.EntityTypeC;
import entity.EntityTypeD;

public class GamePhysics {
public static boolean Collision(EntityTypeA enta, EntityTypeB bb){
@@ -31,4 +31,12 @@ public static boolean Collision(EntityTypeC entc, EntityTypeA aa){

return false;
}
public static boolean Collision(EntityTypeA entA, EntityTypeD dd){

if(entA.getBounds().intersects(dd.getBounds())){
return true;
}

return false;
}
}
@@ -3,26 +3,30 @@
import java.awt.Rectangle;

import entity.EntityTypeA;
import entity.EntityTypeD;

public class Player extends GameObject implements EntityTypeA{

private double velX = 0;
private double velY = 0;


private int health = 3;


private Skins skin;
private Game game;

public Player(double x, double y, Skins skin, Game game){
private Controller controller;

public Player(double x, double y, Skins skin, Game game, Controller controller){
super(x,y);
this.skin = skin;
this.game = game;
this.controller = controller;
}

public void tick(){
x += velX;
y += velY;

if (x <= 0 ){
x = 0;
}
@@ -35,9 +39,20 @@ public void tick(){
if (y >= 536){
y = 536;
}

for(int n = 0; n < game.ed.size(); n++){
EntityTypeD tempa = game.ed.get(n);
if(GamePhysics.Collision(this, tempa)){
if(health == 1){
controller.removeEntity(this);}
else{
health--;
controller.removeEntity(tempa);
}
}
}

}

public void render(Graphics g){
g.drawImage(skin.player, (int)x, (int)y, null);
}
@@ -52,7 +67,7 @@ public void setX(double x){
}
public void setY(double y){
this.y = y;

}
public void setVelX(double velX){
this.velX = velX;
@@ -3,6 +3,7 @@
import java.awt.Rectangle;

import entity.EntityTypeA;
import entity.EntityTypeD;

public class Player2 extends GameObject implements EntityTypeA{

@@ -12,11 +13,14 @@

private Skins skin;
private Game game;
private Controller controller;
private int health = 4;

public Player2(double x, double y, Skins skin, Game game){
public Player2(double x, double y, Skins skin, Game game, Controller controller){
super(x,y);
this.skin = skin;
this.game = game;
this.controller = controller;
}

public void tick(){
@@ -35,6 +39,17 @@ public void tick(){
if (y >= 536){
y = 536;
}
for(int n = 0; n < game.ed.size(); n++){
EntityTypeD tempa = game.ed.get(n);
if(GamePhysics.Collision(this, tempa)){
if(health == 1){
controller.removeEntity(this);}
else{
health--;
controller.removeEntity(tempa);
}
}
}

}

@@ -36,8 +36,8 @@ public void tick(){
if(GamePhysics.Collision(this, tempa)){
if(health ==1)
{controller.removeEntity(this);
game.setKills(game.getKills()+1);}
else{health--;}
}
else{health--;}
controller.removeEntity(tempa);
}
}
@@ -48,7 +48,7 @@ public void shoot(){
controller.addEntity(new EnemyLaser(x, y, skin, game));
is_shooting++;
}
else if(is_shooting == r.nextDouble()* 60 + 60){
else if(is_shooting == 100){
is_shooting = 0;
}
else{

0 comments on commit 3e1e64e

Please sign in to comment.
You can’t perform that action at this time.