diff --git a/Entity/entityacts.c b/Entity/entityacts.c index b1b317a..6ebd5d0 100644 --- a/Entity/entityacts.c +++ b/Entity/entityacts.c @@ -82,7 +82,7 @@ void LumberjackAct(Game *game, Entity *entity){ EntityMoveToDestination(entity); } else{ - printf("%f\n", entity->task->progress); + //printf("%f\n", entity->task->progress); // Is beim target angekommen if(entity->task->progress == 0){ // Angekommen, noch nicht mit arbeiten begonnen @@ -92,7 +92,7 @@ void LumberjackAct(Game *game, Entity *entity){ else if(entity->task->progress >= 1.0){ // Fertig mit arbeiten, Animation zu Idle zurück AnimationChangeType(entity->animationHandler, AN_ENTITY_IDLE); - printf("Fertig\n"); + //printf("Fertig\n"); StaticObjectListRemove(game, entity->task->target); entity->task->target = 0; @@ -101,6 +101,7 @@ void LumberjackAct(Game *game, Entity *entity){ } else{ entity->task->progress += 0.2 * ACT_TIME; + } } } diff --git a/Input/inputHandler.c b/Input/inputHandler.c index 68222ff..dfa6981 100644 --- a/Input/inputHandler.c +++ b/Input/inputHandler.c @@ -61,7 +61,7 @@ static void SelectEntitiesInsideSelectionRect(Game *game){ // Jetzt neu anwählen while (current != 0){ Vector2 currPos = {current->sprite->x + current->sprite->texture->width, current->sprite->y + current->sprite->texture->height/2}; - IsometricMapUnproject(game->map, game->camera, currPos.x, currPos.y, &currPos); + IsometricMapUnproject(game->camera, currPos.x, currPos.y, &currPos); deltaX = currPos.x - game->camera->target.x - (rect.x + game->camera->target.x); deltaY = currPos.y - game->camera->target.y - (rect.y + game->camera->target.y); @@ -80,9 +80,6 @@ void mouseInput(Game *game){ game->inputHandler->cursorPos.x = GetMousePosition().x; game->inputHandler->cursorPos.y = GetMousePosition().y; - // resetting last selected Tile to grass texture - IsometricMapChangeTextureIdOfTile(game->map, (int) game->inputHandler->cursorWorldTile.x, (int) game->inputHandler->cursorWorldTile.y, 0); - // Updating cursorWorldPos IsometricMapProject(game->map, game->camera, (game->inputHandler->cursorPos.x / game->camera->zoom) - (game->map->textureWidth/2), @@ -94,8 +91,6 @@ void mouseInput(Game *game){ if(currentlySelectedTile != 0){ game->inputHandler->cursorWorldTile.x = currentlySelectedTile->x; game->inputHandler->cursorWorldTile.y = currentlySelectedTile->y; - // setting the currently selected Tile to "selected" Texture - IsometricMapChangeTextureIdOfTile(game->map, (int) game->inputHandler->cursorWorldTile.x, (int) game->inputHandler->cursorWorldTile.y, 1); } /* --- CURSOR SPRITE --- */ diff --git a/IsometricMap/isometricMap.c b/IsometricMap/isometricMap.c index b7c6efc..24db7b0 100644 --- a/IsometricMap/isometricMap.c +++ b/IsometricMap/isometricMap.c @@ -74,10 +74,32 @@ void IsometricMapProject(IsometricMap *isometricMap, Camera2D *camera, float x, } // Unproject: World Coordinates -> Screen Coordinates writes result in tmp Vector -void IsometricMapUnproject(IsometricMap *isometricMap, Camera2D *camera, int x, int y, Vector2 *tmp){ +void IsometricMapUnproject(Camera2D *camera, int x, int y, Vector2 *tmp){ tmp->x = ((x - y)/2) + camera->target.x; tmp->y = ((x + y)/4) + camera->target.y; +} +void IsometricMapUnprojectIgnoreCam(int x, int y, Vector2 *tmp){ + tmp->x = ((x - y)/2); + tmp->y = ((x + y)/4); +} +// USE INSIDE MODE2D!! +void IsometricMapDrawRectangle(Vector2 from, Vector2 to, Color color){ + from.x += 32; + to.x += 32; + Vector2 corner1 = {from.x, from.y}; + IsometricMapUnprojectIgnoreCam(corner1.x, corner1.y, &corner1); + Vector2 corner2 = {to.x, from.y}; + IsometricMapUnprojectIgnoreCam(corner2.x, corner2.y, &corner2); + Vector2 corner3 = {to.x, to.y}; + IsometricMapUnprojectIgnoreCam(corner3.x, corner3.y, &corner3); + Vector2 corner4 = {from.x, to.y}; + IsometricMapUnprojectIgnoreCam(corner4.x, corner4.y, &corner4); + + DrawLineV(corner1, corner2, RED); + DrawLineV(corner2, corner3, RED); + DrawLineV(corner3, corner4, RED); + DrawLineV(corner4, corner1, RED); } // returns Tile * -> tile at coordinates x y z=layer diff --git a/IsometricMap/isometricMap.h b/IsometricMap/isometricMap.h index 414b6c6..df4f296 100644 --- a/IsometricMap/isometricMap.h +++ b/IsometricMap/isometricMap.h @@ -42,7 +42,8 @@ Vector2 * IsometricMapCalcOffsetForTileAt(int x, int y, int halfTextureSize, int void IsometricMapProject(IsometricMap *isometricMap, Camera2D *camera, float x, float y, Vector2 *tmp); // Unproject: World Coordinates -> Screen Coordinates writes result in tmp Vector -void IsometricMapUnproject(IsometricMap *isometricMap, Camera2D *camera, int x, int y, Vector2 *tmp); +void IsometricMapUnproject(Camera2D *camera, int x, int y, Vector2 *tmp); +void IsometricMapUnprojectIgnoreCam(int x, int y, Vector2 *tmp); // changes to Texture ID of tile at x y on maplayer layer void IsometricMapChangeTextureIdOfTile(IsometricMap *map, int x, int y, int id); @@ -53,4 +54,6 @@ Tile * IsometricMapGetTileFromWorldCoordinates(IsometricMap *isometricMap, float // Draws Isometric Map and Sprites in between :) void IsometricMapDraw(Game *game); +void IsometricMapDrawRectangle(Vector2 from, Vector2 to, Color color); + #endif diff --git a/README.md b/README.md index 5c347e7..04c19d8 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,20 @@ KI Gegner ist erstmal zu aufwändig, ein wenig Ackern muss man aber immer! [turn off EXIT on ESC Key, for later](https://github.com/raysan5/raylib/issues/520) -[Texturentyp](https://opengameart.org/content/germanic-worker) +#### Gebäudetexturen +##### User ++ https://opengameart.org/users/feudalwars ++ https://opengameart.org/users/bleed +##### einzelne Texturen ++ https://opengameart.org/content/germanic-worker ++ https://opengameart.org/content/6-isometric-buildings ++ https://opengameart.org/content/isometric-medieval-buildings-2 ++ https://opengameart.org/content/2d-isometric-homes-part-1 ++ https://opengameart.org/content/isometric-buildings ++ https://opengameart.org/content/isometric-medieval-buildings ++ https://opengameart.org/content/western-european-castle-isometric-25d ++ https://opengameart.org/content/medieval-building-tiles ++ https://opengameart.org/content/watermill-bleeds-game-art ## TODO diff --git a/Screen/screen.c b/Screen/screen.c index e0e1139..99fe328 100644 --- a/Screen/screen.c +++ b/Screen/screen.c @@ -29,6 +29,11 @@ void ScreenRenderGameScreen(Game *game){ IsometricMapDraw(game); SpriteListDrawAllSprites(game->sprites, game->map, game->camera); + + // Draws rect above selected Tile, no need for changing the texture any more + IsometricMapDrawRectangle((Vector2){game->inputHandler->cursorWorldTile.x * 32, game->inputHandler->cursorWorldTile.y * 32}, + (Vector2){(game->inputHandler->cursorWorldTile.x+1) * 32, (game->inputHandler->cursorWorldTile.y+1) * 32}, RED); + EndMode2D(); // User Input Handling diff --git a/Sprite/sprite.c b/Sprite/sprite.c index 10c2c3f..f19433c 100644 --- a/Sprite/sprite.c +++ b/Sprite/sprite.c @@ -13,10 +13,8 @@ void DrawSpriteToWorld(Sprite *sprite, IsometricMap *map, Camera2D *camera){ Vector2 pos = {sprite->x - sprite->texture->width, sprite->y - sprite->texture->height/2}; - IsometricMapUnproject(map, camera, pos.x, pos.y, &pos); + IsometricMapUnprojectIgnoreCam( pos.x, pos.y, &pos); - pos.x -= camera->target.x; - pos.y -= camera->target.y; DrawTexture(*sprite->texture, pos.x, pos.y, WHITE); } diff --git a/Ui/selectable.c b/Ui/selectable.c index d037abb..aed0711 100644 --- a/Ui/selectable.c +++ b/Ui/selectable.c @@ -99,8 +99,15 @@ void SelectableDrawSelectable(Selectable * selectable){ DrawTexture((*(selectable->backgroundTexture))[selectable->state], selectable->position.x, selectable->position.y, WHITE); } - //DrawTextureEx(selectable->texture[selectable->state], selectable->position, targetWidth / selectable->texture[selectable->state].width, 2, WHITE); - DrawTexture(*selectable->texture, selectable->position.x, selectable->position.y, WHITE); + // ich weiss zwar nicht wieso genau aber das hier skaliert die Texturen richtig + int padding = 19; + Rectangle from = {0, 0 , selectable->texture->width, selectable->texture->height}; + Rectangle to = {selectable->position.x +padding, selectable->position.y + padding, selectable->backgroundTexture[0]->width - 2*padding, selectable->backgroundTexture[0]->height - 2*padding}; + DrawTexturePro(*selectable->texture, from, to, (Vector2){0,0}, 0.0f, WHITE); + if(selectable->state == SELECTABLE_STATE_SELECTED){ + DrawTexture(*selectable->texture, GetMouseX() - selectable->texture->width / 2, GetMouseY() - selectable->texture->height*0.75, (Color){255, 255, 255, 150}); + DrawRectangleLines(GetMouseX() - selectable->texture->width / 2, GetMouseY() - selectable->texture->height*0.75, selectable->texture->width, selectable->texture->height, GREEN); + } if(selectable->showDescription == 1){ DrawText(selectable->description, selectable->position.x, selectable->position.y, selectable->fontSize, WHITE); } diff --git a/Ui/uiContainer.c b/Ui/uiContainer.c index 5877a74..4644ae2 100644 --- a/Ui/uiContainer.c +++ b/Ui/uiContainer.c @@ -69,22 +69,20 @@ static UiContainer * UiContainerInitGameUiContainer(Game *game){ Vector2 position = (Vector2){20, 300}; int showDescription = 1; int hasBackground = 1; - int groupOne = 0; - int groupTwo = 1; int fontSize = 16; int unselectAfterExecute = 1; // creating the ui elements Selectable *selectable1 = SelectableInit(texture1, backgroundTextures, hasBackground , &position, "Building", showDescription, 9/*String len*/, fontSize, SELECTABLE_ID_SPAWN_BUILDING, - groupOne, unselectAfterExecute); + 1/*Group*/, unselectAfterExecute); position.y += 100; Selectable *selectable2 = SelectableInit(texture2, backgroundTextures, hasBackground,&position, "Worker", - showDescription, 7/*String len*/, fontSize, SELECTABLE_ID_SPAWN_WORKER, groupOne, + showDescription, 7/*String len*/, fontSize, SELECTABLE_ID_SPAWN_WORKER, 1/*Group*/, unselectAfterExecute); position.y += 100; Selectable *selectable3 = SelectableInit(texture3, backgroundTextures, hasBackground,&position, "Lumberjack", - showDescription, 11/*String len*/, fontSize, SELECTABLE_ID_SPAWN_LUMBERJACK, groupOne, + showDescription, 11/*String len*/, fontSize, SELECTABLE_ID_SPAWN_LUMBERJACK, 1/*Group*/, unselectAfterExecute); // adding the ui elements diff --git a/assets/grass.png b/assets/grass.png index 86f783e..93903d9 100644 Binary files a/assets/grass.png and b/assets/grass.png differ diff --git a/assets/mapobjects/baustelle/idle.png b/assets/mapobjects/baustelle/idle.png index aed93f2..70d3a8a 100644 Binary files a/assets/mapobjects/baustelle/idle.png and b/assets/mapobjects/baustelle/idle.png differ diff --git a/assets/mapobjects/building/idle.png b/assets/mapobjects/building/idle.png index d214339..57e5a3a 100644 Binary files a/assets/mapobjects/building/idle.png and b/assets/mapobjects/building/idle.png differ diff --git a/definitions.h b/definitions.h index 7bf3aaf..d30074e 100644 --- a/definitions.h +++ b/definitions.h @@ -59,24 +59,23 @@ #define SCREEN_AMOUNT 5 -#define UI_CONTAINER_MAX_BUTTONS 20 -#define UI_CONTAINER_MAX_SELECTABLES 20 - -#define SCREEN_EXIT 0 // Will exit the game using code 0 +#define SCREEN_EXIT 0 // Will exit the game using exit-code 0 #define SCREEN_MAINMENU 1 #define SCREEN_OPTIONS 2 #define SCREEN_GAME 3 #define SCREEN_PAUSE 4 +#define UI_CONTAINER_MAX_BUTTONS 20 +#define UI_CONTAINER_MAX_SELECTABLES 20 + #define BUTTON_STATE_DEFAULT 0 #define BUTTON_STATE_HOVERED 1 #define BUTTON_STATE_PRESSED 2 -#define BUTTON_STATE_RELEASED 3 +#define BUTTON_STATE_RELEASED 3 // Buttons code will be executed when in Released state #define SELECTABLE_STATE_DEFAULT 0 #define SELECTABLE_STATE_HOVERED 1 -#define SELECTABLE_STATE_SELECTED 2 - +#define SELECTABLE_STATE_SELECTED 2 // Selectable code will be executed every frame while in Selected state #define BUTTON_ID_CONTINUE 0 #define BUTTON_ID_EXIT 1