Permalink
Browse files

Merge pull request #8 from frekfra/master

added some menu functionality and two new weapons to enemies.
  • Loading branch information...
2 parents 5646657 + 1b89786 commit c4c85e2c73556f8db921da8116532bff4b32db59 @SubSage committed Jul 30, 2013
View
@@ -0,0 +1,4 @@
+1000,Thomas
+40000,Eddison
+10000,George
+5000,Micheal
@@ -10,7 +10,6 @@
private static final int SIZE_WIDTH = 9;
private static final int SIZE_HEIGHT = 5;
- private float damage;
private Vector2f velocity;
private Image bullet;
@@ -19,7 +18,7 @@ public Bullet(EntityManager manager, Vector2f position, int dmg, Entity.Alliance
super(manager);
pos.set(position);
size = new Vector2f(SIZE_WIDTH, SIZE_HEIGHT);
- damage = dmg;
+ collisionDamage = dmg;
velocity = new Vector2f(0, 0);
alliance = alnc;
@@ -101,9 +100,6 @@ else if(other instanceof Player)
}
}
- public float getDamage(){
- return damage;
- }
public Entity.Alliance getAlliance() {
@@ -29,6 +29,7 @@
private Vector2f startPos, pathVelocity;
private float fireRate;
private float fireRateDT;
+ private Gun shipGun;
private Random rand;
private EnemyGroup group;
@@ -37,6 +38,9 @@
protected AudioManager audioManager;
+ protected static Player player;
+
+
public Enemy(EntityManager manager, Vector2f position)
{
super(manager);
@@ -58,13 +62,18 @@ public Enemy(EntityManager manager, Vector2f position)
rand = new Random(System.currentTimeMillis());
fireRate = rand.nextInt(MAX_FIRE);
fireRateDT = 0;
-
+
try {
ship = new Image("Pics/Enemy.png");
} catch (SlickException e) {
e.printStackTrace();
}
+ Gun.GunType gunType = Gun.GunType.values()[rand.nextInt(Gun.MAX_GUN_TYPES)];
+ shipGun = new Gun(entities, 250, alliance, gunType);
+
+
+
audioManager = AudioManager.getAudioManager();
}
@@ -146,17 +155,15 @@ public void Collide(Entity other)
{
if(other instanceof Bullet && ((Bullet)other).getAlliance()!=alliance)
{
- Hurt(((Bullet)other).getDamage());
+ Hurt(((Entity)other).getCollisionDamage());
}
}
public void fire()
{
- Vector2f bulletPosition = new Vector2f((pos.x - size.x / 2) + 3, pos.y);
- Bullet newBullet = new Bullet(entities, bulletPosition, 1, alliance);
- newBullet.setSpeed(-250, 0);
- //audioManager.playSFX(AudioAsset.SFX_FIRE2);
+ Vector2f bulletPosition = new Vector2f((pos.x - size.x / 2) + 3, pos.y);
+ shipGun.shoot(bulletPosition, player);
}
@@ -24,6 +24,7 @@
protected Shape shape;
+ protected float collisionDamage;
public Entity(EntityManager manager)
{
@@ -33,11 +34,14 @@ public Entity(EntityManager manager)
dying = false;
alliance = Alliance.ENEMY;
pos = new Vector2f(0, 0);
+
+ collisionDamage = 1;
}
public Entity(int xpos, int ypos)
{
pos = new Vector2f(xpos, ypos);
+ collisionDamage = 1;
}
public Entity(int xpos, int ypos, float w, float h)
@@ -46,6 +50,7 @@ public Entity(int xpos, int ypos, float w, float h)
pos = new Vector2f(xpos, ypos);
size = new Vector2f(w, h);
+ collisionDamage = 1;
}
public Entity(Vector2f position, Vector2f size)
@@ -64,6 +69,10 @@ public void Destroy()
dying = true;
}
+ public float getCollisionDamage(){
+ return collisionDamage;
+ }
+
public Entity.Alliance getAlliance()
{
return alliance;
@@ -8,6 +8,10 @@
public class GDCalaga {
+ static final int SCREEN_SIZE_X = 1280;
+ static final int SCREEN_SIZE_Y = 720;
+
+
static {
String path = System.getProperties().get("java.library.path").toString();
@@ -41,7 +45,7 @@ else if (os.indexOf("linux") >= 0) {
public static void main(String[] argv) {
try {
AppGameContainer container = new AppGameContainer(new GDCalagaGame());
- container.setDisplayMode(1280, 720, false);
+ container.setDisplayMode(SCREEN_SIZE_X, SCREEN_SIZE_Y, false);
container.start();
} catch (SlickException e) {
e.printStackTrace();
@@ -0,0 +1,81 @@
+package org.gdc.gdcalaga;
+
+import org.newdawn.slick.geom.Vector2f;
+
+
+public class Gun {
+
+ public static int MAX_GUN_TYPES = 3; //fixme use enum max value correctly.
+
+
+ enum GunType {
+ StraightShot,
+ AimedShot,
+ TripleShot,
+ }
+
+ protected float velocity;
+ protected GunType gunType;
+ protected EntityManager entityManager;
+ protected Entity.Alliance alliance;
+
+ public Gun(EntityManager entityManager, float velocity, Entity.Alliance alliance, GunType gunType)
+ {
+ this.entityManager = entityManager;
+ this.velocity = velocity;
+ this.alliance = alliance;
+ this.gunType = gunType;
+
+ }
+
+ public void shoot(Vector2f bulletPosition, Player player)
+ {
+ switch(gunType)
+ {
+ case StraightShot:
+ straightShot(bulletPosition);
+ break;
+ case AimedShot:
+ aimedShot(bulletPosition, player);
+ break;
+ case TripleShot:
+ tripleShot(bulletPosition);
+ break;
+ default:
+ break;
+ }
+ }
+
+ private void straightShot(Vector2f bulletPosition) {
+ Bullet newBullet = new Bullet(entityManager, bulletPosition, 1, alliance);
+ newBullet.setSpeed(-250, 0);
+ }
+
+ private void aimedShot(Vector2f bulletPosition, Player player) {
+
+ Bullet newBullet = new Bullet(entityManager, bulletPosition, 1, alliance);
+
+ Vector2f directionOfPlayer = new Vector2f(player.getPosition());
+ directionOfPlayer.x -= bulletPosition.x;
+ directionOfPlayer.y += (-bulletPosition.y) + (Math.random() * 20) - 10;
+ directionOfPlayer.normalise();
+
+ newBullet.setSpeed(directionOfPlayer.x * 250,directionOfPlayer.y * 250);
+ }
+
+ private void tripleShot(Vector2f bulletPosition){
+
+ Bullet diagonalUpBullet = new Bullet(entityManager, bulletPosition, 1, alliance);
+ Vector2f diagonalUp = new Vector2f(-2,1);
+ diagonalUp.normalise();
+ diagonalUpBullet.setSpeed(diagonalUp.x * velocity, diagonalUp.y * velocity);
+
+ straightShot(bulletPosition);
+
+ Vector2f diagonalDown = new Vector2f(-2,-1);
+ diagonalDown.normalise();
+ Bullet diagonalDownBullet = new Bullet(entityManager, bulletPosition, 1, alliance);
+
+ diagonalDownBullet.setSpeed(diagonalDown.x * velocity, diagonalDown.y * velocity);
+ }
+}
@@ -20,7 +20,7 @@
public GunPositions(float width, float height)
{
- playerWidth = width;
+ playerWidth = width;
playerHeight = height;
positions = new ArrayList<Vector2f>();
@@ -0,0 +1,142 @@
+package org.gdc.gdcalaga;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.newdawn.slick.Graphics;
+
+public class HighscoreList {
+ private int centerX;
+ private int centerY;
+ private final int lineSpacing = 15;
+ private final int maxScoreLength = 9;
+
+
+ List<Highscore> scores = new ArrayList<Highscore>();
+
+
+ public HighscoreList(int screenSizeX, int screenSizeY)
+ {
+ this.centerX = screenSizeX / 2;
+ this.centerY = screenSizeY / 2;
+ }
+
+
+ public void render(Graphics g) {
+ drawHighscoreList(g);
+ }
+
+
+ private void drawHighscoreList(Graphics g) {
+ for(int i = 0; i < getHighscoreList().size(); ++i)
+ {
+ String number = String.valueOf(getHighscoreList().get(i).getScore());
+ number = String.format("%1$" + maxScoreLength + "s", number);
+ String score = (i+1) + ": " + number + " - " + getHighscoreList().get(i).getName();
+
+ g.drawString(score,
+ centerX - (maxScoreLength * 10),
+ centerY + (lineSpacing * i));
+ }
+ }
+
+
+ private List<Highscore> getHighscoreList() {
+ //if the scores list is empty read highscores from file.
+ if(scores.size() == 0)
+ {
+ try {
+ String current = new java.io.File( "." ).getCanonicalPath();
+ System.out.println("Current dir:"+current);
+
+ BufferedReader in = new BufferedReader(new FileReader("highscore.dat"));
+
+ String line;
+ while ((line = in.readLine()) != null) {
+
+ String[] split = line.split(",");
+ scores.add(new Highscore(Integer.parseInt(split[0]), split[1]));
+ }
+ in.close();
+
+ } catch (FileNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (NumberFormatException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ Collections.sort(scores,Collections.reverseOrder());
+ }
+
+ return scores;
+ }
+
+ public void addHighscore(int score, String name) {
+
+ scores.add(new Highscore(score,name));
+ Collections.sort(scores,Collections.reverseOrder());
+ }
+
+ public void saveHighscore()
+ {
+ try {
+ String current = new java.io.File( "." ).getCanonicalPath();
+ System.out.println("Current dir:"+current);
+
+ BufferedWriter out = new BufferedWriter(new FileWriter("highscore.dat"));
+
+ for(int i = 0; i < scores.size(); ++i)
+ {
+ out.write( scores.get(i).getScore() + "," + scores.get(i).getName() + "\n");
+ }
+
+ out.close();
+
+ } catch (FileNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+
+ private class Highscore implements Comparable<Highscore> {
+
+ private int score;
+ private String name;
+
+ public Highscore(int score, String name) {
+ this.score = score;
+ this.name = name;
+ }
+
+ public int getScore() { return score; }
+ public String getName() { return name; }
+
+ @Override
+ public int compareTo(Highscore arg0) {
+ Highscore otherHighScore = (Highscore)arg0;
+ if(score > otherHighScore.getScore())
+ return 1;
+ else if (score < otherHighScore.getScore())
+ return -1;
+
+ return 0;
+ }
+ }
+
+}
Oops, something went wrong.

0 comments on commit c4c85e2

Please sign in to comment.