1
Programming / Re: Basic game programming concepts
« on: October 10, 2013, 06:42:03 PM »
I'm up to a few thousand lines of code already into my project and so far using tables to keep track of everything seems to be working out:
;pWorldTable coords from (0,0) to (4 Billion,4 Billion)
; DWORD,DWORD == # entries,ID# of active area (used to calculate which WX,WY to -> to)
; DWORD,DWORD == WorldX,WorldY our first area starts at (2 Billion, 2 Billion)
; DWORD,DWORD == pLocalTable,RESERVED
; DWORD,DWORD == WorldX,WorldY
; DWORD,DWORD == pLocalTable,RESERVED
; etc.
;
; pLocalTable coords start from (0,0) to (width of window,height of window)
; DWORD == <RESERVED>
; DWORD == MobsTable
; DWORD == StructsTable
; etc.
;
; pMobsTable
; DWORD,DWORD == # mobs,<RESERVED>
; DWORD,DWORD == X|Y,pChar pointer to char/mob/item detail sheet
; DWORD,DWORD == X|Y,pChar pointer to char/mob/item detail sheet
; etc.
;
; pStructsTable
; DWORD == RESERVED
; DWORD == pStructure
; DWORD == pStructure
; ...
; ...
; 0
;
; pStructure
; DWORD,DWORD == RESERVED, RESERVED
; DWORD,DWORD == RoomX|RoomY,RoomW|RoomH
; DWORD,DWORD == WallX|WallY,pChar pointer to char/mob/item detail sheet
; DWORD,DWORD == WallX|WallY,pChar pointer to char/mob/item detail sheet
; etc.
I use nested tables, so for instance my WorldTable contains a bunch of LocalTables and each LocalTable contains a MobTable, StructsTable and soon an ItemsTable. And each MobsTable would list an X,Y and it's corresponding pointer to a Character Sheet of the mob/item at that location.
And everything, you, the mobs and even a piece of the wall in a structure has their own Character Sheet:
;Char sheet offsets
OFFSET_MOB_OBJ_ID equ 0
OFFSET_MOBSPEED equ 4
OFFSET_NAME equ 8
OFFSET_SYMB equ 12
OFFSET_COLOR equ 16
OFFSET_ALTCOLOR equ 20
OFFSET_VISIBLE equ 24
OFFSET_MOBMEM equ 28
OFFSET_MOBMEM_COMBATANT equ 0
OFFSET_MOBMEM_NUMSTEPS equ 4
OFFSET_MOBMEM_ENCCS equ 8
OFFSET_MOBMEM_ORIGPATH equ 12
OFFSET_MOBMEM_ALTPATH1 equ 16
OFFSET_MOBMEM_ALTPATH2 equ 20
OFFSET_MOBMEM_DMGMSG equ 24
OFFSET_FONTWH equ 32
OFFSET_STATS equ 36
OFFSET_HPCURRHP equ 40
OFFSET_ALLEGIANCE equ 44
OFFSET_WEAPON equ 48
OFFSET_DOORWAY equ 52
OFFSET_BgXY equ 56
OFFSET_STATUS equ 60
OFFSET_STATUSMSG equ 64
To keep it simple I'm just using a single character sheet for everything so not all the fields would be used by some things so I'm wasting quite a few bytes for sure but OTOH if I decide later on to implement destructible environments, the HP field is already in place for me to use for the walls for instance.
I'm using Assembly btw so I don't know if any of this would apply at all in an OOP language.
;pWorldTable coords from (0,0) to (4 Billion,4 Billion)
; DWORD,DWORD == # entries,ID# of active area (used to calculate which WX,WY to -> to)
; DWORD,DWORD == WorldX,WorldY our first area starts at (2 Billion, 2 Billion)
; DWORD,DWORD == pLocalTable,RESERVED
; DWORD,DWORD == WorldX,WorldY
; DWORD,DWORD == pLocalTable,RESERVED
; etc.
;
; pLocalTable coords start from (0,0) to (width of window,height of window)
; DWORD == <RESERVED>
; DWORD == MobsTable
; DWORD == StructsTable
; etc.
;
; pMobsTable
; DWORD,DWORD == # mobs,<RESERVED>
; DWORD,DWORD == X|Y,pChar pointer to char/mob/item detail sheet
; DWORD,DWORD == X|Y,pChar pointer to char/mob/item detail sheet
; etc.
;
; pStructsTable
; DWORD == RESERVED
; DWORD == pStructure
; DWORD == pStructure
; ...
; ...
; 0
;
; pStructure
; DWORD,DWORD == RESERVED, RESERVED
; DWORD,DWORD == RoomX|RoomY,RoomW|RoomH
; DWORD,DWORD == WallX|WallY,pChar pointer to char/mob/item detail sheet
; DWORD,DWORD == WallX|WallY,pChar pointer to char/mob/item detail sheet
; etc.
I use nested tables, so for instance my WorldTable contains a bunch of LocalTables and each LocalTable contains a MobTable, StructsTable and soon an ItemsTable. And each MobsTable would list an X,Y and it's corresponding pointer to a Character Sheet of the mob/item at that location.
And everything, you, the mobs and even a piece of the wall in a structure has their own Character Sheet:
;Char sheet offsets
OFFSET_MOB_OBJ_ID equ 0
OFFSET_MOBSPEED equ 4
OFFSET_NAME equ 8
OFFSET_SYMB equ 12
OFFSET_COLOR equ 16
OFFSET_ALTCOLOR equ 20
OFFSET_VISIBLE equ 24
OFFSET_MOBMEM equ 28
OFFSET_MOBMEM_COMBATANT equ 0
OFFSET_MOBMEM_NUMSTEPS equ 4
OFFSET_MOBMEM_ENCCS equ 8
OFFSET_MOBMEM_ORIGPATH equ 12
OFFSET_MOBMEM_ALTPATH1 equ 16
OFFSET_MOBMEM_ALTPATH2 equ 20
OFFSET_MOBMEM_DMGMSG equ 24
OFFSET_FONTWH equ 32
OFFSET_STATS equ 36
OFFSET_HPCURRHP equ 40
OFFSET_ALLEGIANCE equ 44
OFFSET_WEAPON equ 48
OFFSET_DOORWAY equ 52
OFFSET_BgXY equ 56
OFFSET_STATUS equ 60
OFFSET_STATUSMSG equ 64
To keep it simple I'm just using a single character sheet for everything so not all the fields would be used by some things so I'm wasting quite a few bytes for sure but OTOH if I decide later on to implement destructible environments, the HP field is already in place for me to use for the walls for instance.
I'm using Assembly btw so I don't know if any of this would apply at all in an OOP language.