rendered paste body// -----------------------------
// iGamer.c
// --> Main File for iGamer
// -----------------------------
// Created by Daniel Shaw
// -----------------------------
// VERSION: Alpha
// -----------------------------
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include "pz.h"
static PzModule *module;
static PzEvent *ev;
static PzWindow * startw; // || Make Window ||
static PzWindow * menu_windowd;
static TWidget *game;
static ttk_surface image;
static ttk_surface character;
static ttk_surface user;
static ttk_surface srf;
static char tileset[80];
static int *start_x = 0;
static int *start_y = 0;
static int player_x = 0;
static int player_y = 0;
static int facing = 3; // --> Facing position (1 - UP, 2 - RIGHT, 3 - DOWN, 4 - LEFT)
static char game_name[20];
void update_screen() // --> Refresh the map and sprites!
{
game->dirty++;
}
//--------------//
#include "Map.c"
#include "XFunc.c"
#include "Menu.c"
//--------------//
void close() // --> Close iGamer!
{
printf ("Exiting iGamer |Ok|\n");
}
void draw_data(PzWidget *wid, ttk_surface srf) // --> Draw the map, sprites, etc!
{
char tileset_path [104];
sprintf(tileset_path, "game_data/Visuals/Tiles/%s", tileset);
image = ttk_load_image (pz_module_get_datapath (module, tileset_path));
if (!image)
{
pz_message ("Error: Unable to load tiles!\n");
}
else
{
draw_map_l1_tiles(srf); // --> Show Layer 1 Tiles
//draw_map_l2_tiles(srf); // --> Show Layer 2 Tiles
//draw_map_l3_tiles(srf); // --> Show Layer 3 Tiles
character_draw(facing); // --> Draw the main character
}
}
void movement(int dir) // --> Movement for the main character!
{
switch(dir)
{
case 1:
player_y -= 1;
facing = 1;
break;
case 2:
player_x += 1;
facing = 2;
break;
case 3:
player_y += 1;
facing = 3;
break;
case 4:
player_x -= 1;
facing = 4;
break;
}
game->dirty++;
}
static int event_data (PzEvent *e) // --> Input data receieved!
{
static ttk_surface srf;
switch (e->arg) {
case PZ_BUTTON_MENU: // Up
if (can_move(1))
movement(1);
break;
case PZ_BUTTON_NEXT: // Right
if (can_move(2))
movement(2);
break;
case PZ_BUTTON_PLAY: // Down
if (can_move(3))
ttk_delay(40);
movement(3);
break;
case PZ_BUTTON_PREVIOUS: // Left
if (can_move(4))
movement(4);
break;
case PZ_BUTTON_ACTION: // Action
break;
case PZ_BUTTON_HOLD: // Hold - Exit
pz_close_window (e->wid->win);
break;
case PZ_EVENT_DESTROY:
ttk_free_surface (image);
ttk_free_surface (character);
ttk_free_surface (user);
break;
}
return 0;
}
void check_files() // --> Check for the neccessary files!
{
FILE *game_data;
game_data = fopen(pz_module_get_datapath (module, "game_data/gdata.igame"), "r");
fscanf(game_data, "%s %s", game_name, game_name);
fscanf(game_data, "%d", &start_x);
//printf("Data: %d\n", start_x);
fscanf(game_data, "%d", &start_y);
player_x = start_x;
player_y = start_y;
fclose(game_data);
if (!game_data)
{
pz_message ("Error: Unable to locate 'gdata.igame'");
}
printf ("Setup iGamer Data |Ok|.\n");
}
PzWindow *start_engine_window () // --> Starting window; Neccessity
{
check_files(); // || Assure all files exist ||
load_map_data(3);
startw = pz_new_window (game_name, PZ_WINDOW_FULLSCREEN); // || Setup new window + Title ||
game = pz_add_widget (startw, draw_data, event_data); // || Add Map and Sprites Widget ||
return pz_finish_window (startw);
}
void init() // Initialize the module!
{
module = pz_register_module ("iGamer", close);
pz_menu_add_action ("/Extras/aGame-Engine/iGamer", start_engine_window);
}
PZ_MOD_INIT (init)