Covert. vers png, affichage blobs, machines actives
BIN
assets/blobbleu1.png
Normal file
After Width: | Height: | Size: 714 B |
Before Width: | Height: | Size: 152 B |
BIN
assets/blobbleu2.png
Normal file
After Width: | Height: | Size: 719 B |
Before Width: | Height: | Size: 154 B |
BIN
assets/blobbleu3.png
Normal file
After Width: | Height: | Size: 722 B |
Before Width: | Height: | Size: 160 B |
BIN
assets/blobrouge1.png
Normal file
After Width: | Height: | Size: 717 B |
Before Width: | Height: | Size: 148 B |
BIN
assets/blobrouge2.png
Normal file
After Width: | Height: | Size: 719 B |
Before Width: | Height: | Size: 152 B |
BIN
assets/blobrouge3.png
Normal file
After Width: | Height: | Size: 722 B |
Before Width: | Height: | Size: 158 B |
BIN
assets/blobvert1.png
Normal file
After Width: | Height: | Size: 719 B |
Before Width: | Height: | Size: 154 B |
BIN
assets/blobvert2.png
Normal file
After Width: | Height: | Size: 719 B |
Before Width: | Height: | Size: 156 B |
BIN
assets/blobvert3.png
Normal file
After Width: | Height: | Size: 722 B |
Before Width: | Height: | Size: 162 B |
54
src/draw.c
|
@ -11,21 +11,63 @@
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include "draw.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++){
|
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){
|
void draw_machines(Machines *machines){
|
||||||
for(int i = 0; i < machines->machine_n; i++){
|
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){
|
void draw(Game *game){
|
||||||
draw_machines(&game->machines);
|
draw_machines(&game->machines);
|
||||||
draw_workers(&game->workers);
|
draw_workers(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,4 +12,6 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
int init_draw();
|
||||||
|
|
||||||
void draw(Game *game);
|
void draw(Game *game);
|
||||||
|
|
42
src/game.c
|
@ -11,9 +11,9 @@
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
|
||||||
MachineDef machine_dict[] = {
|
MachineDef machine_dict[] = {
|
||||||
{{}, 0, R_Coal, 4}, // MT_CoalMine
|
{{{0,0},{32,0},{0,32},{32,32}}, {}, 0, R_Coal, 4}, // MT_CoalMine
|
||||||
{{}, 0, R_Iron, 4}, // MT_IronMine
|
{{{0,0},{32,0},{0,32},{32,32}}, {}, 0, R_Iron, 4}, // MT_IronMine
|
||||||
{{R_Coal, R_Iron}, 2, R_Steel, 0}, // MT_Furnace
|
{{{0,0},{32,0},{0,32},{32,32}}, {R_Coal, R_Iron}, 2, R_Steel, 0}, // MT_Furnace
|
||||||
};
|
};
|
||||||
|
|
||||||
int init_machines(Machines *machines){
|
int init_machines(Machines *machines){
|
||||||
|
@ -38,6 +38,11 @@ int init_workers(Workers *workers){
|
||||||
}
|
}
|
||||||
|
|
||||||
int init_game(Game *game){
|
int init_game(Game *game){
|
||||||
|
int rand_seed = GetTime();
|
||||||
|
rand_seed &= 0xFFFFFFFF;
|
||||||
|
|
||||||
|
srand(rand_seed);
|
||||||
|
|
||||||
int err = init_machines(&game->machines);
|
int err = init_machines(&game->machines);
|
||||||
err |= init_workers(&game->workers);
|
err |= init_workers(&game->workers);
|
||||||
if(err){
|
if(err){
|
||||||
|
@ -92,9 +97,8 @@ Machine *add_machine(Machines *machines, V2d pos){
|
||||||
}
|
}
|
||||||
|
|
||||||
Machine *mach = &machines->machine_stack[machines->machine_n++];
|
Machine *mach = &machines->machine_stack[machines->machine_n++];
|
||||||
|
*mach = (Machine){.pos=pos};
|
||||||
mach->id = machines->machine_id++;
|
mach->id = machines->machine_id++;
|
||||||
mach->pos = pos;
|
|
||||||
mach->assign_workers = 0;
|
|
||||||
|
|
||||||
return mach;
|
return mach;
|
||||||
}
|
}
|
||||||
|
@ -121,6 +125,10 @@ int get_machine_localres(Machine *machine, int globalres){
|
||||||
return -1;
|
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){
|
void update_worker(Game *game, Worker *worker){
|
||||||
AiInternal *ai = &worker->ai;
|
AiInternal *ai = &worker->ai;
|
||||||
if(ai->assigned_machine < 0 && ai->assigned_machine1 < 0)
|
if(ai->assigned_machine < 0 && ai->assigned_machine1 < 0)
|
||||||
|
@ -154,7 +162,6 @@ void update_worker(Game *game, Worker *worker){
|
||||||
case S_Loading:
|
case S_Loading:
|
||||||
if(!Vector2Equals(worker->pos,mach[0]->pos)){
|
if(!Vector2Equals(worker->pos,mach[0]->pos)){
|
||||||
ai->status = S_Transporting;
|
ai->status = S_Transporting;
|
||||||
ai->going_to = 0;
|
|
||||||
ai->dest = mach[0]->pos;
|
ai->dest = mach[0]->pos;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -165,7 +172,6 @@ void update_worker(Game *game, Worker *worker){
|
||||||
else {
|
else {
|
||||||
ai->status = S_Transporting;
|
ai->status = S_Transporting;
|
||||||
ai->dest = mach[1]->pos;
|
ai->dest = mach[1]->pos;
|
||||||
ai->going_to = 1;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case S_Unloading:
|
case S_Unloading:
|
||||||
|
@ -177,7 +183,6 @@ void update_worker(Game *game, Worker *worker){
|
||||||
if(!Vector2Equals(worker->pos, mach[1]->pos)){
|
if(!Vector2Equals(worker->pos, mach[1]->pos)){
|
||||||
ai->status = S_Transporting;
|
ai->status = S_Transporting;
|
||||||
ai->dest = mach[1]->pos;
|
ai->dest = mach[1]->pos;
|
||||||
ai->going_to = 1;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(ai->carrying && mach[1]->storage[localres] <= 200){
|
if(ai->carrying && mach[1]->storage[localres] <= 200){
|
||||||
|
@ -187,7 +192,6 @@ void update_worker(Game *game, Worker *worker){
|
||||||
else{
|
else{
|
||||||
ai->status = S_Transporting;
|
ai->status = S_Transporting;
|
||||||
ai->dest = mach[0]->pos;
|
ai->dest = mach[0]->pos;
|
||||||
ai->going_to = 0;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case S_Operating:
|
case S_Operating:
|
||||||
|
@ -195,11 +199,17 @@ void update_worker(Game *game, Worker *worker){
|
||||||
break;
|
break;
|
||||||
case S_Transporting:
|
case S_Transporting:
|
||||||
case S_Walking:
|
case S_Walking:
|
||||||
worker->pos = ai->dest;
|
Vector2 mov = Vector2Normalize(Vector2Subtract(ai->dest, worker->pos));
|
||||||
if(Vector2Equals(worker->pos, mach[0]->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;
|
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;
|
ai->status = S_Unloading;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -218,12 +228,16 @@ void update_machine(Game *game, Machine *machine){
|
||||||
if(!machine->storage[i])
|
if(!machine->storage[i])
|
||||||
can_output = false;
|
can_output = false;
|
||||||
}
|
}
|
||||||
if(can_output){
|
if(can_output){
|
||||||
for(int i = 0; i < def->input_n; i++){
|
for(int i = 0; i < def->input_n; i++){
|
||||||
machine->storage[i]--;
|
machine->storage[i]--;
|
||||||
}
|
}
|
||||||
machine->storage[4]++;
|
machine->storage[4]++;
|
||||||
|
if(machine->active < 254)
|
||||||
|
machine->active+=2;
|
||||||
}
|
}
|
||||||
|
else if(machine->active)
|
||||||
|
machine->active--;
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_machines(Game *game){
|
void update_machines(Game *game){
|
||||||
|
@ -238,7 +252,7 @@ void update(Game *game){
|
||||||
}
|
}
|
||||||
|
|
||||||
int assign_worker_machine(Machine *machine, Worker *worker){
|
int assign_worker_machine(Machine *machine, Worker *worker){
|
||||||
machine->assign_workers++;
|
worker->assign_n = machine->assign_workers++;
|
||||||
AiInternal *ai = &worker->ai;
|
AiInternal *ai = &worker->ai;
|
||||||
ai->assigned_machine = machine->id;
|
ai->assigned_machine = machine->id;
|
||||||
ai->assigned_machine1 = -1;
|
ai->assigned_machine1 = -1;
|
||||||
|
|
31
src/main.c
|
@ -18,20 +18,27 @@ int try_interface(Game *game){
|
||||||
return 0;
|
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 main(){
|
||||||
|
|
||||||
int rand_seed = GetTime();
|
|
||||||
rand_seed &= 0xFFFFFFFF;
|
|
||||||
|
|
||||||
srand(rand_seed);
|
|
||||||
|
|
||||||
InitWindow(1280, 720, "Mineur Tycoon");
|
|
||||||
|
|
||||||
SetTargetFPS(60);
|
|
||||||
|
|
||||||
Game game;
|
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});
|
Machine *coal_mine = add_machine(&game.machines, (V2d){40,40});
|
||||||
coal_mine->type = MT_CoalMine;
|
coal_mine->type = MT_CoalMine;
|
||||||
|
@ -61,9 +68,7 @@ int main(){
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
clean_game(&game);
|
clean(&game);
|
||||||
|
|
||||||
CloseWindow();
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
15
src/types.h
|
@ -27,7 +27,8 @@ enum WorkerTraits {
|
||||||
enum MachineTypes {
|
enum MachineTypes {
|
||||||
MT_CoalMine = 0,
|
MT_CoalMine = 0,
|
||||||
MT_IronMine = 1,
|
MT_IronMine = 1,
|
||||||
MT_Furnace = 2
|
MT_Furnace = 2,
|
||||||
|
MT_Sell = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
enum Ressources {
|
enum Ressources {
|
||||||
|
@ -41,7 +42,7 @@ typedef struct {
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
uint8_t carrying; //Quantity
|
uint8_t carrying; //Quantity
|
||||||
uint8_t carry_type; //Global type
|
uint8_t carry_type; //Global type
|
||||||
uint8_t going_to;
|
uint8_t __padding;
|
||||||
int16_t assigned_machine; // Machine if working
|
int16_t assigned_machine; // Machine if working
|
||||||
int16_t assigned_machine1; // 2nd machine if carrying
|
int16_t assigned_machine1; // 2nd machine if carrying
|
||||||
V2d dest;
|
V2d dest;
|
||||||
|
@ -55,7 +56,8 @@ typedef struct {
|
||||||
uint8_t fatigue;
|
uint8_t fatigue;
|
||||||
uint8_t satisf;
|
uint8_t satisf;
|
||||||
AiInternal ai;
|
AiInternal ai;
|
||||||
uint8_t __padding[4];
|
uint8_t assign_n; // To offset on machines
|
||||||
|
uint8_t __padding[3];
|
||||||
|
|
||||||
} Worker;
|
} Worker;
|
||||||
|
|
||||||
|
@ -71,14 +73,15 @@ typedef struct {
|
||||||
V2d pos;
|
V2d pos;
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
uint8_t assign_workers;
|
uint8_t assign_workers;
|
||||||
uint8_t rot; // Rotation
|
uint8_t active;
|
||||||
uint8_t storage[5]; // <=> inputs ; 4 is out storage
|
uint8_t storage[5]; // <=> inputs ; 4 is output storage
|
||||||
int16_t id;
|
int16_t id;
|
||||||
|
|
||||||
} Machine;
|
} Machine;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
||||||
|
V2d offsets[4]; // Worker pos offsets
|
||||||
uint8_t inputs[4];
|
uint8_t inputs[4];
|
||||||
uint8_t input_n;
|
uint8_t input_n;
|
||||||
uint8_t output;
|
uint8_t output;
|
||||||
|
@ -102,5 +105,3 @@ typedef struct {
|
||||||
int64_t cash;
|
int64_t cash;
|
||||||
|
|
||||||
} Game;
|
} Game;
|
||||||
|
|
||||||
|
|
||||||
|
|