-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.s
More file actions
715 lines (519 loc) · 11.8 KB
/
player.s
File metadata and controls
715 lines (519 loc) · 11.8 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
.const JOYSTICK_2 = $dc00
.const JOYSTICK_1 = $dc01
.const JOYSTICK_UP = %00000001
.const JOYSTICK_DOWN = %00000010
.const JOYSTICK_LEFT = %00000100
.const JOYSTICK_RIGHT = %00001000
.const JOYSTICK_BUTTON = %00010000
.const JUMP_STEPS = 12
// number of pixels actor will go up on each step
actor_jump_table:
.byte -4, -06, -08, -08, -8, -10, -11, -13, -12, -10, -10, -10, -10, -12, -12, -12
joystick_left_pushed:
.byte 0
joystick_right_pushed:
.byte 0
joystick_button_pushed:
.byte 0
// player has died, start countdown to restarting the level
PlayerDie: {
jsr StatusIncreaseTries
lda #(diesound - soundsstart)
jsr QueueSound
lda #GAME_STATE_DEAD
sta game_state
lda #25
sta game_state_counter
rts
}
// accumulator should be 1 if player can boost, 0 otherwise
SetPlayerCanBoost: {
phy
phx
sta player_can_boost
cmp #0
beq player_cant_boost
ldy #3
ldx #1
jsr CopySpriteColor
jmp set_player_can_boost_done
player_cant_boost:
ldy #4
ldx #1
jsr CopySpriteColor
set_player_can_boost_done:
plx
ply
rts
}
// respond to player controls
PlayerControls: {
// want to store if player is holding left or right
// do this better..
lda #0
sta joystick_right_pushed
lda right_key_pressed
bne set_joystick_right_pushed
lda JOYSTICK_1
and #JOYSTICK_RIGHT
beq set_joystick_right_pushed
lda JOYSTICK_2
and #JOYSTICK_RIGHT
beq set_joystick_right_pushed
jmp !+
set_joystick_right_pushed:
lda #1
sta joystick_right_pushed
!:
lda #0
sta joystick_left_pushed
lda left_key_pressed
bne set_joystick_left_pushed
lda JOYSTICK_1
and #JOYSTICK_LEFT
beq set_joystick_left_pushed
lda JOYSTICK_2
and #JOYSTICK_LEFT
beq set_joystick_left_pushed
jmp !+
set_joystick_left_pushed:
lda #1
sta joystick_left_pushed
!:
lda #0
sta joystick_button_pushed
lda JOYSTICK_1
and #JOYSTICK_BUTTON
beq set_joystick_button_pushed
lda JOYSTICK_2
and #JOYSTICK_BUTTON
beq set_joystick_button_pushed
// z key can also be used
lda z_key_pressed
bne set_joystick_button_pushed
lda x_key_pressed
bne set_joystick_button_pushed
jmp !+
set_joystick_button_pushed:
lda #1
sta joystick_button_pushed
!:
dec blink_timer
adjust_coyote:
// player can start a jump when coyote counter is not zero
dec player_coyote_counter
bpl adjust_coyote_done
lda #00
sta player_coyote_counter
adjust_coyote_done:
check_boost_counter:
lda player_boost_counter
beq check_boost_counter_done
dec player_boost_counter
bne continue_boost
// boost has just finished, reset things
continue_boost:
// check not boosting into wall
lda actor_direction
cmp #1
bne !+
lda actor_char_left
cmp #TILE_BLOCK
beq check_boost_counter_done
jmp player_controls_done
!:
lda actor_char_right
cmp #TILE_BLOCK
beq check_boost_counter_done
jmp player_controls_done
check_boost_counter_done:
lda #$0
sta player_boost_counter
// set default frame, in air sprite
lda #FRAME_JUMP
sta actor_base_frame
lda #JUMP_FRAME_COUNT
sta actor_frame_count
test_on_ground:
lda actor_char_below
cmp #TILE_SOLID
bne actor_is_in_air
// on ground
lda actor_on_ground
bne actor_is_on_ground
// actor has just reached ground
lda #FRAME_LAND_EFFECT
jsr player_add_effect
actor_is_on_ground:
// player is on the ground..
lda #01
sta actor_on_ground
jsr SetPlayerCanBoost
// sta player_can_boost
lda #$00
sta player_boost_counter
lda #COYOTE_TIME
sta player_coyote_counter
lda #PLAYER_GROUND_FORCE
sta actor_force
lda #PLAYER_GROUND_FORCE_NO_INPUT
sta actor_force_no_input
// lda #FRAME_STAND
// sta actor_base_frame
lda blink_time
bne blink_frame
lda #FRAME_STAND
sta actor_base_frame
lda blink_timer
bne test_on_ground_done
lda #$05
sta blink_time
blink_frame:
lda #FRAME_BLINK
sta actor_base_frame
dec blink_time
test_on_ground_done:
jmp check_joystick
actor_is_in_air:
lda #0
sta actor_on_ground
lda #PLAYER_AIR_FORCE
sta actor_force
lda #PLAYER_AIR_FORCE_NO_INPUT
sta actor_force_no_input
set_gravity_force:
lda #GRAVITY_FORCE
sta actor_gravity_force
lda #MAX_DOWN_SPEED
sta actor_max_down_speed
set_gravity_check_left:
lda actor_char_left
cmp #TILE_SOLID
beq set_gravity_touching_wall
set_gravity_check_right:
lda actor_char_right
cmp #TILE_SOLID
bne apply_gravity
// different max speed if touching wall
set_gravity_touching_wall:
lda #MAX_DOWN_SPEED
sta actor_max_down_speed
lda #FRAME_SCRAPE
sta actor_base_frame
lda #FRAME_WALLSCRAPE_EFFECT
jsr player_add_effect
// move this to general actor code
apply_gravity:
clc
lda actor_sy
adc actor_gravity_force
sta actor_sy
cmp actor_max_down_speed
bmi apply_gravity_done
lda actor_max_down_speed
sta actor_sy
apply_gravity_done:
check_joystick:
lda joystick_button_pushed
bne joystick_button
jmp joystick_not_fire
joystick_button:
// if fire is already down, continuing jump
// otherwise maybe start a jump
lda player_button_down
beq player_check_start_jump
jmp player_continue_jump
// check if the player can start a jump
player_check_start_jump:
// if touching open door, player could be trying to exit instead of jump
lda player_touching_door
beq !+
lda dot_count
bne !+
lda #$01
sta player_button_down
jsr EnterDoor
jmp player_controls_done
!:
// can jump if coyote counter is not zero
lda player_coyote_counter
bne player_start_jump
// if against left wall, start a wall jump
lda actor_char_left
cmp #TILE_SOLID
bne player_check_start_wall_jump_right
// jumping off left wall
lda #WALL_JUMP_SPEED
sta actor_sx
// have to add the effect before settings the direction
lda #FRAME_WALLJUMP_EFFECT
jsr player_add_effect
lda #0
sta actor_direction
jmp player_wall_jump
player_check_start_wall_jump_right:
lda actor_char_right
cmp #TILE_SOLID
bne joystick_fire_in_air
lda #-WALL_JUMP_SPEED
sta actor_sx
// have to add the effect before setting the direction
lda #FRAME_WALLJUMP_EFFECT
jsr player_add_effect
lda #1
sta actor_direction
player_wall_jump:
// lda #WALL_JUMP_SPRITE
// sta actor_base_frame
// player loses control for wall jump time
lda #WALL_JUMP_TIME
sta player_wall_jump_counter
jmp player_start_jump
// player has pushed fire while in the air
joystick_fire_in_air:
lda player_can_boost
bne !+
jmp joystick_fire_done
!:
// start a boost
player_check_boost_direction:
lda actor_direction
bne player_boost_left
player_boost_right:
lda #BOOST_SPEED
jmp player_start_boost
player_boost_left:
lda #-BOOST_SPEED
player_start_boost:
sta actor_sx
lda #$01
sta player_button_down
lda #$00
// no gravity in boost
sta actor_sy
// sta player_can_boost
jsr SetPlayerCanBoost
lda #FRAME_BOOST_X
sta actor_base_frame
lda #BOOST_STEPS
sta player_boost_counter
lda #FRAME_BOOST_EFFECT
jsr player_add_effect
lda #(boostsound - soundsstart)
jsr QueueSound
// started a boost, so lose control
jmp player_controls_done
// start a jump
player_start_jump:
lda #$01
sta player_button_down
lda #WALL_STICK_TIME
sta player_wall_stick_counter
lda #$0
sta actor_current_frame
lda #JUMP_STEPS
sta player_jump_counter
lda #(jumpsound - soundsstart)
jsr QueueSound
player_continue_jump:
// if jump counter is zero, jump is over
ldy player_jump_counter
beq check_wall_stick
// put the value from the jump table into y speed
lda actor_jump_table,y
sta actor_sy
// decrease jump counter
dec player_jump_counter
jmp joystick_fire_done
check_wall_stick:
// only want to stick if actor is about to move down and fire button pushed
lda actor_sy
bmi player_wall_stick_done
lda player_wall_stick_counter
beq player_wall_stick_done
// stick the player to the wall if touching wall and fire held down after jump
lda actor_char_right
cmp #TILE_SOLID
beq player_wall_stick
lda actor_char_left
cmp #TILE_SOLID
beq player_wall_stick
jmp joystick_fire_done
player_wall_stick:
// set y speed to 0
dec player_wall_stick_counter
lda #0
sta actor_sy
player_wall_stick_done:
jmp joystick_fire_done
joystick_not_fire:
// reset button down
lda #$0
sta player_button_down
sta player_jump_counter
joystick_fire_done:
// left/right joystick shouldn't work if
// just started a wall jump
check_wall_jump_counter:
lda player_wall_jump_counter
beq check_wall_jump_counter_done
dec player_wall_jump_counter
jmp check_joystick_up
check_wall_jump_counter_done:
check_joystick_left:
// lda JOYSTICK_1
// and #JOYSTICK_LEFT
// beq joystick_is_left
lda joystick_left_pushed
bne joystick_is_left
// lda left_key_pressed
// bne joystick_is_left
jmp check_joystick_right
joystick_is_left:
lda #$01
sta actor_direction
lda actor_char_left
cmp #TILE_SOLID
bne joystick_left_check_on_ground
joystick_left_check_on_ground:
lda actor_on_ground
beq do_joystick_left
joystick_left_on_ground:
lda #FRAME_WALK
sta actor_base_frame
lda #WALK_FRAME_COUNT
sta actor_frame_count
do_joystick_left:
// subtract force from x speed
sec
lda actor_sx
sbc #$01
sta actor_sx
cmp #-(MAX_PLAYER_SPEED)
bpl joystick_left_done
lda #-(MAX_PLAYER_SPEED - 1)
sta actor_sx
joystick_left_done:
jmp check_joystick_up
check_joystick_right:
// lda JOYSTICK_1
// and #JOYSTICK_RIGHT
// beq joystick_is_right
// lda right_key_pressed
// bne joystick_is_right
lda joystick_right_pushed
bne joystick_is_right
jmp joystick_not_left_or_right
joystick_is_right:
lda #$00
sta actor_direction
lda actor_char_right
cmp #TILE_SOLID
bne joystick_right_check_on_ground
joystick_right_check_on_ground:
lda actor_on_ground
beq do_joystick_right
joystick_right_on_ground:
lda #FRAME_WALK
sta actor_base_frame
lda #WALK_FRAME_COUNT
sta actor_frame_count
do_joystick_right:
clc
lda actor_sx
adc #$01 // force
sta actor_sx
cmp #MAX_PLAYER_SPEED
bmi joystick_right_done
lda #MAX_PLAYER_SPEED
sta actor_sx
joystick_right_done:
jmp check_joystick_up
joystick_not_left_or_right:
jsr player_reduce_speed
check_joystick_up:
lda JOYSTICK_1
and #JOYSTICK_UP
bne check_joystick_down
check_joystick_down:
lda JOYSTICK_2
and #JOYSTICK_DOWN
beq joystick_is_down
lda down_key_pressed
bne joystick_is_down
jmp player_controls_done
joystick_is_down:
// if touching door, could be trying to exit
lda player_touching_door
beq player_controls_done
jsr EnterDoor
player_controls_done:
rts
player_reduce_speed:
// joystick is not left or right..reduce player speed if moving
lda actor_sx
bmi player_reduce_negative_speed // branch if minus
// speed is positive
// subtract force from speed
sec
sbc actor_force_no_input
sta actor_sx
// if speed is still positive, go to next joystick test
bpl check_joystick_up
// speed is negative, gone too far, reset to zero
jmp set_speed_to_zero
player_reduce_negative_speed:
// speed is negative
clc
adc actor_force_no_input
sta actor_sx
// if speed is still negative, go to next joystick test
bmi check_joystick_up
set_speed_to_zero:
// gone too far, set speed to zero
lda #$00
sta actor_sx
rts
// use actor 7 to add visual effects
// jump, land, boost
player_add_effect:
cmp actor_base_frame + 7
beq player_add_effect_done
sta actor_base_frame + 7
lda #EFFECTS
sta actor_type + 7
// all effects are 3 frames
lda #03
sta actor_frame_count + 7
lda #0
sta actor_frame_timer + 7
sta actor_current_frame + 7
// copy values from player
// same position as player sprite
lda actor_xl
sta actor_xl + 7
lda actor_xh
sta actor_xh + 7
lda actor_yl
sta actor_yl + 7
lda actor_yh
sta actor_yh + 7
player_add_effect_done:
lda actor_direction
sta actor_direction + 7
rts
}
PlayerCheckInPlayArea: {
// if player out of play area, then they die
lda actor_screen_xh
beq !+
cmp #$3f
beq out_of_play_area
lda actor_screen_xl
cmp #$3e
out_of_play_area:
bmi !+
jsr PlayerDie
!:
rts
}