-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working on animations, resources and the architecture
- Loading branch information
Robert Wolfinger
committed
Oct 10, 2015
1 parent
682749d
commit 253a10b
Showing
15 changed files
with
501 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<map version="1.0" orientation="orthogonal" renderorder="right-down" width="10" height="10" tilewidth="64" tileheight="64" nextobjectid="1"> | ||
<tileset firstgid="1" name="Test" tilewidth="64" tileheight="64" tilecount="72"> | ||
<image source="Tileset.png" width="512" height="576"/> | ||
<tile id="34"> | ||
<properties> | ||
<property name="BlockVolume" value="true"/> | ||
</properties> | ||
</tile> | ||
<tile id="35"> | ||
<properties> | ||
<property name="BlockVolume" value="true"/> | ||
</properties> | ||
</tile> | ||
</tileset> | ||
<layer name="Kachelebene 1" width="10" height="10"> | ||
<data encoding="base64" compression="zlib"> | ||
eJzjZGBg4BzFgwYDAMfWA4U= | ||
</data> | ||
</layer> | ||
<layer name="Kachelebene 2" width="10" height="10"> | ||
<data encoding="base64" compression="zlib"> | ||
eJxjYCAOKBKhRnWEq1PBwQap0wRiZQJYF4gB6dsD5w== | ||
</data> | ||
</layer> | ||
</map> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<tileset name="Tileset" tilewidth="64" tileheight="64"> | ||
<image source="Tileset.png" width="512" height="576"/> | ||
</tileset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<map version="1.0" orientation="orthogonal" renderorder="right-down" width="23" height="12" tilewidth="64" tileheight="64" nextobjectid="1"> | ||
<tileset firstgid="1" source="Tileset.tsx"/> | ||
<layer name="background" width="23" height="12"> | ||
<data encoding="base64" compression="zlib"> | ||
eJy1kjEOwCAIRVkdHBw8SFPtCXr/MzUkkv4QoDj0Jy82QvELEv2nExhq1ej9EfzLKg4NvmuQ50GrBjOhpkUNYlaOiGteCS9zIy6+79WnyHdb52fjom54OMieZzYuvju9s8MV0XvFyZO+R76zYE0t9P3l1cPrkWjnPWRzM+/Bm5vg3ecB/PEU2A== | ||
</data> | ||
</layer> | ||
<layer name="foreground" width="23" height="12"> | ||
<data encoding="base64" compression="zlib"> | ||
eJy1ks0KwkAMhKOgh9qTerGtPdgqaKl3fyoo+P6v5CxuaAipbqkufITNJNOlSUFEFSgElZGTmhV1752+nzKgxjrzgJrNAO+ZZ23oETiAuKM/Ev26xnk/6P1/aqWtQAIWIDO+z3rqyZTuvJcdb9pTOxem7qF/8h56/uHNs/+l9wmcwcXHpKf3CIzBBEwNPVeRd0Ci95HfdKV2bo3P3UTdTkW3Y6nA3bfgqSgDckcVX5aAEa8= | ||
</data> | ||
</layer> | ||
<layer name="objects" width="23" height="12"> | ||
<data encoding="base64" compression="zlib"> | ||
eJxjYKAd4EDj65OpF90cSt1BKhCgUD8+IEFl80BhrI7FbHYcbGLlkc1HN5uQe0gF1A4TZKAApd2A2B0Je2BRS2y64afQTep45MQpNBtb+MPil1KzsQEAeaoDtQ== | ||
</data> | ||
</layer> | ||
</map> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package de.dungeonrunner; | ||
|
||
import org.jsfml.graphics.Drawable; | ||
import org.jsfml.graphics.IntRect; | ||
import org.jsfml.graphics.RenderStates; | ||
import org.jsfml.graphics.RenderTarget; | ||
import org.jsfml.graphics.Sprite; | ||
import org.jsfml.system.Time; | ||
import org.jsfml.system.Vector2i; | ||
|
||
import de.dungeonrunner.TextureHolder.TextureID; | ||
|
||
public class Animation implements Drawable { | ||
|
||
private Sprite mSprite; | ||
private Vector2i mFrameSize; | ||
private int mNumFrames; | ||
private int mCurrentFrame; | ||
private Time mDuration; | ||
private Time mElapsedTime; | ||
private boolean mRepeat; | ||
|
||
public Animation(TextureID textureID) { | ||
mSprite = new Sprite(TextureHolder.getInstance().getTexture(textureID)); | ||
mElapsedTime = Time.ZERO; | ||
} | ||
|
||
public void update(Time dt) { | ||
Time timePerFrame = Time.div(mDuration, (float) mNumFrames); | ||
mElapsedTime = Time.add(mElapsedTime, dt); | ||
|
||
Vector2i textureBounds = mSprite.getTexture().getSize(); | ||
IntRect textureRect = mSprite.getTextureRect(); | ||
if (mCurrentFrame == 0) { | ||
textureRect = new IntRect(0, 0, mFrameSize.x, mFrameSize.y); | ||
} | ||
while (mElapsedTime.asMilliseconds() >= timePerFrame.asMilliseconds() | ||
&& (mCurrentFrame <= mNumFrames || mRepeat)) { | ||
int textureLeft = textureRect.left + textureRect.width; | ||
|
||
if(textureLeft + textureRect.width > textureBounds.x){ | ||
textureRect = new IntRect(0, 0, mFrameSize.x, mFrameSize.y); | ||
} else { | ||
textureRect = new IntRect(textureLeft, textureRect.top, textureRect.width, textureRect.height); | ||
} | ||
|
||
mElapsedTime = Time.sub(mElapsedTime, timePerFrame); | ||
if (mRepeat) { | ||
mCurrentFrame++; | ||
if(mCurrentFrame > mNumFrames){ | ||
mCurrentFrame = 0; | ||
textureRect = new IntRect(0, 0, mFrameSize.x, mFrameSize.y); | ||
} | ||
} | ||
} | ||
|
||
mSprite.setTextureRect(textureRect); | ||
} | ||
|
||
@Override | ||
public void draw(RenderTarget target, RenderStates states) { | ||
target.draw(mSprite); | ||
} | ||
|
||
public Vector2i getFrameSize() { | ||
return mFrameSize; | ||
} | ||
|
||
public void setFrameSize(Vector2i frameSize) { | ||
mFrameSize = frameSize; | ||
} | ||
|
||
public int getNumFrames() { | ||
return mNumFrames; | ||
} | ||
|
||
public void setNumFrames(int numFrames) { | ||
mNumFrames = numFrames; | ||
} | ||
|
||
public Time getDuration() { | ||
return mDuration; | ||
} | ||
|
||
public void setDuration(Time duration) { | ||
mDuration = duration; | ||
} | ||
|
||
public boolean isRepeat() { | ||
return mRepeat; | ||
} | ||
|
||
public void setRepeat(boolean repeat) { | ||
mRepeat = repeat; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,99 @@ | ||
package de.dungeonrunner; | ||
|
||
import org.jsfml.graphics.RenderWindow; | ||
import org.jsfml.graphics.View; | ||
import org.jsfml.system.Vector2f; | ||
import org.jsfml.system.Clock; | ||
import org.jsfml.system.Time; | ||
import org.jsfml.window.VideoMode; | ||
import org.jsfml.window.event.Event; | ||
|
||
import tiled.core.Map; | ||
|
||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
Map map = null; | ||
SFMLTileRenderer renderer = null; | ||
private final Time FPS = Time.getSeconds(1.0f / 60.0f); | ||
private RenderWindow mRenderWindow; | ||
private Clock mClock; | ||
private GameWorld mGameWorld; | ||
|
||
for (String arg : args) { | ||
map = TmxMapLoader.loadMap(arg); | ||
} | ||
public Application() { | ||
mRenderWindow = new RenderWindow(); | ||
mRenderWindow.create(new VideoMode(800, 480, 32), "DungeonRunner"); | ||
mRenderWindow.setFramerateLimit(30); | ||
|
||
mGameWorld = new GameWorld(mRenderWindow); | ||
|
||
if (map != null) { | ||
TextureHolder.getInstance().loadTiledTextures(map); | ||
renderer = new SFMLTileRenderer(map); | ||
} | ||
mClock = new Clock(); | ||
|
||
RenderWindow window = new RenderWindow(); | ||
window.create(new VideoMode(800, 480, 32), "Test"); | ||
window.setFramerateLimit(30); | ||
|
||
View view = new View(new Vector2f(window.getSize().x / 2, window.getSize().y / 2), new Vector2f(window.getSize())); | ||
window.setView(view); | ||
|
||
while (window.isOpen()) { | ||
for (Event event : window.pollEvents()) { | ||
|
||
switch(event.type){ | ||
case CLOSED: | ||
window.close(); | ||
break; | ||
case RESIZED: | ||
view= new View(new Vector2f(window.getSize().x / 2, window.getSize().y / 2), new Vector2f(window.getSize())); | ||
window.setView(view); | ||
break; | ||
case KEY_PRESSED: | ||
view.move(new Vector2f(10, 0)); | ||
window.setView(view); | ||
default: | ||
break; | ||
} | ||
} | ||
} | ||
|
||
window.clear(); | ||
if (renderer != null) { | ||
window.draw(renderer); | ||
public void run() { | ||
Time timeSinceLastUpdate = Time.ZERO; | ||
while (mRenderWindow.isOpen()) { | ||
timeSinceLastUpdate = Time.add(timeSinceLastUpdate, mClock.restart()); | ||
while (timeSinceLastUpdate.asMicroseconds() > FPS.asMilliseconds()) { | ||
timeSinceLastUpdate = Time.sub(timeSinceLastUpdate, FPS); | ||
processEvents(); | ||
update(FPS); | ||
} | ||
window.display(); | ||
render(); | ||
} | ||
} | ||
|
||
private void processEvents() { | ||
for (Event event : mRenderWindow.pollEvents()) | ||
if (event.type == Event.Type.CLOSED) { | ||
mRenderWindow.close(); | ||
} | ||
} | ||
|
||
private void update(Time fPS2) { | ||
mGameWorld.update(fPS2); | ||
|
||
} | ||
|
||
private void render() { | ||
mRenderWindow.clear(); | ||
mGameWorld.draw(); | ||
mRenderWindow.display(); | ||
|
||
} | ||
|
||
public static void main(String[] args) { | ||
|
||
Application application = new Application(); | ||
application.run(); | ||
// GameWorld world = new GameWorld(window); | ||
|
||
// while (window.isOpen()) { | ||
// window.clear(); | ||
// // world.draw(); | ||
// window.display(); | ||
// } | ||
|
||
// while (window.isOpen()) { | ||
// for (Event event : window.pollEvents()) { | ||
// | ||
// switch (event.type) { | ||
// case CLOSED: | ||
// window.close(); | ||
// break; | ||
// case RESIZED: | ||
// view = new View(new Vector2f(window.getSize().x / 2, | ||
// window.getSize().y / 2), | ||
// new Vector2f(window.getSize())); | ||
// window.setView(view); | ||
// break; | ||
// case KEY_PRESSED: | ||
// view.move(new Vector2f(10, 0)); | ||
// window.setView(view); | ||
// default: | ||
// break; | ||
// } | ||
// } | ||
// | ||
// window.clear(); | ||
// | ||
// window.draw(playerEntity); | ||
// window.display(); | ||
// } | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package de.dungeonrunner; | ||
|
||
import java.io.File; | ||
|
||
public class Constants { | ||
|
||
public static final String ROOT_DIR = System.getProperty("user.dir") + File.separator; | ||
public static final String RES_DIR = ROOT_DIR + "resources" + File.separator; | ||
public static final String MAP_DIR = RES_DIR + "maps" + File.separator; | ||
public static final String ANIM_DIR = RES_DIR + "textures" + File.separator + "animations" + File.separator; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package de.dungeonrunner; | ||
|
||
import org.jsfml.system.Time; | ||
import org.jsfml.system.Vector2f; | ||
|
||
public abstract class GameEntity extends SceneNode { | ||
|
||
private Vector2f mVelocity; | ||
|
||
public GameEntity() { | ||
mVelocity = Vector2f.ZERO; | ||
} | ||
|
||
public void setVelocity(Vector2f velocity) { | ||
mVelocity = velocity; | ||
} | ||
|
||
public void setVelocity(float vx, float vy) { | ||
mVelocity = new Vector2f(vx, vy); | ||
} | ||
|
||
public Vector2f getVelocity() { | ||
return mVelocity; | ||
} | ||
|
||
@Override | ||
protected void updateCurrent(Time dt) { | ||
move(Vector2f.mul(mVelocity, dt.asSeconds())); | ||
} | ||
} |
Oops, something went wrong.