Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
I added a ton of stuff including collision(right now lasers kill stuff
and continue on), movement, shooting, enemies spawning in randomly and moving to the left with random speeds, background, I created some interfaces. Right now the game is an actual "game" but you can't lose. There is not yet a menu
- Loading branch information
Showing
11 changed files
with
303 additions
and
47 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package entity; | ||
|
||
import java.awt.Graphics; | ||
import java.awt.Rectangle; | ||
|
||
public interface EntityTypeA { | ||
|
||
public void tick(); | ||
public void render(Graphics g); | ||
public Rectangle getBounds(); | ||
public double getX(); | ||
public double getY(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package entity; | ||
|
||
import java.awt.Graphics; | ||
import java.awt.Rectangle; | ||
|
||
public interface EntityTypeB { | ||
|
||
public void tick(); | ||
public void render(Graphics g); | ||
public Rectangle getBounds(); | ||
|
||
public double getX(); | ||
public double getY(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package main; | ||
|
||
import java.awt.Graphics; | ||
import java.awt.Rectangle; | ||
import java.util.Random; | ||
|
||
import entity.EntityTypeB; | ||
|
||
public class EnemyFighter extends GameObject implements EntityTypeB{ | ||
private Skins skin; | ||
|
||
Random r = new Random(); | ||
private Game game; | ||
private Controller controller; | ||
private int speed = r.nextInt(3)+1; | ||
|
||
public EnemyFighter(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; | ||
if(GamePhysics.Collision(this, game.ea)){ | ||
controller.removeEntity(this); | ||
|
||
game.setKills(game.getKills()+1); | ||
} | ||
} | ||
public void render(Graphics g){ | ||
g.drawImage(skin.enemy1, (int)x, (int)y, null); | ||
} | ||
public double getY() { | ||
return y; | ||
} | ||
public Rectangle getBounds(){ | ||
return new Rectangle((int)x, (int) y, 64, 64); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package main; | ||
|
||
import java.awt.Rectangle; | ||
|
||
public class GameObject { | ||
public double x; | ||
public double y; | ||
public GameObject(double x, double y){ | ||
this.x = x; | ||
this.y = y; | ||
|
||
} | ||
|
||
public Rectangle getBounds(int width, int height){ | ||
return new Rectangle((int)x, (int) y, width, height); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package main; | ||
|
||
import java.util.LinkedList; | ||
|
||
import entity.EntityTypeA; | ||
import entity.EntityTypeB; | ||
|
||
public class GamePhysics { | ||
public static boolean Collision(EntityTypeA enta, LinkedList<EntityTypeB> bb){ | ||
for(int n = 0; n <bb.size(); n++ ){ | ||
if(enta.getBounds().intersects(bb.get(n).getBounds())){ | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
public static boolean Collision(EntityTypeB entb, LinkedList<EntityTypeA> aa){ | ||
for(int n = 0; n <aa.size(); n++ ){ | ||
if(entb.getBounds().intersects(aa.get(n).getBounds())){ | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
Oops, something went wrong.