It uses a lot of objects and then if statements between them.
Something like this, though with actual coding language:
Create circle, name it “Player”
Create rectangle, name it “Floor”
Correspond “Player” position on screen to WASD, speed 3
If “Player” touches “Floor,” add friction of some -x
If “Player” not touching “Floor,” add gravity of some -y
Create rectangle, name it “Gun”
Create triangle, name it “Bullet”
Create circle, name it “Enemy”
Create number counter, name it “Kill Count”
If “Player” has “Gun” and X button pressed, spawn “Bullet”
When spawned, send “Bullet” x direction at x speed
If “Bullet” touches “Floor,” delete “Bullet”
If “Bullet” touches “Enemy,” change “Kill Count” +1
If “Bullet” touches “Player,” reset the game
I would not say that most statements if statements but many are.
If you are interested you can look at the code of some older computer games that have been published. So take a look at some older ID software games like DOOM 3 from 2004 where you can see what code for a commercial game looks like. A game from back then is fundamentally not that different from games today.
https://github.com/id-Software
Well, if statements are really the fundamental building block of programming. In assembly language, if statements are comparable to branch statements, which tells the execution to hop from the branch to the line of code to which it points.
So, yes and no. All logic driven code is done with branch statements, but there is a considerable amount of stuff happening in between. From a code density perspective, no, most lines of a game’s code are not if statements. However, in the underlying libraries used by the game, a single method call might entail the use of 100 if statements.
Latest Answers