-
Notifications
You must be signed in to change notification settings - Fork 0
/
engine.js
executable file
·73 lines (59 loc) · 1.36 KB
/
engine.js
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
var CANVAS, ctx, ALTURA, LARGURA, TEMPORIZADOR, FRAMES=0
var estados = {
current:'',
jogar: function(){
this.current = "jogar"
FRAMES=0
},
jogando: function(){
this.current = "jogando"
},
perdeu:function(){
this.current = "perdeu"
clearInterval(TEMPORIZADOR)
alert("perdeu")
},
acabou:function(){
this.current = "acabou"
clearInterval(TEMPORIZADOR)
alert("acabou")
}
}
function status(status, callback)
{
if( estados.current == status ) callback.call(estados)
}
function atualiza(fnc)
{
fnc()
}
function desenha(fnc)
{
fnc()
}
var GAME = {
main:function(fnc){
this.load()
fnc()
TEMPORIZADOR = setInterval(function(){
fnc()
if(estados.current == "jogando")FRAMES++
}, 30)
},
load:function(){
LARGURA = 400
ALTURA = 400
CANVAS = document.createElement("canvas")
CANVAS.width = LARGURA
CANVAS.height= ALTURA
ctx = CANVAS.getContext("2d")
document.body.appendChild(CANVAS)
estados.jogar()
},
cursor:function(evt, fnc){
CANVAS.addEventListener(evt, fnc)
},
key:function(evt, fnc){
document.body.addEventListener(evt, fnc)
}
}