Permalink
Browse files

Should work?

Testing out this update. Had to go into CMD line, so hope for the best.

Gives a HUD
  • Loading branch information...
1 parent 2ef0d1f commit 671b3d5601a84c1938cf78c25b55c6b870161c37 @SubSage committed Aug 2, 2013
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -1 +0,0 @@
-170,Player1
@@ -163,7 +163,7 @@ public void Collide(Entity other)
public void fire()
{
Vector2f bulletPosition = new Vector2f((pos.x - size.x / 2) + 3, pos.y);
- shipGun.shoot(bulletPosition, player);
+ shipGun.shoot(bulletPosition, player.getPosition());
}
@@ -1,13 +1,13 @@
package org.gdc.gdcalaga;
+import org.gdc.gdcalaga.Entity.Alliance;
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,
@@ -18,6 +18,8 @@
protected GunType gunType;
protected EntityManager entityManager;
protected Entity.Alliance alliance;
+ protected int bulletDamage = 1;
+
public Gun(EntityManager entityManager, float velocity, Entity.Alliance alliance, GunType gunType)
{
@@ -28,15 +30,15 @@ public Gun(EntityManager entityManager, float velocity, Entity.Alliance alliance
}
- public void shoot(Vector2f bulletPosition, Player player)
+ public void shoot(Vector2f bulletPosition, Vector2f target)
{
switch(gunType)
{
case StraightShot:
straightShot(bulletPosition);
break;
case AimedShot:
- aimedShot(bulletPosition, player);
+ aimedShot(bulletPosition, target);
break;
case TripleShot:
tripleShot(bulletPosition);
@@ -47,25 +49,30 @@ public void shoot(Vector2f bulletPosition, Player player)
}
private void straightShot(Vector2f bulletPosition) {
- Bullet newBullet = new Bullet(entityManager, bulletPosition, 1, alliance);
- newBullet.setSpeed(-250, 0);
+ Bullet newBullet = new Bullet(entityManager, bulletPosition, bulletDamage, alliance);
+ if(alliance == Alliance.ENEMY)
+ newBullet.setSpeed(-250, 0);
+ else
+ newBullet.setSpeed(250, 0);
}
- private void aimedShot(Vector2f bulletPosition, Player player) {
+ private void aimedShot(Vector2f bulletPosition, Vector2f target) {
- Bullet newBullet = new Bullet(entityManager, bulletPosition, 1, alliance);
+ Bullet newBullet = new Bullet(entityManager, bulletPosition, bulletDamage, alliance);
- Vector2f directionOfPlayer = new Vector2f(player.getPosition());
- directionOfPlayer.x -= bulletPosition.x;
- directionOfPlayer.y += (-bulletPosition.y) + (Math.random() * 20) - 10;
- directionOfPlayer.normalise();
+ // change the x direction to point towards target,
+ // add random y direction to make the shot seem not 100% accurate.
+ Vector2f directionOfTarget = new Vector2f(target);
+ directionOfTarget.x -= bulletPosition.x;
+ directionOfTarget.y += (-bulletPosition.y) + (Math.random() * 20) - 10;
+ directionOfTarget.normalise();
- newBullet.setSpeed(directionOfPlayer.x * 250,directionOfPlayer.y * 250);
+ newBullet.setSpeed(directionOfTarget.x * 250, directionOfTarget.y * 250);
}
private void tripleShot(Vector2f bulletPosition){
- Bullet diagonalUpBullet = new Bullet(entityManager, bulletPosition, 1, alliance);
+ Bullet diagonalUpBullet = new Bullet(entityManager, bulletPosition, bulletDamage, alliance);
Vector2f diagonalUp = new Vector2f(-2,1);
diagonalUp.normalise();
diagonalUpBullet.setSpeed(diagonalUp.x * velocity, diagonalUp.y * velocity);
@@ -74,8 +81,12 @@ private void tripleShot(Vector2f bulletPosition){
Vector2f diagonalDown = new Vector2f(-2,-1);
diagonalDown.normalise();
- Bullet diagonalDownBullet = new Bullet(entityManager, bulletPosition, 1, alliance);
+ Bullet diagonalDownBullet = new Bullet(entityManager, bulletPosition, bulletDamage, alliance);
diagonalDownBullet.setSpeed(diagonalDown.x * velocity, diagonalDown.y * velocity);
}
+
+ public String getName() {
+ return gunType.toString();
+ }
}
@@ -0,0 +1,79 @@
+package org.gdc.gdcalaga;
+import org.newdawn.slick.Color;
+import org.newdawn.slick.Graphics;
+import org.newdawn.slick.Image;
+import org.newdawn.slick.SlickException;
+
+public class HeadsUpDisplay {
+
+ private Image lifeIcon = null;
+ private Image healthIcon = null;
+
+ private int livesX = 100;
+ private int livesY = 15;
+ private int livesIconOffset = 20;
+
+ private int healthX = 180;
+ private int healthY = 15;
+ private int healthIconOffset = 25;
+
+ private int weaponX = 450;
+ private int weaponY = 15;
+
+
+ private int imageScale = 1;
+ private Player player;
+
+ public HeadsUpDisplay(Player player) {
+ this.player = player;
+ }
+
+ public void render(Graphics g) {
+
+ loadResources();
+ if(player != null) {
+ drawHealthBar(g);
+ drawLives(g);
+ drawWeapon(g);
+ }
+ }
+
+ private void loadResources() {
+ if(lifeIcon == null){
+ try {
+ lifeIcon = new Image("Pics/upgrade_invalid.png");
+ }
+ catch (SlickException e) {
+ e.printStackTrace();
+ }
+
+ try {
+ healthIcon = new Image("Pics/HealthBar.png");
+ }
+ catch (SlickException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private void drawHealthBar(Graphics g)
+ {
+ for(int i = 0; i < player.getHealth(); ++i)
+ {
+ healthIcon.draw(healthX + (healthIconOffset*i), healthY, imageScale, Color.white);
+ }
+ }
+
+ private void drawLives(Graphics g) {
+ for(int i = 0; i < player.getLives(); ++i)
+ {
+ lifeIcon.draw(livesX + (livesIconOffset*i), livesY, imageScale, Color.white);
+ }
+ }
+
+ private void drawWeapon(Graphics g) {
+
+ String weaponName = new String("Weapon: " + player.getWeapon().getName());
+ g.drawString(weaponName, weaponX, weaponY);
+ }
+}
@@ -53,8 +53,8 @@ private void drawHighscoreList(Graphics g) {
if(scores.size() == 0)
{
try {
- String current = new java.io.File( "." ).getCanonicalPath();
- System.out.println("Current dir:"+current);
+ //String current = new java.io.File( "." ).getCanonicalPath();
+ //System.out.println("Current dir:"+current);
BufferedReader in = new BufferedReader(new FileReader("highscore.dat"));
@@ -92,8 +92,8 @@ public void addHighscore(int score, String name) {
public void saveHighscore()
{
try {
- String current = new java.io.File( "." ).getCanonicalPath();
- System.out.println("Current dir:"+current);
+ //String current = new java.io.File( "." ).getCanonicalPath();
+ //System.out.println("Current dir:"+current);
BufferedWriter out = new BufferedWriter(new FileWriter("highscore.dat"));
@@ -23,7 +23,8 @@
PostGame,
}
- public static final int ID = 0;
+ public static final int ID = 0;
+
private Player player;
final int menuKeyDelay = 250;
@@ -40,7 +41,7 @@
private AudioManager audioManager = AudioManager.getAudioManager();
private HighscoreList highscoreList = new HighscoreList(GDCalaga.SCREEN_SIZE_X,GDCalaga.SCREEN_SIZE_Y);
private Menu mainMenu = new Menu(GDCalaga.SCREEN_SIZE_X,GDCalaga.SCREEN_SIZE_Y);
-
+ private HeadsUpDisplay hud;
private List<DisplayObject> disObjs = new LinkedList<DisplayObject>();
@@ -60,6 +61,7 @@ public void init(GameContainer container, StateBasedGame game) throws SlickExcep
paths.loadFromJson("./data/paths.json");
disObjs.add(new Background(container.getWidth(), container.getHeight()));
+ hud = new HeadsUpDisplay(player);
}
@Override
@@ -73,6 +75,7 @@ public void render(GameContainer container, StateBasedGame game, Graphics g) thr
switch(state)
{
case Playing:
+ hud.render(g);
break;
case Pause:
break;
@@ -85,9 +88,7 @@ public void render(GameContainer container, StateBasedGame game, Graphics g) thr
case PostGame:
renderPostGame(g);
break;
- }
-
-
+ }
renderDebugText(g);
}
@@ -150,6 +151,7 @@ private void updateGame(int delta) {
}
}
+
private void renderDebugText(Graphics g) {
/* If we use this same monospace font, each letter takes up 10 pixels
@@ -200,8 +202,6 @@ private void postGameInput() {
highscoreList.addHighscore(Player.getTotalPoints(), playerName);
changeState(State.MainMenu);
}
-
-
}
@@ -1,4 +1,5 @@
package org.gdc.gdcalaga;
+import org.gdc.gdcalaga.Gun.GunType;
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
@@ -29,10 +30,14 @@
//Upgradable Player attributes
private static float health;
+ private static final float maxHealth = 10;
private static float shields;
private static float fireRate; //fireRate in bullets per second
private static int numGuns;
private static float damage;
+ private static int lives;
+
+ private Gun gun;
protected Vector2f velocity;
private static boolean shieldActivated;
@@ -57,6 +62,7 @@ public Player(EntityManager manager, Vector2f position)
shields = 0;
fireRate = 5; //bullets per second
numGuns = 1;
+ lives = 3;
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
@@ -67,6 +73,8 @@ public Player(EntityManager manager, Vector2f position)
gunPositions = new GunPositions(SIZE_WIDTH, SIZE_HEIGHT);
+ gun = new Gun(manager, 250, Entity.Alliance.FRIENDLY, GunType.StraightShot);
+
try {
ship= new Image("Pics/Player.png");
} catch (SlickException e) {
@@ -128,11 +136,8 @@ public boolean fire(float delta)
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);
+ Vector2f shotOrigin = new Vector2f(gunPositions.getPosition(i));
+ gun.shoot(shotOrigin.add(pos), gunPositions.getPosition(i));
}
ticksSinceLastBullet = 0;
@@ -184,8 +189,16 @@ public void Hurt(float dmg)
if(health <= 0)
{
- Destroy();
- }
+ --lives;
+ if(lives < 0)
+ {
+ Destroy();
+ }
+ else
+ {
+ health = maxHealth;
+ }
+ }
}
public float getHealth()
@@ -208,6 +221,15 @@ public Vector2f getPosition()
return pos;
}
+ public int getLives()
+ {
+ return lives;
+ }
+
+ public Gun getWeapon() {
+ return gun;
+ }
+
public static int getTotalPoints()
{
return totalPoints;
@@ -217,6 +239,7 @@ 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)
{

0 comments on commit 671b3d5

Please sign in to comment.