Skip to content

tdecorso/pong

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Pong

image

About this game

This game is the first episode of the experiment "Let's make a CPU-only game engine in C", in which I try to develop both a game and the engine itself from features that I would probably reuse for other games.

What you can reuse

This project currently offers these reusable features:

  • a platform layer: this gives you a os-agnostic window and it is currently implemented using SDL. It is abstracted enough that adding a new platform should be quite straightforward.
  • a framebuffer layer: this is the array of pixels that you can manipulate and that it gets drawn at the end of each game step.
  • an engine layer: it is a wrapper for both the platform and the framebuffer, so you get less boilerplate in the main file but you can still tweak each component as you like

If you strip the game logic from the main program, you end up with:

#include "engine.h"
#include <stdio.h>

#define SCREEN_W 800
#define SCREEN_H 600

const pixel_t BG_COLOR     = {14, 22, 12, 255};

int main(void) {
    engine_t engine = {0};

    if (!engine_Init(&engine)) {
        printf("[ERROR] Could not initialize engine.\n");
        return 1;
    }

    if (!engine_CreateWindow(&engine, SCREEN_W, SCREEN_H, "Pong")) {
        printf("[ERROR] Could not create window.\n");
        return 1;
    }

    engine_SetTargetFPS(&engine, 60);

    while (!engine_WindowShouldClose(&engine)) {
        engine_BeginFrame(&engine);
        engine_ClearBackground(&engine, BG_COLOR);
        engine_EndFrame(&engine);
    }

    engine_Quit(&engine);
    return 0;
}


You can basically copy this code and add your logic / extensions and you have another game. Have fun!

About

CPU-only 2D pong game in C

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors