-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMeatball.java#backup
More file actions
62 lines (57 loc) · 1.7 KB
/
Meatball.java#backup
File metadata and controls
62 lines (57 loc) · 1.7 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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Meatball here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Meatball extends SmoothMover
{
/**
* Act - do whatever the Meatball wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
private int vSpeed = 30;
public void act()
{
if (Check == true) {
getDirection();
getPower();
MyWorld.resetPower = true;
}
arc();
remove();
}
boolean Check = true;
double direction = 1;
public void getDirection() //gets direction Mobby is facing
{
direction = ((Mobby) getWorld().getObjects(Mobby.class).get(0)).getDirection();
}
public double power;
public void getPower()
{
power = ((MyWorld) getWorld()).power;
Check = false; //makes sure direction is only checked once so meatball flies in correct direction
}
public void arc() //sets the path of the flight of the meatball
{
World w = getWorld();
if( getY() <= w.getHeight() - 10) {
move(power*direction);
setLocation(getX(), getY() - (power/2) - vSpeed);
vSpeed = vSpeed - 3;
}
else {
setLocation(getX(), getY());
}
}
private int timer = 0;
public void remove() //removes meatball after time period
{
timer++;
if (timer >= 200) {
getWorld().removeObject(this);
}
}
}