diff --git a/assets/blobbleu1.png b/assets/blobbleu1.png new file mode 100644 index 0000000..18194d9 Binary files /dev/null and b/assets/blobbleu1.png differ diff --git a/assets/blobbleu1.webp b/assets/blobbleu1.webp deleted file mode 100644 index 8f0fdcc..0000000 Binary files a/assets/blobbleu1.webp and /dev/null differ diff --git a/assets/blobbleu2.png b/assets/blobbleu2.png new file mode 100644 index 0000000..874a229 Binary files /dev/null and b/assets/blobbleu2.png differ diff --git a/assets/blobbleu2.webp b/assets/blobbleu2.webp deleted file mode 100644 index a4f5179..0000000 Binary files a/assets/blobbleu2.webp and /dev/null differ diff --git a/assets/blobbleu3.png b/assets/blobbleu3.png new file mode 100644 index 0000000..871525d Binary files /dev/null and b/assets/blobbleu3.png differ diff --git a/assets/blobbleu3.webp b/assets/blobbleu3.webp deleted file mode 100644 index 0ddeb8c..0000000 Binary files a/assets/blobbleu3.webp and /dev/null differ diff --git a/assets/blobrouge1.png b/assets/blobrouge1.png new file mode 100644 index 0000000..96494cc Binary files /dev/null and b/assets/blobrouge1.png differ diff --git a/assets/blobrouge1.webp b/assets/blobrouge1.webp deleted file mode 100644 index 65afeff..0000000 Binary files a/assets/blobrouge1.webp and /dev/null differ diff --git a/assets/blobrouge2.png b/assets/blobrouge2.png new file mode 100644 index 0000000..e672c02 Binary files /dev/null and b/assets/blobrouge2.png differ diff --git a/assets/blobrouge2.webp b/assets/blobrouge2.webp deleted file mode 100644 index 4bb6d78..0000000 Binary files a/assets/blobrouge2.webp and /dev/null differ diff --git a/assets/blobrouge3.png b/assets/blobrouge3.png new file mode 100644 index 0000000..fbe77a9 Binary files /dev/null and b/assets/blobrouge3.png differ diff --git a/assets/blobrouge3.webp b/assets/blobrouge3.webp deleted file mode 100644 index 8285383..0000000 Binary files a/assets/blobrouge3.webp and /dev/null differ diff --git a/assets/blobvert1.png b/assets/blobvert1.png new file mode 100644 index 0000000..7b2fdf3 Binary files /dev/null and b/assets/blobvert1.png differ diff --git a/assets/blobvert1.webp b/assets/blobvert1.webp deleted file mode 100644 index e9e16ab..0000000 Binary files a/assets/blobvert1.webp and /dev/null differ diff --git a/assets/blobvert2.png b/assets/blobvert2.png new file mode 100644 index 0000000..305d3a9 Binary files /dev/null and b/assets/blobvert2.png differ diff --git a/assets/blobvert2.webp b/assets/blobvert2.webp deleted file mode 100644 index 1919e26..0000000 Binary files a/assets/blobvert2.webp and /dev/null differ diff --git a/assets/blobvert3.png b/assets/blobvert3.png new file mode 100644 index 0000000..5debb06 Binary files /dev/null and b/assets/blobvert3.png differ diff --git a/assets/blobvert3.webp b/assets/blobvert3.webp deleted file mode 100644 index 3fb8a4b..0000000 Binary files a/assets/blobvert3.webp and /dev/null differ diff --git a/src/draw.c b/src/draw.c index c3c99a0..8ce1fc1 100644 --- a/src/draw.c +++ b/src/draw.c @@ -11,21 +11,63 @@ #include "game.h" #include "draw.h" -void draw_workers(Workers *workers){ +#define TEX_N 9 + +char *tex_files[TEX_N] = { + "assets/blobbleu1.png", + "assets/blobbleu2.png", + "assets/blobbleu3.png", + "assets/blobrouge1.png", + "assets/blobrouge2.png", + "assets/blobrouge3.png", + "assets/blobvert1.png", + "assets/blobvert2.png", + "assets/blobvert3.png" +}; + +Texture2D tex_index[TEX_N]; + +int init_draw(){ + + InitWindow(1280, 720, "Mineur Tycoon"); + + SetTargetFPS(60); + + for(int i = 0; i < TEX_N; i++){ + tex_index[i] = LoadTexture(tex_files[i]); + } + return 0; +} + +void draw_workers(Game *game){ + Workers *workers = &game->workers; for(int i = 0; i < workers->worker_n; i++){ - DrawRectangleV(workers->worker_stack[i].pos, (V2d){.x=32,.y=32}, WHITE); + Worker *worker = &workers->worker_stack[i]; + if(worker->pos.x + 32 < 0 || worker->pos.x >= 1280 || + worker->pos.y + 32 < 0 || worker->pos.y >= 720) + continue; + V2d pos = worker->pos; + if(worker->ai.status == S_Operating){ + Machine *machine = get_machine_from_id(&game->machines, + worker->ai.assigned_machine); + pos = Vector2Add(pos, + machine_dict[machine->type].offsets[worker->assign_n]); + } + + //DrawRectangleV(pos, (V2d){.x=32,.y=32}, WHITE); + DrawTextureV(tex_index[0], pos, WHITE); } } void draw_machines(Machines *machines){ for(int i = 0; i < machines->machine_n; i++){ - DrawRectangleV(machines->machine_stack[i].pos, (V2d){.x=64,.y=64}, BLUE); + Machine *machine = &machines->machine_stack[i]; + float active_per = Remap((float)machine->active,0,255,0.2,1); + DrawRectangleV(machine->pos, (V2d){.x=64,.y=64}, Fade(BLUE,active_per)); } } void draw(Game *game){ draw_machines(&game->machines); - draw_workers(&game->workers); + draw_workers(game); } - - diff --git a/src/draw.h b/src/draw.h index ea00af4..d14ba63 100644 --- a/src/draw.h +++ b/src/draw.h @@ -12,4 +12,6 @@ #pragma once +int init_draw(); + void draw(Game *game); diff --git a/src/game.c b/src/game.c index aafe410..6c21ff2 100644 --- a/src/game.c +++ b/src/game.c @@ -11,9 +11,9 @@ #include "game.h" MachineDef machine_dict[] = { - {{}, 0, R_Coal, 4}, // MT_CoalMine - {{}, 0, R_Iron, 4}, // MT_IronMine - {{R_Coal, R_Iron}, 2, R_Steel, 0}, // MT_Furnace + {{{0,0},{32,0},{0,32},{32,32}}, {}, 0, R_Coal, 4}, // MT_CoalMine + {{{0,0},{32,0},{0,32},{32,32}}, {}, 0, R_Iron, 4}, // MT_IronMine + {{{0,0},{32,0},{0,32},{32,32}}, {R_Coal, R_Iron}, 2, R_Steel, 0}, // MT_Furnace }; int init_machines(Machines *machines){ @@ -38,6 +38,11 @@ int init_workers(Workers *workers){ } int init_game(Game *game){ + int rand_seed = GetTime(); + rand_seed &= 0xFFFFFFFF; + + srand(rand_seed); + int err = init_machines(&game->machines); err |= init_workers(&game->workers); if(err){ @@ -92,9 +97,8 @@ Machine *add_machine(Machines *machines, V2d pos){ } Machine *mach = &machines->machine_stack[machines->machine_n++]; + *mach = (Machine){.pos=pos}; mach->id = machines->machine_id++; - mach->pos = pos; - mach->assign_workers = 0; return mach; } @@ -121,6 +125,10 @@ int get_machine_localres(Machine *machine, int globalres){ return -1; } +double V2d_dotp(V2d a, V2d b){ + return a.x*b.x + a.y*b.y; +} + void update_worker(Game *game, Worker *worker){ AiInternal *ai = &worker->ai; if(ai->assigned_machine < 0 && ai->assigned_machine1 < 0) @@ -154,7 +162,6 @@ void update_worker(Game *game, Worker *worker){ case S_Loading: if(!Vector2Equals(worker->pos,mach[0]->pos)){ ai->status = S_Transporting; - ai->going_to = 0; ai->dest = mach[0]->pos; break; } @@ -165,7 +172,6 @@ void update_worker(Game *game, Worker *worker){ else { ai->status = S_Transporting; ai->dest = mach[1]->pos; - ai->going_to = 1; } break; case S_Unloading: @@ -177,7 +183,6 @@ void update_worker(Game *game, Worker *worker){ if(!Vector2Equals(worker->pos, mach[1]->pos)){ ai->status = S_Transporting; ai->dest = mach[1]->pos; - ai->going_to = 1; break; } if(ai->carrying && mach[1]->storage[localres] <= 200){ @@ -187,7 +192,6 @@ void update_worker(Game *game, Worker *worker){ else{ ai->status = S_Transporting; ai->dest = mach[0]->pos; - ai->going_to = 0; } break; case S_Operating: @@ -195,11 +199,17 @@ void update_worker(Game *game, Worker *worker){ break; case S_Transporting: case S_Walking: - worker->pos = ai->dest; - if(Vector2Equals(worker->pos, mach[0]->pos)) + Vector2 mov = Vector2Normalize(Vector2Subtract(ai->dest, worker->pos)); + worker->pos = Vector2Add(worker->pos, mov); + if(Vector2LengthSqr(Vector2Subtract(mach[0]->pos, worker->pos)) < 0.3){ + worker->pos = mach[0]->pos; ai->status = S_Loading; - else if(Vector2Equals(worker->pos, mach[1]->pos)) + } + else if(Vector2LengthSqr(Vector2Subtract(mach[1]->pos, worker->pos)) + < 0.3){ + worker->pos = mach[1]->pos; ai->status = S_Unloading; + } break; } } @@ -218,12 +228,16 @@ void update_machine(Game *game, Machine *machine){ if(!machine->storage[i]) can_output = false; } - if(can_output){ + if(can_output){ for(int i = 0; i < def->input_n; i++){ machine->storage[i]--; } machine->storage[4]++; + if(machine->active < 254) + machine->active+=2; } + else if(machine->active) + machine->active--; } void update_machines(Game *game){ @@ -238,7 +252,7 @@ void update(Game *game){ } int assign_worker_machine(Machine *machine, Worker *worker){ - machine->assign_workers++; + worker->assign_n = machine->assign_workers++; AiInternal *ai = &worker->ai; ai->assigned_machine = machine->id; ai->assigned_machine1 = -1; diff --git a/src/main.c b/src/main.c index a33488f..2dc7b9d 100644 --- a/src/main.c +++ b/src/main.c @@ -18,20 +18,27 @@ int try_interface(Game *game){ return 0; } +int init(Game *game){ + int err = init_draw(); + err |= init_game(game); + return err; +} + +void clean(Game *game){ + clean_game(game); + + CloseWindow(); +} + int main(){ - int rand_seed = GetTime(); - rand_seed &= 0xFFFFFFFF; - - srand(rand_seed); - - InitWindow(1280, 720, "Mineur Tycoon"); - - SetTargetFPS(60); - Game game; - init_game(&game); + if(init(&game)){ + printf("Failed to init game ! Exiting...\n"); + clean(&game); + return 1; + } Machine *coal_mine = add_machine(&game.machines, (V2d){40,40}); coal_mine->type = MT_CoalMine; @@ -61,9 +68,7 @@ int main(){ EndDrawing(); } - clean_game(&game); - - CloseWindow(); + clean(&game); return 0; } diff --git a/src/types.h b/src/types.h index 52f2f12..fed228b 100644 --- a/src/types.h +++ b/src/types.h @@ -27,7 +27,8 @@ enum WorkerTraits { enum MachineTypes { MT_CoalMine = 0, MT_IronMine = 1, - MT_Furnace = 2 + MT_Furnace = 2, + MT_Sell = 3 }; enum Ressources { @@ -41,7 +42,7 @@ typedef struct { uint8_t status; uint8_t carrying; //Quantity uint8_t carry_type; //Global type - uint8_t going_to; + uint8_t __padding; int16_t assigned_machine; // Machine if working int16_t assigned_machine1; // 2nd machine if carrying V2d dest; @@ -55,7 +56,8 @@ typedef struct { uint8_t fatigue; uint8_t satisf; AiInternal ai; - uint8_t __padding[4]; + uint8_t assign_n; // To offset on machines + uint8_t __padding[3]; } Worker; @@ -71,14 +73,15 @@ typedef struct { V2d pos; uint8_t type; uint8_t assign_workers; - uint8_t rot; // Rotation - uint8_t storage[5]; // <=> inputs ; 4 is out storage + uint8_t active; + uint8_t storage[5]; // <=> inputs ; 4 is output storage int16_t id; } Machine; typedef struct { + V2d offsets[4]; // Worker pos offsets uint8_t inputs[4]; uint8_t input_n; uint8_t output; @@ -102,5 +105,3 @@ typedef struct { int64_t cash; } Game; - -