-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdinoGame.wlk
149 lines (118 loc) · 2.74 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import wollok.game.*
const velocidad = 250
object juego{
method configurar(){
game.width(12)
game.height(8)
game.title("Dino Gaay")
game.boardGround("fondo.png")
game.addVisual(suelo)
game.addVisual(cactus)
game.addVisual(dino)
game.addVisual(reloj)
keyboard.space().onPressDo{ self.jugar()}
game.onCollideDo(dino,{ obstaculo => obstaculo.chocar()})
}
method iniciar(){
dino.iniciar()
reloj.iniciar()
cactus.iniciar()
}
method jugar(){
if (dino.estaVivo())
dino.saltar()
else {
game.removeVisual(gameOver)
self.iniciar()
}
}
method terminar(){
game.boardGround("fondo3.png")
game.addVisual(gameOver)
cactus.detener()
reloj.detener()
dino.morir()
}
}
object gameOver {
method position() = game.center()
method text() = "NINJA DINO DALTO MURIO"
}
object reloj {
var property tiempo = 0
method text() = tiempo.toString()
//method textColor() = "00FF00FF"
method position() = game.at(1, game.height()-1)
method pasarTiempo() {
tiempo = tiempo + 1
}
method iniciar(){
tiempo = 0
game.onTick(100,"tiempo",{self.pasarTiempo()})
}
method detener(){
//completar
}
}
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(){
position = position.left(1)
if (position.x() == -1){
position = self.posicionInicial()
}
}
method chocar(){
if(self.position() == dino.position()){
juego.terminar()
}
}
method detener(){
game.schedule(0000, { game.stop() })
}
}
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(){
position = position.up(0.5)
game.schedule(100, {position = position.up(0.5)})
game.schedule(200, {position = position.up(0.5)})
game.schedule(450, {position = position.down(0.5)})
game.schedule(500, {position = position.down(0.5)})
game.schedule(600, {position = position.down(0.5)})
position = position.up(0.5)
game.schedule(100, {position = position.up(0.5)})
game.schedule(200, {position = position.up(0.5)})
game.schedule(450, {position = position.down(0.5)})
game.schedule(500, {position = position.down(0.5)})
game.schedule(600, {position = position.down(0.5)})
}
method subir(){
position = position.up(1)
}
method bajar(){
position = position.down(1)
}
method morir(){
game.say(self,"¡Auch mi colaa!")
vivo = false
}
method iniciar() {
vivo = true
}
method estaVivo() {
return vivo
}
}