Pretty much the only thing you need to do to make just about any game are two main subroutines:
1) Initializing all the assets. Like how big the paddles are, where the ball starts, how the ball will move before you do anything to the game, etc and telling the game where all these value will be stored in memory.
2) The Main Loop. This where the game runs the majority of the time, waiting for your input. It's literally just an endless loop that just continues forever until something happens, like you telling the paddle to move, the ball hitting the paddle, the ball hitting the walls, etc. As it loops, it'll call different subroutines to check if you did anything or if any status need to be applied.
I'm in the process of writing a dirt simple 2D platforming engine and here's an example from my gravity test version.
Code: Select all
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; initializing Physics test position, dot color and first spawn
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
LDX #$02 ;setting high and low byte of spawn
STX $02
LDX #$08
STX $01
LDA #$01 ;setting color
STA ($01),y ;spawning dot
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Main Loop
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
mainloop:
JSR gravity
JSR applymomentum ;Empty for now
JSR checkcollision ;Empty for now
JSR readkeys ;Empty for now
JMP mainloop
All this does so far is spawn a dot and run it through some conditions.
1) Spawn Dot
2) Start Loop
a. Is it in the air? If yes, make it fall.
b. Was it being moved forward from a previous loop? If yes, push it forward.
c. Did it hit anything? If yes, stop it from moving.
d. Did the player push a button? If yes:
i. What button did they push?
ii. What does that button do?
iii. Do what the button does.
e. Restart Loop with new conditions.
You can literally put anything into the main loop, heck if you're just doing a Demoscene you don't even need a subroutine for accepting user input. But the loop ITSELF needs to be in place. Without it, the program will literally do only ONE THING then exit.
So to summarize: the 100% bare minimum a game needs is two main subroutines.
1) Define "Stuff"
2) Do Stuff, then loop back and do more Stuff.