-
Notifications
You must be signed in to change notification settings - Fork 6
/
Parrot.java
executable file
·65 lines (58 loc) · 2.05 KB
/
Parrot.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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
import greenfoot.World;
import java.util.logging.Logger;
/**
* Write a description of class parrot here.
*
* @author (João Paulo S. Abreu ([email protected]), Mateus C. Moura
* ([email protected]), Rafael P. Casaes Sampaio
* ([email protected]),
* Uanderson S. Celestino ([email protected]), Lílian T. de
* Sousa ([email protected]), Jefferson Raimon de B. Silva
* ([email protected]))
* @version (a version number or a date)
*/
public class Parrot extends AllObjects {
boolean shoot = true;
private static final Logger log = Logger.getLogger(Parrot.class.getName());
/* construtor */
public Parrot() {
setImage("pDireita.png");
}
/**
* Act - do whatever the parrot 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 da ação do objeto
fall();
isTouch();
movers();
shootMush();
}
// método para quando tocar nos objetos Fire e Vulture
public void isTouch() {
// condicionais utilizando metodo gameover através de getters e também chamando
// o metodo de midia de som do Greenfoot
try{if(isTouching(Fire.class) || isTouching(Vulture.class)) {
Greenfoot.playSound("sounds/death.wav");
((Florest) getWorld()).gameOver();
}
}catch (SecurityException se) {
//exceção caso não seja executado a condição
log.info("ERRO AO EXECUTAR O JOGO");
}
}
//metodo para atirar nos inimigos
public void shootMush(){
if(Greenfoot.isKeyDown("space") && shoot){
Greenfoot.playSound("sounds/tiro.mp3");
getWorld().addObject(new GunMush(), getX() - 3, getY());
shoot = false;
}
else if(!Greenfoot.isKeyDown("space")){
shoot = true;
}
}
}