Permalink
Browse files

Basic Player animations implemented.

  • Loading branch information...
1 parent b5594a0 commit 923a003df568f4ca7902bf19f0c6043d71d66331 @Jademalo committed Feb 24, 2011
View
2 nbproject/configs/Slick.properties
@@ -1,2 +0,0 @@
-main.class=Game.Game
-run.jvmargs=-Djava.library.path="C:\\Program Files\\NetBeans 6.9.1\\lwjgl\\lwjgl-2.6\\native\\windows"
View
2 nbproject/private/config.properties
@@ -1 +1 @@
-config=Slick
+config=LWJGL_Windows
View
0 nbproject/private/configs/Slick.properties
No changes.
View
8 src/Assets/Maps/TestMap.tmx
@@ -13,22 +13,22 @@
</layer>
<layer name="Background" width="27" height="36">
<data encoding="base64" compression="gzip">
- H4sIAAAAAAAAC+2WwQ6EMAhE4WLi9v//14tkcYKAW3A9SEI8tOVBm5lIRLQ4WRlSk42s5p1xNO9OVtUdC2s1ksnvBXlRTzMshjrRu1ewPA7u81icXI+yg+Xdz1NYVZlh6ehmcbBuRRfrqna0rrHnK+ueZ6F34D6sgT1nvNKrG+nxFx1bnpk5N+MZ/2R16vhlvawMq/LfTDgdtdF39EyWd8yytHY/e57puZo1mlmDvjMJT5jVLF1/0HG+Lpb+yrt13KGe6a65Ot/Lq1Wt50xslY/NlzAPAAA=
+ H4sIAAAAAAAAC+2WyQ6DMAxE00tQ4dTl0uXSwv9/Y0GKVWuE4wlNeiLSqEJYfkOKh3QhhM5RrbX0Os06rOjcgHUzWPcGrJfBegd/f0u8LLVx1nFFMXB7zPphWN4eixhPHovdY8aTxbqk2qvjRcR4sliPVPt0vIgYTxZrTD0mx4vI8sSwPI3AsjyxrLDRRykrOvfFi6yWLHwP2bq1mpL7ubzC7MA67IGe0Submbl8sWYHZ8sSfpdy+WLNDs6WJfwu5fLFmh2cLUuST5q1dZ7Z2dpZO4th1TqbIav2mVbnjs4XyZaaZ1qdO0u+9EmSLTXPtDp3psQZwjdbMDt+ZcXUv1cakvD9qMHS/Qd13ZKlf/tGLHymfz1Xy/8r16vmLLPrA0o7CMAwDwAA
</data>
</layer>
<layer name="BackgroundScenery" width="27" height="36">
<data encoding="base64" compression="gzip">
- H4sIAAAAAAAAC2NgGP7AGY0eBSMDDOd4dxxoBwwwGOn+HwUDD9DLFULlDDb54Vg2jQIIGC2jRgEtgDMO9nAA9MozA5U3aWnvaHlDewAA85SJ2jAPAAA=
+ H4sIAAAAAAAAC2NgGP7AGY0eBSMDDKZ4r6aQjw4cKXPOkAcD7X9S42sUDD+AXq4QKmewyQ+GsmkU0AYMdBk1CugDKuhoVwMWseFUhiDnGRc62UNPQEt7R8sb2gMAar0UDDAPAAA=
</data>
</layer>
<layer name="Foreground" width="27" height="36">
<data encoding="base64" compression="gzip">
- H4sIAAAAAAAAC+3UQQoAIAhE0dp4/yPXIiFEsFpUwn8wRBAyGysFAHKqPTLO17SL5odOlu20e1fiJHoHACu8/+Uk8zwA+US7fVMDZWyGoTAPAAA=
+ H4sIAAAAAAAAC+3UMQoAIAxD0W519P6ntYso0qJOVvgPMtkhixEBgD9Vi1rK6yIyuvRk6LRaO9XL906d7O4A4IS3L7eZtyzaMQC5Rf/7hQaY8mXYMA8AAA==
</data>
</layer>
<layer name="ForegroundScenery" width="27" height="36">
<data encoding="base64" compression="gzip">
- H4sIAAAAAAAAC2NgGAVDEVRSyCcFVFHIH7WLgaGaAJ+a8UUIUNNfI9UuQvE50MAJikfBKBgFCDCaL0bBKBgFo4C6YKSUqwDmNrHDMA8AAA==
+ H4sIAAAAAAAAC2NgGAVDEVRSyCcFVFHIH7WLMKBmfBEC9PTXcLVrsANXKB4Fo2AUIMBovhgFo2AUjALqgpFSrgIAH1puNjAPAAA=
</data>
</layer>
<layer name="ForegroundScenery2" width="27" height="36">
View
BIN src/Assets/Sprites/Elf/bobbingelf(notranspancy).gif
Deleted file not rendered
View
BIN src/Assets/Sprites/Elf/elf4steptest.gif
Deleted file not rendered
View
BIN src/Assets/Sprites/Elf/elfLeftStatic.png
Deleted file not rendered
View
BIN src/Assets/Sprites/Elf/elfLeftwalking2.gif
Deleted file not rendered
View
BIN src/Assets/Sprites/Elf/elfbacksidle.gif
Deleted file not rendered
View
BIN src/Assets/Sprites/Elf/elfbackstill.png
Deleted file not rendered
View
BIN src/Assets/Sprites/Elf/elfbackwalk.gif
Deleted file not rendered
View
BIN src/Assets/Sprites/Elf/elffrontwalk.png
Deleted file not rendered
View
BIN src/Assets/Sprites/Elf/elfleftidle.png
Deleted file not rendered
View
BIN src/Assets/Tiles/scenery.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN src/Assets/Tiles/terrain.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
128 src/Game/Game.java
@@ -10,42 +10,136 @@
import org.newdawn.slick.tiled.TiledMap;
public class Game extends BasicGame {
- private float playerX=320;
- private float playerY=240;
+ private float playerX=340; //32
+ private float playerY=480; //22
private TiledMap map;
- private Animation player;
+ private Animation sprite, animUp, animDown, animLeft, animRight, animIdleUp, animIdleDown, animIdleLeft, animIdleRight;
+ boolean movingUp;
+ boolean movingDown;
+ boolean movingLeft;
+ boolean movingRight;
+ boolean movedUp;
+ boolean movedDown;
+ boolean movedLeft;
+ boolean movedRight;
+ boolean moving;
public Game() {
super("DorfElf");
}
public void init(GameContainer container) throws SlickException {
container.setVSync(true);
- SpriteSheet sheet = new SpriteSheet("Assets/Sprites/Karbonator.png",32,32);
+ SpriteSheet ssUp = new SpriteSheet("Assets/Sprites/Elf/up.png",16,16);
+ SpriteSheet ssDown = new SpriteSheet("Assets/Sprites/Elf/down.png",16,16);
+ SpriteSheet ssLeft = new SpriteSheet("Assets/Sprites/Elf/left.png",16,16);
+ SpriteSheet ssRight = new SpriteSheet("Assets/Sprites/Elf/right.png",16,16);
+ SpriteSheet ssIdleUp = new SpriteSheet("Assets/Sprites/Elf/idleUp.png",16,16);
+ SpriteSheet ssIdleDown = new SpriteSheet("Assets/Sprites/Elf/idleDown.png",16,16);
+ SpriteSheet ssIdleLeft = new SpriteSheet("Assets/Sprites/Elf/idleLeft.png",16,16);
+ SpriteSheet ssIdleRight = new SpriteSheet("Assets/Sprites/Elf/idleRight.png",16,16);
map = new TiledMap("Assets/Maps/TestMap.tmx");
- player = new Animation();
- player.setAutoUpdate(true);
- for (int frame=0;frame<3;frame++) {
- player.addFrame(sheet.getSprite(frame,0), 150);
-// player.addFrame(Scenery.getSprite(frame,0), 150);
+ animUp = new Animation();
+ animUp.setAutoUpdate(true);
+ for (int frame=0;frame<4;frame++) {
+ animUp.addFrame(ssUp.getSprite(frame,0), 130);
}
+ animDown = new Animation();
+ animDown.setAutoUpdate(true);
+ for (int frame=0;frame<4;frame++) {
+ animDown.addFrame(ssDown.getSprite(frame,0), 130);
+ }
+ animLeft = new Animation();
+ animLeft.setAutoUpdate(true);
+ for (int frame=0;frame<2;frame++) {
+ animLeft.addFrame(ssLeft.getSprite(frame,0), 130);
+ }
+ animRight = new Animation();
+ animRight.setAutoUpdate(true);
+ for (int frame=0;frame<2;frame++) {
+ animRight.addFrame(ssRight.getSprite(frame,0), 130);
+ }
+ animIdleUp = new Animation();
+ animIdleUp.setAutoUpdate(true);
+ for (int frame=0;frame<2;frame++) {
+ animIdleUp.addFrame(ssIdleUp.getSprite(frame,0), 260);
+ }
+ animIdleDown = new Animation();
+ animIdleDown.setAutoUpdate(true);
+ for (int frame=0;frame<2;frame++) {
+ animIdleDown.addFrame(ssIdleDown.getSprite(frame,0), 260);
+ }
+ animIdleLeft = new Animation();
+ animIdleLeft.setAutoUpdate(true);
+ for (int frame=0;frame<1;frame++) {
+ animIdleLeft.addFrame(ssIdleLeft.getSprite(frame,0), 260);
+ }
+ animIdleRight = new Animation();
+ animIdleRight.setAutoUpdate(true);
+ for (int frame=0;frame<1;frame++) {
+ animIdleRight.addFrame(ssIdleRight.getSprite(frame,0), 260);
+ }
+ sprite = animIdleDown;
+ movingUp = false;
+ movingDown = false;
+ movingLeft = false;
+ movingRight = false;
+ moving = false;
+
}
public void update(GameContainer container, int delta) {
- if (container.getInput().isKeyDown(Input.KEY_LEFT)) {playerX--;}
- if (container.getInput().isKeyDown(Input.KEY_RIGHT)) {playerX++;}
- if (container.getInput().isKeyDown(Input.KEY_UP)) {playerY--;}
- if (container.getInput().isKeyDown(Input.KEY_DOWN)) {playerY++;}
+
+ Input input = container.getInput();
+
+ if(input.isKeyDown(Input.KEY_UP)) {moving = true; movingUp = true; movedDown = false; movedLeft = false; movedUp = true; movedRight = false;}
+ else movingUp = false;
+ if(input.isKeyDown(Input.KEY_DOWN)) {moving = true; movingDown = true; movedDown = true; movedLeft = false; movedUp = false; movedRight = false;}
+ else movingDown = false;
+ if(input.isKeyDown(Input.KEY_LEFT)) {moving = true; movingLeft = true; movedDown = false; movedLeft = true; movedUp = false; movedRight = false;}
+ else movingLeft = false;
+ if(input.isKeyDown(Input.KEY_RIGHT)) {moving = true; movingRight = true; movedDown = false; movedLeft = false; movedUp = false; movedRight = true;}
+ else movingRight = false;
+
+ if (movingLeft == false){if(movingRight == false){if(movingUp == false){if(movingDown == false) moving = false;}}}
+
+ if (movingLeft == true) {playerX--; sprite = animLeft;}
+ if (movingRight == true) {playerX++; sprite = animRight;}
+ if (movingUp == true) {playerY--; sprite = animUp;}
+ if (movingDown == true) {playerY++; sprite = animDown;}
+ if (movedDown == true){
+ if (movedRight == false){
+ if(movedUp == false){
+ if (movedLeft == false){
+ if (moving == false)
+ sprite = animIdleDown;}}}}
+ if (movedUp == true){
+ if (movedRight == false){
+ if(movedLeft == false){
+ if (movedDown == false){
+ if (moving == false)
+ sprite = animIdleUp;}}}}
+ if (movedRight == true){
+ if (movedLeft == false){
+ if(movedUp == false){
+ if (movedDown == false){
+ if (moving == false)
+ sprite = animIdleRight;}}}}
+ if (movedLeft == true){
+ if (movedRight == false){
+ if(movedUp == false){
+ if (movedDown == false){
+ if (moving == false)
+ sprite = animIdleLeft;}}}}
}
public void render(GameContainer container, Graphics g) {
map.render(0, 0, 1);
map.render(0, 0, 2);
- g.drawAnimation(player, playerX, playerY);
+ g.drawAnimation(sprite, playerX, playerY);
map.render(0, 0, 3);
map.render(0, 0, 4);
map.render(0, 0, 5);
-// map.render(0, 0, 6);
}
public static void main(String[] argv) throws SlickException {
AppGameContainer container =
- new AppGameContainer(new Game(), 360, 420, false);
+ new AppGameContainer(new Game(), 432, 560, false);
container.start();
}
-}
+}

0 comments on commit 923a003

Please sign in to comment.