Yesterday I started making a game in asm using ion. Eventually I want it to be sorta like a game in C# from a book I have read (sorry for the size Razz)

Here is my beginning representation:


And here is the code. (MIMAS syntax, btw)
It's not very optimized right now, but I should fix that eventually.

Code:
;#SECTION "MAIN", CODE

storage equ   appBackUpScreen
mex equ   storage + 1
shotinscreen equ   storage + 2
shotx equ   storage + 3
shoty equ   storage + 4
   org   userMem - 2
   db   0BBh, 6Dh
   ret

   jr   nc, Start
   db   "Move", 0
Start:
   ld   a, 0
   ld   (shotinscreen), a
   ld   a, 47
   ld   (shoty), a
   B_CALL   _ClrLCDFull
   B_CALL   _GrBufClr
   ld   a, 48
   ld   (mex), a
   ld   b, 8
   ld   a, 0
   ld   l, 56
   call   Quick
   ld   b, 8
   ld   a, 8
   ld   l, 56
   call   Quick
   ld   b, 8
   ld   a, 16
   ld   l, 56
   call   Quick
   ld   b, 8
   ld   a, 24
   ld   l, 56
   call   Quick
   ld   b, 8
   ld   a, 32
   ld   l, 56
   call   Quick
   ld   b, 8
   ld   a, 40
   ld   l, 56
   call   Quick
   ld   b, 8
   ld   a, 48
   ld   l, 56
   call   Quick
   ld   b, 8
   ld   a, 56
   ld   l, a
   call   Quick
   ld   b, 8
   ld   a, 64
   ld   l, 56
   call   Quick
   ld   b, 8
   ld   a, 72
   ld   l, 56
   call   Quick
   ld   b, 8
   ld   a, 80
   ld   l, 56
   call   Quick
   ld   b, 8
   ld   a, 88
   ld   l, 56
   call   Quick
   ld   b, 8
   ld   a, (mex)
   ld   l, 48
   ld   ix, Me
   call   ionPutSprite
   call   ionFastCopy
   ld   b, 8
   ld   a, (mex)
   ld   l, 48
   ld   ix, Me
   call   ionPutSprite
Game:
   ld   b, 8
   ld   a, (mex)
   ld   l, 48
   ld   ix, Me
   call   ionPutSprite
   call   ionFastCopy
   ld   b, 8
   ld   a, (mex)
   ld   l, 48
   ld   ix, Me
   call   ionPutSprite
   ld   a, (shotinscreen)
   cp   1
   call   z, Shot
   call   getkd
   ld   a, b
   cp   KD_CLEAR
   jr   z, Exit
   cp   KD_LEFT
   call   z, Left
   cp   KD_RIGHT
   call   z, Right
   cp   KD_2ND
   call   z, Shoot
   cp   11101101b
   jr   z, BL
   cp   11101011b
   jr   z, BR
   jr   Game

Exit:
   B_CALL   _GrBufClr
   B_CALL   _ClrLCDFull
   ret

BL:
   call   Shoot
   call   Left
   jr   Game

BR:
   call   Shoot
   call   Right
   jr   Game

Left:
   ld   a, (mex)
   cp   0
   ret   z
   sub   1
   ld   (mex), a
   ret

Right:
   ld   a, (mex)
   cp   88
   ret   z
   add   a, 1
   ld   (mex), a
   ret

Shoot:
   ld   a, (shotinscreen)
   cp   1
   ret   z
   ld   a, 1
   ld   (shotinscreen), a
   ld   b, 8
   ld   a, (shoty)
   ld   l, a
   ld   a, (mex)
   ld   (shotx), a
   ld   ix, Sm
   call   ionPutSprite
   ret

Shot:
   ld   b, 8
   ld   a, (shoty)
   ld   l, a
   ld   a, (shotx)
   ld   ix, Sm
   call   ionPutSprite
   ld   a, (shoty)
   cp   0
   jr   z, Ends
   dec   a
   ld   (shoty), a
   ld   l, a
   ld   b, 8
   ld   a, (shotx)
   ld   ix, Sm
   call   ionPutSprite
   ret

Ends:
   ld   a, 47
   ld   (shoty), a
   ld   a, 0
   ld   (shotinscreen), a
   ret

Quick:
   ld   ix, block1
   call   ionPutSprite
   ret

block1:
   db   11111111b
   db   11101110b
   db   01010101b
   db   10101010b
   db   01010101b
   db   10101010b
   db   01110111b
   db   11111111b
