-
Notifications
You must be signed in to change notification settings - Fork 0
/
CTRL.bb
139 lines (116 loc) · 3.05 KB
/
CTRL.bb
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
Const CTRL_HORIZONTAL=0
Const CTRL_VERTICAL=1
Const CTRL_FIRE=2
Const CTRL_MAX=2
Const KEY_DEF_LEFT=203
Const KEY_DEF_RIGHT=205
Const KEY_DEF_UP=200
Const KEY_DEF_DOWN=208
Const KEY_DEF_FIRE=57
Const KEY_DEF_PAUSE=25
Const JOY_DEF_FIRE=1
Const JOY_DEF_PORT=0
Const JOY_DEF_X_DEADZONE#=0.25
Const JOY_DEF_Y_DEADZONE#=0.25
Const JOY_DEF_X_REVERSED=False
Const JOY_DEF_Y_REVERSED=True
Const JOY_ALTERNATIVE_0=0;;(Default, X and Y Axis)
Const JOY_ALTERNATIVE_1=1;;(Use Z Axis instead of Y)
Const JOY_ALTERNATIVE_2=2;;(Use Y Axis instead of X and X instead of Y)
Const JOY_ALTERNATIVE_3=4;;(Use Z Axis instead of X and X instead of Y)
Const JOY_DEF_ALTERNATIVE=JOY_ALTERNATIVE_0;Default, X and Y Axis
Const PLAYER_FIRE_DELAY=30 ; In number of FRAME UPDATES
Global LAST_PLAYER_FIRE; In number of FRAME UPDATES
Global KEY_LEFT
Global KEY_RIGHT
Global KEY_UP
Global KEY_DOWN
Global KEY_FIRE
Global KEY_PAUSE
Global JOY_FIRE
Global JOY_PORT
Global JOY_X_DEADZONE#
Global JOY_Y_DEADZONE#
Global JOY_X_REVERSED
Global JOY_Y_REVERSED
Global JOY_ALTERNATIVE
Function AdditonalControlInputs()
If (KeyHit(KEY_PAUSE))
GAME_PAUSE=Not(GAME_PAUSE)
End If
End Function
Function InitialiseDefaultControls()
KEY_LEFT=KEY_DEF_LEFT
KEY_RIGHT=KEY_DEF_RIGHT
KEY_UP=KEY_DEF_UP
KEY_DOWN=KEY_DEF_DOWN
KEY_FIRE=KEY_DEF_FIRE
JOY_FIRE=JOY_DEF_FIRE
JOY_PORT=JOY_DEF_PORT
JOY_X_DEADZONE#=JOY_DEF_X_DEADZONE#
JOY_Y_DEADZONE#=JOY_DEF_Y_DEADZONE#
JOY_X_REVERSED=JOY_DEF_X_REVERSED
JOY_Y_REVERSED=JOY_DEF_Y_REVERSED
JOY_ALTERNATIVE=JOY_DEF_ALTERNATIVE
KEY_PAUSE=KEY_DEF_PAUSE
End Function
Function GetControlInput(Control[2])
;0=X
;1=Y
;2=FIRE
Control[CTRL_HORIZONTAL]=Sgn(KeyboardInputX()+JoypadInputX())
Control[CTRL_VERTICAL]=Sgn(KeyboardInputY()+JoypadInputY())
Control[CTRL_FIRE]=Sgn(KeyboardInputFire()+JoypadInputFire())
End Function
Function KeyboardInputX()
Return KeyDown(KEY_RIGHT)-KeyDown(KEY_LEFT)
End Function
Function JoypadInputX()
Local X
Local XX
Select JOY_ALTERNATIVE
Case JOY_ALTERNATIVE_1:
XX=JoyX(JOY_PORT)
Case JOY_ALTERNATIVE_2:
XX=JoyY(JOY_PORT)
Case JOY_ALTERNATIVE_3:
XX=JoyZ(JOY_PORT)
Default:
;JOY_ALTERNATIVE_0:
XX=JoyX(JOY_PORT)
End Select
X=Sgn(XX)*(Abs(XX)>JOY_X_DEADZONE)
If (JOY_X_REVERSED) Then X=0-X
Return X
End Function
Function KeyboardInputY()
Return KeyDown(KEY_UP)-KeyDown(KEY_DOWN)
End Function
Function JoypadInputY()
Local Y
Local YY
Select JOY_ALTERNATIVE
Case JOY_ALTERNATIVE_1:
YY=JoyZ(JOY_PORT)
Case JOY_ALTERNATIVE_2:
YY=JoyX(JOY_PORT)
Case JOY_ALTERNATIVE_3:
YY=JoyX(JOY_PORT)
Default:
;JOY_ALTERNATIVE_0:
YY=JoyY(JOY_PORT)
End Select
Y=Sgn(YY)*(Abs(YY)>JOY_Y_DEADZONE)
If (JOY_Y_REVERSED) Then Y=0-Y
Return Y
End Function
Function KeyboardInputFire()
Return KeyDown(KEY_FIRE)
End Function
Function JoypadInputFire()
Local Y=JoyDown(JOY_FIRE,JOY_PORT)
Return Y
End Function
;~IDEal Editor Parameters:
;~F#2C#32#45#4F#53#67#6B#7F#83
;~C#Blitz3D