home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 39 / af039a.adf / month1.doc < prev    next >
Text File  |  1992-08-24  |  5KB  |  143 lines

  1. ********************************************************************************
  2. *                   oo                              oo                           *
  3. *                 \(  )/      Bullfrog Demo      \(  )/                           *
  4. *                 ^ ^^ ^         Month 1         ^ ^^ ^                           *
  5. ********************************************************************************
  6.  
  7.  
  8. So you want to be a games programmer.  Well then read on, and you should get a
  9. few helpful hints.  Included on the disk is a simple shell for writing programs
  10. in assembler.  It sets you up with all you need to swap screens, draw sprites,
  11. and so on...
  12.  
  13.  
  14. With this shell you don't have to wade through loads of reference manuals to
  15. find out how to set up screens, or display sprites, its been done for you.  Over
  16. the course of several months we will be putting together a very simple game, but
  17. there are several things you will need:-
  18.  
  19.     * Enthusiasm.  Yep I know, sounds obvious but you will always be just a
  20.       standard programmer unless you really want to do it.
  21.     * It would be nice if you read a 68000 assembler book.
  22.     * Do you know what binary / hexidecimal are, no then thry and find out, get
  23.       one of those boring reference manauls out the libarary.
  24.  
  25.  
  26. Ok, thats the boring introduction done, lets have a look at the disk.  If you
  27. first assemble Demo.s and then run Demo.  All that should happen is that we
  28. display a sprite on the screen.  To exit from the program press the Q Key.
  29. Great.  There you go.  What?  You want more?
  30.  
  31. Then lets try and move the sprite.  Have a look in draw.s in the routine
  32.  
  33. _draw_all 
  34.  
  35. you will see we have
  36.  
  37.         moveq.w    #0,d0
  38.         moveq.w    #0,d1
  39.         moveq    #0,d2
  40.  
  41. now if we change these to
  42.  
  43.         move.w    man_x,d0
  44.         move.w    man_y,d1
  45.         move.w    man_frame,d2
  46.  
  47. Right, now the impatient ones of you will have assembled that.  No change, of
  48. course not, but if you go into move.s and remove the indicated ;'s our sprite
  49. should start to move to the right and return to the start when he reaches the
  50. end of the screen.  The way these instructions work is as follows.  First we
  51. increment the value of the man x co-ordinate by 1 every turn.  The value is then
  52. compared with 304 and if it is greater than this the position is reset to 0
  53. otherwise we jump over the reset command.  The value is then stored back into
  54. man_x ready for the next draw.
  55.  
  56. You can change the value in the add command to increase the speed of movement.
  57.  
  58. A small challenge for you, see if you can write the code to move the man down
  59. the screen.  The code will be basically the same as the move x stuff, but
  60. remember the screen size is 320 by 200 pixels, and that the label lessthanx
  61. has already been used, so use something different.  A note on labels, try
  62. and keep them meaningful, 6 labels with the name .here is not very helpful.
  63.  
  64. We should have, by now, got the man moving down and across the screen, but thats
  65. the problem he is not moving.  Lets put a bit of animation into the man.
  66. To do this we took the same routine as was used in the movement and changed a 
  67. few things.  Be careful, we only have 4 frames of animation so dont set the
  68. compare to high.
  69.  
  70. Compile this and have a look.  He is changing frames just a little bit fast,
  71. too fast in fact so we need to slow him down.  To do this change the line
  72.     cmp    #4,d0
  73. to    cmp    #4*4,d0
  74.  
  75. thats not quite all, we need to scale the number back down.  To do this
  76. after the line
  77.     move.w    man_frame,d2
  78. in draw.s, place the following piece of code:-
  79.     asr.w    #2,d2
  80.  
  81. Assemble this, and the man should be walking a bit slower.
  82.  
  83.  
  84. COMMAND OVERVIEW
  85.  
  86. move.w    1,2
  87. The move command is one of the most heavily used commands for simplicity we
  88. are using move.w the w means word sized data.  It is the equivelent of the
  89. basic LET statement.  It loads 1 into 2.
  90.  
  91. add.w    1,2
  92. The add command does just that adds the value of 1 to 2.
  93.  
  94. sub.w    1,2
  95. The sub command is similar to the add but does subtracts instead.
  96.  
  97. cmp.w    1,2
  98. The compare command compares the value of 1 with the value of 2.  When used
  99. in conjunction with a branch you get the equivelent of the basic IF statement
  100.  
  101. Branches
  102. The branch checks on the flags set by the compare statement.  There are 15
  103. different versions of this command:-
  104.     bra        Branch always.  Same as GOTO
  105.     bcc        Branch if carry clear
  106.     bcs        Branch if carry set
  107.     beq        Branch if equal
  108.     bge        Branch if greater than or equal to
  109.     bhi        Branch if higher
  110.     ble        Branch if less than or equal to
  111.     bls        Branch if low or same
  112.     blt        Branch if less than
  113.     bmi        Branch if minus
  114.     bne        Branch if not equal to
  115.     bpl        Branch if plus
  116.     bvc        Branch if overflow clear
  117.     bvs        Branch if overflow set
  118.  
  119. Dont worry if you dont understand what all of these do, we want be using all of
  120. them.  I hope.  Anyway, when the condition is true the branch is taken, if not
  121. them we move onto the next instruction.
  122.  
  123. Labels
  124. You will notice that some of the labels have a '.' in front of them, these are
  125. called local labels.  Now that means that you can use words like .finished more
  126. than once, though not inside the same routine.  Routines are defined by labels
  127. which have not got a period '.' in front of them and are finished with an RTS
  128. command.
  129.  
  130. jsr
  131. Jump to subroutine.  This command is basically the same as the GOSUB command.
  132.  
  133. rts
  134. This is basically the same as the RETURN command.
  135.  
  136. asr.w    1,2
  137. The asr command means Arithmetic Shift Right and works by moving a binary
  138. number to the right the define number of times.
  139. eg.        on a asr.w    #1,10
  140. we get an answer of 5. This is because 10 in binary looks like this:-
  141.     1010 = 10
  142. and when we move it to the right by one it becomes:-
  143.     0101 = 5