JanEhehalt 3 years ago
parent d43ff313f0
commit 86252225c9

@ -66,7 +66,7 @@ void mouseInput(Game *game){
// resetting last selected Tile to grass texture // resetting last selected Tile to grass texture
if(inputHandler->selectedLayer != -1){ if(inputHandler->selectedLayer != -1){
IsometricMapChangeTextureIdOfTile(layers[inputHandler->selectedLayer], (int) inputHandler->cursorWorldTile.x, (int) inputHandler->cursorWorldTile.y, 0); IsometricMapChangeTextureIdOfTile(layers, (int) inputHandler->cursorWorldTile.x, (int) inputHandler->cursorWorldTile.y, inputHandler->selectedLayer, 0);
} }
/* /*
TODO: n=9 no good style, Segmentation fault when n > layerAmount TODO: n=9 no good style, Segmentation fault when n > layerAmount
@ -74,6 +74,7 @@ void mouseInput(Game *game){
-> Stash size in another variable. -> Stash size in another variable.
printf("%ld \n", sizeof(*layers) / sizeof(layers[0])); printf("%ld \n", sizeof(*layers) / sizeof(layers[0]));
*/ */
// hardcoded layer amount
int n = 9; int n = 9;
for(n = 9; n >= 0 ; n--){ for(n = 9; n >= 0 ; n--){
if(layers[n] != 0){ if(layers[n] != 0){
@ -84,14 +85,14 @@ void mouseInput(Game *game){
IsometricMapProject(layers[n], camera, inputHandler->cursorPos.x + mouseAdjustmentX, inputHandler->cursorPos.y + mouseAdjustmentY, &inputHandler->cursorWorldPos); IsometricMapProject(layers[n], camera, inputHandler->cursorPos.x + mouseAdjustmentX, inputHandler->cursorPos.y + mouseAdjustmentY, &inputHandler->cursorWorldPos);
Tile *selectedTile = IsometricMapGetTileFromWorldCoordinates(layers[n], inputHandler->cursorWorldPos.x, inputHandler->cursorWorldPos.y); Tile *selectedTile = IsometricMapGetTileFromWorldCoordinates(layers, inputHandler->cursorWorldPos.x, inputHandler->cursorWorldPos.y, n);
if(selectedTile != 0){ if(selectedTile != 0){
inputHandler->cursorWorldTile.x = selectedTile->x; inputHandler->cursorWorldTile.x = selectedTile->x;
inputHandler->cursorWorldTile.y = selectedTile->y; inputHandler->cursorWorldTile.y = selectedTile->y;
inputHandler->selectedLayer = n; inputHandler->selectedLayer = n;
// setting currently selected tile to tower // setting currently selected tile to tower
IsometricMapChangeTextureIdOfTile(layers[n], inputHandler->cursorWorldTile.x, inputHandler->cursorWorldTile.y, 1); IsometricMapChangeTextureIdOfTile(layers, inputHandler->cursorWorldTile.x, inputHandler->cursorWorldTile.y, n, 1);
break; break;
} }
} }
@ -123,8 +124,8 @@ void mouseInput(Game *game){
// Add Sprite // Add Sprite
if(abs(width) + abs(height) < 20){ if(abs(width) + abs(height) < 20){
int maxWidth = (game->layers[0]->widthBounds-1) * game->layers[0]->textureWidth; int maxWidth = (game->layers[0]->width-1) * game->layers[0]->textureWidth;
int maxHeight = (game->layers[0]->heightBounds-1) * game->layers[0]->textureHeight; int maxHeight = (game->layers[0]->height-1) * game->layers[0]->textureHeight;
if(inputHandler->cursorWorldPos.x < 0){ printf("OutOfBoundsDestination Spawn\n");} if(inputHandler->cursorWorldPos.x < 0){ printf("OutOfBoundsDestination Spawn\n");}
else if(inputHandler->cursorWorldPos.y < 0){ printf("OutOfBoundsDestination Spawn\n");} else if(inputHandler->cursorWorldPos.y < 0){ printf("OutOfBoundsDestination Spawn\n");}
else if(inputHandler->cursorWorldPos.x > maxWidth){ printf("OutOfBoundsDestination Spawn\n");} else if(inputHandler->cursorWorldPos.x > maxWidth){ printf("OutOfBoundsDestination Spawn\n");}
@ -150,8 +151,8 @@ void mouseInput(Game *game){
float deltaY; float deltaY;
Node *current = sprites->head; Node *current = sprites->head;
while (current != 0){ while (current != 0){
Vector2 currPos = {current->data.x, current->data.y}; Vector2 currPos = {current->data.x + current->data.texture->width, current->data.y + current->data.texture->height/2};
IsometricMapUnproject(layers[0], camera, currPos.x, currPos.y, &currPos); IsometricMapUnproject(layers, camera, currPos.x, currPos.y, current->data.z, &currPos);
deltaX = currPos.x - camera->target.x - (rect.x + camera->target.x); deltaX = currPos.x - camera->target.x - (rect.x + camera->target.x);
deltaY = currPos.y - camera->target.y - (rect.y + camera->target.y); deltaY = currPos.y - camera->target.y - (rect.y + camera->target.y);
@ -175,10 +176,10 @@ void mouseInput(Game *game){
while (current != 0){ while (current != 0){
if(current->data.selected){ if(current->data.selected){
current->data.hasDestination = 1; current->data.hasDestination = 1;
float destX = inputHandler->cursorWorldTile.x * game->layers[0]->textureWidth; float destX = inputHandler->cursorWorldPos.x;
float destY = inputHandler->cursorWorldTile.y * game->layers[0]->textureHeight; float destY = inputHandler->cursorWorldPos.y;
int maxWidth = (game->layers[0]->widthBounds-1) * game->layers[0]->textureWidth; int maxWidth = (game->layers[0]->width-1) * game->layers[0]->textureWidth;
int maxHeight = (game->layers[0]->heightBounds-1) * game->layers[0]->textureHeight; int maxHeight = (game->layers[0]->height-1) * game->layers[0]->textureHeight;
if(destX < 0){ printf("OutOfBoundsDestination"); continue; } if(destX < 0){ printf("OutOfBoundsDestination"); continue; }
if(destY < 0){ printf("OutOfBoundsDestination"); continue; } if(destY < 0){ printf("OutOfBoundsDestination"); continue; }
if(destX > maxWidth){ printf("OutOfBoundsDestination"); continue; } if(destX > maxWidth){ printf("OutOfBoundsDestination"); continue; }

@ -15,28 +15,28 @@ IsometricMap * IsometricMapInit(int layer){
//map->tileTextures[0] = LoadTexture("assets/desert.png"); //map->tileTextures[0] = LoadTexture("assets/desert.png");
//map->tileTextures[1] = LoadTexture("assets/bigtower.png"); //map->tileTextures[1] = LoadTexture("assets/bigtower.png");
map->originX = 0; map->width = 100;
map->originY = -layer * map->tileTextures[0].width / 4; map->height = 100;
map->width = 100 * map->tileTextures[0].width;
map->height = 100 * map->tileTextures[0].height;
map->widthBounds = 100;
map->heightBounds = 100;
map->layer = layer;
map->textureWidth = map->tileTextures[0].width; map->textureWidth = map->tileTextures[0].width;
map->textureHeight = map->tileTextures[0].height; map->textureHeight = map->tileTextures[0].height;
map->worldPixelWidth = map->width * map->textureWidth;
map->worldPixelWidth = map->height * map->textureHeight;
map->layer = layer;
Tile*** tiles = (Tile***)malloc(map->widthBounds*sizeof(Tile*)); // mallocating the twodimensional Tiles Array
Tile*** tiles = (Tile***)malloc(map->width*sizeof(Tile*));
int n = 0; int n = 0;
for(n=0; n < map->widthBounds; n++){ for(n=0; n < map->width; n++){
tiles[n] = (Tile**)malloc(map->heightBounds*sizeof(Tile*)); tiles[n] = (Tile**)malloc(map->height*sizeof(Tile*));
} }
int i = 0; int i = 0;
int j = 0; int j = 0;
for(i=0; i < map->widthBounds; i++){ for(i=0; i < map->width; i++){
for(j=0; j < map->heightBounds; j++){ for(j=0; j < map->height; j++){
Tile *tmp = (Tile *) malloc(sizeof(Tile)); Tile *tmp = (Tile *) malloc(sizeof(Tile));
// initially all the Tiles are "empty"
tmp->textureId = -1; tmp->textureId = -1;
tmp->x = i; tmp->x = i;
tmp->y = j; tmp->y = j;
@ -50,6 +50,7 @@ IsometricMap * IsometricMapInit(int layer){
return map; return map;
} }
// Only works for tiles with texture width == height (and for 22.5 degree?)
Vector2 * IsometricMapCalcOffsetForTileAt(int x, int y, int textureSize){ Vector2 * IsometricMapCalcOffsetForTileAt(int x, int y, int textureSize){
Vector2* offset = (Vector2 *)malloc(sizeof(Vector2)); Vector2* offset = (Vector2 *)malloc(sizeof(Vector2));
offset->x = x * textureSize/2 - y * textureSize/2; offset->x = x * textureSize/2 - y * textureSize/2;
@ -61,11 +62,10 @@ Tile * IsometricMapGetTileFromArrayPosition(IsometricMap *map, int x, int y){
return map->tiles[x][y]; return map->tiles[x][y];
} }
// Project: Screen Coordinates -> World Coordinates
void IsometricMapProject(IsometricMap *isometricMap, Camera2D *camera, float x, float y, Vector2 *tmp){ void IsometricMapProject(IsometricMap *isometricMap, Camera2D *camera, float x, float y, Vector2 *tmp){
float tileWidthHalf = isometricMap->tileTextures[0].width / 2; float tileWidthHalf = isometricMap->textureWidth / 2;
float tileHeightQuarter = isometricMap->tileTextures[0].height / 4; float tileHeightQuarter = isometricMap->textureHeight / 4;
x += camera->target.x; x += camera->target.x;
y += camera->target.y; y += camera->target.y;
@ -73,7 +73,6 @@ void IsometricMapProject(IsometricMap *isometricMap, Camera2D *camera, float x,
float xPos = (float) x; float xPos = (float) x;
float yPos = (float) y; float yPos = (float) y;
float isoX = 0.5 * ( xPos / tileWidthHalf + yPos / tileHeightQuarter); float isoX = 0.5 * ( xPos / tileWidthHalf + yPos / tileHeightQuarter);
float isoY = 0.5 * ( -xPos / tileWidthHalf + yPos / tileHeightQuarter); float isoY = 0.5 * ( -xPos / tileWidthHalf + yPos / tileHeightQuarter);
@ -81,47 +80,47 @@ void IsometricMapProject(IsometricMap *isometricMap, Camera2D *camera, float x,
tmp->y = isoY * isometricMap->tileTextures[0].height; tmp->y = isoY * isometricMap->tileTextures[0].height;
} }
// Unproject: World Coordinates -> Screen Coordinates // Unproject: World Coordinates -> Screen Coordinates writes result in tmp Vector
void IsometricMapUnproject(IsometricMap *isometricMap, Camera2D *camera, int x, int y, Vector2 *tmp){ void IsometricMapUnproject(IsometricMap **isometricMap, Camera2D *camera, int x, int y, float z, Vector2 *tmp){
float xPos = (float) x; float xPos = (float) x;
float yPos = (float) y; float yPos = (float) y;
float worldX = (xPos - yPos) / 2; float screenX = (xPos - yPos) / 2;
float worldY = (xPos + yPos) / 4; float screenY = (xPos + yPos) / 4;
screenX += camera->target.x;
screenY += camera->target.y;
worldX += camera->target.x; // z is currently implemented as z=1 equals 1 layer, z=2 would be two layers height (could be smoothed)
worldY += camera->target.y; // TODO drift
screenY -= z *(isometricMap[0]->textureHeight/2);
tmp->x = worldX; tmp->x = screenX;
tmp->y = worldY; tmp->y = screenY;
} }
Tile * IsometricMapGetTileFromWorldCoordinates(IsometricMap *isometricMap, float x, float y){ Tile * IsometricMapGetTileFromWorldCoordinates(IsometricMap **isometricMap, float x, float y, float z){
x = (int)(x / isometricMap->tileTextures->width); int layer = (int) z;
y = (int)(y / isometricMap->tileTextures->height);
Tile *ptr = (Tile *) malloc(sizeof(Tile *));
ptr->x = 0;
ptr->y = 0;
if( x < isometricMap->widthBounds && y < isometricMap->heightBounds && x = (int)(x / isometricMap[layer]->textureWidth);
x >= 0 && y >= 0 ){ y = (int)(y / isometricMap[layer]->textureHeight);
if(isometricMap->tiles[(int)x][(int)y]->textureId != -1){
ptr->x = isometricMap->tiles[(int)x][(int)y]->x; if( x < isometricMap[layer]->width && y < isometricMap[layer]->height && x >= 0 && y >= 0 ){
ptr->y = isometricMap->tiles[(int)x][(int)y]->y; if(isometricMap[layer]->tiles[(int)x][(int)y]->textureId != -1){
return ptr; return (isometricMap[layer]->tiles[(int)x][(int)y]);
} }
} }
ptr = 0; Tile *ptr = 0;
return ptr; return ptr;
} }
Tile * IsometricMapGetMostUpperTile(IsometricMap **isometricMap, Tile *tile){ Tile * IsometricMapGetMostUpperTile(IsometricMap **isometricMap, Tile *tile){
Tile *ptr = (Tile *) malloc(sizeof(Tile *)); Tile *ptr = (Tile *) malloc(sizeof(Tile *));
// hardcoded layer amount
int n = 9; int n = 9;
for(n=9;n>=0;n--){ for(n=9;n>=0;n--){
if( tile->x < isometricMap[n]->widthBounds && tile->y < isometricMap[n]->heightBounds && if( tile->x < isometricMap[n]->width && tile->y < isometricMap[n]->height &&
tile->x >= 0 && tile->y >= 0 ){ tile->x >= 0 && tile->y >= 0 ){
if(isometricMap[n]->tiles[tile->x][tile->y]->textureId != -1){ if(isometricMap[n]->tiles[tile->x][tile->y]->textureId != -1){
ptr->x = isometricMap[n]->tiles[tile->x][tile->y]->x; ptr->x = isometricMap[n]->tiles[tile->x][tile->y]->x;
@ -135,17 +134,13 @@ Tile * IsometricMapGetMostUpperTile(IsometricMap **isometricMap, Tile *tile){
return ptr; return ptr;
} }
// IsometricMapAddTile and IsometricMapChangeTextureIdOfTile pretty much do the same by now... void IsometricMapChangeTextureIdOfTile(IsometricMap **map, int x, int y, int layer, int id){
void IsometricMapAddTile(IsometricMap *isometricMap, int x, int y, int textureId){ if( x < map[layer]->width && y < map[layer]->height &&
isometricMap->tiles[x][y]->textureId = textureId;
isometricMap->tiles[x][y]->x = x;
isometricMap->tiles[x][y]->y = y;
isometricMap->tiles[x][y]->z = isometricMap->layer;
}
void IsometricMapChangeTextureIdOfTile(IsometricMap *map, int x, int y, int id){
if( x < map->widthBounds && y < map->heightBounds &&
x >= 0 && y >= 0 ){ x >= 0 && y >= 0 ){
(map->tiles[x][y])->textureId = id; (map[layer]->tiles[x][y])->textureId = id;
} }
else{
printf("WARNING: trying to change Texture of Tile which is out of bounds!\n");
}
} }

@ -4,31 +4,55 @@
#include "tile.c" #include "tile.c"
typedef struct IsometricMap{ typedef struct IsometricMap{
// Array with all the needed textures for this layer
Texture2D tileTextures[10]; Texture2D tileTextures[10];
// twodimensional array of all the tiles in this layer
Tile ***tiles; Tile ***tiles;
int originX;
int originY; // amount of tiles in x-direction
// TODO: überprüfen, ob width/height und widthBounds/heightBounds überhaupt noch unterschiedlich sind. Wenn nicht eins der beiden löschen
int width; int width;
// amount of tiles in y-direction
int height; int height;
int widthBounds;
int heightBounds; // pixel width of a single tile texture
int textureWidth; int textureWidth;
// pixel height of a single tile texture
int textureHeight; int textureHeight;
// pixel width of the entire map
int worldPixelWidth;
// pixel height of the entire map
int worldPixelHeight;
// layer of the map
int layer; int layer;
} IsometricMap; } IsometricMap;
// returns pointer to IsometricMap Instance
IsometricMap * IsometricMapInit(int layer); IsometricMap * IsometricMapInit(int layer);
// For Rendering: calculates
Vector2 * IsometricMapCalcOffsetForTileAt(int x, int y, int textureSize); Vector2 * IsometricMapCalcOffsetForTileAt(int x, int y, int textureSize);
Tile * IsometricMapGetMostUpperTile(IsometricMap **isometricMap, Tile *tile); Tile * IsometricMapGetMostUpperTile(IsometricMap **isometricMap, Tile *tile);
Tile * IsometricMapGetTileFromArrayPosition(IsometricMap *isometricMap, int x, int y); Tile * IsometricMapGetTileFromArrayPosition(IsometricMap *isometricMap, int x, int y);
// Project: Screen Coordinates -> World Coordinates
// Project: Screen Coordinates -> World Coordinates writes result in tmp Vector
// Currently only calcing coords on layer 0
void IsometricMapProject(IsometricMap *isometricMap, Camera2D *camera, float x, float y, Vector2 *tmp); void IsometricMapProject(IsometricMap *isometricMap, Camera2D *camera, float x, float y, Vector2 *tmp);
// Unproject: World Coordinates -> Screen Coordinates
void IsometricMapUnproject(IsometricMap *isometricMap, Camera2D *camera, int x, int y, Vector2 *tmp); // Unproject: World Coordinates -> Screen Coordinates writes result in tmp Vector
void IsometricMapAddTile(IsometricMap *isometricMap, int x, int y, int textureId); void IsometricMapUnproject(IsometricMap **isometricMap, Camera2D *camera, int x, int y, float z, Vector2 *tmp);
void IsometricMapChangeTextureIdOfTile(IsometricMap *map, int x, int y, int id);
Tile * IsometricMapGetTileFromWorldCoordinates(IsometricMap *isometricMap, float x, float y); // changes to Texture ID of tile at x y on maplayer layer
void IsometricMapChangeTextureIdOfTile(IsometricMap **map, int x, int y, int layer, int id);
Tile * IsometricMapGetTileFromWorldCoordinates(IsometricMap **isometricMap, float x, float y, float layer);
#endif #endif

@ -4,6 +4,7 @@
#include "../Input/inputHandler.h" #include "../Input/inputHandler.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "../game.h"
// @param deprecated // @param deprecated
void IsometricRendererDrawMap(IsometricRenderer *renderer, int height){ void IsometricRendererDrawMap(IsometricRenderer *renderer, int height){
@ -38,23 +39,20 @@ void IsometricRendererDrawMap(IsometricRenderer *renderer, int height){
} }
} }
void IsometricRendererRenderIsometricMap(IsometricMap **map, InputHandler *input){ void IsometricRendererRenderIsometricMap(Game *game){
int n = 0; int n = 0;
int i = 0; int i = 0;
int j = 0; int j = 0;
for(n = 0; n < 10; n++){ for(n = 0; n < 10; n++){
for(i=0; i < map[n]->widthBounds; i++){ for(i=0; i < game->layers[n]->width; i++){
for(j=0; j < map[n]->heightBounds; j++){ for(j=0; j < game->layers[n]->height; j++){
if(map[n]->tiles[i][j]->textureId != -1){ if(game->layers[n]->tiles[i][j]->textureId != -1){
Vector2 *offset = IsometricMapCalcOffsetForTileAt(i,j, map[n]->textureWidth); Vector2 *offset = IsometricMapCalcOffsetForTileAt(i,j, game->layers[n]->textureWidth);
offset->y -= n * (game->layers[n]->textureHeight/4);
int textureId = game->layers[n]->tiles[i][j]->textureId;
int textureId = map[n]->tiles[i][j]->textureId; DrawTexture(game->layers[n]->tileTextures[textureId], offset->x, offset->y, WHITE);
float x = map[n]->originX + offset->x;
float y = map[n]->originY + offset->y;// + map[n]->textureHeight - map[n]->tileTextures[textureId].height;
DrawTexture(map[n]->tileTextures[textureId], x, y, WHITE);
free(offset); free(offset);
} }
} }

@ -3,6 +3,7 @@
#include "raylib.h" #include "raylib.h"
#include "isometricMap.h" #include "isometricMap.h"
#include "../Input/inputHandler.h" #include "../Input/inputHandler.h"
#include "../game.h"
typedef struct IsometricRenderer{ typedef struct IsometricRenderer{
Texture *texture; Texture *texture;
@ -11,6 +12,6 @@ typedef struct IsometricRenderer{
// @param deprecated // @param deprecated
void IsometricRendererDrawMap(IsometricRenderer *renderer, int height); void IsometricRendererDrawMap(IsometricRenderer *renderer, int height);
void IsometricRendererRenderIsometricMap(IsometricMap **map, InputHandler *input); void IsometricRendererRenderIsometricMap(Game *game);
#endif #endif

@ -115,9 +115,9 @@ void ListActAllSprites(Game *game){
} }
// updating z-position // updating z-position
Tile *floorTile = IsometricMapGetTileFromWorldCoordinates(game->layers[0], current->data.x, current->data.y); Tile *floorTile = IsometricMapGetTileFromWorldCoordinates(game->layers, current->data.x, current->data.y, 0);
floorTile = IsometricMapGetMostUpperTile(game->layers, floorTile); Tile *topTile = IsometricMapGetMostUpperTile(game->layers, floorTile);
current->data.z = floorTile->z; current->data.z = topTile->z;
current = current->next; current = current->next;
} }

@ -26,6 +26,8 @@ Fantasy Welt oder Realistisch?
+ Parser für Map-Dateien + Parser für Map-Dateien
+ MapEditor + MapEditor
+ IsometricMap variablen auf Duplikate prüfen + IsometricMap variablen auf Duplikate prüfen
+ IsometricMap struct erstellen, das den IsometricMap(+Layer) Array speichert
+ Sprites drift too high when going up mountain
### WiP ### WiP

@ -78,32 +78,32 @@ Game *GameInit()
switch (n) switch (n)
{ {
case 0: case 0:
IsometricMapAddTile(((game->layers))[n], i, j, 0); IsometricMapChangeTextureIdOfTile(game->layers, i, j, n, 0);
break; break;
case 1: case 1:
if (i > 35 && i < 50 && j > 45 && j < 60) if (i > 35 && i < 50 && j > 45 && j < 60)
{ {
IsometricMapAddTile(((game->layers))[n], i, j, 0); IsometricMapChangeTextureIdOfTile(game->layers, i, j, n, 0);
} }
break; break;
case 2: case 2:
if (i > 40 && i < 44 && j > 50 && j < 54) if (i > 40 && i < 44 && j > 50 && j < 54)
{ {
IsometricMapAddTile(((game->layers))[n], i, j, 2); IsometricMapChangeTextureIdOfTile(game->layers, i, j, n, 2);
} }
break; break;
} }
if(i == j && n == 1){ if(i == j && n == 1){
IsometricMapAddTile(((game->layers))[n], i, j, 0); IsometricMapChangeTextureIdOfTile(game->layers, i, j, n, 0);
} }
if(i == j && n == 2){ if(i == j && n == 2){
IsometricMapAddTile(((game->layers))[n], i, j, 0); IsometricMapChangeTextureIdOfTile(game->layers, i, j, n, 0);
} }
if(i == j-1 && n == 1){ if(i == j-1 && n == 1){
IsometricMapAddTile(((game->layers))[n], i, j, 0); IsometricMapChangeTextureIdOfTile(game->layers, i, j, n, 0);
} }
if(i-1 == j && n == 1){ if(i-1 == j && n == 1){
IsometricMapAddTile(((game->layers))[n], i, j, 0); IsometricMapChangeTextureIdOfTile(game->layers, i, j, n, 0);
} }
} }
} }
@ -115,11 +115,7 @@ Game *GameInit()
{ {
for (j = 0; j < 20 - n * 2; j++) for (j = 0; j < 20 - n * 2; j++)
{ {
IsometricMapAddTile(((game->layers))[n], i, j, 0); IsometricMapChangeTextureIdOfTile(game->layers, i, j, n, 0);
if (n == 9)
{
IsometricMapAddTile(((game->layers))[n], i, j, 2);
}
} }
} }
} }

@ -3,7 +3,6 @@
#include "raylib.h" #include "raylib.h"
// So kann man die includes umgehen, also keine Circular dependencies mehr :)
typedef struct Game{ typedef struct Game{
Texture2D cursorTextures[2]; Texture2D cursorTextures[2];
Texture2D worker[8]; Texture2D worker[8];

BIN
game.o

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
list.o

Binary file not shown.

@ -29,10 +29,11 @@ int main(){
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
BeginDrawing(); BeginDrawing();
//printf("ALARM\n");
BeginMode2D(*(game->camera)); BeginMode2D(*(game->camera));
IsometricRendererRenderIsometricMap(game->layers, game->inputHandler); IsometricRendererRenderIsometricMap(game);
ListDrawAllSprites(game->sprites, game->layers, game->camera); ListDrawAllSprites(game->sprites, game->layers, game->camera);
EndMode2D(); EndMode2D();

BIN
main.o

Binary file not shown.

BIN
spiel

Binary file not shown.

@ -28,20 +28,18 @@ void DrawSpriteToWorld(Sprite *sprite, IsometricMap **map, Camera2D *camera){
// Wir müssen beachten, dass sie nach den unprojezierten Screen-Koordinaten sortiert werden müssen. // Wir müssen beachten, dass sie nach den unprojezierten Screen-Koordinaten sortiert werden müssen.
// Macht es vielleicht sinn den Sprites auch einen Vector mit ihren Screen Koordinaten zu geben? // Macht es vielleicht sinn den Sprites auch einen Vector mit ihren Screen Koordinaten zu geben?
Vector2 pos = {sprite->x, sprite->y}; Vector2 pos = {sprite->x - sprite->texture->width, sprite->y - sprite->texture->height/2};
IsometricMapUnproject(map[0], camera, pos.x, pos.y, &pos); IsometricMapUnproject(map, camera, pos.x, pos.y, sprite->z, &pos);
// Also erst ab hier sortieren, mit den Werten aus dem pos Vector // Also erst ab hier sortieren, mit den Werten aus dem pos Vector
// nvm, Isometric map muss mit reingerechnet werden
pos.y -= sprite->z * (map[0]->textureHeight/2);
pos.x -= camera->target.x; pos.x -= camera->target.x;
pos.y -= camera->target.y; pos.y -= camera->target.y;
if(sprite->selected){ if(sprite->selected){
DrawTexture(*sprite->texture, pos.x - sprite->texture->width/4, pos.y - sprite->texture->height/4, BLACK); DrawTexture(*sprite->texture, pos.x, pos.y, BLACK);
//DrawTexture(*sprite->texture, sprite->x, sprite->y, BLACK); //DrawTexture(*sprite->texture, sprite->x, sprite->y, BLACK);
} }
else{ else{
DrawTexture(*sprite->texture, pos.x - sprite->texture->width/4, pos.y - sprite->texture->height/4, WHITE); DrawTexture(*sprite->texture, pos.x, pos.y, WHITE);
} }
//printf("%f %f \n", sprite->x, sprite->y); //printf("%f %f \n", sprite->x, sprite->y);
} }

Binary file not shown.

BIN
tile.o

Binary file not shown.
Loading…
Cancel
Save