-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFireBall.java
More file actions
executable file
·129 lines (99 loc) · 3.31 KB
/
Copy pathFireBall.java
File metadata and controls
executable file
·129 lines (99 loc) · 3.31 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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.awt.image.*;
import java.awt.Image;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.lang.Math;
public class FireBall extends Actor
{
static GreenfootImage[] images=null;
int imageIndex = 7;
static{
images = new GreenfootImage[8];
images[0] = new GreenfootImage("ball.png");
BufferedImage master = images[0].getAwtImage();
int rad = 15;
for(int i = 1; i < 8; i++)
{
rad -= 1;
images[i] = new GreenfootImage(rad,rad);
BufferedImage bi = images[i].getAwtImage();
Graphics2D g = (Graphics2D)bi.getGraphics();
g.drawImage(master,0,0,rad,rad,null);
}
}
public static enum State {FLYING,
DYING,NAN}
State playerState = State.NAN;
Platform landedon = null;
v2 pos = new v2();
v2 velocity = new v2();
v2 gravityv = new v2(0.0,100);
int picindex = 0;
long picStartTime = System.currentTimeMillis();
public long timeStart = -1;
public long timeEnd = -1;
public int millsPassed = 0;
public double timeDelta = 0.0;
int pingIndex = 0;
public FireBall()
{
}
public void act()
{
if(timeStart < 0)
{
timeStart = System.currentTimeMillis();
}
imageIndex = (int)(-velocity.y / 50);
if (imageIndex > 7)
{
imageIndex = 7;
}
if(imageIndex < 0)
{
imageIndex = 0;
}
//System.out.println("Image Index " + imageIndex);
timeEnd = System.currentTimeMillis();
millsPassed = (int)(timeEnd - timeStart);
timeDelta = (double)millsPassed/1000.0;
if(timeDelta > 0.066)
{
timeDelta = 0.066;
}
timeStart = System.currentTimeMillis();
v2 Acceleration = gravityv;
long endTime = System.currentTimeMillis();
long picStTime = System.currentTimeMillis();
velocity = velocity.Add(Acceleration.Scale(timeDelta));
v2 PlayerDelta = velocity.Scale(timeDelta).Add(Acceleration.Scale(timeDelta * timeDelta * 0.5f));
//Rocks have less drag
v2 minusvelocity = new v2(-velocity.x,-velocity.y);
velocity = velocity.Add(minusvelocity.Scale(0.95 * timeDelta));
pos = pos.Add(PlayerDelta.Scale(1.0f));
setImage(images[imageIndex]);
//put smoke in old location
Smoke smoke = new Smoke();
getWorld().addObject(smoke,getX(),getY());
smoke = new Smoke();
getWorld().addObject(smoke,getX() + Greenfoot.getRandomNumber(15) - 7,getY() + Greenfoot.getRandomNumber(15) - 7);
setLocation((int)pos.x,(int)pos.y);
if(velocity.y > 30)
{
int x = getX();
int y = getY();
LavaRock lr = new LavaRock();
getWorld().addObject(lr,x,y);
getWorld().removeObject(this);
lr.velocity = velocity;
return;
}
}
@Override
public void addedToWorld(World world) {
super.addedToWorld(world);
pos = new v2((double)getX(),(double)getY());
velocity = new v2((double)(Greenfoot.getRandomNumber(51)-25) * 13.f,-480.f);
}
}