Skip to content

Commit

Permalink
Added mainmenu, (newgame button will not reset game state.)
Browse files Browse the repository at this point in the history
Added Highscore list, will be read and written to file.
Added Gun clas which acts as a bullet factory.
Enemies have randomized guns (three variants, straight shot, shot in player direction, and triple shot)
change damage to be on entity instead of bullet in order to do ship-to-ship collision damage.
Modified PlayState to use state variable to change render and input mechanics.
  • Loading branch information
frekfra committed Jul 30, 2013
1 parent 5646657 commit 19be149
Show file tree
Hide file tree
Showing 12 changed files with 819 additions and 80 deletions.
4 changes: 4 additions & 0 deletions GDCalaga/highscore.dat
@@ -0,0 +1,4 @@
1000,Thomas
40000,Eddison
10000,George
5000,Micheal
255 changes: 255 additions & 0 deletions GDCalaga/src/org/gdc/gdcalaga/#Player.java#
@@ -0,0 +1,255 @@
package org.gdc.gdcalaga;
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Vector2f;

/*
* Upgrades planned for the player:
* Droppable: Health, shields, fire rate, more bullets, damage
* Buyable: Speed
*
* TODO
* Store the upgrades in an easily retrievable, searchable, and identifiable manner
* We want to have levels of upgrades, so this should be considered
* Create a shop at the end of a wave/stage (or something like that)
* for the player to buy upgrades.
* Create functionality for the player to be able to activate shields/invuln mode
* Create functionality for the player to have more guns
*/