Me:
   db   00000000b
   db   00011000b
   db   00011000b
   db   00111100b
   db   00111100b
   db   01111110b
   db   01111110b
   db   01111110b
Sm:
   db   00011000b
   db   00011000b
   db   00000000b
   db   00000000b
   db   00000000b
   db   00000000b
   db   00000000b
   db   00000000b
;#IMPORT "GETKEY"
;#IMPORT "IonEqu"


I hope to complete this eventually. I will need to learn a lot more complex parts of asm before finishing it, though. (Note to self - finish reading "Learn Asm in 28 Days") Very Happy
Despite not reading the entire tutorial, this looks really great for a beginner! Smile I see barely optimizations Wink
Great job!
Looks very nice indeed! A small suggestion though; this:


Code:
ld   b, 8
   ld   a, 0
   ld   l, 56
   call   Quick
   ld   b, 8
   ld   a, 8
   ld   l, 56
   ld   ix, block1
   call   ionPutSprite
   ld   b, 8
   ld   a, 16
   ld   l, 56
   call   Quick
   ld   b, 8
   ld   a, 24
   ld   l, 56
   call   Quick
   ld   b, 8
   ld   a, 32
   ld   l, 56
   call   Quick
   ld   b, 8
   ld   a, 40
   ld   l, 56
   call   Quick
   ld   b, 8
   ld   a, 48
   ld   l, 56
   call   Quick
   ld   b, 8
   ld   a, 56
   ld   l, a
   call   Quick
   ld   b, 8
   ld   a, 64
   ld   l, 56
   call   Quick
   ld   b, 8
   ld   a, 72
   ld   l, 56
   call   Quick
   ld   b, 8
   ld   a, 80
   ld   l, 56
   call   Quick
   ld   b, 8
   ld   a, 88
   ld   l, 56
   call   Quick


Can simply be:


Code:
   ld a,88
loop:
   ld   b, 8
   ld   l, 56
   push   af
   ld   ix, block1
   call   ionPutSprite
   pop   af
   sub 8
   jr nc,loop


Also note that 'sub 1' and 'add 1' can just be 'dec a' and 'inc a' respectively. They are smaller and faster Smile
Thanks guys. Very Happy
I added the optimization, Mateo, the code looks way better now Razz
What should I use to keep track of the "Bees"? A list?

Is this how a list looks in asm: .db 1,1,1,1,1,1 ...
Switchblade wrote:
Thanks guys. Very Happy
I added the optimization, Mateo, the code looks way better now Razz
What should I use to keep track of the "Bees"? A list?

Is this how a list looks in asm: .db 1,1,1,1,1,1 ...
Great work so far! Smile

A list or array would be suitable for the bees - depending on how many things you need to keep track of per bee. Eg. if you need to track x & y coordinates for each bee, and if there are 10 bees, then a 2-dimensional array of 20 bytes (2 bytes per bee, multiplied by 10 bees) would be suitable.

This section of the 28-days tutorials will probably explain things better than I could! Razz
I need a list or array to keep track of which bees are shown or not. For example, a 1 would show the sprite, a 0 would hide it. I'll post the updated code later today.

EDIT:

Here is the updated code. The bees are included and move back and forth, but the are always there, and you can't shoot them to make them disappear. Pretty much, the easy part is done. Now I will need to start asking questions and finishing reading the tutorial (I'm only half-way through week 2).
I wrote a comment in the code that draws the bees that tells what I need help with.


Code:

;#SECTION "MAIN", CODE

storage equ   appBackUpScreen
mex equ   storage + 1
shotinscreen equ   storage + 2
shotx equ   storage + 3
shoty equ   storage + 4
bee_max_x equ   storage + 5
bee_min_x equ   storage + 6
bee_dir equ   storage + 7
delay equ   storage + 8
max_delay equ   storage + 9
bee_y equ   storage + 10
bee_min_y equ   storage + 11
   org   userMem - 2
   db   0BBh, 6Dh
   ret

   jr   nc, Start
   db   "Move", 0
Start:
   ld   a, 48
   ld   (mex), a
   ld   (shotx), a
   ld   a, 47
   ld   (shoty), a
   ld   a, 0
   ld   (shotinscreen), a
   inc   a
   ld   (bee_dir), a
   ld   a, 56
   ld   (bee_max_x), a
   sub   64
   ld   (bee_min_x), a
   ld   a, 3
   ld   (max_delay), a
   ld   (delay), a
   ld   a, 8
   ld   (bee_y), a
   ld   a, 48
   ld   (bee_min_y), a
