Erfolgreich aufgeräumt

main
Jonathan Hager 3 years ago
parent 523df09ab8
commit 2b3a7e33a3
Signed by: JonathanHager
GPG Key ID: 34881E488569708C

@ -7,6 +7,8 @@
"isometricmap.h": "c",
"animationhandler.h": "c",
"textureids.h": "c",
"tile.h": "c"
"tile.h": "c",
"raylib.h": "c",
"game.h": "c"
}
}

@ -6,7 +6,7 @@
Bucket * BucketInit(Sprite *sprite, Tile *tile){
Bucket *bucket = (Bucket *) malloc(sizeof(Bucket));
Bucket *bucket = malloc(sizeof(Bucket));
if(sprite != 0){
bucket->type = 0;
bucket->sprite = sprite;

@ -2,55 +2,6 @@
#include "stdlib.h"
#include "stdio.h"
/*
void MergeSort(Bucket *liste[], int groesse){
if(groesse > 1){
Bucket *haelfte1[groesse/2];
Bucket *haelfte2[(groesse + 1)/2];
int i;
for(i = 0; i < groesse/2; ++i)
haelfte1[i] = liste[i];
for(i = groesse/2; i < groesse; ++i)
haelfte2[i - groesse/2] = liste[i];
MergeSort(haelfte1,groesse/2);
MergeSort(haelfte2,(groesse + 1)/2);
Bucket **pos1 = haelfte1;
Bucket **pos2 = haelfte2;
for(i = 0; i < groesse; ++i){
if((*pos1)->depth <= (*pos2)->depth){
liste[i] = *pos1;
if (pos1 != &haelfte2[(groesse+1)/2 - 1]) { // pos1 nicht verändern, wenn der größte Wert mehrmals vorkommt
if(pos1 == &haelfte1[groesse/2 - 1]){
pos1 = &haelfte2[(groesse+1)/2 - 1];
}
else{
++pos1;
}
}
}
else{
liste[i] = *pos2;
if(pos2 == &haelfte2[(groesse + 1)/2 - 1]){
pos2 = &haelfte1[groesse/2 - 1];
}
else{
++pos2;
}
}
}
}
int k = 0;
for(k = 0; k < groesse; k++){
printf("%f\n", liste[k]->depth);
}
//exit(0);
}
*/
void MergeSort(Bucket *liste[], int groesse){
}

@ -10,24 +10,10 @@
#include "../game.h"
void DrawRect(Vector2 rectStart, Vector2 *mousePosition){
float width = GetMousePosition().x - rectStart.x;
float height = GetMousePosition().y - rectStart.y;
if(width < 0 && height >= 0){
width *= -1;
rectStart.x -= width;
}
else if(height < 0 && width >= 0){
height *= -1;
rectStart.y -= height;
}
else if(height < 0 && width < 0){
height *= -1;
width *= -1;
rectStart.x -= width;
rectStart.y -= height;
}
rectStart = GetRectangle(rectStart);
DrawRectangleLines(rectStart.x, rectStart.y, width, height, GREEN);
}
@ -68,12 +54,7 @@ void mouseInput(Game *game){
if(inputHandler->selectedLayer != -1){
IsometricMapChangeTextureIdOfTile(layers, (int) inputHandler->cursorWorldTile.x, (int) inputHandler->cursorWorldTile.y, inputHandler->selectedLayer, 0);
}
/*
TODO: n=9 no good style, Segmentation fault when n > layerAmount
impossible to find out size of array on the fly?
-> Stash size in another variable.
printf("%ld \n", sizeof(*layers) / sizeof(layers[0]));
*/
// hardcoded layer amount
int n = 9;
for(n = 9; n >= 0 ; n--){
@ -85,7 +66,7 @@ void mouseInput(Game *game){
IsometricMapProject(layers[n], camera, inputHandler->cursorPos.x + mouseAdjustmentX, inputHandler->cursorPos.y + mouseAdjustmentY, &inputHandler->cursorWorldPos);
Tile *selectedTile = IsometricMapGetTileFromWorldCoordinates(layers, inputHandler->cursorWorldPos.x, inputHandler->cursorWorldPos.y, n);
/*N I C E*/ Tile *selectedTile = IsometricMapGetTileFromWorldCoordinates(layers, inputHandler->cursorWorldPos.x, inputHandler->cursorWorldPos.y, n);
if(selectedTile != 0){
inputHandler->cursorWorldTile.x = selectedTile->x;
@ -135,31 +116,31 @@ void mouseInput(Game *game){
ListInsertBack(sprites, SpriteCreate(game->textures, 1, inputHandler->cursorWorldPos.x, inputHandler->cursorWorldPos.y));
//ListInsertSorted(sprites, SpriteCreate(game->textures, 1, inputHandler->cursorWorldPos.x, inputHandler->cursorWorldPos.y));
}
}
// Berechnung, welche Sprites ausgewählt wurden
Vector2 rect = GetRectangle(inputHandler->rectStart);
width = abs(width);
height = abs(height);
float deltaX;
float deltaY;
Node *current = sprites->head;
while (current != 0){
Vector2 currPos = {current->data->x + current->data->texture->width, current->data->y + current->data->texture->height/2};
IsometricMapUnproject(layers, camera, currPos.x, currPos.y, current->data->z, &currPos);
deltaX = currPos.x - camera->target.x - (rect.x + camera->target.x);
deltaY = currPos.y - camera->target.y - (rect.y + camera->target.y);
if(deltaX > 0 && deltaX < width && deltaY > 0 && deltaY < height){
current->data->selected = 1;
}
else{
current->data->selected = 0;
} else{
// Berechnung, welche Sprites ausgewählt wurden
Vector2 rect = GetRectangle(inputHandler->rectStart);
width = abs(width);
height = abs(height);
float deltaX;
float deltaY;
Node *current = sprites->head;
while (current != 0){
Vector2 currPos = {current->data->x + current->data->texture->width, current->data->y + current->data->texture->height/2};
IsometricMapUnproject(layers, camera, currPos.x, currPos.y, current->data->z, &currPos);
deltaX = currPos.x - camera->target.x - (rect.x + camera->target.x);
deltaY = currPos.y - camera->target.y - (rect.y + camera->target.y);
if(deltaX > 0 && deltaX < width && deltaY > 0 && deltaY < height){
current->data->selected = 1;
}
else{
current->data->selected = 0;
}
current = current->next;
}
current = current->next;
}
}

@ -23,4 +23,6 @@ void keyboardInput(InputHandler *inputHandler, Camera2D *camera);
void DrawRect(Vector2 rectStart, Vector2 *mousePosition);
Vector2 GetRectangle(Vector2 rectStart);
#endif

@ -11,15 +11,12 @@
// returns pointer to IsometricMap Instance
IsometricMap * IsometricMapInit(int layer){
IsometricMap* map = (IsometricMap *) malloc(sizeof(IsometricMap));
IsometricMap* map = malloc(sizeof(IsometricMap));
map->tileTextures[0] = LoadTexture("assets/grass.png");
map->tileTextures[1] = LoadTexture("assets/grass_selected.png");
map->tileTextures[2] = LoadTexture("assets/tower.png");
//map->tileTextures[0] = LoadTexture("assets/desert.png");
//map->tileTextures[1] = LoadTexture("assets/bigtower.png");
map->width = 500;
map->height = 500;
map->textureWidth = map->tileTextures[0].width;
@ -30,10 +27,10 @@ IsometricMap * IsometricMapInit(int layer){
// mallocating the twodimensional Tiles Array
Tile*** tiles = (Tile***)malloc(map->width*sizeof(Tile*));
Tile*** tiles = malloc(map->width*sizeof(Tile*));
int n = 0;
for(n=0; n < map->width; n++){
tiles[n] = (Tile**)malloc(map->height*sizeof(Tile*));
tiles[n] = malloc(map->height*sizeof(Tile*));
}
int i = 0;
@ -42,14 +39,14 @@ IsometricMap * IsometricMapInit(int layer){
int halfTextureSize = map->textureWidth / 2;
for(i=0; i < map->width; i++){
for(j=0; j < map->height; j++){
Tile *tmp = (Tile *) malloc(sizeof(Tile));
Tile *tmp = malloc(sizeof(Tile));
// initially all the Tiles are "empty"
tmp->textureId = -1;
tmp->x = i;
tmp->y = j;
tmp->z = layer;
Vector2 *offset = IsometricMapCalcOffsetForTileAtEfficient(i,j, halfTextureSize, quarterTextureSize);
Vector2 *offset = IsometricMapCalcOffsetForTileAt(i,j, halfTextureSize, quarterTextureSize);
// the higher the layer the higher it needs to be drawed
offset->y -= layer * quarterTextureSize;
tmp->offsetX = offset->x;
@ -67,25 +64,13 @@ IsometricMap * IsometricMapInit(int layer){
// For Rendering: calculates coordinate offset for a single tile at arrayPosition x y
// Only works for tiles with texture width == height (and for 22.5 degree?)
Vector2 * IsometricMapCalcOffsetForTileAt(int x, int y, int textureSize){
Vector2* offset = (Vector2 *)malloc(sizeof(Vector2));
offset->x = x * textureSize/2 - y * textureSize/2;
offset->y = x * textureSize/4 + y * textureSize/4;
return offset;
}
Vector2 * IsometricMapCalcOffsetForTileAtEfficient(int x, int y, int halfTextureSize, int quarterTextureSize){
Vector2* offset = (Vector2 *)malloc(sizeof(Vector2));
Vector2 * IsometricMapCalcOffsetForTileAt(int x, int y, int halfTextureSize, int quarterTextureSize){
Vector2* offset = malloc(sizeof(Vector2));
offset->x = x * halfTextureSize - y * halfTextureSize;
offset->y = x * quarterTextureSize + y * quarterTextureSize;
return offset;
}
// returns Tile at x y on layer isometricMap
Tile * IsometricMapGetTileFromArrayPosition(IsometricMap *map, int x, int y){
return map->tiles[x][y];
}
// Unproject: World Coordinates -> Screen Coordinates writes result in tmp Vector
void IsometricMapProject(IsometricMap *isometricMap, Camera2D *camera, float x, float y, Vector2 *tmp){
@ -145,6 +130,7 @@ Tile * IsometricMapGetTileFromWorldCoordinates(IsometricMap **isometricMap, floa
Tile * IsometricMapGetMostUpperTile(IsometricMap **isometricMap, Tile *tile){
//Tile *ptr = (Tile *) malloc(sizeof(Tile *));
// hardcoded layer amount
int n = 9;
for(n=9;n>=0;n--){
if( tile->x < isometricMap[n]->width && tile->y < isometricMap[n]->height &&
@ -233,26 +219,18 @@ void IsometricMapDraw(Game *game){
// Merge Sort ist scuffed
MergeSort(buckets, hmmm);
//printf("HÄÄÄÄÄÄ\n");
int k = 0;
for(k = 0; k < counter; k++){
if(buckets[k]->type == 1){
//printf("Tile begin -");
//printf("Tile %f\n", buckets[k]->depth);
DrawTexture(
game->layers[0]->tileTextures[buckets[k]->tile->textureId],
buckets[k]->tile->offsetX,
buckets[k]->tile->offsetY,
WHITE);
//printf("- Tile end \n");
}
else if(buckets[k]->type == 0){
//printf("Sprite %f\n", buckets[k]->depth);
DrawSpriteToWorld(buckets[k]->sprite, game->layers, game->camera);
//printf("- Sprite end \n");
}
}
//printf("\n\n");
}

@ -1,7 +1,7 @@
#ifndef ISOMETRICMAP_H_
#define ISOMETRICMAP_H_
#include "raylib.h"
#include "tile.c"
#include "tile.h"
#include "../game.h"
typedef struct IsometricMap{
@ -38,16 +38,11 @@ IsometricMap * IsometricMapInit(int layer);
// For Rendering: calculates coordinate offset for a single tile at arrayPosition x y
// Only works for tiles with texture width == height (and for 22.5 degree?)
Vector2 * IsometricMapCalcOffsetForTileAt(int x, int y, int textureSize);
// saves many divisions
Vector2 * IsometricMapCalcOffsetForTileAtEfficient(int x, int y, int halfTextureSize, int quarterTextureSize);
Vector2 * IsometricMapCalcOffsetForTileAt(int x, int y, int halfTextureSize, int quarterTextureSize);
// Gives the most upper Tile above *tile
Tile * IsometricMapGetMostUpperTile(IsometricMap **isometricMap, Tile *tile);
// returns Tile at x y on layer isometricMap
Tile * IsometricMapGetTileFromArrayPosition(IsometricMap *isometricMap, int x, int y);
// 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);

@ -1,116 +0,0 @@
#include "isometricRenderer.h"
#include "raylib.h"
#include "isometricMap.h"
#include "../Input/inputHandler.h"
#include <stdio.h>
#include <stdlib.h>
#include "../game.h"
#include "../List/list.h"
// @param deprecated
void IsometricRendererDrawMap(IsometricRenderer *renderer, int height)
{
printf("WARNING: Using deprecated Function IsometricRendererDrawMap!\n");
float originX = 0.0f;
float originY = 0.0f;
int i = 0;
int j = 0;
int amount = 1;
for (i = 0; i <= height; i++)
{
for (j = 0; j < amount; j++)
{
float x = originX - amount / 2 * renderer->texture->width + j * renderer->texture->width;
if (amount % 2 == 1)
{
x -= renderer->texture->width / 2;
}
float y = i * renderer->texture->height / 4;
DrawTexture(*renderer->texture, x, y, WHITE);
}
if (i < height / 2)
{
amount++;
}
else
{
amount--;
}
}
}
// parameter could be changed to only IsometricMap[]
void IsometricRendererRenderIsometricMap(Game *game){
int windowWidth = GetScreenWidth();
int windowHeight = GetScreenHeight();
// HARDCODED
Vector2 topleft = {0, 0};
IsometricMapProject(game->layers[0], game->camera, topleft.x, topleft.y, &topleft);
Vector2 topright = {windowWidth, 0};
IsometricMapProject(game->layers[0], game->camera, topright.x, topright.y, &topright);
Vector2 botleft = {0, windowHeight};
IsometricMapProject(game->layers[0], game->camera, botleft.x, botleft.y, &botleft);
Vector2 botright = {windowWidth, windowHeight};
IsometricMapProject(game->layers[0], game->camera, botright.x, botright.y, &botright);
// drawing some extra corner tiles
// if extraTiles == 0 you can see flickering in the corners
int extraTiles = 1;
int n = 0;
int itmp = (int)(topleft.x / game->layers[0]->textureWidth) - extraTiles;
int jtmp = (int)(topright.y / game->layers[0]->textureHeight) - extraTiles;
int maxI = (int)(botright.x / game->layers[0]->textureWidth) + extraTiles;
int maxJ = (int)(botleft.y / game->layers[0]->textureHeight) + extraTiles;
if (itmp < 0)
{
itmp = 0;
}
if (jtmp < 0)
{
jtmp = 0;
}
if (maxI > game->layers[0]->width)
{
maxI = game->layers[0]->width;
}
if (maxJ > game->layers[0]->height)
{
maxJ = game->layers[0]->height;
}
int i = 0; // x
int j = 0; // y
for (n = 0; n < 10; n++){
for (j = jtmp; j < maxJ; j++){
for (i = itmp; i < maxI; i++){
if (game->layers[n]->tiles[i][j]->textureId == -1){
}
else{
DrawTexture(
game->layers[n]->tileTextures[game->layers[n]->tiles[i][j]->textureId],
game->layers[n]->tiles[i][j]->offsetX,
game->layers[n]->tiles[i][j]->offsetY,
WHITE);
}
}
/*
Node *current = game->sprites->head;
// Draw sprites that are over the tile
while(current != 0 && current->data.y <= (j + 1) * game->layers[n]->textureWidth && current->data.y >= (j) * game->layers[n]->textureWidth){
//if(current->data.z == n){
DrawSpriteToWorld(&current->data, game->layers, game->camera);
//}
current = current->next;
}*/
}
}
}

@ -1,17 +0,0 @@
#ifndef ISOMETRICRENDERER_H_
#define ISOMETRICRENDERER_H_
#include "raylib.h"
#include "isometricMap.h"
#include "../Input/inputHandler.h"
#include "../game.h"
typedef struct IsometricRenderer{
Texture *texture;
} IsometricRenderer;
// @param deprecated
void IsometricRendererDrawMap(IsometricRenderer *renderer, int height);
void IsometricRendererRenderIsometricMap(Game *game);
#endif

@ -1,2 +0,0 @@
#include "tile.h"

@ -7,7 +7,7 @@
#include "../Textures/textureIDs.h"
Node * ListCreateNode(Sprite *data){
Node *new = (Node *) malloc(sizeof(Node));
Node *new = malloc(sizeof(Node));
new->data = data;
new->next = 0;
new->prev = 0;
@ -63,39 +63,9 @@ void ListInsertBack(List *list, Sprite *data){
}
}
void ListInsertSorted(List *list, Sprite *data){
Node *new = ListCreateNode(data);
int inserted = 1;
Node *current = list->head;
while(inserted == 1){
if(current == 0){
free(new);
ListInsertBack(list, data);
inserted = 0;
continue;
}
else if(data->y <= current->data->y){
if(current == list->head){
free(new);
ListInsertFront(list, data);
inserted = 0;
}
else{
new->prev = current->prev;
new->next = current;
current->prev->next = new;
current->prev = new;
inserted = 0;
}
continue;
}
current = current->next;
}
}
List * ListInit(){
List *newList = (List *) malloc(sizeof(List));
List *newList = malloc(sizeof(List));
newList->head = 0;
newList->tail = 0;
return newList;

@ -28,7 +28,6 @@ void ListPrintForward(List *list);
void ListInsertFront(List *list, Sprite *data);
void ListInsertBack(List *list, Sprite *data);
void ListInsertSorted(List *list, Sprite *data);
List * ListInit();
void ListDrawAllSprites(List *list, IsometricMap **map, Camera2D *camera);
void ListActAllSprites(Game *game);

@ -1,8 +1,9 @@
CC = gcc
FLAGS = -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
OBJS = main.o sprite.o inputHandler.o isometricMap.o list.o game.o textureatlas.o animation.o animationHandler.o bucket.o mergeSort.o
spiel: main.o sprite.o inputHandler.o isometricRenderer.o isometricMap.o tile.o list.o game.o textureatlas.o animation.o animationHandler.o bucket.o mergeSort.o
$(CC) -o spiel main.o sprite.o inputHandler.o isometricRenderer.o isometricMap.o tile.o list.o game.o textureatlas.o animation.o animationHandler.o bucket.o mergeSort.o $(FLAGS)
spiel: $(OBJS)
$(CC) -o spiel $(OBJS) $(FLAGS)
main.o: main.c
$(CC) -c main.c $(FLAGS)
@ -15,16 +16,10 @@ inputHandler.o: Input/inputHandler.c
list.o: List/list.c
$(CC) -c List/list.c $(FLAGS)
isometricRenderer.o: IsometricMap/isometricRenderer.c
$(CC) -c IsometricMap/isometricRenderer.c $(FLAGS)
isometricMap.o: IsometricMap/isometricMap.c
$(CC) -c IsometricMap/isometricMap.c $(FLAGS)
tile.o: IsometricMap/tile.c
$(CC) -c IsometricMap/tile.c $(FLAGS)
game.o: game.c
$(CC) -c game.c $(FLAGS)

@ -2,7 +2,7 @@
#include "stdlib.h"
Animation * AnimationInit(){
Animation *animation = (Animation *) malloc(sizeof(Animation));
Animation *animation = malloc(sizeof(Animation));
animation->head = 0;
animation->tail = 0;
@ -11,7 +11,7 @@ Animation * AnimationInit(){
}
AnimationFrame * AnimationFrameCreate(Texture2D *texture){
AnimationFrame *frame = (AnimationFrame *) malloc(sizeof(AnimationFrame));
AnimationFrame *frame = malloc(sizeof(AnimationFrame));
frame->texture = texture;
frame->next = 0;

@ -4,7 +4,7 @@
#include "stdio.h"
AnimationHandler * AnimationHandlerInit(Animation **animations){
AnimationHandler *new = (AnimationHandler *) malloc(sizeof(AnimationHandler));
AnimationHandler *new = malloc(sizeof(AnimationHandler));
new->animations = animations;
new->currentAnimation = 0;

@ -5,7 +5,7 @@
#include "stdio.h"
TextureAtlas * TextureAtlasInit(){
TextureAtlas *textures = (TextureAtlas *) malloc(sizeof(TextureAtlas));
TextureAtlas *textures = malloc(sizeof(TextureAtlas));
LoadCursorTextures(textures->cursorTextures, textures->cursorAnimation);
LoadWorkerTextures(textures->workerTextures);
@ -24,23 +24,6 @@ void LoadCursorTextures(Texture2D *cursorTextures, Animation **cursorAnimation){
}
void LoadWorkerTextures(Texture2D *workerTextures){
/*
Image worker1flip = LoadImage("assets/worker/worker-1.png");
ImageFlipHorizontal(&worker1flip);
Image worker2flip = LoadImage("assets/worker/worker-2.png");
ImageFlipHorizontal(&worker2flip);
Image worker3flip = LoadImage("assets/worker/worker-3.png");
ImageFlipHorizontal(&worker3flip);
textures->workerTextures[6] = LoadTexture("assets/worker/worker-0.png");
textures->workerTextures[5] = LoadTexture("assets/worker/worker-1.png");
textures->workerTextures[7] = LoadTextureFromImage(worker1flip);
textures->workerTextures[4] = LoadTexture("assets/worker/worker-2.png");
textures->workerTextures[0] = LoadTextureFromImage(worker2flip);
textures->workerTextures[3] = LoadTexture("assets/worker/worker-3.png");
textures->workerTextures[1] = LoadTextureFromImage(worker3flip);
textures->workerTextures[2] = LoadTexture("assets/worker/worker-4.png");
assets/worker/umackern-20.png
*/
char beginning[30] = "assets/worker/walk-";
char filename[30] = "";

@ -11,28 +11,12 @@
// returns pointer to new Game instance
Game *GameInit()
{
Game *game = (Game *)malloc(sizeof(Game));
Game *game = malloc(sizeof(Game));
game->textures = TextureAtlasInit();
game->cursorSprite = SpriteCreate(game->textures, 0, 450, 225);
/*
Image worker1flip = LoadImage("assets/worker/worker-1.png");
ImageFlipHorizontal(&worker1flip);
Image worker2flip = LoadImage("assets/worker/worker-2.png");
ImageFlipHorizontal(&worker2flip);
Image worker3flip = LoadImage("assets/worker/worker-3.png");
ImageFlipHorizontal(&worker3flip);
game->worker[6] = LoadTexture("assets/worker/worker-0.png");
game->worker[5] = LoadTexture("assets/worker/worker-1.png");
game->worker[7] = LoadTextureFromImage(worker1flip);
game->worker[4] = LoadTexture("assets/worker/worker-2.png");
game->worker[0] = LoadTextureFromImage(worker2flip);
game->worker[3] = LoadTexture("assets/worker/worker-3.png");
game->worker[1] = LoadTextureFromImage(worker3flip);
game->worker[2] = LoadTexture("assets/worker/worker-4.png");
*/
game->inputHandler = (InputHandler *)malloc(sizeof(InputHandler));
game->inputHandler = malloc(sizeof(InputHandler));
game->inputHandler->pressed = 0;
game->inputHandler->rectStart.x = 0;
game->inputHandler->rectStart.y = 0;
@ -46,7 +30,7 @@ Game *GameInit()
game->inputHandler->cursorTextures = game->textures->cursorTextures;
game->inputHandler->cursorSprite = game->cursorSprite;
game->camera = (Camera2D *)malloc(sizeof(Camera2D));
game->camera = malloc(sizeof(Camera2D));
game->camera->target.x = 0;
game->camera->target.y = 0;
game->camera->rotation = 0.0f;
@ -56,7 +40,7 @@ Game *GameInit()
game->sprites = ListInit();
game->layers = ((IsometricMap **)malloc(10 * sizeof(IsometricMap *)));
game->layers = malloc(10 * sizeof(IsometricMap *));
// Test Layers ---
int n = 0;

@ -5,7 +5,6 @@
#include "Input/inputHandler.h"
#include "raymath.h"
#include "List/list.h"
#include "IsometricMap/isometricRenderer.h"
#include "IsometricMap/isometricMap.h"
#include "game.h"
#include "DepthSorting/bucket.h"
@ -15,32 +14,12 @@ int main(){
InitWindow(800, 450, "basic window");
//Texture2D amulet = LoadTexture("assets/amulet.png");
Game *game = GameInit();
// Hides the operating systems own cursor
HideCursor();
SetTargetFPS(60);
/*
Bucket *buckets[10];
int i = 0;
for(i = 9; i >= 0; i--){
buckets[9-i] = (BucketInit(0, game->layers[0]->tiles[i][i]));
}
printf("\n");
for(i = 0; i < 10; i++){
printf("%f\n", buckets[i]->depth);
}
printf("\n");
MergeSort(buckets, 10);
printf("\n");
for(i = 0; i < 10; i++){
printf("%f\n", buckets[i]->depth);
}
printf("\n");
*/
//SetTargetFPS(60);
// GAME MAIN ROUTINE
while(!WindowShouldClose()){
@ -71,10 +50,6 @@ int main(){
EndDrawing();
}
CloseWindow();

@ -10,41 +10,11 @@
#include "IsometricMap/tile.h"
#include "DepthSorting/bucket.h"
// @param deprecated
void SpriteAdd(Sprite *sprites, int *spriteAmount, Texture2D *texture, int x, int y){
printf("WARNING: Using deprecated Function SpriteAdd!\n");
/*
if(*spriteAmount < 100){
(sprites + *spriteAmount) -> texture = texture;
(sprites + *spriteAmount) -> x = x;
(sprites + *spriteAmount) -> y = y;
(sprites + *spriteAmount) -> z = 0;
(sprites + *spriteAmount) -> destX = x;
(sprites + *spriteAmount) -> destY = y;
(sprites + *spriteAmount) -> hasDestination = 0;
(sprites + *spriteAmount) -> selected = 0;
(*spriteAmount)++;
}
else{
printf("Voll\n");
}
*/
}
void DrawSpriteToWorld(Sprite *sprite, IsometricMap **map, Camera2D *camera){
// TODO: Nach y sortieren, bevor sie gedrawed werden
// 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?
//Vector2 pos = {sprite->x, sprite->y};
Vector2 pos = {sprite->x - sprite->texture->width, sprite->y - sprite->texture->height/2};
IsometricMapUnproject(map, camera, pos.x, pos.y, sprite->z, &pos);
// Also erst ab hier sortieren, mit den Werten aus dem pos Vector
// IsometricMap muss auch mit reingerechnet werden -> mögliche Container Lösung steht in der README
pos.x -= camera->target.x;
pos.y -= camera->target.y;
@ -55,7 +25,6 @@ void DrawSpriteToWorld(Sprite *sprite, IsometricMap **map, Camera2D *camera){
else{
DrawTexture(*sprite->texture, pos.x, pos.y, WHITE);
}
//printf("%f %f \n", sprite->x, sprite->y);
}
void DrawSpriteToScreen(Sprite *sprite){
@ -74,10 +43,9 @@ void SpriteUpdateAnimation(Sprite *sprite){
}
Sprite * SpriteCreate(TextureAtlas *atlas, int textureID, int x, int y){
Sprite *newSprite = (Sprite *) malloc(sizeof(Sprite));
Sprite *newSprite = malloc(sizeof(Sprite));
//AnimationHandler create
//Animation **animations = atlas->workerAnimations;
Animation **animations = 0;
if(textureID == worker){

@ -19,9 +19,6 @@ typedef struct Sprite {
Bucket *sortable;
} Sprite;
// @param deprecated
void SpriteAdd(Sprite *sprites, int *spriteAmount, Texture2D *texture, int x, int y);
void DrawSpriteToWorld(Sprite *sprite, IsometricMap **map, Camera2D *camera);
void DrawSpriteToScreen(Sprite *sprite);
void SpriteUpdateAnimation(Sprite *sprite);

Loading…
Cancel
Save