-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
176 lines (153 loc) · 4.66 KB
/
Copy pathPlayer.java
File metadata and controls
176 lines (153 loc) · 4.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package GameObjects;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
/**
* Created by Shadilan on 07.10.2015.
*/
public class Player implements GameObject {
Image img;
Graphics graphics;
int X;
int Y;
int Width;
int Height;
int Life;
int Energy;
int Power;
Image StatView;
ArrayList<Spirit> Spirits;
public Image drawStat(){
StatView=new BufferedImage(100,100,BufferedImage.TYPE_INT_ARGB);
Graphics gr=StatView.getGraphics();
gr.clearRect(0, 0, 100, 100);
gr.setColor(Color.white);
gr.drawString("Life:", 5, 10);
gr.drawString("Energy:",5,20);
gr.drawString("Power:",5,30);
gr.drawString("Spirits:",5,40);
gr.drawString(""+Life,50,10);
gr.drawString(""+Energy,50,20);
gr.drawString(""+Power,50,30);
gr.drawString("" + Spirits.size(), 50, 40);
return StatView;
}
public Player(int x,int y){
Width=40;
Height=40;
X=x;
Y=y;
Life=20;
Energy=20;
Power=0;
img=new BufferedImage(40,40,BufferedImage.TYPE_INT_ARGB);
graphics = img.getGraphics();
graphics.setColor(Color.white);
//graphics.clearRect(0, 0, Width, Height);
double rnd=Math.random();
int www=(int) rnd*Width;
int hhh=(int) rnd*Height;
graphics.setColor(Color.white);
graphics.drawOval(0, 0, Width - 1, Height - 1);
Spirits=new ArrayList<Spirit>();
}
public void Move(int xcoord,int ycoord){
X+=xcoord;
Y+=ycoord;
}
@Override
public Image draw() {
return img;
}
@Override
public int GetX() {
return X;
}
@Override
public int GetY() {
return Y;
}
@Override
public int GetWidth() {
return Width;
}
@Override
public int GetHeight() {
return Height;
}
@Override
public int GetRadius() {
return 20;
}
@Override
public void Tick(World world) {
/* Graphics graphics = img.getGraphics();
graphics.setColor(Color.WHITE);
graphics.clearRect(0, 0, Width, Height);
double rnd=Math.random();
int www=(int) rnd*Width;
int hhh=(int) rnd*Height;
graphics.setColor(Color.BLACK);
graphics.drawOval(0,0,Width,Height);
graphics.drawLine(www,0,Width-www,Height);
graphics.drawLine(0,hhh,Width,Height-hhh);*/
}
@Override
public void destroy(World world) {
}
@Override
public void Action(World world, GameObject actor) {
}
@Override
public String GetType() {
return "Player";
}
public void Act(World world){
System.out.println("Act");
ArrayList<GameObject> Intersects=world.getObject(X,Y,GetRadius());
GameObject Target=null;
for (GameObject obj:Intersects){
if (obj!=this){
Target=obj;
break;
}
}
if (Target!=null) {
System.out.println("Target Take");
if (Target.GetType().equals("Anomaly")) {
System.out.println("Anomaly");
if (((Anomaly)Target).GetOwner()!=this && Life>=5) {
Life -= 5;
Energy += 5;
}
} else if (Target.GetType().equals("Spirit")) {
System.out.println("Spirit");
if (((Spirit)Target).GetOwner()!=null) {
System.out.println("Owner not NULL");
if (((Anomaly)((Spirit)Target).GetOwner()).GetOwner()==null) {
System.out.println("Anomaly owner NULL");
if (Spirits.size()<Power/10+10) {
System.out.println("We have Energy to catch");
((Anomaly) ((Spirit) Target).GetOwner()).RemoveSpirit((Spirit) Target);
((Spirit) Target).SetOwner(this);
world.RemoveObject(Target);
Spirits.add((Spirit) Target);
Energy-=5;
}
}
} else
{
System.out.println("Spirit owner NULL");
if (Spirits.size()<Power/10+10) {
System.out.println("We have Energy to catch");
((Spirit) Target).SetOwner(this);
world.RemoveObject(Target);
Spirits.add((Spirit) Target);
Energy-=5;
}
}
}
;
}
}
}