public class Player extends Entity
{
private static final int SIZE_WIDTH = 49;
private static final int SIZE_HEIGHT = 29;

private static int totalPoints = 0; //the score is static in case we give players multiple lives in the future
Image ship;

//Upgradable Player attributes
private static float health;
private static float shields;
private static float fireRate; //fireRate in bullets per second
private static int numGuns;
private static float damage;
protected Vector2f velocity;

private static boolean shieldActivated;

//these values are intertwined with fireRate to create a standard fire rate
private static int ticksPerBullet;
private int ticksSinceLastBullet;

private GunPositions gunPositions;

public Player(EntityManager manager, Vector2f position)
{
super(manager);

pos.set(position);
size = new Vector2f(SIZE_WIDTH, SIZE_HEIGHT);
velocity = new Vector2f(220, 220);
damage = 1;
alliance = Alliance.FRIENDLY;

health = 10;
shields = 0;
fireRate = 5; //bullets per second
numGuns = 1;
ticksPerBullet = (int)(1000 / fireRate); //milliseconds in a second / fireRate
//since delta time is in milliseconds
ticksSinceLastBullet = ticksPerBullet; //so we can shoot right off the bat

shieldActivated = false;

shape = new RectShape(pos, size);

gunPositions = new GunPositions(SIZE_WIDTH, SIZE_HEIGHT);

try {
ship= new Image("Pics/Player.png");
} catch (SlickException e) {
e.printStackTrace();
}
}


public void update(float delta)
{
ticksSinceLastBullet += delta;
if (shields <= 0)
{
deactivateShield();
shields = 0;
}

RectShape rect = (RectShape)shape;
rect.pos.set(this.pos);
}

public void draw(Graphics g)
{
int drawX = (int)(pos.x - size.x / 2);
int drawY = (int)(pos.y - size.y / 2);
float scale = size.x / ship.getWidth();
ship.draw(drawX, drawY, scale, Color.white);
}


public void moveUp(float delta)
{
pos.y -= velocity.y * delta / 1000;
pos.y = Math.max(size.y / 2, pos.y);
}

public void moveDown(float delta)
{
pos.y += velocity.y * delta / 1000;
pos.y = Math.min(720 - size.y / 2, pos.y);
}

public void moveLeft(float delta)
{
pos.x -= velocity.x * delta / 1000;
pos.x = Math.max(0 + size.x / 2, pos.x);
}

public void moveRight(float delta)
{
pos.x += velocity.x * delta / 1000;
pos.x = Math.min(1280 - size.x / 2, pos.x);
}

public boolean fire(float delta)
{
//TODO add more firing positions and more bullets depending on the upgrades
if (ticksSinceLastBullet >= ticksPerBullet)
{
int max = numGuns < gunPositions.getSize() ? numGuns : gunPositions.getSize();
for (int i = 0; i < max; i++)
{
Vector2f position = new Vector2f(gunPositions.getPosition(i));
position.add(pos);
Bullet newBullet = new Bullet(entities, position, (int)(damage), alliance);
Vector2f direction = gunPositions.getDirection(i);
newBullet.setSpeed(direction.x * 500, direction.y * 500);
}

ticksSinceLastBullet = 0;
return true;
}
else
{
return false;
}

}

public boolean activateShield(float delta)
{
if (shields > 0)
{
shieldActivated = true;
shields -= delta;
return true;
}
else
{
deactivateShield();
shields = 0;
return false;
}
}

public void deactivateShield()
{
shieldActivated = false;
}

public void Collide(Entity other)
{
if(other instanceof Bullet && ((Bullet)other).getAlliance() != alliance
|| other instanceof Enemy)
{
Hurt(((Entity)other).getCollisionDamage());
}
}

public void Hurt(float dmg)
{
if (shieldActivated)
return;

health -= dmg;
}

public float getHealth()
{
return health;
}

public float getShields()
{
return shields;
}

public Entity.Alliance getAlliance()
{
return alliance;
}

public Vector2f getPosition()
{
return pos;
}

public static int getTotalPoints()
{
return totalPoints;
}

public static void increaseTotalPoints(int pointValue)
{
totalPoints += pointValue;
}
//my idea here is that ship upgrades will cost points to buy, like in most games.
public static void decreaseTotalPoints(int pointValue)
{
if(totalPoints - pointValue >= 0)
totalPoints -= pointValue;
else
System.out.println("Can't spend any more points!"); //TODO Fix error message
}

public static void upgrade(Upgrade.UpgradeType upgrade)
{
//TODO Change the ealth, hp/armor, fire rate, amount of guns, speed
//according to the upgrade passed in
switch (upgrade)
{
case HEALTH:
health += 5;
break;
case SHIELD:
shields += 3000; //Give 3 seconds worth of shielding
break;
case FIRE_RATE:
fireRate += .5; //Having these two variables separated makes it easier to debug and read
ticksPerBullet = (int)(1000 / fireRate); //A little bit weird that we have to do these two things...
break;
case NUM_GUNS:
numGuns++;
break;
case DAMAGE:
damage++;
break;
case INVALID_UPGRADE:

break;
default:

break;
}
}
}
6 changes: 1 addition & 5 deletions GDCalaga/src/org/gdc/gdcalaga/Bullet.java
Expand Up @@ -10,7 +10,6 @@ public class Bullet extends Entity
private static final int SIZE_WIDTH = 9;
private static final int SIZE_HEIGHT = 5;

private float damage;
private Vector2f velocity;
private Image bullet;

Expand All @@ -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;

Expand Down Expand Up @@ -101,9 +100,6 @@ else if(other instanceof Player)
}
}

public float getDamage(){
return damage;
}


public Entity.Alliance getAlliance() {
Expand Down
19 changes: 13 additions & 6 deletions GDCalaga/src/org/gdc/gdcalaga/Enemy.java
Expand Up @@ -29,6 +29,7 @@ public class Enemy extends Entity
private Vector2f startPos, pathVelocity;
private float fireRate;
private float fireRateDT;
private Gun shipGun;
private Random rand;

private EnemyGroup group;
Expand All @@ -37,6 +38,9 @@ public class Enemy extends Entity

protected AudioManager audioManager;

protected static Player player;


public Enemy(EntityManager manager, Vector2f position)
{
super(manager);
Expand All @@ -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();
}

Expand Down Expand Up @@ -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);
}


Expand Down
9 changes: 9 additions & 0 deletions GDCalaga/src/org/gdc/gdcalaga/Entity.java
Expand Up @@ -24,6 +24,7 @@ public enum Alliance

protected Shape shape;

protected float collisionDamage;

public Entity(EntityManager manager)
{
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -64,6 +69,10 @@ public void Destroy()
dying = true;
}

public float getCollisionDamage(){
return collisionDamage;
}

public Entity.Alliance getAlliance()
{
return alliance;
Expand Down

0 comments on commit 19be149

Please sign in to comment.