#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->screen = SCREEN_GAME; } void OnClickExitButton(Game *game, Button *button){ game->screen = SCREEN_EXIT; } void OnClickStartButton(Game *game, Button *button){ game->screen = SCREEN_GAME; } // RETURNS 1 IF COORDS INSIDE MAP static int InsideMapBounds(Vector2 coords, IsometricMap *map){ int maxWidth = map->width * map->textureWidth; int maxHeight = map->height * map->textureHeight; if(coords.x < 0 || coords.y < 0 || coords.x > maxWidth || coords.y > maxHeight){ 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(IsMouseButtonDown(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); selectable->state = SELECTABLE_STATE_DEFAULT; } } void OnSelectedSpawnWorker(Game *game, Selectable *selectable){ if(IsMouseButtonDown(MOUSE_BUTTON_LEFT) && game->mouseOnUI == 0){ // Can only be spawned inside map bounds if(InsideMapBounds(game->inputHandler->cursorWorldPos, game->map) == 0){ return; } Sprite *newSprite = SpriteCreate(game->textures, TE_WORKER, game->inputHandler->cursorWorldPos.x, game->inputHandler->cursorWorldPos.y); Entity *entity = EntityInit(newSprite, PR_BUILDER, game->textures); EntityListInsert(game->entities, entity); SpriteListInsert(game->sprites, newSprite); selectable->state = SELECTABLE_STATE_DEFAULT; } }