home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 42 / af042b.adf / BULL5.LHA / move.s < prev    next >
Text File  |  1992-11-19  |  12KB  |  385 lines

  1. ********************************************************************************
  2. *                   oo                              oo                           *
  3. *                 \(  )/      Bullfrog Demo      \(  )/                           *
  4. *                 ^ ^^ ^         Movement        ^ ^^ ^                           *
  5. ********************************************************************************
  6.  
  7. _move_all
  8.     tst.w    died
  9.     bne.s    .died
  10.         tst.w    _pressed_fire                ;are we in the middle of a jump    
  11.         bne.s    .no_fire                    ;yes so dont check for jump
  12.             tst.w    _fire                    ;is the fire button pressed
  13.             beq.s    .no_fire                ;no so dont jump
  14.                 move.w    #-JUMP,man_vy        ;yes it was, jump into y-velocity
  15.                 move.w    #1,_pressed_fire    ;and set jump flag
  16. .no_fire
  17.     jsr        _man_x            ;move the man left and right
  18. .died
  19.     jsr        _man_y            ;move the man up and down
  20.     jsr        _man_anim        ;animate the man.
  21.     jsr        _bad_move        ;move any bad guys
  22.     jsr        _map_collision    ;has the man hit a block
  23.     jsr        _collect_collision    ;have we picked up a collectable.
  24.     jsr        _bad_collision    ;have we touched one of the bad guys.
  25.     rts                        ;return
  26.  
  27. ********************************************************************************
  28.  
  29. *Move man left and right with joystick
  30. *Uses the variables man_x    - mans x position on screen
  31. *                    man_vx    - mans current x velocity
  32. *                    _dx_joy    - reads the joystick x. -1 if left, 1 if right.
  33. _man_x
  34.     move.w    man_vx,d0            ;move the value in man_vx into d0
  35.     move.w    #0,d2
  36.     tst.w    _pressed_fire            ;are we jumping
  37.     bne.s    .jumping
  38.         move.w    _dx_joy,d2            ;move joystick value to d2
  39.         mulu    #ACEL,d2            ;multiply it by accleration
  40.         add.w    d2,d0
  41.         cmp.w    #MAX_SPEED+1,d0        ;is the value in d0 is
  42.         ble.s    .lessthanx            ;less than or equal to the maximum speed
  43.             move.w    #MAX_SPEED+1,d0    ;if it isnt then change it back to max speed
  44. .lessthanx
  45.         cmp.w    #-MAX_SPEED-1,d0    ;see if value in d0 is
  46.         bge.s    .greaterthanx        ;greater than or equal to the maximum speed
  47.             move.w    #-MAX_SPEED-1,d0    ;if not then replace with max speed
  48. .greaterthanx
  49. .jumping
  50.     move.w    man_x,d1                ;where the man is
  51.     add.w    d0,d1                    ;add his velocity
  52.     bgt.s    .not_left_side            ;if greater than 0 not at edge of screen
  53.         move.w    #0,d0                ;otherwise stop momentum
  54.         move.w    #0,d1                ;and place us at edge of screen
  55. .not_left_side
  56.     cmp.w    #304*4,d1                ;at the right hand edge of screen?
  57.     blt.s    .not_right_side            ;no.  good.
  58.         move.w    #0,d0                ;otherwise stop momentum
  59.         move.w    #304*4,d1            ;place at edge of screen
  60. .not_right_side
  61.  
  62.     tst.w    _dx_joy                    ;have we actual changed velocity
  63.     bne.s    .no_reduction            ;yes, then dont slow down
  64.         tst.w    d0                    ;which way are we going
  65.         beq.s    .no_reduction        ;we are not moving
  66.         blt.s    .going_left            ;going left
  67. .going_right                        ;where going right
  68.             sub.w    #SLOW_DOWN,d0    ;reduce speed
  69.             bge.s    .finished_slow_down
  70.             move.w    #0,d0
  71.             bra.s    .finished_slow_down
  72. .going_left
  73.             add.w    #1,d0            ;reduce speed
  74.             ble.s    .finished_slow_down
  75.             move.w    #0,d0
  76. .finished_slow_down
  77. .no_reduction                        ;finished
  78.     move.w    d0,man_vx                ;store new momentum
  79.     move.w    d1,man_x                ;store the new value in man_x
  80.     rts                                ;return
  81.  
  82. ********************************************************************************
  83.  
  84.  
  85. _man_y
  86.     tst.w    died
  87.     bne.s    .finished
  88.         move.w    #1,_pressed_fire        ;set falling/jump flag
  89.         move.w    man_y,d0                ;get man y position
  90.         move.w    man_vy,d1                ;get man y velocity
  91.         add.w    #GRAVITY,d1                ;add gravity to it
  92.         cmp.w    #MAX_SPEED,d1            ;see if we have gone over max speed
  93.         ble.s    .below_max_speed        ;no then jump past this bit
  94.             add.w    #1,fallen
  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.         cmp.w    #200*4,d0
  99.         blt.s    .still_on_screen
  100.             move.w    #-48,d0
  101. .still_on_screen
  102.         move.w    d0,man_y                ;store new position
  103.         move.w    d1,man_vy                ;store new speed
  104. .finished
  105.     rts                                ;return
  106.  
  107.  
  108.  
  109. ********************************************************************************
  110.  
  111. *Animation of man.
  112. _man_anim
  113.     move.w    man_frame,d0                ;pick up current frame of man
  114.     tst.w    man_vx                        ;see if man is stationary
  115.     beq.s    .stationary_man                ;he is so goto that code
  116. ;    tst.w    _dx_joy
  117.     blt.s    .man_move_left                ;is he going left
  118.         cmp.w    #MAN_RIGHT_START,d0
  119.         bge.s    .already_going_right
  120.             move.w    #MAN_RIGHT_START,d0
  121. .already_going_right
  122.  
  123.         add.w    #1,d0                    ;no so add 1 to animation frame
  124.         cmp.w    #MAN_RIGHT_FINISH,d0    ;see if we have got to the end
  125.         blt.s    .finished_anim            ;if not then we have finished
  126.             move.w    #MAN_RIGHT_START,d0    ;otherwise replace with start anim
  127.             bra.s    .finished_anim        ;again we have finished
  128. .man_move_left                            ;OK so we are going left
  129.         cmp.w    #MAN_LEFT_START,d0
  130.         ble.s    .already_going_left
  131.             move.w    #MAN_LEFT_START,d0
  132. .already_going_left
  133.  
  134.         sub.w    #1,d0                    ;subtract 1 from animation frame
  135.         cmp.w    #MAN_LEFT_FINISH,d0        ;have we got to end of animation
  136.         bgt.s    .finished_anim            ;no then we have finished
  137.             move.w    #MAN_LEFT_START,d0    ;yes, so restart animation
  138.             bra.s    .finished_anim        ;again we have finished
  139. .stationary_man                            ;the man is not moving
  140.     cmp.w    #MAN_BOUNCE,d0                ;has the man just landed
  141.     blt.s    .no_he_hasnt
  142.         add.w    #1,d0
  143.         cmp.w    #MAN_BOUNCE+4,d0
  144.         blt.s    .finished_anim
  145.             tst.w    died
  146.             beq.s    .no_he_hasnt
  147.                 cmp.w    #MAN_CRUMBLE_FINISH,d0
  148.                 blt.s    .finished_anim
  149.                     sub.w    #1,total_levels
  150.                     move.w    #0,to_collect
  151.                     move.w    #1,new_level
  152.                     move.w    #0,died
  153.                     sub.w    #1,current_level
  154.                     add.w    #1,game_over
  155.                     move.w    #MAN_CRUMBLE_FINISH,d0
  156.                     bra.s    .finished_anim
  157. .no_he_hasnt
  158.     move.w    #MAN_STATIONARY,d0            ;so lets put the animation frame in
  159. .finished_anim                            ;finished changing things
  160.     move.w    d0,man_frame                ;so put back current frame
  161.     rts                                    ;and return.
  162.  
  163. ********************************************************************************
  164. _map_collision
  165.     move.w    man_x,d0                    ;mans x position
  166.     move.w    man_y,d1                    ;mans y position
  167.     move.l    map_pointer,a0                ;point at map data
  168.     asr.w    #FOUR,d0                    ;hi res co-ord
  169.     move.w    d0,d4                        ;take a copy of current x
  170.     add.w    #LEFT_FOOT,d0                ;his feet size
  171.     asr.w    #SIXTEEN,d0                    ;block coord
  172.  
  173.     asr.w    #FOUR,d1                    ;hi res co-ord
  174.     add.w    #24,d1                        ;find bottom of man
  175.     asr.w    #FOUR,d1                    ;scale down
  176.     btst    #0,d1                        ;is this an odd number
  177.     bne.s    .no_collision                ;yes, then no collide
  178.         btst    #1,d1                    ;is the second bit set
  179.         bne.s    .no_collision            ;yes, then no collide
  180.             asr.w    #FOUR,d1            ;scale y position rest of way down
  181.  
  182.             move.w    d1,d3                ;copy of current y
  183.             mulu    #20,d1                ;offset into map data
  184.             adda.l    d1,a0                ;move to start of line
  185.             adda.l    d0,a0                ;move to column
  186.             tst.b    (a0)                ;is this a block or not
  187.             bne.s    .collision            ;yes then goto collide
  188.                                         ;that was his left foot, now do
  189.                                         ;his right foot
  190.             move.l    map_pointer,a0        ;point at data
  191.             adda.l    d1,a0                ;move to start row
  192.             add.w    #RIGHT_FOOT,d4        ;change x by size of foot
  193.             asr.w    #SIXTEEN,d4            ;and scale down to grid
  194.             adda.l    d4,a0                ;move into data
  195.             tst.b    (a0)                ;is this a block
  196.             beq.s    .no_collision        ;no then finished here
  197. .collision
  198.                 cmp.w    #MAX_SPEED,man_vy
  199.                 bne.s    .no_change
  200.                     move.w    #MAN_BOUNCE,man_frame
  201.                     cmp.w    #MAX_FALL,fallen
  202.                     blt.s    .still_alive
  203.                         move.w    #0,man_vx
  204.                         move.w    #1,died
  205. .still_alive
  206.                         move.w    #0,fallen
  207. .no_change
  208.                 clr.w    _pressed_fire    ;clear falling flag as on a block
  209.                 move.w    #-1,man_vy        ;stop mans speed
  210.                 asl.w    #SIXTEEN,d3        ;and recalculate his y position
  211.                 sub.w    #24,d3            ;so that he is standing
  212.                 asl.w    #FOUR,d3        ;on top of the block
  213.                 move.w    d3,man_y        ;store his new y position
  214.  
  215. .no_collision
  216.     rts                                    ;finished
  217.  
  218. ********************************************************************************
  219. _collect_collision
  220.  
  221.     move.w    man_x,d0            ;pick up our man_x position
  222.     asr.w    #FOUR,d0            ;scale down to a screen co-ord
  223.     move.w    man_y,d1            ;pick up our man_y position
  224.     asr.w    #FOUR,d1            ;scale down to a screen co-ord
  225.     move.w    d0,d2                ;take a copy of x
  226.     add.w    #MAN_WIDTH,d2        ;and add the width of our man to it
  227.     move.w    d1,d3                ;take a copy of y
  228.     add.w    #MAN_HEIGHT,d3        ;and add the height of our man to it
  229.  
  230.     lea        _objects,a0            ;point at our objects
  231.     move.w    #MAX_OBJECTS-1,d7    ;counter of how many objects to look at
  232. .loop
  233.     tst.w    OBJ_ON(a0)            ;is the first one present
  234.     beq.s    .next                ;no so lets look at the next on
  235.         move.w    OBJ_X(a0),d4    ;yes it was, get the object x
  236.         move.w    OBJ_Y(a0),d5    ;and y values
  237.         cmp.w    d3,d5            ;Is the bottom of the man greater than the
  238.                                 ;top of the object.
  239.         bgt.s    .no_collision    ;yes then we cant collide with it.
  240.         add.w    #ANKH_HEIGHT,d5    ;move to top of the object
  241.         cmp.w    d1,d5            ;is the top of the man less than the
  242.                                 ;the bottom of the object
  243.         blt.s    .no_collision    ;yes then we cant collide with it
  244.         cmp.w    d2,d4            ;compare right of man with left of object
  245.         bgt.s    .no_collision    ;if it is greater then we cant collide
  246.         add.w    #ANKH_WIDTH,d4    ;move to the right side of object
  247.         cmp.w    d0,d4            ;compare left of man with right of object
  248.         blt.s    .no_collision    ;if less than then we cant collide with it
  249.             move.w    #0,OBJ_ON(a0)    ;clear out the object as we have just touched it
  250.             sub.w    #1,to_collect    ;reduce the number left to get
  251.             move.w    total_levels,d6    ;as compute the score
  252.             mulu    #SCORE,d6        ;that is received by getting the object
  253.             add.w    d6,score        ;score = level * multiplier
  254.             move.w    #DELAY,delay    ;place a delay to stop instant jump
  255. .next                                ;we want to get the next object
  256. .no_collision                        ;because the last one did not exist or we
  257.                                     ;didnt touch it.
  258.         lea        OBJ_SIZE(a0),a0        ;so move the pointer to the next object
  259.     dbra    d7,.loop                ;repeat until there are no more objects
  260.     rts
  261.  
  262. ********************************************************************************
  263. _bad_move
  264.     lea        _bad_guys,a0
  265.     moveq.w    #MAX_BADDIES,d0
  266. .loop
  267.     move.w    BAD_ON(a0),d1
  268.     beq.s    .next
  269.         asl.w    #TWO,d1
  270.         move.w    .jump_table(pc,d1.w),d1
  271.         jmp        .jump_table(pc,d1.w)
  272. .jump_table    dc.w    .spare-.jump_table
  273.             dc.w    .bad_left-.jump_table
  274.             dc.w    .bad_middle-.jump_table
  275.             dc.w    .bad_middle-.jump_table
  276.             dc.w    .bad_right-.jump_table
  277.  
  278. .bad_left
  279.     jsr        _bad_left
  280.     bra.s    .next
  281. .bad_middle
  282.     jsr        _bad_middle
  283.     bra.s    .next
  284. .bad_right
  285.     jsr        _bad_right
  286. ;    bra.s    .next
  287. .spare
  288. .next
  289.     lea        BAD_SIZE(a0),a0
  290.     dbra    d0,.loop
  291.     rts
  292. ********************************************************************************
  293. _bad_left
  294.     sub.w    #1,BAD_DELAY(a0)
  295.     bne.s    .no_change
  296.         move.w    #BAD_FRAME_DELAY,BAD_DELAY(a0)
  297.         add.w    #1,BAD_FRAME(a0)
  298.         cmp.w    #BAD_LEFT_END,BAD_FRAME(a0)
  299.         ble.s    .changed
  300.             move.w    #BAD_LEFT_START,BAD_FRAME(a0)
  301. .changed
  302. .no_change
  303.     move.w    BAD_X(a0),d2
  304.     sub.w    #1,d2
  305.     blt.s    .off_side_of_screen
  306.         move.w    d2,d3
  307.         jsr        _still_on_floor
  308.         tst.w    d3
  309.         bne.s    .still_on_floor
  310. .off_side_of_screen
  311.             add.w    #1,d2
  312.             move.w    #BAD_STATE_FROM_LEFT,BAD_STATE(a0)
  313.             move.w    #BAD_MIDDLE,BAD_FRAME(a0)
  314.             move.w    #BAD_FRAME_DELAY,BAD_DELAY(a0)
  315. .still_on_floor
  316.         move.w    d2,BAD_X(a0)
  317.     rts
  318. ********************************************************************************
  319. _bad_middle
  320.     sub.w    #1,BAD_DELAY(a0)
  321.     bne.s    .no_change
  322.         move.w    #BAD_FRAME_DELAY,BAD_DELAY(a0)
  323.         cmp.w    #BAD_STATE_FROM_LEFT,BAD_STATE(a0)
  324.         beq.s    .came_from_left
  325. .came_from_right
  326.             move.w    #BAD_STATE_LEFT,BAD_STATE(a0)
  327.             move.w    #BAD_LEFT_START,BAD_FRAME(a0)
  328.             bra.s    .finished
  329. .came_from_left
  330.             move.w    #BAD_STATE_RIGHT,BAD_STATE(a0)
  331.             move.w    #7,BAD_FRAME(a0)
  332. ;            bra.s    .finished
  333. .finished
  334. .no_change
  335.     rts
  336. ********************************************************************************
  337. _bad_right
  338.     sub.w    #1,BAD_DELAY(a0)
  339.     bne.s    .no_change
  340.         move.w    #BAD_FRAME_DELAY,BAD_DELAY(a0)
  341.         add.w    #1,BAD_FRAME(a0)
  342.         cmp.w    #BAD_RIGHT_END,BAD_FRAME(a0)
  343.         ble.s    .changed
  344.             move.w    #BAD_RIGHT_START,BAD_FRAME(a0)
  345. .changed
  346. .no_change
  347.     move.w    BAD_X(a0),d2
  348.     add.w    #1,d2
  349.     cmp.w    #304,BAD_X(a0)
  350.     bgt.s    .off_side_of_screen
  351.         move.w    d2,d3
  352.         add.w    #16,d3
  353.         jsr        _still_on_floor
  354.         tst.w    d3
  355.         bne.s    .still_on_floor
  356. .off_side_of_screen
  357.         sub.w    #1,d2
  358.         move.w    #BAD_STATE_FROM_RIGH,BAD_STATE(a0)
  359.         move.w    #BAD_MIDDLE,BAD_FRAME(a0)
  360.         move.w    #BAD_FRAME_DELAY,BAD_DELAY(a0)
  361. .still_on_floor
  362.     move.w    d2,BAD_X(a0)
  363.     rts
  364. ********************************************************************************
  365. _still_on_floor
  366.     move.l    map_pointer,a1
  367.     moveq.l    #0,d4
  368.     move.w    BAD_Y(a0),d4
  369.     asr.w    #SIXTEEN,d4
  370.     add.w    #1,d4
  371.     mulu    #20,d4
  372.     adda.l    d4,a1
  373.     asr.w    #SIXTEEN,d3
  374.     adda.l    d3,a1
  375.     move.b    (a1),d3
  376.     rts
  377. ********************************************************************************
  378. *place the collision with the bad guys here.
  379.  
  380. _bad_collision
  381.  
  382.     rts                                ;finished so return
  383. ********************************************************************************
  384.  
  385. ;;;