Game Actors
Moderator: Moderators
Game Actors
I'm trying to wrap my head around how to define an array of game actors in 6502 asm. I believe there is a way to define a struct and then allocate ram for an array of that struct. Say, 8 byte struct, 16 total game actors maximum, so lets say I wanna use addresses $0400 through $047F to store that data. How do I define this structure and repeat it 16 times over that area of memory? Hope this makes sense.
Re: Game Actors
You probably don't want to define an array of structs because 6502 isn't very good at accessing this kind of data structure. Normally, games will instead define individual arrays of each byte, so you have an array of x positions, an array of y positions, etc. Then you can simply have the actor index in X and get the desired property from any of the arrays with ease.
If you're using an array of structures, you either have to have actors with indices that are arraysize apart, or if your array is larger than 256 bytes, you have to use a zero page pointer and (indirect),Y addressing, which is limiting and expensive.
If you're using an array of structures, you either have to have actors with indices that are arraysize apart, or if your array is larger than 256 bytes, you have to use a zero page pointer and (indirect),Y addressing, which is limiting and expensive.
Re: Game Actors
That makes a lot more sense. Thank you.
Re: Game Actors
Yeah, a structure of arrays is how most games do it. When processing an actor, it's customary to have the X register control which actor is being manipulated. If you need to use X for anything else during this period, you can simply save its value to RAM and restore later, but in my own experience, this is hardly ever necessary.
For things like collisions between actors, where you need to compare properties from both actors, you can just use the Y register to point to the secondary object.
Most types of games will need way more than 8 bytes per actor, though. Even if the gameplay takes place in a single screen, in order to produce smooth movement you're gonna need to keep track of velocities and sub-pixel positions. Each actor often needs to keep track of the animation frame it's in and how long to wait before switching to the next frame. There's also health, logic states, and a bunch of other things that you're only gonna realize you need once you start designing and coding their logic, so try to plan ahead and be generous with the amount of RAM you're setting aside for this.
For things like collisions between actors, where you need to compare properties from both actors, you can just use the Y register to point to the secondary object.
Most types of games will need way more than 8 bytes per actor, though. Even if the gameplay takes place in a single screen, in order to produce smooth movement you're gonna need to keep track of velocities and sub-pixel positions. Each actor often needs to keep track of the animation frame it's in and how long to wait before switching to the next frame. There's also health, logic states, and a bunch of other things that you're only gonna realize you need once you start designing and coding their logic, so try to plan ahead and be generous with the amount of RAM you're setting aside for this.