-
Notifications
You must be signed in to change notification settings - Fork 0
/
pepita.wlk
56 lines (42 loc) · 1.2 KB
/
pepita.wlk
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
import comidas.*
import extras.*
import wollok.game.*
object pepita {
var property energia = 100
var property position = game.origin()
method image() {
return if (self.estaEnElNido()) "pepita-grande.png" else if (self.estaEnSilvestre() or self.estaCansada()) "pepita-gris.png" else "pepita.png"
}
method come(comida) {
energia = energia + comida.energiaQueOtorga()
game.removeVisual(comida)
}
method vola(kms) {
energia = energia - kms * 9
}
method irA(nuevaPosicion) {
if (nuevaPosicion.x() >= 0 && nuevaPosicion.x() <= game.width() -1 && nuevaPosicion.y() >= 0 && nuevaPosicion.y() <= game.height() -1 ) {
self.vola(position.distance(nuevaPosicion))
position = nuevaPosicion
keyboard.c().onPressDo({if (!game.colliders(self).isEmpty()) {self.come(game.uniqueCollider(self))}})
}
}
method estaCansada() {
if (energia <= 0) game.schedule(0000,{game.stop()})
return energia <= 0
}
method estaEnElNido() {
return position == nido.position()
}
method estaEnElSuelo() {
return position.y() == 0
}
method estaEnSilvestre(){
return position == silvestre.position()
}
method caer() {
if (!self.estaEnElSuelo()){
position = position.down(1)
}
}
}