-
Notifications
You must be signed in to change notification settings - Fork 6
/
GunMush.java
executable file
·52 lines (43 loc) · 1.41 KB
/
GunMush.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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class GunMush here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class GunMush extends AllObjects{
int velGun = 2;
public GunMush(){
setImage("gunmush.png");
scaleImage(4, 4);
}
/**
* Act - do whatever the GunMush wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
@Override
public void act(){
//chama os metodos
gunMushMove();
hitEnemy();
// Add your action code here.
}
//move o cogumelo para acertar o urubu
public void gunMushMove(){
setLocation(getX() + velGun, getY());
}
//metodo para remover o urubu caso ele seja atingido pelo cogumelo. "getOneIntersectingObject" usado para facilitar a remoção
//dois objetos(cogumelo e urubu)
public void hitEnemy(){
Actor enemy = getOneIntersectingObject(Vulture.class);
if(enemy != null){
Greenfoot.playSound("sounds/grito.mp3");
getWorld().removeObject(enemy);
getWorld().removeObject(this);
}
//cogumelo removido quando chegar na posição 651px
else if (getX() >= 651) {
getWorld().removeObject(this);
}
}
}