forked from jacobabrennan/CasualQuest-DM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
key_state.dm
74 lines (74 loc) · 1.45 KB
/
key_state.dm
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
client{
var{
key_state = 0
key_pressed = 0
old_keys = 0
keys_stick = 0
}
proc{
reset(){
key_state = 0
old_keys = 0
key_pressed = 0
}
}
verb{
key_up(which as num){
set name = "key_up"
set hidden = TRUE
key_state &= ~which
old_keys &= ~which
if(which < 16){
var/opposite = turn(which, 180)
if(opposite & old_keys){
key_state |= opposite
keys_stick |= opposite
old_keys &= ~opposite
}
}
//key_check()
}
key_down(which as num){
set name = "key_down"
set hidden = TRUE
if(which == PRIMARY && eye != game.eye && !(src in game.waiting + game.spectators)){
join()
}
if((which in list(SHIFT_PRIMARY)) && (eye != game.eye)){
join_hard()
}
if(which < 16){
var/opposite = turn(which, 180)
if(opposite & key_state){
key_state &= ~opposite
keys_stick &= ~opposite
old_keys |= opposite
}
}
keys_stick |= which
key_state |= which
key_pressed |= which
//key_check()
}
}
proc{
key_state(which){
return (key_state | keys_stick) & which
}
key_check(){
var/u = key_state & NORTH
var/d = key_state & SOUTH
var/l = key_state & WEST
var/r = key_state & EAST
world << "[u? "\green":"\red"]^[d?"\green":"\red"]v[l?"\green":"\red"]<[r?"\green":"\red"]>"
}
clear_key(which){
key_state &= ~which
}
clear_keys(save_buttons){
key_pressed = 0
//keys_stick = 0
//key_state = 0
}
}
}