Skip to content
Permalink
Browse files

Added shooting star destroyers

  • Loading branch information
jdm13003 committed Apr 20, 2016
1 parent c961da2 commit 4ad74b61e88a0e17d8194e9b59fce15103596d99
BIN +9.1 KB (120%) resources/sprite_sheet.png
Binary file not shown.
@@ -0,0 +1,13 @@
package entity;

import java.awt.Graphics;
import java.awt.Rectangle;
//used for Star Destroyer
public interface EntityTypeC {

public void tick();
public void render(Graphics g);
public Rectangle getBounds();
public double getX();
public double getY();
}
@@ -0,0 +1,13 @@
package entity;

import java.awt.Graphics;
import java.awt.Rectangle;

public interface EntityTypeD {

public void tick();
public void render(Graphics g);
public Rectangle getBounds();
public double getX();
public double getY();
}
@@ -6,13 +6,20 @@


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


public class Controller { public class Controller {
private LinkedList<EntityTypeA> ea = new LinkedList<EntityTypeA>(); private LinkedList<EntityTypeA> ea = new LinkedList<EntityTypeA>();
private LinkedList<EntityTypeB> eb = new LinkedList<EntityTypeB>(); private LinkedList<EntityTypeB> eb = new LinkedList<EntityTypeB>();
private LinkedList<EntityTypeC> ec = new LinkedList<EntityTypeC>();
private LinkedList<EntityTypeD> ed = new LinkedList<EntityTypeD>();



EntityTypeA tempea; EntityTypeA tempea;
EntityTypeB tempeb; EntityTypeB tempeb;
EntityTypeC tempec;
EntityTypeD temped;
Random r = new Random(); Random r = new Random();
private Skins skin; private Skins skin;
private Game game; private Game game;
@@ -27,6 +34,12 @@ public void createEnemy(int enemy_count){


} }
} }
public void createStarDestroyer(int SDcount){
for(int i = 0; i < SDcount; i++){
addEntity(new StarDestroyer(810, r.nextInt(400), skin, this, game));

}
}