Splash:
   B_CALL   _GrBufClr
   B_CALL   _ClrLCDFull
   B_CALL   _HomeUp
   ld   de, 256 * 0 + 3
   ld   hl, 256 * 95 + 3
   call   lineDraw
   ld   de, 256 * 0 + 5
   ld   hl, 256 * 95 + 5
   call   lineDraw
   ld   de, 256 * 0 + 17
   ld   hl, 256 * 95 + 17
   call   lineDraw
   ld   de, 256 * 0 + 19
   ld   hl, 256 * 95 + 19
   call   lineDraw
   ld   de, 256 * 0 + 60
   ld   hl, 256 * 95 + 60
   call   lineDraw
   call   ionFastCopy
   ld   a, 1
   ld   (curRow), a
   ld   hl, Title
   B_CALL   _PutS
   ld   a, 34
   ld   (penRow), a
   ld   a, 37
   ld   (penCol), a
   ld   hl, T1
   B_CALL   _VPutS
   ld   a, 41
   ld   (penRow), a
   ld   a, 37
   ld   (penCol), a
   ld   hl, T2
   B_CALL   _VPutS
   ld   a, 48
   ld   (penRow), a
   ld   a, 37
   ld   (penCol), a
   ld   hl, T3
   B_CALL   _VPutS
GKLoop:
   B_CALL   _GetKey
   cp   k1
   jr   z, Clrscreen
   cp   k2
   jq   z, Exit
   cp   k3
   jq   z, Exit
   jr   GKLoop

Clrscreen:
   B_CALL   _GrBufClr
   B_CALL   _ClrLCDFull
   ld   a, 88
Loop:
   ld   b, 8
   ld   l, 56
   push   af
   ld   ix, block1
   call   ionPutSprite
   pop   af
   sub   8
   jr   nc, Loop
   ld   b, 8
   ld   a, (mex)
   ld   l, 48
   ld   ix, Me
   call   ionPutSprite
   call   Display_bees
   call   ionFastCopy
   ld   b, 8
   ld   a, (mex)
   ld   l, 48
   ld   ix, Me
   call   ionPutSprite
Game:
   ld   b, 8
   ld   a, (mex)
   ld   l, 48
   ld   ix, Me
   call   ionPutSprite
   call   ionFastCopy
   ld   b, 8
   ld   a, (mex)
   ld   l, 48
   ld   ix, Me
   call   ionPutSprite
   ld   a, (delay)
   cp   0
   call   z, Draw_bees
   ld   a, (delay)
   dec   a
   ld   (delay), a
   ld   a, (shotinscreen)
   cp   1
   call   z, Shot
   call   getkd
   ld   a, b
   cp   KD_CLEAR
   jr   z, Exit
   cp   KD_LEFT
   call   z, Left
   cp   KD_RIGHT
   call   z, Right
   cp   KD_2ND
   call   z, Shoot
   cp   11101101b
   jr   z, BL
   cp   11101011b
   jr   z, BR
   jr   Game

Exit:
   B_CALL   _GrBufClr
   B_CALL   _ClrLCDFull
   ret

Dec_y:
   ld   a, (bee_min_y)
   ld   d, a
   ld   a, (bee_y)
   cp   d
   ret   nc
   ld   a, (bee_y)
   inc   a
   ld   (bee_y), a
   ret

BL:
   call   Shoot
   call   Left
   jq   Game

BR:
   call   Shoot
   call   Right
   jq   Game

Left:
   ld   a, (mex)
   cp   0
   ret   z
   dec   a
   ld   (mex), a
   ret

Right:
   ld   a, (mex)
   cp   88
   ret   z
   inc   a
   ld   (mex), a
   ret

Shoot:
   ld   a, (shotinscreen)
   cp   1
   ret   z
   ld   a, 1
   ld   (shotinscreen), a
   ld   b, 8
   ld   a, (shoty)
   ld   l, a
   ld   a, (mex)
   ld   (shotx), a
   ld   ix, Sm
   call   ionPutSprite
   ret

Shot:
   ld   b, 8
   ld   a, (shoty)
   ld   l, a
   ld   a, (shotx)
   ld   ix, Sm
   call   ionPutSprite
   ld   a, (shoty)
   cp   0
   jr   z, Ends
   dec   a
   ld   (shoty), a
   ld   l, a
   ld   b, 8
   ld   a, (shotx)
   ld   ix, Sm
   call   ionPutSprite
   ret

