Skip to content
Browse files

Deprecated Position, fixes #8 Using java.awt.Point

  • Loading branch information...
1 parent ba19b25 commit 52145b83551acdac4c8ad1a84394fc41a66cc331 @johanbrook committed
View
11 src/gui/Actor.java
@@ -5,6 +5,7 @@
import graphics.bitmap.BitmapTool;
import java.awt.Color;
+import java.awt.Point;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
import java.io.File;
@@ -19,12 +20,12 @@
public class Actor {
- private Position position;
+ private Point position;
private Bitmap[] animationFrames;
private Bitmap currentFrame;
- public Actor(Position startingPosition) {
- this.position = new Position(startingPosition);
+ public Actor(Point startingPosition) {
+ this.position = new Point(startingPosition);
animationFrames = new Bitmap[8];
try {
@@ -91,7 +92,7 @@ public Bitmap getCurrentFrame() {
}
- public Position getPosition() {
+ public Point getPosition() {
return this.position;
}
public void setDirection(Direction direction)
@@ -124,7 +125,7 @@ public void setDirection(Direction direction)
}
}
- public void setPosition(Position pos) {
+ public void setPosition(Point pos) {
this.position = pos;
}
}
View
3 src/gui/ViewController.java
@@ -10,6 +10,7 @@
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
+import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.KeyListener;
import java.awt.image.BufferStrategy;
@@ -84,7 +85,7 @@ public ViewController(KeyListener listener, int screenWidth, int screenHeight) {
}
private void initScene() {
- this.player = new Actor(new Position(SCREEN_WIDTH / 2,
+ this.player = new Actor(new Point(SCREEN_WIDTH / 2,
SCREEN_HEIGHT / 2));
try {
this.gameMap = new TileMap("rec/images/levels/l3.bmp");
View
13 src/model/CollidableObject.java
@@ -1,6 +1,7 @@
package model;
import java.awt.Dimension;
+import java.awt.Point;
import java.awt.Rectangle;
/**
@@ -51,12 +52,12 @@ public Dimension getSize() {
*
* @return The position
*/
- public Position getPosition(){
+ public Point getPosition(){
int x = this.collisionBox.x - xoffset;
int y = this.collisionBox.y - yoffset;
- return new Position(x, y);
+ return new Point(x, y);
}
/**
@@ -64,10 +65,10 @@ public Position getPosition(){
*
* @param pos The position
*/
- public void setPosition(Position pos){
+ public void setPosition(Point pos){
- this.collisionBox.x = pos.getX() + this.xoffset;
- this.collisionBox.y = pos.getY() + this.yoffset;
+ this.collisionBox.x = pos.x + this.xoffset;
+ this.collisionBox.y = pos.y + this.yoffset;
}
/**
@@ -79,7 +80,7 @@ public void setPosition(Position pos){
public void setPosition(int x, int y) {
this.collisionBox.x = x + this.xoffset;
- this.collisionBox.y = y + this.yoffset;
+ this.collisionBox.y = y + this.yoffset;
}
View
10 src/model/Entity.java
@@ -1,5 +1,7 @@
package model;
+import java.awt.Point;
+
import constants.Direction;
import event.Event;
import event.EventBus;
@@ -46,14 +48,12 @@ public void move(double dt) {
// Upper left corner is origin
if(isMoving()){
- Position currPos = getPosition();
+ Point currPos = getPosition();
EventBus.INSTANCE.publish(new Event(Property.DID_MOVE, this));
int x = (int) (this.direction.getXRatio() * (double) this.movementSpeed * dt);
int y = (int) (this.direction.getYRatio() * (double) this.movementSpeed * dt);
-
- System.out.println(this.movementSpeed + "\t" + dt);
-
- this.setPosition(currPos.getX() + x, currPos.getY() + y);
+
+ this.setPosition(currPos.x + x, currPos.y + y);
}
}
View
8 src/model/Position.java
@@ -1,11 +1,11 @@
+package model;
+
/**
-* Position.java
+* Position
*
* @author Johan
+* @deprecated Using java.awt.Point instead (2012-03-29)
*/
-
-package model;
-
public class Position {
private final int x;
View
4 test/model/TestCollidableObject.java
@@ -46,12 +46,14 @@ public void testIsNotColliding() {
@Test
public void testCharacterCollision() {
Character player = new Player();
+ int playerSpeed = player.getMovementSpeed();
+
player.setDirection(Direction.EAST);
player.move(1.0);
player.setDirection(Direction.SOUTH);
player.move(1.0);
- this.obj.setPosition(15, 10);
+ this.obj.setPosition(1*playerSpeed, 1*playerSpeed);
assertTrue(this.obj.isColliding(player));
}
View
20 test/usecase/TestCharacterMove.java
@@ -8,6 +8,8 @@
import static org.junit.Assert.*;
+import java.awt.Point;
+
import model.character.*;
import model.character.Character;
@@ -37,7 +39,7 @@ public void setUp() throws Exception {
@Test
public void testMoveNull(){
- assertEquals(new Position(0,0), this.player.getPosition());
+ assertEquals(new Point(0,0), this.player.getPosition());
}
@@ -46,7 +48,7 @@ public void testMoveNorth() {
this.player.setDirection(constants.Direction.NORTH);
this.player.move(DELTA);
- assertEquals(new Position(0, -this.playerMovement), this.player.getPosition());
+ assertEquals(new Point(0, -this.playerMovement), this.player.getPosition());
}
@@ -55,7 +57,7 @@ public void testMoveSouth() {
this.player.setDirection(constants.Direction.SOUTH);
this.player.move(DELTA);
- assertEquals(new Position(0, this.playerMovement), this.player.getPosition());
+ assertEquals(new Point(0, this.playerMovement), this.player.getPosition());
}
@Test
@@ -63,7 +65,7 @@ public void testMoveEast() {
this.player.setDirection(constants.Direction.EAST);
this.player.move(DELTA);
- assertEquals(new Position(this.playerMovement,0), this.player.getPosition());
+ assertEquals(new Point(this.playerMovement,0), this.player.getPosition());
}
@Test
@@ -71,7 +73,7 @@ public void testMoveWest() {
this.player.setDirection(constants.Direction.WEST);
this.player.move(DELTA);
- assertEquals(new Position(-this.playerMovement,0), this.player.getPosition());
+ assertEquals(new Point(-this.playerMovement,0), this.player.getPosition());
}
@Test
@@ -81,7 +83,7 @@ public void testMoveNorthWest() {
int xmovement = (int) (Direction.NORTH_WEST.getXRatio() * this.playerMovement);
int ymovement = (int) (Direction.NORTH_WEST.getYRatio() * this.playerMovement);
- assertEquals(new Position(xmovement, ymovement), this.player.getPosition());
+ assertEquals(new Point(xmovement, ymovement), this.player.getPosition());
}
@Test
@@ -92,7 +94,7 @@ public void testMoveNorthEast() {
int xmovement = (int) (Direction.NORTH_EAST.getXRatio() * this.playerMovement);
int ymovement = (int) (Direction.NORTH_EAST.getYRatio() * this.playerMovement);
- assertEquals(new Position(xmovement, ymovement), this.player.getPosition());
+ assertEquals(new Point(xmovement, ymovement), this.player.getPosition());
}
@Test
@@ -103,7 +105,7 @@ public void testMoveSouthWest() {
int xmovement = (int) (Direction.SOUTH_WEST.getXRatio() * this.playerMovement);
int ymovement = (int) (Direction.SOUTH_WEST.getYRatio() * this.playerMovement);
- assertEquals(new Position(xmovement, ymovement), this.player.getPosition());
+ assertEquals(new Point(xmovement, ymovement), this.player.getPosition());
}
@Test
@@ -114,6 +116,6 @@ public void testMoveSouthEast() {
int xmovement = (int) (Direction.SOUTH_EAST.getXRatio() * this.playerMovement);
int ymovement = (int) (Direction.SOUTH_EAST.getYRatio() * this.playerMovement);
- assertEquals(new Position(xmovement, ymovement), this.player.getPosition());
+ assertEquals(new Point(xmovement, ymovement), this.player.getPosition());
}
}

0 comments on commit 52145b8

Please sign in to comment.
Something went wrong with that request. Please try again.