SHOW:
|
|
- or go back to the newest paste.
1 | /// @description Movement code | |
2 | ||
3 | //Inputs | |
4 | keyMoveRight = keyboard_check_direct(vk_right); | |
5 | keyMoveLeft = -keyboard_check_direct(vk_left); | |
6 | keyJump = keyboard_check_pressed(ord("Z")); | |
7 | keyJumpHold = keyboard_check_direct(ord("Z")); | |
8 | ||
9 | //Direction and speed: | |
10 | move = keyMoveRight + keyMoveLeft; | |
11 | ||
12 | hsp = move * moveSpeed; | |
13 | ||
14 | //Limit fallspeed: | |
15 | if (vsp >= maxFallSpeed){ | |
16 | vsp = maxFallSpeed; | |
17 | } | |
18 | else{ | |
19 | vsp += grav; | |
20 | } | |
21 | ||
22 | //Jumping | |
23 | if place_meeting(x, y + 1, objBlock) && keyJump{ | |
24 | ||
25 | vsp += jumpSpeed; | |
26 | } | |
27 | if place_meeting(x, y + 1, objPlatform) && keyJump{ | |
28 | ||
29 | vsp += jumpSpeed; | |
30 | } | |
31 | ||
32 | //Jump boosting | |
33 | if keyJumpHold && vsp < 0{ | |
34 | ||
35 | vsp += jumpHoldBoost; | |
36 | } | |
37 | ||
38 | //Horizontal collision | |
39 | if (place_meeting(x + hsp,y,objBlock)){ | |
40 | ||
41 | while (!place_meeting(x + sign(hsp),y,objBlock)){ | |
42 | ||
43 | x += sign(hsp); | |
44 | } | |
45 | hsp = 0; | |
46 | } | |
47 | ||
48 | //Vertical collision | |
49 | if (place_meeting(x ,y + vsp,objBlock)){ | |
50 | ||
51 | while (!place_meeting(x,y + sign(vsp),objBlock)){ | |
52 | ||
53 | y += sign(vsp); | |
54 | } | |
55 | vsp = 0; | |
56 | } | |
57 | ||
58 | //Diagonal collision | |
59 | if (place_meeting(x + hsp, y + vsp, objBlock)){ | |
60 | ||
61 | while(!place_meeting(x + sign(hsp), y + sign(vsp), objBlock)){ | |
62 | ||
63 | x += sign(hsp); | |
64 | y += sign(vsp); | |
65 | } | |
66 | hsp = 0; | |
67 | vsp = 0; | |
68 | } | |
69 | ||
70 | //Move object | |
71 | if !moveLock{ | |
72 | x += hsp; | |
73 | } | |
74 | y += vsp; | |
75 | ||
76 | ///Shooting | |
77 | keyShoot = keyboard_check_pressed(ord("X")); | |
78 | var shootDir = 0; | |
79 | ||
80 | //Get last moved direction: | |
81 | ||
82 | if !moveLock{ | |
83 | if -keyMoveLeft{ | |
84 | lastMove = -1; | |
85 | } | |
86 | else if keyMoveRight{ | |
87 | lastMove = 1; | |
88 | } | |
89 | } | |
90 | ||
91 | shootDir = scrGetShootDirection(); | |
92 | ||
93 | if keyShoot scrCreateBullet(x, y, shootDir); | |
94 | ||
95 | ||
96 | ///Deflecting | |
97 | ||
98 | var keyDeflectCharge = keyboard_check_direct(ord("C")); | |
99 | var keyDeflect = keyboard_check_released(ord("C")); | |
100 | ||
101 | //Create deflect hitbox: | |
102 | ||
103 | var deflectHitboxWidth = 42; | |
104 | ||
105 | //x1 | |
106 | deflectHitbox[0] = x + (10 * lastMove); | |
107 | //y1 | |
108 | deflectHitbox[1] = y - 18; | |
109 | //x2 | |
110 | deflectHitbox[2] = x + ((10 + deflectHitboxWidth) * lastMove); | |
111 | //y2 | |
112 | deflectHitbox[3] = (y - 18) + sprite_height; | |
113 | ||
114 | //Charge deflect: | |
115 | if keyDeflectCharge{ | |
116 | ||
117 | moveLock = true; | |
118 | deflectCharge ++; | |
119 | } | |
120 | ||
121 | //Swing for deflects: | |
122 | if keyDeflect{ | |
123 | ||
124 | with(collision_rectangle(deflectHitbox[0], deflectHitbox[1], deflectHitbox[2], deflectHitbox[3], objDeflectable, true, true)){ | |
125 | ||
126 | scrDeflect(); | |
127 | } | |
128 | with(collision_rectangle(deflectHitbox[0], deflectHitbox[1], deflectHitbox[2], deflectHitbox[3], objEnemyProjectile, true, true)){ | |
129 | ||
130 | scrDeflect(); | |
131 | } | |
132 | moveLock = false; | |
133 | deflectCharge = 0; | |
134 | } | |
135 | ||
136 | //Cap power | |
137 | if deflectCharge > deflectChargeMax{ | |
138 | ||
139 | deflectCharge = deflectChargeMax; | |
140 | } | |
141 | ||
142 | ||
143 | ///Animation handling | |
144 | ||
145 | //Direction | |
146 | image_xscale = lastMove; | |
147 | ||
148 | //Running | |
149 | if move != 0{ | |
150 | ||
151 | sprite_index = sprPlayerRunning; | |
152 | } | |
153 | //Idle | |
154 | else{ | |
155 | global.jumping = false; | |
156 | sprite_index = sprIdle; | |
157 | } | |
158 | ||
159 | //Jumping: | |
160 | if vsp < 0{ | |
161 | global.jumping = true; | |
162 | sprite_index = sprJump; | |
163 | } | |
164 | ||
165 | //Falling | |
166 | ||
167 | //Deflect charge: | |
168 | if keyDeflectCharge{ | |
169 | ||
170 | sprite_index = sprChargeDeflect; | |
171 | } | |
172 | ||
173 | //Allow passage through platform | |
174 | ||
175 | //Vertical | |
176 | if (place_meeting(x ,y + vsp,objPlatform)){ | |
177 | ||
178 | while (!place_meeting(x,y + sign(vsp),objPlatform)){ | |
179 | ||
180 | y += sign(vsp); | |
181 | } | |
182 | vsp = 0; | |
183 | } | |
184 | ||
185 | //Diagonal | |
186 | if (place_meeting(x + hsp, y + vsp, objPlatform)){ | |
187 | ||
188 | while(!place_meeting(x + sign(hsp), y + sign(vsp), objPlatform)){ | |
189 | ||
190 | x += sign(hsp); | |
191 | y += sign(vsp); | |
192 | } | |
193 | hsp = 0; | |
194 | vsp = 0; | |
195 | } | |
196 | ||
197 | //Horizontal | |
198 | if (place_meeting(x + hsp,y,objPlatform)){ | |
199 | ||
200 | while (!place_meeting(x + sign(hsp),y,objPlatform)){ | |
201 | ||
202 | x += sign(hsp); | |
203 | } | |
204 | hsp = 0; | |
205 | } |