move.s 14 KB

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