source: lost-haven/main/Model.java@ 8edd04e

Last change on this file since 8edd04e was 8edd04e, checked in by Dmitry Portnoy <dmitry.portnoy@…>, 4 years ago

Make the decompiled game code compile successfully

  • Property mode set to 100644
File size: 2.3 KB
RevLine 
[8edd04e]1package main;
2
3import gamegui.Animation;
4import java.awt.Graphics;
5
6public class Model {
7
8 private Direction dir;
9 private Action action;
10 private Animation[] anims;
11 private boolean death;
12
13 public Model(boolean death) {
14 if (death) {
15 this.anims = new Animation[13];
16 } else {
17 this.anims = new Animation[12];
18 }
19 this.dir = Direction.North;
20 this.action = Action.Walking;
21 this.death = death;
22 }
23
24 public Model(Model copy) {
25 this.dir = copy.dir;
26 this.action = copy.action;
27 if (copy.death) {
28 this.anims = new Animation[13];
29 } else {
30 this.anims = new Animation[12];
31 }
32 for (int x = 0; x < this.anims.length; x++) {
33 this.anims[x] = new Animation(copy.anims[x]);
34 }
35 this.death = copy.death;
36 }
37
38 public boolean hasDeath() {
39 return this.death;
40 }
41
42 public void addAnimation(Direction dir, Action action, Animation anim) {
43 this.anims[getIndex(dir, action)] = anim;
44 }
45
46 public void draw(Graphics g, int x, int y) {
47 if (this.anims[getIndex(this.dir, this.action)] != null) {
48 if (this.action == Action.Attacking && this.anims[getIndex(this.dir, this.action)].reachedEnd()) {
49 this.anims[getIndex(this.dir, this.action)].reset();
50 this.action = Action.Standing;
51 }
52 this.anims[getIndex(this.dir, this.action)].draw(g, x, y);
53 }
54 }
55
56 public int getHeight() {
57 return getAnimation(this.dir, this.action).getHeight();
58 }
59
60 public int getWidth() {
61 return getAnimation(this.dir, this.action).getWidth();
62 }
63
64 private int getIndex(Direction dir, Action action) {
65 int pos = 0;
66 switch (action) {
67 case Walking:
68 pos = 4;
69 break;
70 case Standing:
71 pos = 8;
72 break;
73 }
74 switch (dir) {
75 case South:
76 pos++;
77 break;
78 case East:
79 pos += 2;
80 break;
81 case West:
82 pos += 3;
83 break;
84 }
85 if (action == Action.Dying) {
86 pos = 12;
87 }
88 return pos;
89 }
90
91 public Animation getAnimation(Direction dir, Action action) {
92 return this.anims[getIndex(dir, action)];
93 }
94
95 public Direction getDirection() {
96 return this.dir;
97 }
98
99 public Action getAction() {
100 return this.action;
101 }
102
103 public void setDirection(Direction dir) {
104 this.dir = dir;
105 }
106
107 public void setAction(Action action) {
108 this.action = action;
109 }
110}
Note: See TracBrowser for help on using the repository browser.