Coffeescript Game Tutorial Libary an Interlude

지금까지 했던걸 라이브러리 형태로 정리한 코드이다.

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
# BEGIN LIBRARY CODE
x = 150
y = 150
dx = 2
dy = 4
WIDTH = 0
HEIGHT = 0
ctx = null
init = ->
canvas = document.getElementById("myCanvas")
ctx = canvas.getContext("2d")
WIDTH = canvas.width
HEIGHT = canvas.height
intervalId = setInterval(draw, 10)
circle = (x, y, r) ->
ctx.beginPath()
ctx.arc(x, y, r, 0, Math.PI*2, true)
ctx.closePath()
ctx.fill()
rect = (x, y, w, h) ->
ctx.beginPath()
ctx.rect(x, y, w, h)
ctx.closePath()
ctx.fill()
clear = ->
ctx.clearRect(0, 0, WIDTH, HEIGHT)
# END LIBRARY CODE
draw = ->
clear()
circle(x, y, 10)
x += dx;
y += dy;
window.onload = ->
init()

Reference

Share Comments