-
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.
- Loading branch information
Robert Wolfinger
committed
Oct 12, 2015
1 parent
97440ba
commit 954e79b
Showing
8 changed files
with
178 additions
and
95 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
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
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
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
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
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,66 +1,70 @@ | ||
package de.dungeonrunner; | ||
|
||
import java.util.List; | ||
import java.util.Properties; | ||
|
||
import org.jsfml.graphics.FloatRect; | ||
import org.jsfml.graphics.IntRect; | ||
import org.jsfml.graphics.RenderStates; | ||
import org.jsfml.graphics.RenderTarget; | ||
import org.jsfml.system.Time; | ||
import org.jsfml.system.Vector2f; | ||
import org.jsfml.system.Vector2i; | ||
|
||
import de.dungeonrunner.TextureHolder.TextureID; | ||
import tiled.core.Map; | ||
import tiled.core.Tile; | ||
|
||
public class PlayerEntity extends GameEntity { | ||
|
||
private Animation mIdleAnimation; | ||
|
||
public PlayerEntity(TextureID textureID) { | ||
mProperties.setProperty("BlockVolume", "true"); | ||
mIdleAnimation = new Animation(textureID); | ||
mIdleAnimation.setDuration(Time.getMilliseconds(900)); | ||
mIdleAnimation.setRepeat(true); | ||
mIdleAnimation.setNumFrames(6); | ||
mIdleAnimation.setFrameSize(new Vector2i(128, 128)); | ||
setVelocity(new Vector2f(100f, 0)); | ||
|
||
Map map = TmxMapLoader.getMap(); | ||
System.out.println(map.getBounds()); | ||
// checkCollision(); | ||
setPosition(20f, 0f); | ||
mIdleAnimation.setPosition(getPosition()); | ||
setVelocity(new Vector2f(10f, 0f)); | ||
} | ||
|
||
@Override | ||
protected void drawCurrent(RenderTarget target, RenderStates states) { | ||
mIdleAnimation.draw(target, states); | ||
super.drawCurrent(target, states); | ||
} | ||
|
||
@Override | ||
protected void updateCurrent(Time dt) { | ||
super.updateCurrent(dt); | ||
mIdleAnimation.setPosition(getPosition()); | ||
mIdleAnimation.move(Vector2f.mul(getVelocity(), dt.asSeconds())); | ||
mIdleAnimation.update(dt); | ||
System.out.println(getBoundingRect()); | ||
} | ||
|
||
// protected void checkCollision(){ | ||
// Properties propsLeftTop = TmxMapLoader.getTileInstancePropertiesAt((int) (getPosition().x + get, (int) getPosition().y); | ||
// getTransform(). | ||
// Properties propsLeftBottom = TmxMapLoader.getTileInstancePropertiesAt((int) getPosition().x, (int) getPosition().y); | ||
// Properties propsRightTop = TmxMapLoader.getTileInstancePropertiesAt((int) getPosition().x, (int) getPosition().y); | ||
// Properties propsRightBottom = TmxMapLoader.getTileInstancePropertiesAt((int) getPosition().x, (int) getPosition().y); | ||
// | ||
// boolean isBlocking = Boolean.valueOf(props.getProperty("BlockVolume", "false")); | ||
// if(isBlocking) | ||
// } | ||
// | ||
public FloatRect getBoundingRect(){ | ||
|
||
public FloatRect getBoundingRect() { | ||
return getWorldTransform().transformRect(mIdleAnimation.getGlobalBounds()); | ||
} | ||
// | ||
// private void setCollisionRectangle(int left, int top, int width, int height){ | ||
// mCollisionRectangle = new IntRect(left, top, width, height); | ||
// } | ||
|
||
@Override | ||
protected void onCollision(SceneNode node) { | ||
FloatRect boundsNode = node.getBoundingRect(); | ||
FloatRect playerRect = getBoundingRect(); | ||
|
||
float left, top; | ||
left = playerRect.left; | ||
top = playerRect.top; | ||
|
||
if(playerRect.left + playerRect.width > boundsNode.left){ | ||
left = boundsNode.left - boundsNode.width; | ||
|
||
} else if(playerRect.left < boundsNode.left + boundsNode.width){ | ||
left = boundsNode.left + boundsNode.width; | ||
} | ||
|
||
if(playerRect.top < boundsNode.top + boundsNode.height){ | ||
top = boundsNode.top + boundsNode.height; | ||
} else if(playerRect.top + playerRect.height > boundsNode.top){ | ||
top = boundsNode.top - playerRect.height; | ||
} | ||
mIdleAnimation.setPosition(left, top); | ||
|
||
//Check movement collision | ||
|
||
} | ||
} |
Oops, something went wrong.