-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.yue
executable file
·44 lines (37 loc) · 967 Bytes
/
player.yue
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
import band from require'bit'
fixString = (str) ->
return 'noname' unless str
tostring str
class Player
new: (options) => @[k] = v for k, v in pairs options
--if you're familiar with MoonScript you already know that
--mutable variables are assigned in the constructor
--otherwise changing it on an instance changes it across all of them
--but that is a half-truth, almost
--tables that are not declared in the constructor
--shared across all instances
--tables that are declared in the constructor
--are not shared across instances
--numbers, strings, booleans, etc.
--whether declared in the constructor or not
--are not shared across instances
id: 0
x: 0
y: 0
r: 255
g: 255
b: 255
name: ''
inputs: (bin) =>
dx = band bin, 0x3 --0b0011
dy = band bin, 0xC --0b1100
switch dx
when 0x1 --0b0001
@x -= 1
when 0x2 --0b0010
@x += 1
switch dy
when 0x4 --0b0100
@y -= 1
when 0x8 --0b1000
@y += 1