CPCWiki forum

General Category => Programming => Topic started by: Kitsune Mifune on 10:06, 20 December 20

Title: Fetch/store variables for on screen sprites
Post by: Kitsune Mifune on 10:06, 20 December 20
I'm wondering what is the most efficient way to store and fetch values for multiple on screen enemy (and player) variables?

I'm using one draw routine for everything (player, enemies) and currently I have custom variables for all of them which get converted to a general variable before they hit the draw routine like this:



ld a,(PLAYER_XY)
ld (SPRITE_XY),a
call DRAW



ld a,(ENEMY1_XY)
ld (SPRITE_XY),a
call DRAW



ld a,(ENEMY2_XY)
ld (SPRITE_XY),a
call DRAW


[\code]

It works, but there are a lot of variables to convert so it feels very bloated, and I'm sure there's an easier way to do it by using an array or something and some single variable which denotes what type of sprite is being drawn (0 = draw nothing, 1 = player, 2 = enemy1, 3 = enemy2 etc).

My brain is a little fried at the moment, so if someone can nudge me in the right direction that would be great! Thanks.
Title: Re: Fetch/store variables for on screen sprites
Post by: roudoudou on 10:16, 20 December 20
Use a sprite structure and build an array
Then you make a loop of all elements
pseudo code will be like
displaysprites
ld a,(hl) : or a : ret z : inc hl : push hl
DRAW ; not a CALL if you use DRAW only for sprites, you save CALL+RET
pop hl
jr displaysprites
Title: Re: Fetch/store variables for on screen sprites
Post by: Kitsune Mifune on 09:10, 21 December 20
Just what I was after.Thank you!

That'll save me going down dead ends.
Powered by SMFPacks Menu Editor Mod