Skip to content

Instantly share code, notes, and snippets.

@PaperPrototype
Last active February 14, 2021 16:18
Show Gist options
  • Save PaperPrototype/7f3666ab10d77b8e1bf512e979b5bdc7 to your computer and use it in GitHub Desktop.
Save PaperPrototype/7f3666ab10d77b8e1bf512e979b5bdc7 to your computer and use it in GitHub Desktop.
Simple game
# include <renderer.h>
# include <input.h> // other C files except they end in .h
// ... our structs
int main (void) {
// ... initializing a visible os window for rendering
struct Player player;
player.pos = [0, 0, 0]; // array of floats (aka vector3)
player.rot = [0, 0, 0];
player.mesh = renderer.getMeshFromFile("player.fbx");
// a simple update loop
// LOL this will probably run at 100000000000000000000000 fps if we were timing it
while (true) {
input.Update()
MovePlayer (player);
RenderPlayer (player);
if (input.getKeyDown("ctrl") && input.getKeyDown("q")) {
break; // breaks out of the loop
}
}
}
void MovePlayer (struct Player player) {
// move the player based on input
if (input.getKeyDown("a")) {
player.pos[0] += 1.0; // pos[0] is equvalent to pos.x in a struct vector vs an array vector
}
// ... other input checks
}
void RenderPlayer (struct Player player) {
// the C renderer function render takes in a pos (float[3]), rot (also float[3]), and a Mesh struct
renderer.render(player.pos, player.rot, player.mesh);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment