It is currently Mon May 20, 2019 10:11 am

All times are UTC - 7 hours

Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Projectile processing
PostPosted: Wed Feb 08, 2017 5:24 pm 

Joined: Tue Nov 20, 2012 1:59 pm
Posts: 67
I'm trying to get a decent sprite system going and I've ran into a bit of a snag with the sprite management loop. My methods before weren't very intuitive and the way it was coded sprites always started at sprite 01. My methods are running a loop indexed with X for each sprite that's on screen. I've ran into a problem with things such as bullets that need to be destroyed and spawed often. The destroying part is the problem. The way I have it set up now, the loop that runs each bullets code takes the number on screen as the index. The problem is to destroy an entity I thought I could simply decrease the this number. It doesn't work that way I know now because once you decrease this number it could end up destroying other sprites. I got away with this on my entry for the contest by hackish code, but I'm onto a new project now and I'd like to see if anyone could show me a dead simple projectile management system idea that doesn't waste to much RAM. There just bullets and all share the same code so I don't think a linked list is needed. I also tried keeping an array if each one that was active and somehow that didn't work either.

Thanks, zkip.

PostPosted: Wed Feb 08, 2017 5:55 pm 
User avatar

Joined: Sun May 27, 2012 8:43 pm
Posts: 1348
For simple objects like bullets, that rarely expand their roles and do other things, I like to keep a small buffer of object slots.

bullet_x: .res (2 * NUM_BULLETS)
bullet_y: .res (2 * NUM_BULLETS)
bullet_dx: .res (1 * NUM_BULLETS)
bullet_dy: .res (1 * NUM_BULLETS)
bullet_state: .res (1 * NUM_BULLETS)

Then, a few states enums are defined:


If you want to spawn a bullet, you iterate over your bullets until you find one who isn't busy (or has been despawned):


lda bullet_state, x
cmp #BULLET_STATE_INACTIVE ; this can be skipped since it's a comparison to zero, but...
bne @not_found
; We found a bullet, ID number is in X. for this example we mark it as active.
sta bullet_state, x

bne @bulletfind_top
; Bullet not found

Despawning is a matter of setting bullet_active to 0 for that bullet. Any property of a bullet is indexed by X specifying the bullet.

Then, you can have functions that act on certain bullets with X as a parameter for which bullet, then loop through your bullets for logic and render setup.

PostPosted: Sun Feb 19, 2017 6:15 am 
User avatar

Joined: Wed Sep 21, 2016 8:55 am
Posts: 83
Location: Calgary.Alberta,Canada
I handle projectiles quite close to what Mike has posted,I also have the projectile routines for silkworm and Karnov reverse engineered if your interested in looking at it let me know.

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 7 hours

Who is online

Users browsing this forum: No registered users and 4 guests

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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group