C Board  

Go Back   C Board > General Programming Boards > Game Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 04-23-2009, 06:32 AM   #1
Registered User
 
Join Date: Apr 2009
Posts: 6
Lightbulb How does this Game Maker-like c program look

I made this today and I am wondering if there is a better way of making a Game Maker-like game using SDL.
Code:
#include <stdio.h>
#include <stdlib.h>

enum entitytype_enum {
	SPRITE = 1,
	BACKGROUND,
	ROOM,
	OBJECT,
	INSTANCE
};

typedef struct Entity {
	int type;
	/*
    SDL_Surface *image;
	SDL_Rect *rects;
    */
    int cols, rows; /* These variables are for sprite sheets */
	int x, y;
	struct Entity *sprite;
	struct Entity *instances;
	struct Entity *next;
} Entity;

Entity *startEntity = NULL;

Entity *newEntity(int type) {
	Entity *entity = (Entity*)malloc(sizeof(Entity));
	entity->type = type;
	/*
    entity->image = NULL;
    entity->rects = NULL;
    */
	entity->cols = 0;
	entity->rows = 0;
	entity->sprite = NULL;
	entity->instances = NULL;
	entity->next = NULL;
	if (startEntity == NULL) {
		startEntity = entity;
	} else {
		Entity *tmp = startEntity;
		while (tmp->next != NULL) tmp = tmp->next;
		tmp->next = entity;
	}
	return entity;
}

void freeEntities() {
	Entity *current = startEntity;
	while (current != NULL) {
		Entity *tmp = current->next;
		/*
		if (current->image != NULL) {
			SDL_FreeSurface(current->image);
		}
		*/
		free(current);
		current = tmp;
	}
}

Entity *getEntity(int type, int index) {
	Entity *current = startEntity;
	int i = 0;
	while (current != NULL) {
		if (current->type == type) {
			if (i == index) break;
			++i;
		}
		current = current->next;
	}
	return current;
}

int main(int argc, char *argv[]) {
	newEntity(SPRITE);
	newEntity(BACKGROUND);
	newEntity(ROOM);
	newEntity(OBJECT);
    newEntity(ROOM);
	if (getEntity(ROOM, 0)->type == ROOM) printf("ROOM 0 = ROOM");
	freeEntities();
	return 0;
}
hahaguy is offline   Reply With Quote
Reply

Tags
game, maker, programming

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Program Plan Programmer_P C++ Programming 0 05-11-2009 01:42 AM
2D RPG Online Game Project. 30% Complete. To be released and marketed. drallstars Projects and Job Recruitment 2 10-28-2006 12:48 AM
Lottery game geetard C++ Programming 2 12-20-2005 12:50 AM
I want to program a game, what do i need? DarkViper Game Programming 53 11-19-2002 05:39 PM


All times are GMT -6. The time now is 08:38 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22