You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
3.1 KiB

#include "../game.h"
#include "selectable.h"
#include "button.h"
#include "../definitions.h"
#include "raylib.h"
#include "stdio.h"
#include "../MapObject/building.h"
#include "../Sprite/sprite.h"
#include "../Entity/entity.h"
#include "../Input/inputHandler.h"
void OnClickButton(Game *game, Button *button){
printf("\n\n\n\n\n\n Unsupported Button ID %d \n\n\n\n\n\n", button->id);
return;
}
void OnClickContinueButton(Game *game, Button *button){
game->currentScreen = SCREEN_GAME;
}
void OnClickExitButton(Game *game, Button *button){
game->currentScreen = SCREEN_EXIT;
}
void OnClickStartButton(Game *game, Button *button){
game->currentScreen = SCREEN_GAME;
}
// RETURNS 1 IF COORDS INSIDE MAP
static int InsideMapBounds(Vector2 coords, IsometricMap *map){
if(coords.x < 0 || coords.y < 0 || coords.x > (map->width * map->textureWidth) || coords.y > (map->height * map->textureHeight)){
printf("OutOfBoundsDestination Spawn\n");
return 0;
}
return 1;
}
// Hier sollte eine Bedingung stehen die nur in einem Frame true sein kann
// Oder das selectable wird abgewählt indem seine ID auf default zurückgesetzt wird
// Sonst kann das hier jeden Frame passieren. ID wird nicht automatisch zurückgesetzt
void OnSelectedSelectable(Game *game, Selectable *selectable){
printf("\n\n\n\n\n\n WARNING: Unsupported SELECTABLE ID %d \n\n\n\n\n\n", selectable->id);
return;
}
void OnSelectedSpawnBuilding(Game *game, Selectable *selectable){
if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && game->mouseOnUI == 0){
// Can only be spawned inside map bounds
if(InsideMapBounds(game->inputHandler->cursorWorldPos, game->map) == 0){
return;
}
Building *newObject = BuildingInit(game, BU_HOUSE, game->inputHandler->cursorWorldPos.x, game->inputHandler->cursorWorldPos.y);
BuildingListInsert(game->buildings, newObject);
if(selectable->unselectAfterExecute == 0){
selectable->state = SELECTABLE_STATE_DEFAULT;
}
}
}
void OnSelectedSpawnWorker(Game *game, Selectable *selectable){
if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && game->mouseOnUI == 0){
if(InsideMapBounds(game->inputHandler->cursorWorldPos, game->map) == 0){
return;
}
Entity *builder = EntityInit(game, PR_BUILDER, game->inputHandler->cursorWorldPos.x, game->inputHandler->cursorWorldPos.y);
EntityListInsert(game->entities, builder);
if(selectable->unselectAfterExecute == 0){
selectable->state = SELECTABLE_STATE_DEFAULT;
}
}
}
void OnSelectedSpawnLumberjack(Game *game, Selectable *selectable){
if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT) && game->mouseOnUI == 0){
if(InsideMapBounds(game->inputHandler->cursorWorldPos, game->map) == 0){
return;
}
Entity *lumberjack = EntityInit(game, PR_LUMBERJACK, game->inputHandler->cursorWorldPos.x, game->inputHandler->cursorWorldPos.y);
EntityListInsert(game->entities, lumberjack);
if(selectable->unselectAfterExecute == 0){
selectable->state = SELECTABLE_STATE_DEFAULT;
}
}
}