This is a big commit. Added mouse cursors and a load bar. Started whit the game. and many many other things

This commit is contained in:
Ziver Koc 2007-03-29 23:21:00 +00:00
parent 448fca2fdf
commit 4e7722fedb
34 changed files with 597 additions and 95 deletions

BIN
src/data/cursor.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
src/data/enemy.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
src/data/loadbar.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
src/data/loadbar_back.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 B

BIN
src/data/loadbar_front.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 446 B

BIN
src/data/map/sand.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

View file

@ -86,13 +86,18 @@ public class LWJGLGameWindow {
// Create the display window
Display.create();
// enable textures since we're going to use these for our sprites
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glShadeModel(GL11.GL_SMOOTH);
// disable the OpenGL depth test since we're rendering 2D graphics
GL11.glDisable(GL11.GL_DEPTH_TEST);
// disable lights (we do not nead them)
GL11.glDisable(GL11.GL_LIGHTING);
// Enable Smooth Shading
GL11.glShadeModel(GL11.GL_SMOOTH);
// Black Background
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
// Depth Buffer Setup
GL11.glClearDepth(1.0f);
@ -105,18 +110,16 @@ public class LWJGLGameWindow {
// Select The Modelview Matrix (controls model orientation)
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
// disable the OpenGL depth test since we're rendering 2D graphics
GL11.glDisable(GL11.GL_DEPTH_TEST);
//Enable Blending
GL11.glEnable(GL11.GL_BLEND);
//Type Of Blending To Perform
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
// Enable vsync if we can (due to how OpenGL works, it cannot be guarenteed to always work)
Display.setVSyncEnabled(true);
// The last steps
timer = new FpsTimer();

View file

@ -8,6 +8,8 @@ package ei.engine.effects;
* Visit Our Sites At www.tiptup.com and nehe.gamedev.net
*/
import java.awt.Rectangle;
import org.lwjgl.opengl.GL11;
import ei.engine.scene.Entity;
@ -155,6 +157,8 @@ public class Particles extends Entity{
texture.bindGL();
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
for(int i=0;i<maxParticles;i++) { // Loop Through All The Particles
if (particle[i].active) { // If The Particle Is Active
float x = particle[i].x; // Grab Our Particle X Position
@ -218,6 +222,7 @@ public class Particles extends Entity{
}
}
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
// restore the model view matrix to prevent contamination
GL11.glPopMatrix();
}
@ -249,6 +254,16 @@ public class Particles extends Entity{
particle[i].active = true;
}
}
/**
* Returns the bound of this class
*/
public Rectangle getBound() {
return new Rectangle(
(int)getLocation().getX(),
(int)getLocation().getY(),
(int)size, (int)size);
}
}
class Particle { // Particles Structure

View file

@ -9,7 +9,6 @@ public abstract class Input{
public Input(String name){
this.enabled = true;
InputHandler.getInstance().addInput(this);
}
/**

View file

@ -1,9 +1,11 @@
package ei.engine.input;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import ei.engine.LWJGLGameWindow;
import ei.engine.math.Vector2f;
import ei.engine.math.Vector3f;
import ei.engine.scene.Sprite;
/**
@ -12,6 +14,9 @@ import ei.engine.scene.Sprite;
*
*/
public abstract class MouseInput extends Input{
public static final int LEFT_MOUSE_BUTTON = 0;
public static final int RIGHT_MOUSE_BUTTON = 1;
public static final int MIDDLE_MOUSE_BUTTON = 2;
// The x pos of the mouse
private static int cursorX;
// The y pos of the mouse
@ -22,19 +27,42 @@ public abstract class MouseInput extends Input{
public MouseInput(String name) {
super(name);
// init mouse: this will hide the native cursor (see drawCursor())
Mouse.setGrabbed(true);
Mouse.setGrabbed(false);
// set initial cursor pos to center screen
cursorX = (int) LWJGLGameWindow.getWidth() / 2;
cursorY = (int) LWJGLGameWindow.getHeight() / 2;
}
public MouseInput(String name,String texture){
super(name);
// init mouse: this will hide the native cursor (see drawCursor())
Mouse.setGrabbed(true);
cursor = new Sprite(name+" spatial",texture);
// set initial cursor pos to center screen
cursorX = (int) LWJGLGameWindow.getWidth() / 2;
cursorY = (int) LWJGLGameWindow.getHeight() / 2;
}
/**
* Returns the sprite of th mouse
*
* @return The sprite of the mouse
*/
public Sprite getSprite(){
return cursor;
}
/**
* Renders the mous texture if texture set
*/
public void render() {
if(cursor != null){
cursor.render();
GL11.glPushMatrix();
Vector3f v = LWJGLGameWindow.getCamera().getLocation();
GL11.glTranslatef(v.getX(),v.getY(), v.getZ());
cursor.render();
GL11.glPopMatrix();
}
}
@ -61,36 +89,37 @@ public abstract class MouseInput extends Input{
else if (cursorY > LWJGLGameWindow.getHeight()) {
cursorY = LWJGLGameWindow.getHeight();
}
mouseMove(cursorX,cursorY);
}
mouseUpdate(cursorX,cursorY,mouseDW);
while ( Mouse.next() ) {
if(Mouse.getEventButton() == 0 && Mouse.getEventButtonState() == true) {
mouseDown(cursorX, cursorY);
if(Mouse.getEventButton() >= 0 && Mouse.getEventButtonState() == true) {
mouseDown(Mouse.getEventButton(),cursorX, cursorY);
}
if(Mouse.getEventButton() == 0 && Mouse.getEventButtonState() == false) {
mouseUp(cursorX, cursorY);
if(Mouse.getEventButton() >= 0 && Mouse.getEventButtonState() == false) {
mouseUp(Mouse.getEventButton(),cursorX, cursorY);
}
}
if(cursor != null){
cursor.setLocation(new Vector2f(cursorX, cursorY));
cursor.setLocation(new Vector2f(cursorX,
LWJGLGameWindow.getHeight()-cursorY));
}
}
/**
* Called by update() when mouse moves
*/
public abstract void mouseMove(int x, int y);
public abstract void mouseUpdate(int x, int y, int w);
/**
* Called by update() when mouse button is pressed
*/
public abstract void mouseDown(int x, int y);
public abstract void mouseDown(int event,int x, int y);
/**
* Called by update() when mouse button is released
*/
public abstract void mouseUp(int x, int y);
public abstract void mouseUp(int event,int x, int y);
}

View file

@ -1,5 +1,6 @@
package ei.engine.scene;
import java.awt.Rectangle;
import java.util.HashMap;
import org.lwjgl.opengl.GL11;
@ -113,17 +114,14 @@ public class AnimatedSprite extends Entity {
// store the current model matrix
GL11.glPushMatrix();
//Sets the scale of the sprite
super.setScaleGL();
//Sets the location
super.setTranslationGL();
//the rotation
super.setRotationGL();
//and sets back the rotation so that the rotation pivot is the center of the sprite
super.setTranslationGL(
-textures.get(currentAnimation)[textureId].getImageWidth()/2,
-textures.get(currentAnimation)[textureId].getImageHeight()/2,
0);
super.setRotationGL(
textures.get(currentAnimation)[textureId].getImageWidth()/2,
textures.get(currentAnimation)[textureId].getImageHeight()/2);
//Sets the scale of the sprite
super.setScaleGL();
// bind to the appropriate texture for this sprite
textures.get(currentAnimation)[textureId].bindGL();
@ -160,4 +158,15 @@ public class AnimatedSprite extends Entity {
}
}
}
/**
* Returns the bound of this class
*/
public Rectangle getBound() {
return new Rectangle(
(int)getLocation().getX(),
(int)getLocation().getY(),
textures.get(currentAnimation)[textureId].getImageWidth(),
textures.get(currentAnimation)[textureId].getImageHeight());
}
}

View file

@ -3,6 +3,8 @@
*/
package ei.engine.scene;
import java.awt.Rectangle;
import org.lwjgl.opengl.GL11;
import ei.engine.math.Vector2f;
@ -118,18 +120,6 @@ public abstract class Entity {
GL11.glTranslatef(location.getX(), location.getY(), location.getZ());
}
/**
* Sets the location of the entity in opengl
*
* @param x The value to add x
* @param y The value to add y
* @param z The value to add z
*/
protected void setTranslationGL(float x, float y, float z){
// translate to the right location and prepare to draw
GL11.glTranslatef(x,y, z);
}
protected void setScaleGL(){
// translate to the right location and prepare to draw
GL11.glScalef(size.getX(), size.getY(), size.getZ());
@ -138,21 +128,33 @@ public abstract class Entity {
/**
* Sets the rotation of the entity in opengl
* before rendering.
*
* @param rx The x coordinate of the center of rotation
* @param ry The y coordinate of the center of rotation
*/
protected void setRotationGL(){
protected void setRotationGL(float rx, float ry){
//GL11.glTranslatef(rx,ry, location.getZ());
// rotating the entity
GL11.glRotatef(rotation.getX(), 1.0f, 0.0f, 0.0f); // Rotate On The X Axis
GL11.glRotatef(rotation.getY(), 0.0f, 1.0f, 0.0f); // Rotate On The Y Axis
GL11.glRotatef(rotation.getZ(), 0.0f, 0.0f, 1.0f); // Rotate On The Z Axis
GL11.glTranslatef(-rx,-ry, location.getZ());
}
public boolean intersects(Entity e){
return getBound().intersects(e.getBound());
}
/**
* the render method should be implemented for every entity
* the render method can be implemented for every entity
*/
public abstract void render();
public void render(){}
/**
* the update method can be implemented for every entity
*/
public void update(){}
public abstract Rectangle getBound();
}

View file

@ -1,5 +1,7 @@
package ei.engine.scene;
import java.awt.Rectangle;
import org.lwjgl.opengl.GL11;
import ei.engine.texture.Texture;
@ -74,10 +76,14 @@ public class Sprite extends Entity {
return texture.getImageHeight();
}
protected void bindTexture(){
/**
* Returns the texture
* @return The texture
*/
public Texture getTexture(){
return texture;
}
/**
* Draw the sprite
*/
@ -85,14 +91,12 @@ public class Sprite extends Entity {
// store the current model matrix
GL11.glPushMatrix();
//Sets the scale of the sprite
super.setScaleGL();
//Sets the location
super.setTranslationGL();
//the rotation
super.setRotationGL();
//and sets back the rotation so that the rotation pivot is the center of the sprite
super.setTranslationGL(-texture.getImageWidth()/2,-texture.getImageHeight()/2,0);
super.setRotationGL(texture.getImageWidth()/2,texture.getImageHeight()/2);
//Sets the scale of the sprite
super.setScaleGL();
// bind to the appropriate texture for this sprite
texture.bindGL();
@ -120,4 +124,15 @@ public class Sprite extends Entity {
GL11.glPopMatrix();
}
/**
* Returns the bound of this class
*/
public Rectangle getBound() {
return new Rectangle(
(int)getLocation().getX(),
(int)getLocation().getY(),
texture.getImageWidth(),
texture.getImageHeight());
}
}

View file

@ -1,12 +1,14 @@
package ei.engine.sound;
import java.awt.Rectangle;
import ei.engine.math.Vector3f;
import ei.engine.scene.Entity;
/**
* A sound that can be played through OpenAL
*
* @author Kevin Glass
* @author Ziver Koc
*/
public class Sound extends Entity{
private static int soundId = 1;
@ -91,9 +93,14 @@ public class Sound extends Entity{
return velocity;
}
/**
* unimplamented method
*
/**
* Returns the bound of this class
*/
public void render() {}
public Rectangle getBound() {
return new Rectangle(
(int)getLocation().getX(),
(int)getLocation().getY(),
10, 10);
}
}

View file

@ -14,7 +14,6 @@ import ei.engine.util.MultiPrintStream;
/**
* Responsible for holding and playing the sounds used in the game.
*
* @author Kevin Glass
* @author Ziver Koc
*/
public class SoundManager {

View file

@ -1,11 +1,24 @@
package ei.engine.state;
import ei.engine.input.InputHandler;
public abstract class GameState {
private String name;
private InputHandler input;
private boolean enabled = false;
public GameState(String name){
this.name = name;
input = new InputHandler();
}
/**
* Returns the input handler of this state
*
* @return The input handler
*/
public InputHandler getInput(){
return input;
}
/**
@ -30,6 +43,24 @@ public abstract class GameState {
return name;
}
/**
* Updates the State
*
*/
public void stateUpdate(){
input.update();
update();
}
/**
* Renders the state
*
*/
public void stateRender(){
render();
input.render();
}
public abstract void update();
public abstract void render();

View file

@ -111,7 +111,7 @@ public class GameStateManager {
public void update(){
for(int i=0; i<gameStates.size() ;i++){
if(gameStates.get(i).isEnabled()){
gameStates.get(i).update();
gameStates.get(i).stateUpdate();
}
}
}
@ -122,7 +122,7 @@ public class GameStateManager {
public void render(){
for(int i=0; i<gameStates.size() ;i++){
if(gameStates.get(i).isEnabled()){
gameStates.get(i).render();
gameStates.get(i).stateRender();
}
}
}

View file

@ -0,0 +1,19 @@
package ei.engine.test;
import ei.engine.LWJGLGameWindow;
import ei.engine.state.GameStateManager;
public class GameStateTest extends LWJGLGameWindow{
public static void main(String[] args){
new GameStateTest();
}
public GameStateTest() {
super("GameStateTest");
}
protected void init(){
GameStateManager.getInstance().addState(new GameStateTestState("GameStateTestState"));
GameStateManager.getInstance().setActive("GameStateTestState");
}
}

View file

@ -0,0 +1,49 @@
package ei.engine.test;
import ei.engine.LWJGLGameWindow;
import ei.engine.effects.Particles;
import ei.engine.math.Vector2f;
import ei.engine.scene.Node;
import ei.engine.scene.Sprite;
import ei.engine.sound.Sound;
import ei.engine.state.GameState;
public class GameStateTestState extends GameState{
private Node rootNode;
private Sprite sprite1;
private Sound sound1;
private Particles p;
public GameStateTestState(String name){
super(name);
rootNode = new Node("InGameNode");
sprite1 = new Sprite("tank","data/units/tank.png");
//sprite1.setScale(new Vector2f(0.5f,0.5f));
//sprite1.setLocation(new Vector2f(300,300));
rootNode.add(sprite1);
p = new Particles("particle");
p.setLocation(sprite1.getLocation());
rootNode.add(p);
sound1 = new Sound("sound","data/sounds/center.wav");
sound1.loop();
sound1.setLocation(sprite1.getLocation());
rootNode.add(sound1);
}
@Override
public void render() {
rootNode.render();
}
@Override
public void update() {
LWJGLGameWindow.getCamera().getLocation().add(new Vector2f(-1.5f,-1.5f));
sprite1.getRotation().add(0, 0, 0.5f);
rootNode.update();
}
}

View file

@ -55,7 +55,7 @@ import org.lwjgl.util.WaveData;
* @version $Revision$
* $Id$
*/
public class PositionTest extends BasicTest {
public class SoundPositionTest extends BasicTest {
/** *Small* glut implementation :) */
private GLUT glut;
@ -148,10 +148,6 @@ public class PositionTest extends BasicTest {
// =====================================================
LWJGLUtil.log("Setting up window");
// calc center
int centerX = (Display.getDisplayMode().getWidth() - WINDOW_WIDTH) / 2;
int centerY = (Display.getDisplayMode().getHeight() - WINDOW_HEIGHT) / 2;
// setup window
setDisplayMode();
Display.create();
@ -180,7 +176,7 @@ public class PositionTest extends BasicTest {
AL10.alListener(AL10.AL_POSITION, listenerPosition);
AL10.alListener(AL10.AL_VELOCITY, listenerVelocity);
//AL10.alListener(AL10.AL_ORIENTATION, listenerOrientation);
AL10.alListener(AL10.AL_ORIENTATION, listenerOrientation);
// creating buffers
LWJGLUtil.log("Creating buffers");
@ -481,7 +477,7 @@ public class PositionTest extends BasicTest {
* String array containing arguments
*/
public static void main(String[] args) {
PositionTest positionTest = new PositionTest();
SoundPositionTest positionTest = new SoundPositionTest();
positionTest.execute(args);
System.exit(0);
}

View file

@ -0,0 +1,12 @@
/**
*
*/
package ei.engine.texture;
/**
* @author Ziver
*
*/
public class MultiTexture {
}

View file

@ -25,9 +25,9 @@ public class Texture {
/** The width of the image */
private int width;
/** The width of the texture */
private int texWidth;
private float texWidth;
/** The height of the texture */
private int texHeight;
private float texHeight;
/** The ratio of the width of the image to the texture */
private float widthRatio;
/** The ratio of the height of the image to the texture */
@ -123,7 +123,7 @@ public class Texture {
*
* @param texHeight The height of the texture
*/
public void setTextureHeight(int texHeight) {
public void setTextureHeight(float texHeight) {
this.texHeight = texHeight;
setHeight();
}
@ -133,7 +133,7 @@ public class Texture {
*
* @param texWidth The width of the texture
*/
public void setTextureWidth(int texWidth) {
public void setTextureWidth(float texWidth) {
this.texWidth = texWidth;
setWidth();
}

View file

@ -91,12 +91,12 @@ public class TextureLoader {
* @throws IOException Indicates a failure to access the resource
*/
public Texture getTexture(String resourceName){
MultiPrintStream.out.println("Loading texture: "+resourceName);
Texture tex = (Texture) table.get(resourceName);
if (tex != null) {
return tex;
}
MultiPrintStream.out.println("Loading texture: "+resourceName);
try {
tex = getTexture(resourceName,

View file

@ -3,6 +3,7 @@ package ei.game;
import ei.engine.LWJGLGameWindow;
import ei.engine.state.GameStateManager;
import ei.game.gamestate.InGameState;
import ei.game.gamestate.LoadingState;
public class EI extends LWJGLGameWindow{
public static void main(String[] args){
@ -15,6 +16,7 @@ public class EI extends LWJGLGameWindow{
protected void init(){
GameStateManager.getInstance().addState(new InGameState("InGameState"));
GameStateManager.getInstance().setActive("InGameState");
GameStateManager.getInstance().addState(new LoadingState("LoadingState","InGameState"));
GameStateManager.getInstance().setActive("LoadingState");
}
}

View file

@ -1,48 +1,32 @@
package ei.game.gamestate;
import ei.engine.LWJGLGameWindow;
import ei.engine.effects.Particles;
import ei.engine.math.Vector2f;
import ei.engine.scene.Node;
import ei.engine.scene.Sprite;
import ei.engine.sound.Sound;
import ei.engine.state.GameState;
import ei.game.input.InGameMouseInput;
import ei.game.scene.Map;
public class InGameState extends GameState{
private Node rootNode;
private Sprite sprite1;
private Sound sound1;
private Particles p;
private Map map;
public InGameState(String name){
super(name);
rootNode = new Node("InGameNode");
InGameMouseInput mouse = new InGameMouseInput();
super.getInput().addInput(mouse);
map = new Map(20,20);
rootNode.add(map.getMapNode());
sprite1 = new Sprite("tank","data/units/tank.png");
//sprite1.setScale(new Vector2f(0.5f,0.5f));
//sprite1.setLocation(new Vector2f(300,300));
rootNode.add(sprite1);
p = new Particles("particle");
p.setLocation(sprite1.getLocation());
rootNode.add(p);
sound1 = new Sound("sound","data/sounds/center.wav");
sound1.loop();
sound1.setLocation(sprite1.getLocation());
rootNode.add(sound1);
}
@Override
public void render() {
rootNode.render();
}
@Override
public void update() {
LWJGLGameWindow.getCamera().getLocation().add(new Vector2f(-1.5f,-1.5f));
sprite1.getRotation().add(0, 0, 0.5f);
rootNode.update();
}

View file

@ -0,0 +1,115 @@
package ei.game.gamestate;
import java.util.LinkedList;
import java.util.Queue;
import ei.engine.LWJGLGameWindow;
import ei.engine.math.Vector3f;
import ei.engine.scene.Sprite;
import ei.engine.sound.SoundLoader;
import ei.engine.state.GameState;
import ei.engine.state.GameStateManager;
import ei.engine.texture.TextureLoader;
/**
* This class handels the loading of the
* images and sounds to the memmory.
*
* @author Ziver
*/
public class LoadingState extends GameState{
// The things to load
private Queue<String> loadTextures;
private Queue<String> loadSounds;
// The name of the next state to activate after loading
private String nextState;
// Temp things for the loadingbar
private int status;
private Sprite bar;
private Sprite loadBar;
private Sprite background;
/**
* Creates a loadingstate
* @param name The name of the state
*/
public LoadingState(String name,String nextState) {
super(name);
this.nextState = nextState;
status = 0;
loadTextures = new LinkedList<String>();
loadSounds = new LinkedList<String>();
bar = new Sprite("Bar","data/loadbar_front.png");
bar.setLocation(new Vector3f(
(LWJGLGameWindow.getWidth()/2),
(LWJGLGameWindow.getHeight()/2),0.0f));
loadBar = new Sprite("LoadingBar","data/loadbar.png");
loadBar.setLocation(new Vector3f(
(LWJGLGameWindow.getWidth()/2)-loadBar.getWidth(),
(LWJGLGameWindow.getHeight()/2)+3,0.0f));
background = new Sprite("Bar","data/loadbar_back.png");
background.setLocation(new Vector3f(
(LWJGLGameWindow.getWidth()/2),
(LWJGLGameWindow.getHeight()/2),0.0f));
}
/**
* Add a texture to be loaded
* @param url
*/
public void addTexture(String url){
loadTextures.add(url);
}
/**
* Add a sound to be loaded
* @param url
*/
public void addSound(String url){
loadSounds.add(url);
}
/**
* Loads the things
*/
public void update() {
if(!loadTextures.isEmpty()){
TextureLoader.getTextureLoaderInstance().getTexture(loadTextures.poll());
status++;
}
else if(!loadSounds.isEmpty()){
SoundLoader.getInstnace().loadSound(loadSounds.poll());
status++;
}
else{
status++;
if(status >= 100){
//deactivate this state and activate the next one
GameStateManager.getInstance().removeState(this);
GameStateManager.getInstance().setActive(nextState);
}
}
background.update();
loadBar.update();
bar.update();
}
/**
* Render the load bar
*/
public void render() {
// Calculate the procentage
float procent = (float)status/100;//(loadTextures.size()+loadSounds.size());
System.out.println("lol: "+procent);
loadBar.setLocation(new Vector3f(
(LWJGLGameWindow.getWidth()/2)-loadBar.getWidth()+(loadBar.getWidth()*procent),
(LWJGLGameWindow.getHeight()/2)+6,0.0f));
//render the bar
background.render();
loadBar.render();
bar.render();
}
}

View file

@ -0,0 +1,5 @@
package ei.game.input;
public class InGameKeyboardInput {
}

View file

@ -0,0 +1,54 @@
package ei.game.input;
import ei.engine.LWJGLGameWindow;
import ei.engine.input.MouseInput;
import ei.engine.scene.Sprite;
public class InGameMouseInput extends MouseInput{
private static final int CAMERA_MOVE_BORDER = 40;
private static final float CAMERA_MOVE_SPEED = 6.0f;
public InGameMouseInput() {
super("InGameMouseInput","data/cursor.png");
Sprite s = getSprite();
s.getTexture().setTextureWidth(50);
s.getTexture().setTextureHeight(50);
s.getTexture().setWidth(50);
s.getTexture().setHeight(50);
}
@Override
public void mouseUpdate(int x, int y, int w) {
// mov cam to the left
if(x < CAMERA_MOVE_BORDER){
LWJGLGameWindow.getCamera().getLocation().add(-CAMERA_MOVE_SPEED,0,0);
}
// mov cam to the right
if(x > LWJGLGameWindow.getWidth()-CAMERA_MOVE_BORDER){
LWJGLGameWindow.getCamera().getLocation().add(CAMERA_MOVE_SPEED,0,0);
}
// mov cam upp
if(y < CAMERA_MOVE_BORDER){
LWJGLGameWindow.getCamera().getLocation().add(0,CAMERA_MOVE_SPEED,0);
}
// mov cam down
if(y > LWJGLGameWindow.getHeight()-CAMERA_MOVE_BORDER){
LWJGLGameWindow.getCamera().getLocation().add(0,-CAMERA_MOVE_SPEED,0);
}
//System.out.println(x+"-"+y);
}
@Override
public void mouseDown(int event,int x, int y) {
System.out.println("DOWN("+event+"): "+x+"-"+y);
}
@Override
public void mouseUp(int event,int x, int y) {
System.out.println("UP("+event+"): "+x+"-"+y);
}
}

View file

@ -0,0 +1,5 @@
package ei.game.player;
public class Human {
}

View file

@ -0,0 +1,26 @@
package ei.game.scene;
public abstract class GameEntity{
private int life;
public GameEntity(int l){
life = l;
}
/**
* Returns the life
*
* @return The life
*/
public int getLife(){
return life;
}
/**
* Set the life
* @param l The life to set to
*/
public void setLife(int l){
life = l;
}
}

View file

@ -0,0 +1,92 @@
package ei.game.scene;
import ei.engine.math.Vector3f;
import ei.engine.scene.Node;
import ei.engine.scene.Sprite;
public class Map {
private static final int POS_SIZE = 50;
private int width;
private int hight;
private GameEntity[][] map;
private Node mapNode;
public Map(int w, int h){
this.width = w;
this.hight = h;
init();
}
private void init(){
map = new GameEntity[width][hight];
// init textures
mapNode = new Node("MapNode");
for(int i=0; i<width ;i++){
for(int j=0; j<hight ;j++){
Sprite s = new Sprite("MapPos("+i+","+j+")","data/map/sand.jpg");
s.setLocation(new Vector3f(i*POS_SIZE,j*POS_SIZE,0));
s.getTexture().setTextureWidth(POS_SIZE+1.2f);
s.getTexture().setTextureHeight(POS_SIZE+1.2f);
s.getTexture().setWidth(POS_SIZE+1);
s.getTexture().setHeight(POS_SIZE+1);
mapNode.add(s);
}
}
}
/**
* Returns if the pos inthe map is empty
*
* @param x The x pos
* @param y The y pos
* @return True if empty else false
*/
public boolean isPosEmpty(int x, int y){
if(map[x][y] != null){
return true;
}
return false;
}
/**
* Returns the object at the pos
*
* @param x The x pos
* @param y The y pos
* @return The object in that pos
*/
public GameEntity getPos(int x, int y){
return map[x][y];
}
/**
* Sets an object at the pos
*
* @param e The object
* @param x The x pos
* @param y The y pos
*/
public void setPos(GameEntity e, int x, int y){
map[x][y] = e;
}
/**
* Removes a object from that pos
*
* @param x The x pos
* @param y The y pos
*/
public void removePos(int x, int y){
map[x][y] = null;
}
/**
* Returns the map node
*
* @return The map node
*/
public Node getMapNode(){
return mapNode;
}
}

View file

@ -0,0 +1,17 @@
package ei.game.scene.buildings;
import java.util.ArrayList;
import ei.game.scene.GameEntity;
import ei.game.scene.units.Unit;
public abstract class Building extends GameEntity{
private ArrayList<Unit> availableUnits;
private ArrayList<Unit> buildQueue;
public Building(int l) {
super(l);
// TODO Auto-generated constructor stub
}
}

View file

@ -0,0 +1,12 @@
package ei.game.scene.units;
import ei.game.scene.GameEntity;
public abstract class Unit extends GameEntity{
public Unit(int l) {
super(l);
// TODO Auto-generated constructor stub
}
}

View file

@ -0,0 +1,5 @@
package ei.game.scene.weapons;
public abstract class Weapon {
}