OK, apologies, I was trying to avoid flooding the board with files if it was just another simple misunderstanding of syntax on my part.
To present a fuller explanation... I'm trying to get Joozey's 'structured programming' example to work, firstly to try and understand what's happening and secondly to maybe tweak the principles he introduced to suit my own project.
Here are all of the files.
The 'room' definition -
//ROOM.c
typedef struct
{
int roomNumber;
BMAP* image;
STRING* name;
} ROOM;
//a function to visualize an room on a panel
void room_visualize(DUNGEON* dungeon, PANEL* panel)
{
panel->bmap = dungeon->image;
}
//ROOM creation function, returns pointer to the newly created ROOM
ROOM* room_create( int number, String* imageName )
{
ROOM* room = malloc( sizeof( ROOM ) );
//always fill ALL the room's properties immediately after!
room->roomNumber = number;
room->image = bmap_create( imageName );
room->name = imageName;
return room; //return the new room back
}
//function to remove an room
void room_remove( ROOM* room )
{
ptr_remove( room->image ); //remove bitmap first
ptr_remove( room->name ); //remove name
free( room ); //THEN remove room
}
The 'dungeon' definition -
//DUNGEON.c
typedef struct
{
bool alive;
Panel *panel;
ROOM *item1;
ROOM *room2;
} DUNGEON;
//function to keep the inventory running and catch input
void inventory_run( DUNGEON *inventory )
{
//infinite loop
//in order to check if the object still exists and prevent empty pointer errors,
//you can best add an "alive" state, just add an "alive" boolean in the structure, and check it here
//after the while, call the inventory_remove function to fully destroy
//We simply make an inventory_kill() function, and set the boolean to false to kill the object
while( inventory->alive ) { //as long as the inventory is alive, keep loopin'
//when we press key_1, show room1
if( key_1 )
{
room_visualize( inventory->room1, inventory->panel ); //remember this function in the room code?
}
//when we press key_2, show room2
if( key_2 )
{
room_visualize( inventory->room2, inventory->panel );
}
wait( 1 );
}
inventory_remove( inventory ); //the object is dead, remove it!
}
//function kill
void dungeon_kill( DUNGEON *dungeon )
{
dungeon->alive = false;
}
//function to create a new dungeon
DUNGEON *dungeon_create()
{
//allocate new dungeon structure
DUNGEON *dungeon = malloc( sizeof( DUNGEON ) );
//once again, fill all its parameters immediately after
dungeon->alive = true; //we set this object to alive first!
dungeon->panel = pan_create("bla");
dungeon->room1 = room_create( 1, "room1.tga" ); //easily create an room
dungeon->room2 = room_create( 2, "room2.tga" );
//in addition to the room code, the dungeon code catches player input
//this run function handles this input, and loops infinitely
dungeon_run( dungeon );
return dungeon; //give back the dungeon
}
void dungeon_remove( DUNGEON *dungeon )
{
room_remove( dungeon->room1 ); //remove room1 first
room_remove( dungeon->room2 ); //remove room2
ptr_remove( dungeon->panel ); //don't forget to remove the panel too
free( dungeon ); //THEN remove dungeon safely
}
The main -
////////////////////////////////////////////////////////////////////
//
// Theseus Engine V1.0
//
////////////////////////////////////////////////////////////////////
#include <acknex.h>
#include <default.c>
#include <litec.h>
#include "panels.c"
#include "room.c"
#include "dungeon.c"
////////////////////////////////////////////////////////////////////
void main()
{
//create a new inventory!
DUNGEON *dungeon = dungeon_create();
//main loop (a little dirty, but forgiveable for now :) )
while( 1 ) {
//when we press q, remove the inventory
if( key_q )
{
dungeon_remove( dungeon ); //this should go smooth without errors...
}
wait( 1 );
}
}
As you can see, I have just taken Joozey's example files and renamed the objects to suit the purpose for which I intend to develop them. Joozey's unedited files give a syntax error in the same place, when I compile main.
Error in 'room.c' line 20: syntax error
<void item_visualize( Inventory* inventory, PANEL* panel ) {
>
.
Can't compile MAIN.C