3 ms·
What's funny is that that's roughly how I wrote my first game when I only knew structural programming (and not that well). Game objects were Pascal records. Th
by ajuc 8y ago
What's funny is that that's roughly how I wrote my first game when I only knew structural programming (and not that well).
Game objects were Pascal records. There was 1 global table with all the records. There were many functions called from the game loop processing all the records in some way. Like one function updated orientation, velocity and position. Other did collision detection between objects, another did collision detection with the map. There was a function for possible reactions to collisions (if you collided with a powerup you get 100 health etc).
It was all data driven, objects had integer indices referencing tables with predefined attributes. Like your ship record had "engineNo", which referenced table of engines with power, turning radius, fuel consumption, and other parameters for each kind of engine. Same with guns, armor, power generators.
Map was 2d array of records which had tileType, tileImage, xParam, yParam. If tileType was teleport - it teleported any object it collided with it to (xParam, yParam). If tileType was switch it triggered tile on (xParam, yParam) every time something collided with it. There were also tileTypes that damaged anything that collide with it to a various degree, and tileTypes to jump to the next level.
That was like 3000 lines of code in 2 files (because Turbo Pascal refused to compile it when it was in one file :) ). Everything was global. There were no classes. And it was pretty easy to understand and modify, and allowed a lot of design possibilities.
Well, it would be easy if I used proper variable names and constants. As it was you had to remember what tileType==10 means, and I had 3-screen long function that was nested if-then-else with all possible tiletype-vs-objectType interactions. Like - bullets slow down when entering water tiles and disappear when hitting walls. Napalm particles change into smoke particles which expire after X frames. Napalm particles glue to walls and slowly move down. Grenades explode when touching walls.
There were lots of such rules, but putting them in one place was the right thing now that I think about it.
I'd argue even with abysmal naming practices it was more understandable than most of modern codebases, where this logic would be separated into 20 small classes.
Then I learnt OO programming and tried to make a proper object oriented game architecture, and it was never as simple as that naive approach :)