Skip to content

Commit

Permalink
Merge pull request #2 from fsxfreak/master
Browse files Browse the repository at this point in the history
Finally finished converting to the Vector2f system
  • Loading branch information
SubSage committed Apr 2, 2013
2 parents 018b0a5 + 5490903 commit 12c3433
Show file tree
Hide file tree
Showing 17 changed files with 486 additions and 406 deletions.
82 changes: 41 additions & 41 deletions GDCalaga/src/org/gdc/gdcalaga/Bullet.java
Expand Up @@ -3,71 +3,72 @@
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;

import org.newdawn.slick.geom.Vector2f;

public class Bullet extends Entity
{
private float damage, xVel, yVel;
private int width, height, alliance;
private static final int SIZE_WIDTH = 9;
private static final int SIZE_HEIGHT = 5;

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

public Bullet(EntityManager manager, int xpos, int ypos, int dmg, int alnc)
public Bullet(EntityManager manager, Vector2f position, int dmg, int alnc)
{
super(manager);
x=xpos;
y=ypos;
width=9;
height=5;
damage=dmg;
yVel=0;
xVel=0;
alliance=alnc;
pos.set(position);
size = new Vector2f(SIZE_WIDTH, SIZE_HEIGHT);
damage = dmg;
velocity = new Vector2f(0, 0);
alliance = alnc;

shape = new RectShape(x, y, width, height);
shape = new RectShape(pos, size);


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


public void update(float delta)
{


x+= xVel * delta / 1000;
y+= yVel * delta / 1000;

pos.x += velocity.x * delta / 1000;
pos.y += velocity.y * delta / 1000;

RectShape rect = (RectShape)shape;
rect.xpos = x;
rect.ypos = y;
rect.pos.set(this.pos);

if( x<0 && xVel<=0 ||
x>1280 && xVel>=0 ||
y<0 && yVel<=0 ||
y>780 && yVel>=0){
Destroy();
}
if (pos.x < 0 && velocity.x <= 0 ||
pos.x > 1280 && velocity.x >= 0 ||
pos.y < 0 && velocity.y <= 0 ||
pos.y > 780 && velocity.y >= 0)
{
Destroy();
}
}


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

public void setSpeed(float a, float b)
public void setSpeed(float xSpeed, float ySpeed)
{
velocity.set(xSpeed, ySpeed);
}

public void setSpeed(Vector2f speed)
{
xVel=a;
yVel=b;
velocity = speed;
}

public void Collide(Entity other)
Expand All @@ -87,7 +88,6 @@ else if(other instanceof Player)
{
Destroy();
}

}
}

Expand All @@ -96,7 +96,7 @@ public float getDamage(){
}


public int getAlliance() {
return alliance;
}
public int getAlliance() {
return alliance;
}
}
19 changes: 2 additions & 17 deletions GDCalaga/src/org/gdc/gdcalaga/Collision.java
Expand Up @@ -6,41 +6,26 @@ public class Collision {

public static void checkCollisions(ArrayList<Entity> ents)
{

//Very inefficient, but should work fine for now

for(int entA = 0; entA < ents.size(); entA++)
{

Entity A = ents.get(entA);

if(A.shape != null && A.shape.type != Shape.ShapeType.Null)
{

for(int entB = entA + 1; entB < ents.size(); entB++)
{

Entity B = ents.get(entB);

if(B.shape != null && B.shape.type != Shape.ShapeType.Null)
{

if(A.shape.Intersects(B.shape) && !A.IsDying() && !B.IsDying())
{

A.Collide(B);
B.Collide(A);

}

}

}

}
}
}

}

}

}
36 changes: 36 additions & 0 deletions GDCalaga/src/org/gdc/gdcalaga/DroppableUpgrade.java
@@ -0,0 +1,36 @@
package org.gdc.gdcalaga;

import org.newdawn.slick.Image;
import org.newdawn.slick.geom.Vector2f;

/*
* DroppableUpgrade class. DroppableUpgrades are dropped randomly when enemies
* die, and the player must pickup the upgrade to receive the upgrade.
* Change this class to just an Upgrade class, that only collides with the player
* to activate an upgrade() function
*/


public abstract class DroppableUpgrade extends Entity
{
private static final float SPEED = 50.f;
private static final float SIZE = 25.f;

protected Vector2f pos, vel, size;
protected Shape shape;
protected Image image;

protected Path path;
protected PathNode node;

public DroppableUpgrade(EntityManager manager, Vector2f initPos)
{
super(manager);

pos = initPos;
vel.set(-SPEED, 0);
size.set(SIZE, SIZE);

shape = new RectShape(pos, size);
}
}

0 comments on commit 12c3433

Please sign in to comment.