public void tick(){ public void tick(){
for(int n = 0; n < ea.size(); n++){ for(int n = 0; n < ea.size(); n++){
@@ -39,6 +52,16 @@ public void tick(){


tempeb.tick(); tempeb.tick();
} }
for(int n = 0; n < ec.size(); n++){
tempec = ec.get(n);

tempec.tick();
}
for(int n = 0; n < ed.size(); n++){
temped = ed.get(n);

temped.tick();
}
} }
public void render(Graphics g){ public void render(Graphics g){
for(int n = 0; n < ea.size(); n++){ for(int n = 0; n < ea.size(); n++){
@@ -51,6 +74,16 @@ public void render(Graphics g){


tempeb.render(g); tempeb.render(g);
} }
for(int n = 0; n < ec.size(); n++){
tempec = ec.get(n);

tempec.render(g);
}
for(int n = 0; n < ed.size(); n++){
temped = ed.get(n);

temped.render(g);
}
} }
public void addEntity(EntityTypeA en){ public void addEntity(EntityTypeA en){
ea.add(en); ea.add(en);
@@ -70,6 +103,24 @@ public void removeEntity(EntityTypeB en){
public LinkedList<EntityTypeB> getEntityB(){ public LinkedList<EntityTypeB> getEntityB(){
return eb; return eb;
} }
public void addEntity(EntityTypeC en){
ec.add(en);
}
public void removeEntity(EntityTypeC en){
ec.remove(en);
}
public LinkedList<EntityTypeC> getEntityC(){
return ec;
}
public void addEntity(EntityTypeD en){
ed.add(en);
}
public void removeEntity(EntityTypeD en){
ed.remove(en);
}
public LinkedList<EntityTypeD> getEntityD(){
return ed;
}


} }


@@ -4,6 +4,7 @@
import java.awt.Rectangle; import java.awt.Rectangle;
import java.util.Random; import java.util.Random;


import entity.EntityTypeA;
import entity.EntityTypeB; import entity.EntityTypeB;


public class EnemyFighter extends GameObject implements EntityTypeB{ public class EnemyFighter extends GameObject implements EntityTypeB{
@@ -12,7 +13,7 @@
Random r = new Random(); Random r = new Random();
private Game game; private Game game;
private Controller controller; private Controller controller;
private int speed = r.nextInt(3)+1; private double speed = 0.3 + 3 * r.nextDouble() ;


public EnemyFighter(double x, double y, Skins skin, Controller c, Game game){ public EnemyFighter(double x, double y, Skins skin, Controller c, Game game){
super(x,y); super(x,y);
@@ -26,10 +27,13 @@ public double getX(){


public void tick(){ public void tick(){
x -= speed; x -= speed;
if(GamePhysics.Collision(this, game.ea)){ for(int n = 0; n < game.ea.size(); n++){
controller.removeEntity(this); EntityTypeA tempa = game.ea.get(n);

if(GamePhysics.Collision(this, tempa)){
game.setKills(game.getKills()+1); controller.removeEntity(this);
controller.removeEntity(tempa);
game.setKills(game.getKills()+1);
}
} }
} }
public void render(Graphics g){ public void render(Graphics g){
@@ -0,0 +1,34 @@
package main;

import java.awt.Graphics;
import java.awt.Rectangle;

import entity.EntityTypeD;

public class EnemyLaser extends GameObject implements EntityTypeD{

private Skins skin;
public EnemyLaser(double x, double y, Skins skin, Game game){
super(x,y);
this.skin = skin;

}

public void tick(){
x-=4;
}
public void render(Graphics g){
g.drawImage(skin.enemyLaser, (int)x, (int)y, null);
}
public double getX(){
return x;
}

public double getY() {
return y;
}
public Rectangle getBounds(){
return new Rectangle((int)x, (int) y, 64, 64);
}

}
@@ -15,6 +15,8 @@


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


public class Game extends Canvas implements Runnable{ public class Game extends Canvas implements Runnable{


@@ -36,8 +38,12 @@


private int enemy_count = 1; private int enemy_count = 1;
private int kills = 0; private int kills = 0;
private int SDcount = 0;
public LinkedList<EntityTypeA> ea; public LinkedList<EntityTypeA> ea;
public LinkedList<EntityTypeB> eb; public LinkedList<EntityTypeB> eb;
public LinkedList<EntityTypeC> ec;
public LinkedList<EntityTypeD> ed;



Random r = new Random(); Random r = new Random();


@@ -72,6 +78,9 @@ public void init()
c = new Controller(tp, this); c = new Controller(tp, this);
ea = c.getEntityA(); ea = c.getEntityA();
eb = c.getEntityB(); eb = c.getEntityB();
ec = c.getEntityC();
ed = c.getEntityD();
c.createStarDestroyer(1);
c.createEnemy(enemy_count); c.createEnemy(enemy_count);
} }


@@ -4,22 +4,31 @@


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


public class GamePhysics { public class GamePhysics {
public static boolean Collision(EntityTypeA enta, LinkedList<EntityTypeB> bb){ public static boolean Collision(EntityTypeA enta, EntityTypeB bb){
for(int n = 0; n <bb.size(); n++ ){
if(enta.getBounds().intersects(bb.get(n).getBounds())){ if(enta.getBounds().intersects(bb.getBounds())){
return true; return true;
} }

return false;
}
public static boolean Collision(EntityTypeB entb, EntityTypeA aa){
if(entb.getBounds().intersects(aa.getBounds())){

return true;

} }
return false; return false;
} }
public static boolean Collision(EntityTypeB entb, LinkedList<EntityTypeA> aa){ public static boolean Collision(EntityTypeC entc, EntityTypeA aa){
for(int n = 0; n <aa.size(); n++ ){
if(entb.getBounds().intersects(aa.get(n).getBounds())){ if(entc.getBounds().intersects(aa.getBounds())){
return true; return true;
} }
}
return false; return false;
} }
} }
@@ -35,9 +35,7 @@ public void tick(){
if (y >= 536){ if (y >= 536){
y = 536; y = 536;
} }
if(GamePhysics.Collision(this, game.eb)){
System.out.println("LOSE");
}
} }


public void render(Graphics g){ public void render(Graphics g){
@@ -35,9 +35,7 @@ public void tick(){
if (y >= 536){ if (y >= 536){
y = 536; y = 536;
} }
if(GamePhysics.Collision(this, game.eb)){
System.out.println("LOSE");
}
} }


public void render(Graphics g){ public void render(Graphics g){
@@ -11,8 +11,10 @@
public BufferedImage player; public BufferedImage player;
public BufferedImage laser; public BufferedImage laser;
public BufferedImage enemy1; public BufferedImage enemy1;
public BufferedImage padraic; public BufferedImage starDestroyer;
public BufferedImage player2; public BufferedImage player2;
public BufferedImage enemyLaser;

Game game; Game game;


private SpriteSheet ss = null; private SpriteSheet ss = null;
@@ -29,11 +31,14 @@ private void getTextures(){
laser = ss.grabimage(3, 2, 64, 64); laser = ss.grabimage(3, 2, 64, 64);
enemy1 = ss.grabimage(1, 3, 64, 64); enemy1 = ss.grabimage(1, 3, 64, 64);
player2 = ss.grabimage(2, 2, 64, 64); player2 = ss.grabimage(2, 2, 64, 64);
enemyLaser = ss.grabimage(3, 2, 64, 64);
}else{ }else{
player = ss.grabimage(playerx, playery, 64, 64); player = ss.grabimage(playerx, playery, 64, 64);
laser = ss.grabimage(2, 3, 64, 64); laser = ss.grabimage(2, 3, 64, 64);
enemy1 = ss.grabimage(2, 1, 64, 64); enemy1 = ss.grabimage(2, 1, 64, 64);
player2 = ss.grabimage(3, 1, 64, 64); player2 = ss.grabimage(3, 1, 64, 64);
starDestroyer = ss.grabimage(3, 3, 128, 128);
enemyLaser = ss.grabimage(1, 4, 64, 64);
} }
} }


@@ -0,0 +1,67 @@
package main;

import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.Random;

import entity.EntityTypeA;
import entity.EntityTypeC;

public class StarDestroyer extends GameObject implements EntityTypeC{

private Skins skin;
private Game game;
private Controller controller;
private double speed = 0.3;
private int health = 10;
private int is_shooting = 0;
Random r = new Random();

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

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)){
if(health ==1)
{controller.removeEntity(this);
game.setKills(game.getKills()+1);}
else{health--;}
controller.removeEntity(tempa);
}
}

}
public void shoot(){
if(is_shooting == 0){
controller.addEntity(new EnemyLaser(x, y, skin, game));
is_shooting++;
}
else if(is_shooting == r.nextDouble()* 60 + 60){
is_shooting = 0;
}
else{
is_shooting++;
}
}
public void render(Graphics g){
g.drawImage(skin.starDestroyer, (int)x, (int)y, null);
}
public double getY() {
return y;
}
public Rectangle getBounds(){
return new Rectangle((int)x, (int) y, 64, 64);
}
}

0 comments on commit 4ad74b6

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