It is currently Thu Mar 30, 2017 5:37 pm

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 
Offline

Joined: Tue Nov 20, 2012 1:59 pm
Posts: 64
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.


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

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

Code:
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:

Code:
BULLET_STATE_INACTIVE = 0
BULLET_STATE_ACTIVE = 1
...


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

Code:

spawn_bullet:
ldx #NUM_BULLETS
@bulletfind_top:
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.
lda #BULLET_STATE_ACTIVE
sta bullet_state, x
rts
@not_found:

dex
bne @bulletfind_top
; Bullet not found
rts



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.


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

Joined: Wed Sep 21, 2016 8:55 am
Posts: 28
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.


Top
 Profile  
 
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: Google Adsense [Bot] 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