DrawRect for world added, scaling of Textures on selectables, some new textures and links to textures

main
Jan 3 years ago
parent 313f1dba14
commit 666961f6e1

@ -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;
}
}
}

@ -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 --- */

@ -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

@ -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

@ -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

@ -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

@ -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);
}

@ -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);
}

@ -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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.4 KiB

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 14 KiB

@ -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

Loading…
Cancel
Save