daily pastebin goal
48%
SHARE
TWEET

Enemy Coordinates Compared to Player's

slydogstudios Apr 25th, 2013 114 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; ZEROPAGE
  2. nmi_num:        .res 1
  3. temp_16bit_1:   .res 2
  4. temp_16bit_2:   .res 2
  5. loop_addy:      .res 2
  6. p_floor:        .res 1
  7. p_x_pos:        .res 1
  8. p_y_pos:        .res 1
  9.  
  10. ; CONSTANTS
  11. enemy_amount_on_floors  = $500
  12.  
  13. floors_lo:
  14.         .byte <floor0_big, <floor1_big, <floor2_big, <floor3_big
  15. floors_hi:
  16.         .byte >floor0_big, >floor1_big, >floor2_big, >floor3_big
  17. enemy_y_coords_lo:
  18.         .byte <floor0_enemy_y, <floor1_enemy_y, <floor2_enemy_y, <floor3_enemy_y
  19. enemy_y_coords_hi:
  20.         .byte >floor0_enemy_y, >floor1_enemy_y, >floor2_enemy_y, >floor3_enemy_y
  21. enemy_x_coords_lo:
  22.         .byte <floor0_enemy_x, <floor1_enemy_x, <floor2_enemy_x, <floor3_enemy_x
  23. enemy_x_coords_hi:
  24.         .byte >floor0_enemy_x, >floor1_enemy_x, >floor2_enemy_x, >floor3_enemy_x
  25.  
  26. ; Number of enemy encounters per floor +1. Plus one so
  27. ;  the routine will run entirely through all and exit
  28. enemy_amount_on_floors:
  29.         .byte 21,26,31,36
  30.  
  31. ; Dummy data for testing
  32. floor0_enemy_y:
  33.         .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  34.         .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  35. floor1_enemy_y:
  36.         .byte 46,44,$00,$00,$00,$00,$00,$00,$00,$00
  37.         .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  38. floor2_enemy_y:
  39.         .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  40.         .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  41. floor3_enemy_y:
  42.         .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  43.         .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  44. floor0_enemy_x:
  45.         .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  46.         .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  47. floor1_enemy_x:
  48.         .byte 04,04,$00,$00,$00,$00,$00,$00,$00,$00
  49.         .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  50. floor2_enemy_x:
  51.         .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  52.         .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  53. floor3_enemy_x:
  54.         .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  55.         .byte $00,$00,$00,$00,$00,$00,$00,$00,$00,$00
  56.  
  57. ; Run this AFTER the screen is done loading to find out
  58. ;  if there is an enemy on the coordinate the player has
  59. ;  landed on
  60. enemy_test_coordinate:
  61.         ldx p_floor                                     ; Get floor player is on
  62.         lda enemy_y_coords_lo, x                        ; Get correct table of enemy Y pos
  63.         sta temp_16bit_1+0                              ;
  64.         lda enemy_y_coords_hi, x                        ;
  65.         sta temp_16bit_1+1                              ;
  66.         lda enemy_x_coords_lo, x                        ; Get correct table of enemy X pos
  67.         sta temp_16bit_2+0                              ;
  68.         lda enemy_x_coords_hi, x                        ;
  69.         sta temp_16bit_2+1                              ;
  70.         ldy #00                                         ; Set up Y register
  71. @test_y:                                                ;
  72.         lda (temp_16bit_1), y                           ; Test if enemy Y pos == player Y pos
  73.         cmp p_y_pos                                     ;  and if so...
  74.         bne :+                                          ;
  75.                 lda (temp_16bit_2), y                   ; Test if enemy X pos == player X pos
  76.                 cmp p_x_pos                             ;  and if so...
  77.                 bne :+                                  ;
  78.                         lda enemy_present, y            ; Test if enemy at that coord has been
  79.                         beq :+                          ;  defeated yet or not through RAM table
  80.                                 lda #<loop_nothing      ; Do stuff if enemies are present
  81.                                 sta loop_addy+0         ;
  82.                                 lda #>loop_nothing      ;
  83.                                 sta loop_addy+1         ;
  84.                                 rts                     ;
  85. :       iny                                             ; Increment the Y register and stick it
  86.         tya                                             ;  in A to compare the amount of enemies
  87.         cmp enemy_amount_on_floors, x                   ;  on the floor in order to escape the
  88.         bne @test_y                                     ;  routine
  89.         rts                                             ;
  90.  
  91. loop_nothing:
  92.         jmp end_loop
  93.  
  94. loop:
  95.         jmp (loop_addy)
  96. end_loop:
  97.         jsr nmi_wait
  98.         jmp loop
  99.  
  100. nmi_wait:
  101.         lda nmi_num
  102. :       cmp nmi_num
  103.         beq :-
  104.         rts
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top