1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package erland.game.tileadventure;
20
21 public class MoveAction extends Action {
22 private Vector3D direction;
23
24 public static final Vector3D WEST = new Vector3D(-0.04f,0,0);
25 public static final Vector3D EAST = new Vector3D(0.04f,0,0);
26 public static final Vector3D NORTH = new Vector3D(0,-0.04f,0);
27 public static final Vector3D SOUTH = new Vector3D(0,0.04f,0);
28 public static final Vector3D UP = new Vector3D(0,0,0.04f);
29 public static final Vector3D DOWN = new Vector3D(0,0,-0.04f);
30
31 public static final Vector3D NONE = new Vector3D(0,0,0);
32
33 public MoveAction(ControllerInterface controller, Vector3D direction) {
34 this.direction = direction;
35 setController(controller);
36 }
37
38 public void start() {
39 super.start();
40 getController().getControlledObject().setMoveVector(direction);
41 }
42
43 public void stop() {
44 super.stop();
45 getController().getControlledObject().setMoveVector(NONE);
46 }
47
48 public boolean perform() {
49 GameObject o = getController().getControlledObject();
50 if(o.getMoveVector().getLength()>0) {
51 float x = o.getPosX()+direction.getX();
52 float y = o.getPosY()+direction.getY();
53 float z = o.getPosZ()+direction.getZ();
54 if(o.getActionMap().move(o,x,y,z)) {
55 return false;
56 }else {
57 return true;
58 }
59 }
60 return true;
61 }
62 }