home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 41 / af041b.adf / Bullfrogs / move.s < prev    next >
Text File  |  1992-10-23  |  7KB  |  175 lines

  1. ********************************************************************************
  2. *                   oo                              oo                           *
  3. *                 \(  )/      Bullfrog Demo      \(  )/                           *
  4. *                 ^ ^^ ^         Movement        ^ ^^ ^                           *
  5. ********************************************************************************
  6.  
  7. ;LEVEL                equ    0        ;Current Level 0 or 1
  8. GRAVITY                equ    2        ;Speed at which gravity affects man
  9. MAX_SPEED            equ    16        ;maximum speed of man
  10. JUMP                equ    20
  11. ACEL                equ    3        ;speed of accleration for man
  12. MAN_LEFT_START        equ    4*4        ;start frame number for man running left
  13. MAN_LEFT_FINISH        equ    1*4        ;end frame number for man running left
  14. MAN_STATIONARY        equ    5*4        ;frame for man standing still
  15. MAN_RIGHT_START        equ    6*4        ;start frame number for man running right
  16. MAN_RIGHT_FINISH    equ    9*4        ;end frame number for man running right
  17. LEFT_FOOT            equ    3        ;mans left foot
  18. RIGHT_FOOT            equ    10        ;mans right foot
  19.  
  20. ********************************************************************************
  21.  
  22. _move_all
  23.     tst.w    _pressed_fire                ;are we in the middle of a jump    
  24.     bne.s    .no_fire                    ;yes so dont check for jump
  25.         tst.w    _fire                    ;is the fire button pressed
  26.         beq.s    .no_fire                ;no so dont jump
  27.             move.w    #-JUMP,man_vy        ;yes it was, jump into y-velocity
  28.             move.w    #1,_pressed_fire    ;and set jump flag
  29. .no_fire
  30.     jsr        _man_x            ;move the man left and right
  31.     jsr        _man_y            ;move the man up and down
  32.     jsr        _man_anim        ;animate the man.
  33.     jsr        _map_collision    ;has the man hit a block
  34.     rts                        ;return
  35.  
  36. ********************************************************************************
  37.  
  38. *Move man left and right with joystick
  39. *Uses the variables man_x    - mans x position on screen
  40. *                    man_vx    - mans current x velocity
  41. *                    _dx_joy    - reads the joystick x. -1 if left, 1 if right.
  42. _man_x
  43.     move.w    man_vx,d0            ;move the value in man_vx into d0
  44.     move.w    #0,d2
  45.     tst.w    _pressed_fire            ;are we jumping
  46.     bne.s    .jumping
  47.         move.w    _dx_joy,d2            ;move joystick value to d2
  48.         mulu    #ACEL,d2            ;multiply it by accleration
  49.         add.w    d2,d0
  50.         cmp.w    #MAX_SPEED+1,d0        ;is the value in d0 is
  51.         ble.s    .lessthanx            ;less than or equal to the maximum speed
  52.             move.w    #MAX_SPEED+1,d0    ;if it isnt then change it back to max speed
  53. .lessthanx
  54.         cmp.w    #-MAX_SPEED-1,d0    ;see if value in d0 is
  55.         bge.s    .greaterthanx        ;greater than or equal to the maximum speed
  56.             move.w    #-MAX_SPEED-1,d0    ;if not then replace with max speed
  57. .greaterthanx
  58. .jumping
  59.     move.w    man_x,d1                ;where the man is
  60.     add.w    d0,d1                    ;add his velocity
  61.     bgt.s    .not_left_side            ;if greater than 0 not at edge of screen
  62.         move.w    #0,d0                ;otherwise stop momentum
  63.         move.w    #0,d1                ;and place us at edge of screen
  64. .not_left_side
  65.     cmp.w    #304*4,d1                ;at the right hand edge of screen?
  66.     blt.s    .not_right_side            ;no.  good.
  67.         move.w    #0,d0                ;otherwise stop momentum
  68.         move.w    #304*4,d1            ;place at edge of screen
  69. .not_right_side
  70.  
  71.     tst.w    _dx_joy                    ;have we actual changed velocity
  72.     bne.s    .no_reduction            ;yes, then dont slow down
  73.         tst.w    d0                    ;which way are we going
  74.         beq.s    .no_reduction        ;we are not moving
  75.         blt.s    .going_left            ;going left
  76. .going_right                        ;where going right
  77.             sub.w    #2,d0            ;reduce speed
  78. .going_left
  79.             add.w    #1,d0            ;reduce speed
  80. .no_reduction                        ;finished
  81.     move.w    d0,man_vx                ;store new momentum
  82.     move.w    d1,man_x                ;store the new value in man_x
  83.     rts                                ;return
  84.  
  85. ********************************************************************************
  86.  
  87.  
  88. _man_y
  89.     move.w    #1,_pressed_fire        ;set falling/jump flag
  90.     move.w    man_y,d0                ;get man y position
  91.     move.w    man_vy,d1                ;get man y velocity
  92.     add.w    #GRAVITY,d1                ;add gravity to it
  93.     cmp.w    #MAX_SPEED,d1            ;see if we have gone over max speed
  94.     ble.s    .below_max_speed        ;no then jump past this bit
  95.         move.w    #MAX_SPEED,d1        ;yes, place max speed into d1
  96. .below_max_speed
  97.     add.w    d1,d0                    ;change position by speed
  98.     move.w    d0,man_y                ;store new position
  99.     move.w    d1,man_vy                ;store new speed
  100.     rts                                ;return
  101.  
  102.  
  103. ********************************************************************************
  104.  
  105. *Animation of man.
  106. _man_anim
  107.     move.w    man_frame,d0                ;pick up current frame of man
  108.     tst.w    man_vx                        ;see if man is stationary
  109.     beq.s    .stationary_man                ;he is so goto that code
  110.     blt.s    .man_move_left                ;is he going left
  111.         add.w    #1,d0                    ;no so add 1 to animation frame
  112.         cmp.w    #MAN_RIGHT_FINISH,d0    ;see if we have got to the end
  113.         blt.s    .finished_anim            ;if not then we have finished
  114.             move.w    #MAN_RIGHT_START,d0    ;otherwise replace with start anim
  115.             bra.s    .finished_anim        ;again we have finished
  116. .man_move_left                            ;OK so we are going left
  117.         sub.w    #1,d0                    ;subtract 1 from animation frame
  118.         cmp.w    #MAN_LEFT_FINISH,d0        ;have we got to end of animation
  119.         bgt.s    .finished_anim            ;no then we have finished
  120.             move.w    #MAN_LEFT_START,d0    ;yes, so restart animation
  121.             bra.s    .finished_anim        ;again we have finished
  122. .stationary_man                            ;the man is not moving
  123.     move.w    #MAN_STATIONARY,d0            ;so lets put the animation frame in
  124. .finished_anim                            ;finished changing things
  125.     move.w    d0,man_frame                ;so put back current frame
  126.     rts                                    ;and return.
  127.  
  128. ********************************************************************************
  129. _map_collision
  130.     move.w    man_x,d0                    ;mans x position
  131.     move.w    man_y,d1                    ;mans y position
  132.     lea        _map_data,a0                ;point at map data
  133.     asr.w    #FOUR,d0                    ;hi res co-ord
  134.     move.w    d0,d4                        ;take a copy of current x
  135.     add.w    #LEFT_FOOT,d0                ;his feet size
  136.     asr.w    #SIXTEEN,d0                    ;block coord
  137.  
  138.     asr.w    #FOUR,d1                    ;hi res co-ord
  139.     add.w    #24,d1                        ;find bottom of man
  140.     asr.w    #FOUR,d1                    ;scale down
  141.     btst    #0,d1                        ;is this an odd number
  142.     bne.s    .no_collision                ;yes, then no collide
  143.         btst    #1,d1                    ;is the second bit set
  144.         bne.s    .no_collision            ;yes, then no collide
  145.             asr.w    #FOUR,d1            ;scale y position rest of way down
  146.  
  147.             move.w    d1,d3                ;copy of current y
  148.             mulu    #20,d1                ;offset into map data
  149.             adda.l    d1,a0                ;move to start of line
  150.             adda.l    d0,a0                ;move to column
  151.             tst.b    (a0)                ;is this a block or not
  152.             bne.s    .collision            ;yes then goto collide
  153.                                         ;that was his left foot, now do
  154.                                         ;his right foot
  155.             lea        _map_data,a0        ;point at data
  156.             adda.l    d1,a0                ;move to start row
  157.             add.w    #RIGHT_FOOT,d4        ;change x by size of foot
  158.             asr.w    #SIXTEEN,d4            ;and scale down to grid
  159.             adda.l    d4,a0                ;move into data
  160.             tst.b    (a0)                ;is this a block
  161.             beq.s    .no_collision        ;no then finished here
  162. .collision
  163.                 clr.w    _pressed_fire    ;clear falling flag as on a block
  164.                 move.w    #-1,man_vy        ;stop mans speed
  165.                 asl.w    #SIXTEEN,d3        ;and recalculate his y position
  166.                 sub.w    #24,d3            ;so that he is standing
  167.                 asl.w    #FOUR,d3        ;on top of the block
  168.                 move.w    d3,man_y        ;store his new y position
  169.  
  170. .no_collision
  171.     rts                                    ;finished
  172.  
  173. ********************************************************************************
  174.  
  175. ;;;