-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLink.java
More file actions
143 lines (126 loc) · 3.15 KB
/
Link.java
File metadata and controls
143 lines (126 loc) · 3.15 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
import java.awt.image.BufferedImage;
import java.awt.Graphics;
/*
* Levi Crider
* 2/9/22
* Legend of Zelda
*
*
*/
public class Link extends Sprite{
//Variables
int prevX;
int prevY;
double speed = 8;
int AnimationNum = 0;
static BufferedImage[] linkImages;
public int direction; //1 is up, 2 is right, 3 is down, 4 is left
Link(){
this.x = 100;
this.y = 100;
w = 55;
h = 70;
prevX = x;
prevY = y;
loadImage();
}
@Override
public boolean update(){
return true;
}
public void getOutOfSprite(Sprite b){
//If he's going right into a brick
if (x + w >= b.x && prevX + w <= b.x){
x = prevX;
}
//If he's going left into a brick
if (x <= b.x + b.w && prevX >= b.x + b.w){
x = prevX;
}
//If his head is in a brick
if(y <= b.y + b.h && prevY >= b.y + b.h){
y = prevY;
}
//If his feet are in a brick
if (y + h >= b.y && prevY + h <= b.y){
y = prevY;
}
}
void savePrev(){
prevX = x;
prevY = y;
}
//Direction stuff for link to throw the boomerang properly
public int getDirection(){
return direction;
}
public void moveUp(){
this.direction = 1;
this.y -= this.speed;
if (this.AnimationNum >= 4){
this.AnimationNum = 0;
}
this.AnimationNum++;
}
public void moveDown(){
//Animating link and setting directions for boomerang
this.direction = 3;
this.y += this.speed;
//Animating the character
if (this.AnimationNum >= 9 || this.AnimationNum < 5){
this.AnimationNum = 5;
}
this.AnimationNum++;
}
public void moveRight(){
//Animating link and setting directions for boomerang
this.direction = 2;
this.x += this.speed;
//Animating the character
if (this.AnimationNum >= 19 || this.AnimationNum < 15){
this.AnimationNum = 15;
}
this.AnimationNum++;
}
public void moveLeft(){
//Animating link and setting directions for boomerang
this.direction = 4;
this.x -= this.speed;
//Animating the character
if (this.AnimationNum >= 14 || this.AnimationNum < 10){
this.AnimationNum = 10;
}
this.AnimationNum++;
}
@Override
void loadImage(){
if (linkImages == null){
linkImages = new BufferedImage[25];
for (int i = 1; i < 25; i++){
String tmp = Integer.toString(i) + ".png";
linkImages[i - 1] = View.loadImage("linkPictures/" + tmp);
}
}
}
@Override
void draw(Graphics g){
g.drawImage(linkImages[AnimationNum], x - View.scrollPositonX, y - View.scrollPositonY, null);
}
@Override
public String toString()
{
return "Link (x,y) = (" + x + ", " + y + ")";
}
@Override
Json Marshal(){
Json ob = Json.newObject();
return ob;
}
@Override
boolean isLink(){
return true;
}
@Override
void Collided(){
}
}