GithubHelp home page GithubHelp logo

sdl_game_library's Introduction

SDL GAME LIBRARY [Depricated]

This library contains wrapper functions/ classes for SDL, aimed at making cross-platform 2D game development in C++ a little bit easier.

Note: this project is in the very early stages of development and will probably look very different over the coming months (maybe years???)

NOTE: I have since moved to FNA (c#) and Pico8 for game development. I still keep this repo around for reference, but I don't use it and neither should you :)

INSTALLATION

  1. Install SDL2 and SDL_IMAGE frameworks to your machine. (I used brew on osx)
  2. Include SDL_LIBRARY/FUNCTIONS/ENGINE.h"in your project directory.
  3. MAKE!

TODOs

  • Include should just be path/to/library/engine.h instead of that mess with the functions directory.
  • Fix up this readme.. everything in the api reference is wrong :)
  • Stop rendering offscreen objects (add render padding around screen)

SIMPLE EXAMPLE

ENGINE.h contains all necessary includes and code to get stated.

myObject.h is an example of a custom user-made class for the specific game (where you would put your code :).

// test.cpp

#include <iostream>
#include "pathto/SDL_LIBRARY/FUNCTIONS/ENGINE.h"

Engine* engine = new Engine();

class Test: public Object {
public:
	Test(Engine* parent)
	:Object(parent) {
		// you can add sprites here by calling parent->addSprite(...)
		// and then call linkSprite(pointerToAboveSprite)
	}


	// update, keyDown, and keyUp are virtuals that the child can override
	void update() {
		x+=1;
	}

	void keyDown(int k) {}
	void keyUp(int k){}
};

class TextTest: public Object {
public:
	TextTest(Engine* parent, TTF_Font* f)
	:Object(parent) {
		x = 10;
		y = 10;
		linkFont(f);
	}

	void update() {
		setText("heyo", {255,255,255});
	}
};


void setup() {
	// my preferred way of adding sprites/ fonts is to declare them all in the setup...
	// you can also do this within each object for better organization (see above)
	Sprite* testSprite = engine->addSprite("path/to/sprite.png");
	TTF_Font* testFont = engine->addFont("./myfont.ttf", 10);

	Test* test = new Test(engine);
	test->linkSprite(testSprite);
	engine->addObject(test);

	TextTest* tt = new TextTest(engine, testFont);
	engine->addObject(tt);
}

int main(int argc, char* args[]) {
	if (!engine->init()) {
		printf("Failed to init\n");
	} else {
		setup();
		bool runGame = true;
		while(runGame) {
			runGame = engine->update();
		}
	}

	engine->close();
	return 0;
}

sdl_game_library's People

Contributors

rdelos747 avatar jacoblmacdonald avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.