Skip to content

burlapjack/grumah

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Grumah

Text-based rogue-like engine written in C for the Linux terminal.

Features

License GitHub code size in bytes

  • This engine utilizes a simple ECS (Entity Component System) approach that is popular in many other game engines.

  • Careful memory management is handled automatically, allowing users to focus more on content rather than construction.

  • All type and function names are extra descriptive for confusion-free, human-readable code.

Prerequisites

  • Ncurses: This build was tested using Ncurses 6.0.

Short Summary

Grumah defines an Entity (aka game object), as nothing more than an id number. A Component is merely an attribute with an entity id number assigned to it. A System is a function that continually passes in components during runtime; they manipulate component values as required.

Within the Grumah libraries are the entity, component and system modules. The component module contains the definitions of each component type such as ComponentPosition and ComponentDraw. The entity module contains helpful functions that create various common entities such as a default player entity or a menu entity. Lastly, the system module contains the functions that are run in the game-loop such as gr_system_menu and gr_system_draw_map.

Getting Started

In your project directory that also contains the grumah directory, create a new main.c file that contains #include for ncurses and grumah. Make sure to initialize ncurses so that you have a proper window to work with. If you are using Linux, good chances are you have a recent version of ncurses installed already.

/* main.c */

#include "grumah/include/grumah.h"

int main(int argc, char *argv[]){
	
	int win_width = 80;
	int win_height = 24;
	unsigned int game_running = 1;

	/*----- Create seed using srand() ------*/
	time_t t;
	srand((unsigned) time(&t));	

	/*----- ncurses boilerplate-------------*/
	set_locale(LC_ALL, "");
	initscr();
	cbreak();
	keypad(stdscr, TRUE);					
	noecho();
	curs_set(0);
	WINDOW *win = newwin(win_height, win_width, 0, 0);	

	/*----- game loop ----------------------*/
	while(game_running == 1){
		//game code will go here.
	}

	/*----- game over ----------------------*/
	/*----- free ncurses from memory -------*/
	delwin(win);
	endwin();
	return 0;
}

Next, you will want to set up an entity id counter and a Component object pointer inside your main function.

/*----- Initialize a Component Object --*/
int num_components = 10;
Component *c = malloc(sizeof (*c));
gr_component_init(c, num_components);

Component *c is a pointer to a struct that holds all the different kinds of components that will be needed. You will be using this pointer a lot.

You can use the component_free_all function to deallocate all of that memory when the program ends:

gr_component_free_all(c);

Releases

No releases published

Packages

No packages published

Languages