-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAxe.java
More file actions
142 lines (119 loc) · 2.59 KB
/
Axe.java
File metadata and controls
142 lines (119 loc) · 2.59 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
//lala lalai lalai lala lai lai
import java.awt.Graphics2D;
import java.awt.Color;
import javax.imageio.ImageIO;
import java.io.IOException;
import java.awt.image.BufferedImage;
import java.awt.Dimension;
import java.awt.Graphics;
import java.security.SecureRandom;
import javax.swing.JPanel;
public class Axe extends Entity{
GamePanel gp;
KeyHandler keyH;
int help;
double v0;
int mx = 27 * 48;
int my = 300;
Monster monster;
public boolean feel = true;
public boolean feel2 = false;
public UI ui;
public Axe (GamePanel gp) {
this.gp = gp;
monster = new Monster(gp);
ui = new UI(gp);
setDefaultValues();
getPlayerImage();
}
public void setDefaultValues() {
x = 100;
y = 299;
speed = 13;
help = 0;
int v = SimpleText.a;
v0 = v;
}
public void getPlayerImage() {
try {
up1 = ImageIO.read(getClass().getResourceAsStream("/axe_up.png"));
down1 = ImageIO.read(getClass().getResourceAsStream("/axe_down.png"));
left1 = ImageIO.read(getClass().getResourceAsStream("/axe_left.png"));
right1 = ImageIO.read(getClass().getResourceAsStream("/axe_right.png"));
} catch (IOException e) {
e.printStackTrace();
}
}
public void update() {
if (y >= 300 || x >= mx) {
help = 4;
if (y < 250)
feel = true;
else if (x < mx - 40) {
feel2 = true;
}
else
feel = false;
return;
}
help++;
if (help == 4)
help = 0;
spriteCounter++;
if (spriteCounter > 10) {
if (spriteNum == 1)
spriteNum = 2;
else
spriteNum = 1;
spriteCounter = 0;
}
x += speed;
double aa = deltaY();
int a2 = (int) aa;
y = a2 + 300;
//System.out.printf("%d %d %d %n", a2, x, y);
}
public void draw(Graphics2D g2) {
/* g2.setColor(Color.white);
g2.fillRect(x, y, gp.tileSize, gp.tileSize);*/
BufferedImage image = null;
switch (help) {
case 0 :
image = up1;
break;
case 1 :
image = down1;
break;
case 2 :
image = left1;
break;
case 3 :
image = right1;
break;
}
if (help == 4) {
if (feel == false)
image = right1;
else if (feel2 == true)
image = right1;
else
image = up1;
}
g2.drawImage(image, x, y, gp.tileSize * 2, gp.tileSize * 2, null);
if (help == 4 && feel == false) {
monster.draw(g2, false);
ui.draw_sad(g2);
}
else if (help == 4) {
ui.draw_happy(g2);
}
}
public double deltaY() {
int rand = SimpleText.r;
double g = 9.8;
double komak = g * (x - 100) * (x - 100);
double a2 = 2 * v0 * v0 * Math.cos(Math.PI/rand) * Math.cos(Math.PI/rand);
double ans = komak / a2 - (x - 100) * Math.tan(Math.PI/rand);
return ans;
}
}