News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_Kitsune Mifune

Fetch/store variables for on screen sprites

Started by Kitsune Mifune, 10:06, 20 December 20

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Kitsune Mifune

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.
Unlocking the dark arts of assembly!

roudoudou

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
My pronouns are RASM and ACE

Kitsune Mifune

Just what I was after.Thank you!

That'll save me going down dead ends.
Unlocking the dark arts of assembly!

Powered by SMFPacks Menu Editor Mod