home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 39 / af039a.adf / move.s < prev    next >
Text File  |  1992-09-17  |  4KB  |  107 lines

  1. ********************************************************************************
  2. *                   oo                              oo                           *
  3. *                 \(  )/      Bullfrog Demo      \(  )/                           *
  4. *                 ^ ^^ ^         Movement        ^ ^^ ^                           *
  5. ********************************************************************************
  6.  
  7. MAX_SPEED            equ    16        ;maximum speed of man
  8. ACEL                equ    3        ;speed of accleration for man
  9. MAN_LEFT_START        equ    4*4        ;start frame number for man running left
  10. MAN_LEFT_FINISH        equ    1*4        ;end frame number for man running left
  11. MAN_STATIONARY        equ    5*4        ;frame for man standing still
  12. MAN_RIGHT_START        equ    6*4        ;start frame number for man running right
  13. MAN_RIGHT_FINISH    equ    9*4        ;end frame number for man running right
  14.  
  15. ********************************************************************************
  16.  
  17. _move_all
  18.     jsr        _man_x            ;move the man left and right
  19.     jsr        _man_y            ;move the man up and down
  20.     jsr        _man_anim        ;animate the man.
  21.     rts                        ;return
  22.  
  23. ********************************************************************************
  24.  
  25. *Move man left and right with joystick
  26. *Uses the variables man_x    - mans x position on screen
  27. *                    man_vx    - mans current x velocity
  28. *                    _dx_joy    - reads the joystick x. -1 if left, 1 if right.
  29. _man_x
  30.     move.w    man_vx,d0            ;move the value in man_vx into d0
  31.     move.w    _dx_joy,d2            ;move joystick value to d2
  32.     mulu    #ACEL,d2            ;multiply it by accleration
  33.     add.w    d2,d0
  34.     cmp.w    #MAX_SPEED,d0        ;is the value in d0 is
  35.     ble.s    .lessthanx            ;less than or equal to the maximum speed
  36.         move.w    #MAX_SPEED,d0    ;if it isnt then change it back to max speed
  37. .lessthanx
  38.     cmp.w    #-MAX_SPEED,d0        ;see if value in d0 is
  39.     bge.s    .greaterthanx        ;greater than or equal to the maximum speed
  40.         move.w    #-MAX_SPEED,d0    ;if not then replace with max speed
  41. .greaterthanx
  42.  
  43.     move.w    man_x,d1            ;where the man is
  44.     add.w    d0,d1                ;add his velocity
  45.     bgt.s    .not_left_side        ;if greater than 0 not at edge of screen
  46.         move.w    #0,d0            ;otherwise stop momentum
  47.         move.w    #0,d1            ;and place us at edge of screen
  48. .not_left_side
  49.     cmp.w    #300*4,d1            ;at the right hand edge of screen?
  50.     blt.s    .not_right_side        ;no.  good.
  51.         move.w    #0,d0            ;otherwise stop momentum
  52.         move.w    #300*4,d1        ;place at edge of screen
  53. .not_right_side
  54.  
  55.     tst.w    _dx_joy                ;have we actual changed velocity
  56.     bne.s    .no_reduction        ;yes, then dont slow down
  57.         tst.w    d0                ;which way are we going
  58.         beq.s    .no_reduction    ;we are not moving
  59.         blt.s    .going_left        ;going left
  60. .going_right                    ;where going right
  61.             sub.w    #2,d0        ;reduce speed
  62. .going_left
  63.             add.w    #1,d0        ;reduce speed
  64. .no_reduction                    ;finished
  65.     move.w    d0,man_vx            ;store new momentum
  66.     move.w    d1,man_x            ;store the new value in man_x
  67.     rts                            ;return
  68.  
  69. ********************************************************************************
  70.  
  71. *Place mans Y movement in here.
  72. *Use the variables     man_y    - mans y position on screen
  73. *                    man_vy    - mans current y velocity
  74. *                    _dy_joy    - reads the joystick y. -1 if up, 1 if down.
  75.  
  76. _man_y
  77.  
  78.     rts                            ;return
  79.  
  80.  
  81. ********************************************************************************
  82.  
  83. *Animation of man.
  84. _man_anim
  85.     move.w    man_frame,d0                ;pick up current frame of man
  86.     tst.w    man_vx                        ;see if man is stationary
  87.     beq.s    .stationary_man                ;he is so goto that code
  88.     blt.s    .man_move_left                ;is he going left
  89.         add.w    #1,d0                    ;no so add 1 to animation frame
  90.         cmp.w    #MAN_RIGHT_FINISH,d0    ;see if we have got to the end
  91.         blt.s    .finished_anim            ;if not then we have finished
  92.             move.w    #MAN_RIGHT_START,d0    ;otherwise replace with start anim
  93.             bra.s    .finished_anim        ;again we have finished
  94. .man_move_left                            ;OK so we are going left
  95.         sub.w    #1,d0                    ;subtract 1 from animation frame
  96.         cmp.w    #MAN_LEFT_FINISH,d0        ;have we got to end of animation
  97.         bgt.s    .finished_anim            ;no then we have finished
  98.             move.w    #MAN_LEFT_START,d0    ;yes, so restart animation
  99.             bra.s    .finished_anim        ;again we have finished
  100. .stationary_man                            ;the man is not moving
  101.     move.w    #MAN_STATIONARY,d0            ;so lets put the animation frame in
  102. .finished_anim                            ;finished changing things
  103.     move.w    d0,man_frame                ;so put back current frame
  104.     rts                                    ;and return.
  105.  
  106.  
  107. ;;;