-
Notifications
You must be signed in to change notification settings - Fork 0
/
dinoGame.wlk
130 lines (103 loc) · 2.2 KB
/
dinoGame.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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import wollok.game.*
const velocidad = 250
object juego{
method configurar(){
game.width(12)
game.height(8)
game.title("Dino Game")
game.boardGround("fondo3.png")
game.addVisual(suelo)
game.addVisual(cactus)
game.addVisual(dino)
game.addVisual(reloj)
keyboard.up().onPressDo({dino.saltar()})
keyboard.space().onPressDo{ self.jugar()}
game.onCollideDo(dino,{ obstaculo => obstaculo.chocar(dino)})
}
method iniciar(){
dino.iniciar()
reloj.iniciar()
cactus.iniciar()
}
method jugar(){
if (dino.estaVivo())
dino.saltar()
else {
game.removeVisual(gameOver)
self.iniciar()
}
}
method terminar(){
game.addVisual(gameOver)
cactus.detener()
reloj.detener()
dino.morir()
}
}
object gameOver {
method position() = game.center()
method text() = "GAME OVER"
}
object reloj {
var property tiempo = 0
method text() = tiempo.toString()
method textColor() = "00FF00FF"
method position() = game.at(1, game.height()-1)
method pasarTiempo() {
if (!self.detener()){
tiempo+=1
}
}
method iniciar(){
tiempo = 0
game.onTick(1000,"tiempo",{self.pasarTiempo()})
}
method detener() = cactus.position() == dino.position()
}
object cactus {
var property position = self.posicionInicial()
method image() = "cactus.png"
method posicionInicial() = game.at(game.width()-1,suelo.position().y())
method iniciar(){
position = self.posicionInicial()
game.onTick(velocidad,"moverCactus",{self.mover()})
}
method mover(){
if (!self.detener()){
position = position.left(1)
}
}
method chocar(dino){
game.schedule(1000, {juego.terminar()})
}
method detener() = self.position() == dino.position()
}
object suelo{
method position() = game.origin().up(1)
method image() = "suelo.png"
}
object dino {
var vivo = true
var property position = game.at(1,suelo.position().y())
method image() = "dino.png"
method saltar(){
game.schedule(velocidad, {self.subir()})
game.schedule(1000, {self.bajar()})
}
method subir(){
position = position.up(1)
}
method bajar(){
position = position.down(1)
}
method morir(){
game.say(self,"¡Auch!")
vivo = false
}
method iniciar() {
vivo = true
}
method estaVivo() {
return vivo
}
}