summary refs log tree commit diff stats
path: root/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java')
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java157
1 files changed, 157 insertions, 0 deletions
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java new file mode 100644 index 0000000..3bdb9de --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/HeroEvent.java
@@ -0,0 +1,157 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle.gamestate.mapview.event;
7
8import com.fourisland.fourpuzzle.Layer;
9import java.awt.Graphics;
10import java.awt.Point;
11import com.fourisland.fourpuzzle.Direction;
12import com.fourisland.fourpuzzle.Game;
13import com.fourisland.fourpuzzle.GameCharacter;
14import com.fourisland.fourpuzzle.gamestate.mapview.CharSet;
15import com.fourisland.fourpuzzle.NoCharactersInPartyException;
16
17/**
18 *
19 * @author hatkirby
20 */
21public class HeroEvent implements Event {
22
23 public HeroEvent()
24 {
25 location = new Point();
26 }
27
28 public String getLabel()
29 {
30 return "Hero";
31 }
32
33 private Point location;
34 public Point getLocation()
35 {
36 return location;
37 }
38 public void setLocation(Point location)
39 {
40 this.location = location;
41 }
42 public void setLocation(int x, int y)
43 {
44 location.setLocation(x, y);
45 }
46
47 public void render(Graphics g) throws Exception
48 {
49 int x = (location.x * 16) - 4;
50 int y = (location.y * 16) - 16;
51
52 if (moving)
53 {
54 if (moveDirection == Direction.North)
55 {
56 y -= (4 - moveTimer) * 4;
57 } else if (moveDirection == Direction.West)
58 {
59 x -= (4 - moveTimer) * 4;
60 } else if (moveDirection == Direction.South)
61 {
62 y += (4 - moveTimer) * 4;
63 } else if (moveDirection == Direction.East)
64 {
65 x += (4 - moveTimer) * 4;
66 }
67 }
68
69 try
70 {
71 GameCharacter toDraw = Game.getSaveFile().getParty().getLeader();
72 if (!toDraw.getGraphic().equals("blank"))
73 {
74 g.drawImage(CharSet.getCharSet(toDraw.getGraphic()).getImage(toDraw.getGraphicOffset(), direction, animationStep), x, y, null);
75 }
76 } catch (NoCharactersInPartyException ex)
77 {
78 }
79 }
80
81
82 private boolean moving = false;
83 public boolean isMoving()
84 {
85 return moving;
86 }
87 public void setMoving(boolean moving)
88 {
89 this.moving = moving;
90 }
91
92 private int moveTimer;
93 private Direction moveDirection;
94 public void startMoving(Direction toMove) throws Exception
95 {
96 setDirection(toMove);
97 setAnimationStep(2);
98 moveTimer = 4;
99 moving = true;
100 moveDirection = toMove;
101 }
102 public void processMoving() throws Exception
103 {
104 if (moving)
105 {
106 moveTimer--;
107 if (moveTimer == 2)
108 {
109 setAnimationStep(0);
110 } else if (moveTimer == 0)
111 {
112 setAnimationStep(1);
113 moving = false;
114
115 if (moveDirection == Direction.North)
116 {
117 setLocation(getLocation().x,getLocation().y-1);
118 } else if (moveDirection == Direction.West)
119 {
120 setLocation(getLocation().x-1,getLocation().y);
121 } else if (moveDirection == Direction.South)
122 {
123 setLocation(getLocation().x,getLocation().y+1);
124 } else if (moveDirection == Direction.East)
125 {
126 setLocation(getLocation().x+1,getLocation().y);
127 }
128 }
129 }
130 }
131
132 private Direction direction = Direction.South;
133 public Direction getDirection()
134 {
135 return direction;
136 }
137 public void setDirection(Direction direction)
138 {
139 this.direction = direction;
140 }
141
142 private int animationStep = 1;
143 public int getAnimationStep()
144 {
145 return animationStep;
146 }
147 public void setAnimationStep(int animationStep)
148 {
149 this.animationStep = animationStep;
150 }
151
152 public Layer getLayer() throws Exception
153 {
154 return Layer.Middle;
155 }
156
157}