-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathContainerBlauwDek1.java
70 lines (61 loc) · 1.97 KB
/
ContainerBlauwDek1.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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class ContainerBlauwDek1 here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class ContainerBlauwDek1 extends Dek1
{
/**
* Act - do whatever the ContainerBlauwDek1 wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
// The initial location of the container
private int originalX;
private int originalY;
/**
* Will store the initial location of the container.
*/
public void addedToWorld(World world) {
originalX = getX();
originalY = getY();
}
public void act()
{
// Drag the Container
if(Greenfoot.mouseDragged(this)) {
MouseInfo mouse = Greenfoot.getMouseInfo();
setLocation(mouse.getX(), mouse.getY());
}
int x = getX();
int y = getY();
int ny = getY()+1;
if (isTouching(TreinBlauw.class)){
Actor treinblauw = ((Actor) getWorld().getObjects(TreinBlauw.class).get(0));
int treinblauwY = treinblauw.getY()+1;
setLocation(179, 266);
setLocation (179, treinblauwY - 30);
}
World world=getWorld();
if (getY() == 0 || getY() == 774)//getWorld().getHeight()-1)
{
getWorld().removeObject(this);
world.removeObject(this);
/*Check if the drag has ended. uitgezet Thomas
if(Greenfoot.mouseDragEnded(this)) {
if(getOneIntersectingObject(VrachtwagenBlauw.class) != null)
setLocation(113, 386);
else {
reset();
}
}*/
}
/**
* Reset the container to its original location.
private void reset()
{
setLocation(originalX, originalY);
}*/
}
}