-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mover.java
141 lines (130 loc) · 4.06 KB
/
Mover.java
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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import java.util.List;
/**
* Write a description of class container1 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Mover extends Actor
{
private int acceleration = 0;
private int vSpeed = 0;
private int containerspeed = 0;
private Class[] barrier = new Class[0];
//public static boolean vmg2_containerdown;
//public static boolean vmg2_containerup;
//public static boolean vmg2_containerright;
//public static boolean vmg2_containerleft;
public boolean vmg2_down1;
public boolean vmg2_up1;
public boolean vmg2_right1;
public boolean vmg2_left1;
public void c_move()
/*
* When the hook touches the container and space is pressed and held, it will move with the hook until the spacebar is released.
*/
{
MyWorld world = (MyWorld)getWorld();
if (getOneIntersectingObject(hook.class) != null &&Greenfoot.isKeyDown("space"))
{
setLocation(world.hook.getX(),world.hook.getY()+100);
}
}
public void mg2_MoveCont()
{
MyWorld world = (MyWorld)getWorld();
GreenfootImage image = getImage();
if (world.hook.vmg2_hooked == true && getOneIntersectingObject(hook.class) != null)
{
setLocation(world.hook.getX(),world.hook.getY()+55);
//if (getOneObjectAtOffset(+image.getWidth()/2,0, null) == null && getOneObjectAtOffset(-image.getWidth()/2,0, null) == null)
//{
// setLocation(world.hook.getX(),world.hook.getY()+40);
//}
}
}
public void mg2_MoveCont1()
{
MyWorld world = (MyWorld)getWorld();
GreenfootImage image = getImage();
//System.out.println("mg2_MoveCont1" + getOneObjectAtOffset(0, image.getHeight()/2, null));
if (world.hook.vmg2_hooked == true && getOneIntersectingObject(hook.class) != null)
{
if (vmg2_down1 == true)
{
setLocation(world.hook.getX(),world.hook.getY()+55);
}
//if (getOneObjectAtOffset(+image.getWidth()/2,0, null) == null && getOneObjectAtOffset(-image.getWidth()/2,0, null) == null)
//{
// setLocation(world.hook.getX(),world.hook.getY()+40);
//}
}
}
public void doGravity()
{
if(vSpeed > 0) return;
if(vSpeed <= 0) vSpeed = -1;
setLocation(getX(), getY() + vSpeed);
vSpeed = vSpeed + acceleration;
}
protected void setMovementSpeed(int newSpeed)
{
containerspeed = newSpeed;
}
protected void setBlockingClasses(Class[] c)
{
barrier = c;
}
protected void setGravity(int g)
{
acceleration = g;
}
public void canmove_container()
{
GreenfootImage image = getImage();
if (getOneObjectAtOffset(0, image.getHeight()/2, null) == null)
{
vmg2_down1= true;
}
else
{
vmg2_down1 = false;
}
if (getOneObjectAtOffset(0, -image.getHeight()/2, null) == null)
{
vmg2_up1= true;
}
else
{
vmg2_up1 = false;
}
if (getOneObjectAtOffset(-image.getWidth()/2,0, null) == null)
{
vmg2_left1= true;
}
else
{
vmg2_left1 = false;
}
if (getOneObjectAtOffset(+image.getWidth()/2,0, null) == null)
{
vmg2_right1= true;
}
else
{
vmg2_right1 = false;
}
}
public void mg2_TouchContainer()
{
GreenfootImage image = getImage();
Actor abc = getOneObjectAtOffset(0,image.getHeight()/2, Mover.class);
MyWorld world = (MyWorld)getWorld();
if (getOneObjectAtOffset(0,image.getHeight()/2, Mover.class) != null)
{
setLocation(abc.getX(),abc.getY()-image.getHeight());
world.hook.vmg2_hooked = true;
}
}
}