Ends:
   ld   a, 47
   ld   (shoty), a
   ld   a, 0
   ld   (shotinscreen), a
   ret

Draw_bees:
   ld   a, (max_delay)
   ld   (delay), a
   ld   a, (bee_max_x)
   call   B_Loop
; ^ erase bees
   ld   a, (bee_dir)
   cp   1
   call   z, BMR
   ld   a, (bee_dir)
   cp   2
   call   z, BML
   ld   a, (bee_max_x)
   call   B_Loop
; ^ redraw bees
   ret

Display_bees:
; only use for first draw
   ld   a, (bee_max_x)
B_Loop:    ;draws the bees.  I need to replace this with code that will
      ;only draw a bee if (Bee_list + number) is 1
   ld   b, 8
   push   af
   ld   c, a
   ld   a, (bee_y)
   ld   l, a
   ld   a, c
   ld   ix, Be
   call   ionPutSprite
   pop   af
   sub   8
   ld   b, a
   ld   a, (bee_min_x)
   ld   c, a
   ld   a, b
   cp   c
   jr   nz, B_Loop
   ret

BMR:
   ld   a, (bee_max_x)
   cp   88
   jr   z, CF2
   inc   a
   ld   (bee_max_x), a
   ld   a, (bee_min_x)
   inc   a
   ld   (bee_min_x), a
   ret

CF2:
   ld   a, 2
   ld   (bee_dir), a
   call   Dec_y
   ret

BML:
   ld   a, (bee_min_x)
   cp   -8
   jr   z, CF1
   dec   a
   ld   (bee_min_x), a
   ld   a, (bee_max_x)
   dec   a
   ld   (bee_max_x), a
   ret

CF1:
   ld   a, 1
   ld   (bee_dir), a
   call   Dec_y
   ret

block1:
   db   11111111b
   db   11101110b
   db   01010101b
   db   10101010b
   db   01010101b
   db   10101010b
   db   01010111b
   db   11111111b
Me:
   db   00000000b
   db   00000000b
   db   00011000b
   db   00011000b
   db   00111100b
   db   01111110b
   db   01111110b
   db   00111100b
Sm:
   db   00011000b
   db   00011000b
   db   00000000b
   db   00000000b
   db   00000000b
   db   00000000b
   db   00000000b
   db   00000000b
Be:
   db   00000000b
   db   00100100b
   db   00011000b
   db   00100100b
   db   00111100b
   db   00100100b
   db   00011000b
   db   00000000b
Bee_list:
   db   1
   db   1
   db   1
   db   1
   db   1
   db   1
   db   1
   db   1
Title:
   db   "   \x09 SWARM! \x09   ", 0
T1:
   db   "1  Play", 0
T2:
   db   "2  Help", 0
T3:
   db   "3 Quit", 0
;#IMPORT "LINEDRAW"
;#IMPORT "GETKEY"
;#IMPORT "IonEqu"


Here is the gif:
[/img]
This is really coming along! Keep up the good work, can't wait to see this when its done Smile
Thanks Very Happy
Lookin' great!
At this rate you'll be a BrandonW within the year.
Could someone help me out with a routine that would only show a sprite if a corresponding value in a list was a 1?

If a list was like this:

Code:
List:
    .db 1,1,0,0,1,1,0,1

I would only want it to show a sprite if the corresponding value was 1.

Here is the code I want to modify:

Code:
   ld a,(bee_max_x)
B_Loop:    ;draws the bees.  I need to replace this with code that will
      ;only draw a bee if (Bee_list + number) is 1
   ld   b, 8
   push   af
   ld   c, a
   ld   a, (bee_y)
   ld   l, a
   ld   a, c
   ld   ix, Be
   call   ionPutSprite
   pop   af
   sub   8
   ld   b, a
   ld   a, (bee_min_x)
   ld   c, a
   ld   a, b
   cp   c
   jr   nz, B_Loop
   ret
Something like this perhaps? It will draw the bees in the same order the list is, from left to right. Should be easily changeable if you want it to go the other direction Smile


Code:
B_List:
   .db 1,1,0,0,1,1,0,1



Code:
Draw_Bs:
   ld   a,(bee_max_x)
   ld   hl, B_List + 7 ; this way we draw in the order that the bees are arranged
