-
Notifications
You must be signed in to change notification settings - Fork 0
/
Nave.java
99 lines (94 loc) · 2.43 KB
/
Nave.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
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class Nave here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Nave extends Actor
{
/**
* Act - do whatever the Nave wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
private int Poder;
private int Boost;
public void setPoder(int valorPoder){
this.Poder = valorPoder;
}
public int getPoder(){
return Poder;
}
public void setBoost(int valorBoost){
this.Boost = valorBoost;
}
public int getBoost(){
return Boost;
}
public void act()
{
moveAndTurn();
eat();
}
public Nave()
{
GreenfootImage myImage = getImage ();
myImage.scale (75, 125);
}
public void moveAndTurn()
{
if (Greenfoot.isKeyDown("a"))
{
move(-4-getBoost());
}
if (Greenfoot.isKeyDown("d"))
{
move(4+getBoost());
}
if (Greenfoot.isKeyDown("w"))
{
setLocation(getX(), getY()-4-getBoost());
}
if (Greenfoot.isKeyDown("s"))
{
setLocation(getX(), getY()+4+getBoost());
}
}
public void eat()
{
Actor Reinicio;
Reinicio = getOneObjectAtOffset(0,0, Reinicio.class);
if (Reinicio != null)
{
int valorPoder = 1;
setPoder(valorPoder);
World world;
world = getWorld();
world.removeObject(Reinicio);
}
Actor Boost;
Boost = getOneObjectAtOffset(0,0, Boost.class);
if (Boost != null)
{
int valorBoost = getBoost() +1;
setBoost(valorBoost);
World world;
world = getWorld();
world.removeObject(Boost);
}
Actor Piedra1;
Actor Piedra2;
Actor Eliminar;
Eliminar = getOneObjectAtOffset(0,0, Eliminar.class);
Piedra1 = getOneObjectAtOffset(0,0, Piedra1.class);
Piedra2 = getOneObjectAtOffset(0,0, Piedra2.class);
if (Eliminar != null)
{
World world;
world = getWorld();
world.removeObject(Eliminar);
world.removeObject(Piedra1);
world.removeObject(Piedra2);
}
}
}