Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added shooting star destroyers
  • Loading branch information
jdm13003 committed Apr 20, 2016
1 parent c961da2 commit 4ad74b6
Show file tree
Hide file tree
Showing 12 changed files with 222 additions and 21 deletions.
Binary file modified resources/sprite_sheet.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions src/entity/EntityTypeC.java
@@ -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();
}
13 changes: 13 additions & 0 deletions src/entity/EntityTypeD.java
@@ -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();
}
51 changes: 51 additions & 0 deletions src/main/Controller.java
Expand Up @@ -6,13 +6,20 @@ import java.util.Random;


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;
Expand All @@ -27,6 +34,12 @@ public class Controller {


} }
} }
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++){
Expand All @@ -39,6 +52,16 @@ public class Controller {


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++){
Expand All @@ -51,6 +74,16 @@ public class Controller {


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);
Expand All @@ -70,6 +103,24 @@ public class Controller {
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;
}


} }


14 changes: 9 additions & 5 deletions src/main/EnemyFighter.java
Expand Up @@ -4,6 +4,7 @@ import java.awt.Graphics;
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{
Expand All @@ -12,7 +13,7 @@ public class EnemyFighter extends GameObject implements EntityTypeB{
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);
Expand All @@ -26,10 +27,13 @@ public class EnemyFighter extends GameObject implements EntityTypeB{


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){
Expand Down
34 changes: 34 additions & 0 deletions src/main/EnemyLaser.java
@@ -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);
}

}
9 changes: 9 additions & 0 deletions src/main/Game.java
Expand Up @@ -15,6 +15,8 @@ import javax.swing.JFrame;


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{


Expand All @@ -36,8 +38,12 @@ public class Game extends Canvas implements Runnable{


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();


Expand Down Expand Up @@ -72,6 +78,9 @@ public class Game extends Canvas implements Runnable{
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);
} }


Expand Down
27 changes: 18 additions & 9 deletions src/main/GamePhysics.java
Expand Up @@ -4,22 +4,31 @@ import java.util.LinkedList;


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;
} }
} }
4 changes: 1 addition & 3 deletions src/main/Player.java
Expand Up @@ -35,9 +35,7 @@ public class Player extends GameObject implements EntityTypeA{
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){
Expand Down
4 changes: 1 addition & 3 deletions src/main/Player2.java
Expand Up @@ -35,9 +35,7 @@ public class Player2 extends GameObject implements EntityTypeA{
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){
Expand Down
7 changes: 6 additions & 1 deletion src/main/Skins.java
Expand Up @@ -11,8 +11,10 @@ public class Skins {
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;
Expand All @@ -29,11 +31,14 @@ public class Skins {
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);
} }
} }


Expand Down
67 changes: 67 additions & 0 deletions src/main/StarDestroyer.java
@@ -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.