B_Loop:
   push   hl
   push   af
   ld   c, a
   ld   a, (hl)
   or   a
   jr   z, Dont_Draw_B
   ld   hl, bee_y
   ld   l, (hl)
   ld   a, c
   ld   b, 8
   ld   ix, Be
   call   ionPutSprite
Dont_Draw_B:
   pop   af
   sub   8
   ld   hl, bee_min_x
   cp   (hl)    ; set the z flag
   pop   hl
   dec   hl      ; move to the next (or previous) bee in the list
   jr   nz, B_Loop
   ret
Wow, that looks nice. Its way better than mine:


Code:
Bee_draw:
; bee 1
   ld   a, (Bee_data)
   cp   0
   jr   z, Skip1
   ld   b, 8
   ld   a, (bee_y)
   ld   l, a
   ld   a, (Bee_data + 1)
   ld   ix, Be
   call   ionPutSprite
Skip1:
   ld   a, (Bee_data + 2)
   cp   0
   jr   z, Skip2
   ld   b, 8
   ld   a, (bee_y)
   ld   l, a
   ld   a, (Bee_data + 3)
   ld   ix, Be
   call   ionPutSprite
Skip2:
   ld   a, (Bee_data + 4)
   cp   0
   jr   z, Skip3
   ld   b, 8
   ld   a, (bee_y)
   ld   l, a
   ld   a, (Bee_data + 5)
   ld   ix, Be
   call   ionPutSprite
Skip3:
   ld   a, (Bee_data + 6)
   cp   0
   jr   z, Skip4
   ld   b, 8
   ld   a, (bee_y)
   ld   l, a
   ld   a, (Bee_data + 7)
   ld   ix, Be
   call   ionPutSprite
Skip4:
   ld   a, (Bee_data + 8)
   cp   0
   jr   z, Skip5
   ld   b, 8
   ld   a, (bee_y)
   ld   l, a
   ld   a, (Bee_data + 9)
   ld   ix, Be
   call   ionPutSprite
Skip5:
   ld   a, (Bee_data + 10)
   cp   0
   jr   z, Skip6
   ld   b, 8
   ld   a, (bee_y)
   ld   l, a
   ld   a, (Bee_data + 11)
   ld   ix, Be
   call   ionPutSprite
Skip6:
   ld   a, (Bee_data + 12)
   cp   0
   jr   z, Skip7
   ld   b, 8
   ld   a, (bee_y)
   ld   l, a
   ld   a, (Bee_data + 13)
   ld   ix, Be
   call   ionPutSprite
Skip7:
   ld   a, (Bee_data + 14)
   cp   0
   jr   z, Skip8
   ld   b, 8
   ld   a, (bee_y)
   ld   l, a
   ld   a, (Bee_data + 15)
   ld   ix, Be
   call   ionPutSprite
Skip8:
   ret


Code:
Bee_data: ; db (show/hide),(x-coordinate)
   db   1, 0
   db   1, 8
   db   1, 16
   db   1, 24
   db   1, 32
   db   1, 40
   db   1, 48
   db   1, 56


I'm gonna totally use your code - I think. I changed a whole lot in the main code to use the drawing routine I made.

EDIT:
Actually, maybe you could optimize mine instead. Smile
Ok, here is a gif of SWARM! as of last night (I haven't done anything since than Razz).
It runs a little bit faster than this on my calculator.


Now I need to add projectiles bee-ing dropped by the bees.
Even at the speed the gif looks to be this is nice, imo. Nice work here, switch! Are you going to try and allow more than a single shot on the screen at a time? And what kinds of bonuses are you planning on?
Eventually I will probably try to. Right now I am working on allowing the bees to dropping "stingers", with multiple in the screen at once (probably four). I'm going to make a different variable for each x of each stinger, and each y of each stinger. As for bonuses... I'm not sure. Btw, if anyone thinks that it's unnecessary for the bees to drop stingers, I'll leave it like this and work other features.
Rather than make a variable for each stinger; just use an array of the x and y values. This will make it easy to modify the number in the future if you want to Smile
Ok, I'll start over. Very Happy
Like this?

Code:
stinger_coord ;db x,y
  db 10,24
  db 18,36
  db 58,13
  db 50,48


The value will change every frame in the game.
Yep exactly Smile Then to get the particular bee data you can do this: (Assuming hl holds the bee data that you want)


Code:
 add hl,hl
 ld de,stinger_coord
 add hl,de
 ld c,(hl)
 inc hl
 ld b,(hl)


Which will store the bee's x value in c and the y value in b. Should be modifiable to suit your purposes Smile
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 2
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement