Compare commits
No commits in common. "master" and "v0-1-3" have entirely different histories.
14 changed files with 14 additions and 168 deletions
2
.gitignore
vendored
Executable file → Normal file
2
.gitignore
vendored
Executable file → Normal file
|
@ -7,5 +7,3 @@ raylib/
|
|||
*.swp
|
||||
*.tiled-session
|
||||
map/maps_out.c
|
||||
map/converter
|
||||
log.txt
|
||||
|
|
BIN
map/converter
Executable file
BIN
map/converter
Executable file
Binary file not shown.
|
@ -22,8 +22,3 @@ end
|
|||
function on_frame(game)
|
||||
|
||||
end
|
||||
|
||||
function on_load(game, map)
|
||||
mtprint("loaded map :")
|
||||
mtprint(map)
|
||||
end
|
||||
|
|
|
@ -2,11 +2,7 @@
|
|||
|
||||
#define VERSION_MAJ 0
|
||||
#define VERSION_MIN 1
|
||||
#define VERSION_PATCH 4
|
||||
|
||||
#define DEBUG 1
|
||||
|
||||
#define LOG_PATH "log.txt"
|
||||
#define VERSION_PATCH 3
|
||||
|
||||
// Set in ui.c
|
||||
extern char *VERSION_STR;
|
||||
|
|
10
src/draw.c
10
src/draw.c
|
@ -39,23 +39,17 @@ Image tile_index[TILE_N];
|
|||
extern GUIInfo gui_info;
|
||||
|
||||
int init_draw(){
|
||||
char tmpbuf[4096];
|
||||
|
||||
InitWindow(1280, 720, "Mineur Tycoon");
|
||||
|
||||
SetTargetFPS(60);
|
||||
|
||||
char *cwd = GetApplicationDirectory();
|
||||
puts(cwd);
|
||||
|
||||
for(int i = 0; i < TEX_N; i++){
|
||||
snprintf(tmpbuf, 4096, "%s%s", cwd, tex_files[i]);
|
||||
tex_index[i] = LoadTexture(tmpbuf);
|
||||
tex_index[i] = LoadTexture(tex_files[i]);
|
||||
GenTextureMipmaps(&tex_index[i]);
|
||||
}
|
||||
for(int i = 0; i < TILE_N; i++){
|
||||
snprintf(tmpbuf, 4096, "%s%s", cwd, tile_files[i]);
|
||||
tile_index[i] = LoadImage(tmpbuf);
|
||||
tile_index[i] = LoadImage(tile_files[i]);
|
||||
ImageFormat(&tile_index[i], 4);
|
||||
}
|
||||
|
||||
|
|
24
src/game.c
Executable file → Normal file
24
src/game.c
Executable file → Normal file
|
@ -8,7 +8,6 @@
|
|||
#include <raylib.h>
|
||||
#include <raymath.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "types.h"
|
||||
#include "map.h"
|
||||
#include "game.h"
|
||||
|
@ -20,16 +19,6 @@ MachineDef machine_dict[] = {
|
|||
{{{0,0},{32,0},{0,32},{32,32}}, {R_Coal, R_Iron}, 2, R_Steel, 0}, // MT_Furnace
|
||||
};
|
||||
|
||||
char *worker_names[] = {
|
||||
"Bob",
|
||||
"Jill",
|
||||
"Frank",
|
||||
"Michel",
|
||||
"Sophie"
|
||||
};
|
||||
|
||||
_Static_assert(sizeof(worker_names)/sizeof(void*) >= WORKER_NAMES);
|
||||
|
||||
int init_machines(Machines *machines){
|
||||
machines->machine_n = 0;
|
||||
machines->machine_id = 0;
|
||||
|
@ -63,38 +52,32 @@ int init_game(Game *game){
|
|||
game->camera = (Camera2D){.offset = {0, 0}, .zoom = 1};
|
||||
|
||||
int err = init_machines(&game->machines);
|
||||
err |= init_workers(&game->workers);
|
||||
err |= init_workers(&game->workers);
|
||||
if(err){
|
||||
printf("Failed to init game. Error : %x\n", err);
|
||||
return 1;
|
||||
}
|
||||
|
||||
load_map(game, 0);
|
||||
|
||||
int c_worker = 0;
|
||||
|
||||
for(int k = 0; k < 16; k++){
|
||||
for(int j = 0; j < 16; j++){
|
||||
Machine *coal_mine = add_machine(&game->machines, (V2d){k*250+40,j*400+40});
|
||||
coal_mine->type = MT_CoalMine;
|
||||
int coal_id = coal_mine->id;
|
||||
Machine *iron_mine = add_machine(&game->machines, (V2d){k*250+40,j*400+240});
|
||||
iron_mine->type = MT_IronMine;
|
||||
int iron_id = iron_mine->id;
|
||||
Machine *furnace = add_machine(&game->machines, (V2d){k*250+140,j*400+140});
|
||||
furnace->type = MT_Furnace;
|
||||
|
||||
// The adresses may have changed
|
||||
coal_mine = get_machine_from_id(&game->machines, coal_id);
|
||||
iron_mine = get_machine_from_id(&game->machines, coal_id);
|
||||
|
||||
for(int i = 0; i < 10; i++)
|
||||
add_worker(&game->workers, (V2d){.x=k*250+100,.y=j*400});
|
||||
for(int i = 0; i < 4; i++)
|
||||
assign_worker_machine(coal_mine, &game->workers.worker_stack[c_worker++]);
|
||||
for(int i = 4; i < 8; i++)
|
||||
assign_worker_machine(iron_mine, &game->workers.worker_stack[c_worker++]);
|
||||
game->workers.worker_stack[c_worker].satisf = rand() & 63;
|
||||
assign_worker_fetch(iron_mine, furnace, &game->workers.worker_stack[c_worker++]);
|
||||
game->workers.worker_stack[c_worker].satisf = rand() & 63;
|
||||
assign_worker_fetch(coal_mine, furnace, &game->workers.worker_stack[c_worker++]);
|
||||
if(!(furnace->id%1000))
|
||||
printf("%d\n",furnace->id);
|
||||
|
@ -132,7 +115,6 @@ Worker *add_worker(Workers *workers, V2d pos){
|
|||
|
||||
Worker *work = &workers->worker_stack[workers->worker_n++];
|
||||
work->pos = pos;
|
||||
work->name = rand()%WORKER_NAMES;
|
||||
work->ai = (AiInternal){S_Idle, 0, 0, 0, MACH_NULL, MACH_NULL, {.x=0,.y=0}};
|
||||
|
||||
return work;
|
||||
|
|
|
@ -20,10 +20,7 @@
|
|||
|
||||
#define TPS_TIME (1.0/TPS)
|
||||
|
||||
#define WORKER_NAMES 5
|
||||
|
||||
extern MachineDef machine_dict[];
|
||||
extern char *worker_names[];
|
||||
|
||||
int init_game(Game *game);
|
||||
|
||||
|
|
|
@ -258,29 +258,6 @@ void lua_onframe(Game *game){
|
|||
lua_callloop(game, "on_frame");
|
||||
}
|
||||
|
||||
void lua_onmapload(Game *game, int map){
|
||||
gl_game = game;
|
||||
for(int i = 0; i < lstate_n; i++){
|
||||
lua_State *L = lstates[i];
|
||||
lua_mkgame(L, game);
|
||||
if(lua_getglobal(L, "on_load") == LUA_TNIL){
|
||||
lua_pop(L, 2);
|
||||
continue;
|
||||
}
|
||||
lua_pushvalue(L, -2);
|
||||
lua_pushinteger(L, map);
|
||||
int ret = lua_pcall(L, 2, 0, 0);
|
||||
if(ret)
|
||||
puts(lua_tostring(L, -1));
|
||||
else{
|
||||
lua_pushliteral(L, "cash");
|
||||
lua_gettable(L, -2);
|
||||
if(lua_isinteger(L, -1))
|
||||
game->cash = lua_tointeger(L, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void lua_mt_init(lua_State *L){
|
||||
for(int i = 0; i < sizeof(exported_funcs)/sizeof(*exported_funcs); i++)
|
||||
lua_register(L, exported_funcs[i].name, exported_funcs[i].fn);
|
||||
|
@ -305,17 +282,11 @@ void lua_mt_init(lua_State *L){
|
|||
}
|
||||
|
||||
void script_init(Game *game){
|
||||
char tmpbuf[4096];
|
||||
gl_game = game;
|
||||
|
||||
char *cwd = GetApplicationDirectory();
|
||||
snprintf(tmpbuf, 4096, "%sscript", cwd);
|
||||
FilePathList scripts = LoadDirectoryFilesEx(tmpbuf,".lua",true);
|
||||
|
||||
FilePathList scripts = LoadDirectoryFilesEx("script",".lua",true);
|
||||
lstate_n = scripts.count;
|
||||
lstates = malloc(sizeof(void*)*lstate_n);
|
||||
if(!lstates){
|
||||
puts("Fail 318");
|
||||
return;
|
||||
}
|
||||
for(int i = 0; i < scripts.count; i++){
|
||||
|
@ -326,9 +297,7 @@ void script_init(Game *game){
|
|||
int ret = luaL_dofile(lstates[i], scripts.paths[i]);
|
||||
if(ret)
|
||||
puts(lua_tostring(lstates[i], -1));
|
||||
MemFree(scripts.paths[i]);
|
||||
}
|
||||
MemFree(scripts.paths);
|
||||
}
|
||||
|
||||
void script_clean(){
|
||||
|
|
|
@ -7,8 +7,6 @@ void lua_ontick(Game *game);
|
|||
|
||||
void lua_onframe(Game *game);
|
||||
|
||||
void lua_onmapload(Game *game, int map);
|
||||
|
||||
void script_init();
|
||||
|
||||
void script_clean();
|
||||
|
|
40
src/main.c
40
src/main.c
|
@ -7,7 +7,6 @@
|
|||
#include <raylib.h>
|
||||
#include <raymath.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "types.h"
|
||||
#include "game.h"
|
||||
#include "map.h"
|
||||
|
@ -23,49 +22,14 @@
|
|||
* map :
|
||||
* - Textures : ~
|
||||
* - Affichage :
|
||||
* - convertisseur :
|
||||
*/
|
||||
|
||||
#if DEBUG
|
||||
FILE *log_file;
|
||||
|
||||
char *log_levels[] = {
|
||||
"???",
|
||||
"TRACE",
|
||||
"DEBUG",
|
||||
"INFO",
|
||||
"WARNING",
|
||||
"ERROR",
|
||||
"FATAL",
|
||||
"!!!"
|
||||
};
|
||||
|
||||
void log_callback(int logLevel, const char *text, va_list args){
|
||||
char tmpbuf[1024*16];
|
||||
snprintf(tmpbuf, 1024*16, "%s : %s\n", log_levels[logLevel], text);
|
||||
vfprintf(log_file, tmpbuf, args);
|
||||
}
|
||||
|
||||
int init_log_file(){
|
||||
char tmpbuf[4096];
|
||||
snprintf(tmpbuf, 4096, "%s%s", GetApplicationDirectory(), LOG_PATH);
|
||||
log_file = fopen(tmpbuf, "w");
|
||||
if(!log_file)
|
||||
return 1;
|
||||
SetTraceLogCallback(log_callback);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int init(Game *game){
|
||||
int err;
|
||||
#if DEBUG
|
||||
err = init_log_file();
|
||||
#endif
|
||||
err |= init_draw();
|
||||
int err = init_draw();
|
||||
err |= init_game(game);
|
||||
init_ui();
|
||||
script_init(game);
|
||||
load_map(game, 0);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
|
||||
#include "types.h"
|
||||
#include "draw.h"
|
||||
#include "lua_inter.h"
|
||||
|
||||
extern MapCollec mapcollec;
|
||||
|
||||
|
@ -21,8 +20,6 @@ int generate_coll(Game *game, int mapn){
|
|||
memcpy(lmap->coll, map->layers[1], map->width*map->height);
|
||||
for(int i = 0; i < mach->machine_n; i++){
|
||||
V2d pos = mach->machine_stack[i].pos;
|
||||
pos.x /= 32;
|
||||
pos.y /= 32;
|
||||
lmap->coll[(int)(pos.y * lmap->width + pos.x)] = 1;
|
||||
lmap->coll[(int)(pos.y * lmap->width + pos.x+1)] = 1;
|
||||
lmap->coll[(int)((pos.y+1) * lmap->width + pos.x)] = 1;
|
||||
|
@ -37,14 +34,11 @@ int load_map(Game *game, int mapn){
|
|||
nmap->maptex = mkmap_tex(map);
|
||||
nmap->width = map->width;
|
||||
nmap->height = map->height;
|
||||
nmap->coll = malloc(map->width*map->height);
|
||||
nmap->coll = realloc(nmap->coll, map->width*map->height);
|
||||
if(!nmap->coll)
|
||||
return 1;
|
||||
if(generate_coll(game, mapn))
|
||||
return 1;
|
||||
|
||||
lua_onmapload(game, mapn);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -60,8 +60,7 @@ typedef struct {
|
|||
uint assign_n : 2; // To offset on machines
|
||||
uint satisf : 6;
|
||||
uint8_t fatigue;
|
||||
uint8_t name;
|
||||
uint8_t __padding[2];
|
||||
uint8_t __padding[3];
|
||||
|
||||
} Worker;
|
||||
|
||||
|
|
44
src/ui.c
44
src/ui.c
|
@ -27,20 +27,6 @@ void draw_text_centered(char *str, int y, int font_size, Color color){
|
|||
DrawText(str, 640-width/2, y, font_size, color);
|
||||
}
|
||||
|
||||
void draw_print(int x, int y, int font_size, Color color, char *fmt, ...){
|
||||
char tmpbuf[2048];
|
||||
|
||||
va_list vlist;
|
||||
|
||||
va_start(vlist, fmt);
|
||||
|
||||
vsnprintf(tmpbuf, 2048, fmt, vlist);
|
||||
|
||||
va_end(vlist);
|
||||
|
||||
DrawText(tmpbuf, x, y, font_size, color);
|
||||
}
|
||||
|
||||
void draw_buttons(Widget *widget){
|
||||
for(int i = 0; i < widget->button_n; i++){
|
||||
Button *butt = &widget->buttons[i];
|
||||
|
@ -202,16 +188,6 @@ Widget pause_menu = {
|
|||
|
||||
void worker_widget_draw(Widget *widget, Game *game){
|
||||
DrawRectangleRounded(widget->box, 0.1, 3, color_main_brown);
|
||||
|
||||
draw_buttons(widget);
|
||||
|
||||
Worker *work = gui_info.widg_target;
|
||||
draw_print(205, 100, 17, BLACK, "Name : %s", worker_names[work->name]);
|
||||
draw_print(205, 120, 17, BLACK, "Traits : TODO");
|
||||
draw_print(205, 140, 17, BLACK, "Satisfaction : %.0f%%",
|
||||
(float)work->satisf/64.0f*100.0f);
|
||||
draw_print(205, 160, 17, BLACK, "Fatigue : %.0f%%",
|
||||
(float)work->fatigue/256.0f*100.0f);
|
||||
}
|
||||
|
||||
void worker_widget_do_event(Widget *widget, Game *game, MTEvent event){
|
||||
|
@ -220,27 +196,14 @@ void worker_widget_do_event(Widget *widget, Game *game, MTEvent event){
|
|||
}
|
||||
|
||||
Widget worker_widget = {
|
||||
.box = {.x = 40, .y = 40, .width = 350, .height = 600},
|
||||
.box = {.x = 40, .y = 40, .width = 300, .height = 600},
|
||||
.draw = worker_widget_draw,
|
||||
.do_event = worker_widget_do_event,
|
||||
.capt_flags = CF_Mouse,
|
||||
.buttons = {
|
||||
{.box = {350,50,30,30},
|
||||
.color_0 = RED,
|
||||
.color_1 = BLACK,
|
||||
.color_txt = BLACK,
|
||||
.txt = "X",
|
||||
.handler = NULL
|
||||
},
|
||||
{.box = {55,90,140,140},
|
||||
.color_0 = GRAY,
|
||||
.color_1 = BLACK,
|
||||
.color_txt = WHITE,
|
||||
.txt = "",
|
||||
.handler = NULL
|
||||
},
|
||||
|
||||
},
|
||||
.button_n = 2
|
||||
.button_n = 0
|
||||
};
|
||||
|
||||
Widget machine_widget = {
|
||||
|
@ -343,7 +306,6 @@ void try_interface(Game *game, V2d pos){
|
|||
|
||||
printf("found worker\n");
|
||||
gui_info.widget_active[2] = true;
|
||||
gui_info.widg_target = work;
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
2
src/ui.h
2
src/ui.h
|
@ -72,8 +72,6 @@ typedef struct {
|
|||
Widget *widgets[WIDGET_N];
|
||||
bool widget_active[WIDGET_N];
|
||||
|
||||
void *widg_target;
|
||||
|
||||
float *zoom;
|
||||
|
||||
} GUIInfo;
|
||||
|
|
Loading…
Add table
Reference in a new issue