Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 100 lines (88 sloc) 2.238 kb
152493f @drewlesueur first commit
authored
1
2 $(document).ready () ->
3
4 window.ws = new WebSocket "ws://bomber.the.tl:9998/"
5 ws.onopen = () ->
6 console.log "open"
7 ws.onmessage = (e) ->
8 data = JSON.parse e.data
9 console.log data
10 app[data[0]] data[1]
11 ws.onclose = (e) ->
12 console.log "closed!!"
13 ws.onerror = (e) ->
14 console.log "error"
15
16 window.app = {}
17 app.addField = () ->
18 app.field = document.createElement "div"
19 $(app.field).css
20 height: "320px"
21 width: "320px"
dcdf541 @drewlesueur start
authored
22
152493f @drewlesueur first commit
authored
23 $(app.field).attr "id", "field"
24 $('#wrapper').append app.field
dcdf541 @drewlesueur start
authored
25 if $.os.ios or $.os.android or $.os.webos
26 clicky = "touchstart"
27 else
28 clicky = "click"
29 $('#field').bind clicky, (e) ->
30 e.preventDefault()
31 if e.touches
32 e = e.touches[0]
33 ws.send JSON.stringify ["repos"
34 x: e.clientX
35 y: e.clientY
36 ]
152493f @drewlesueur first commit
authored
37
dcdf541 @drewlesueur start
authored
38 app.getByCid = {}
39 app.renderUser = (user) ->
40 if not (user.__cid of app.getByCid)
41 app.users.push user
42 user.dom = document.createElement "div"
43
44 $(user.dom).html user.__cid
45 $(user.dom).css
46 "position": "absolute"
47 top: "0"
48 left: "0"
49 app.getByCid[user.__cid] = user
50 $('#field').append user.dom
152493f @drewlesueur first commit
authored
51
dcdf541 @drewlesueur start
authored
52 else
53 oldUser = app.getByCid[user.__cid]
54 user = _.extend oldUser, user
55 $(user.dom).anim
3fb67ff @drewlesueur started with users
authored
56 translateX: user.x + "px"
57 translateY: user.y + "px"
dcdf541 @drewlesueur start
authored
58 app.users = []
59 app.updateUsers = (data) ->
3fb67ff @drewlesueur started with users
authored
60 for user in data
61 app.renderUser user
152493f @drewlesueur first commit
authored
62
63 app.log = (str) ->
dcdf541 @drewlesueur start
authored
64 #console.log str
152493f @drewlesueur first commit
authored
65 app.tileWidth = 32
66 app.tileHeight = 32
67 app.renderScreen = (tiles) ->
68 app.addField()
69 x = 0
70 y = 0
71 if _.isString tiles
72 tiles = tiles.split "\n"
73
74 for row in tiles
75 if _.isString row
76 row = row.split ""
77 for cell in row
78 if _.isString cell
79 str = cell
80 cell = {}
81 if str is "-"
82 cell.color = "green"
83 else if str is "o"
84 cell.color = "#aaaaaa"
85
86 tile = document.createElement "div"
87 if "color" of cell
88 $(tile).css "background-color" : cell.color
89 $(tile).attr("data-pos", "#{x},#{y}").css
90 position : "absolute"
91 left: app.tileWidth * x + "px"
92 top: app.tileHeight * y + "px"
93 width: app.tileWidth + "px"
94 height: app.tileHeight + "px"
95 $('#field').append tile
96 x++
97 x = 0
98 y++
99
Something went wrong with that request. Please try again.