Viel behoben

main
Jonathan Hager 3 years ago
parent 1d4d0b60ba
commit 607196d72d
Signed by: JonathanHager
GPG Key ID: 34881E488569708C

@ -122,10 +122,11 @@ void mouseInput(Game *game){
float width = GetMousePosition().x - inputHandler->rectStart.x; float width = GetMousePosition().x - inputHandler->rectStart.x;
float height = GetMousePosition().y - inputHandler->rectStart.y; float height = GetMousePosition().y - inputHandler->rectStart.y;
// Add Sprite // Add Sprite
if(abs(width) + abs(height) < 20){ if(abs(width) + abs(height) < 20){
int maxWidth = (game->layers[0]->width-1) * game->layers[0]->textureWidth; int maxWidth = (game->layers[0]->width) * game->layers[0]->textureWidth;
int maxHeight = (game->layers[0]->height-1) * game->layers[0]->textureHeight; int maxHeight = (game->layers[0]->height) * 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");}
@ -145,17 +146,17 @@ 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.texture->width, current->data.y + current->data.texture->height/2}; 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); 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);
if(deltaX > 0 && deltaX < width && deltaY > 0 && deltaY < height){ if(deltaX > 0 && deltaX < width && deltaY > 0 && deltaY < height){
current->data.selected = 1; current->data->selected = 1;
} }
else{ else{
current->data.selected = 0; current->data->selected = 0;
} }
current = current->next; current = current->next;
@ -166,8 +167,8 @@ void mouseInput(Game *game){
Node *current = sprites->head; Node *current = sprites->head;
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->cursorWorldPos.x; float destX = inputHandler->cursorWorldPos.x;
float destY = inputHandler->cursorWorldPos.y; float destY = inputHandler->cursorWorldPos.y;
int maxWidth = (game->layers[0]->width-1) * game->layers[0]->textureWidth; int maxWidth = (game->layers[0]->width-1) * game->layers[0]->textureWidth;
@ -177,8 +178,8 @@ void mouseInput(Game *game){
if(destX > maxWidth){ printf("OutOfBoundsDestination\n"); goto skip; } if(destX > maxWidth){ printf("OutOfBoundsDestination\n"); goto skip; }
if(destY > maxHeight){ printf("OutOfBoundsDestination\n"); goto skip; } if(destY > maxHeight){ printf("OutOfBoundsDestination\n"); goto skip; }
current->data.destX = destX; current->data->destX = destX;
current->data.destY = destY; current->data->destY = destY;
} }
skip: current = current->next; skip: current = current->next;

@ -219,11 +219,11 @@ void IsometricMapDraw(Game *game){
maxJ = (int)(botleft.y) + extraPixels; maxJ = (int)(botleft.y) + extraPixels;
while(current != 0){ while(current != 0){
// Only drawing the Sprites which are within Camera view // Only drawing the Sprites which are within Camera view
if( current->data.x > itmp && if( current->data->x > itmp &&
current->data.y > jtmp && current->data->y > jtmp &&
current->data.x < maxI && current->data->x < maxI &&
current->data.y < maxJ){ current->data->y < maxJ){
buckets[counter] = current->data.sortable; buckets[counter] = current->data->sortable;
++counter; ++counter;
} }
current = current->next; current = current->next;

@ -8,7 +8,7 @@
Node * ListCreateNode(Sprite *data){ Node * ListCreateNode(Sprite *data){
Node *new = (Node *) malloc(sizeof(Node)); Node *new = (Node *) malloc(sizeof(Node));
new->data = *data; new->data = data;
new->next = 0; new->next = 0;
new->prev = 0; new->prev = 0;
return new; return new;
@ -75,7 +75,7 @@ void ListInsertSorted(List *list, Sprite *data){
inserted = 0; inserted = 0;
continue; continue;
} }
else if(data->y <= current->data.y){ else if(data->y <= current->data->y){
if(current == list->head){ if(current == list->head){
free(new); free(new);
ListInsertFront(list, data); ListInsertFront(list, data);
@ -124,11 +124,11 @@ void ListDrawAllSprites(List *list, IsometricMap **map, Camera2D *camera){
// drawing some extra corner pixels // drawing some extra corner pixels
// if extraPixels == 0 you can see flickering in the corners // if extraPixels == 0 you can see flickering in the corners
// Only drawing the Sprites which are within Camera view // Only drawing the Sprites which are within Camera view
if( current->data.x > itmp && if( current->data->x > itmp &&
current->data.y > jtmp && current->data->y > jtmp &&
current->data.x < maxI && current->data->x < maxI &&
current->data.y < maxJ){ current->data->y < maxJ){
DrawSpriteToWorld(&current->data, map, camera); DrawSpriteToWorld(current->data, map, camera);
} }
current = current->next; current = current->next;
} }
@ -144,21 +144,21 @@ void ListActAllSprites(Game *game){
int counter = 0; int counter = 0;
while (current != 0){ while (current != 0){
counter ++; counter ++;
if(current->data.hasDestination == 1){ if(current->data->hasDestination == 1){
Vector2 movement = { Vector2 movement = {
current->data.destX - current->data.x, current->data->destX - current->data->x,
current->data.destY - current->data.y current->data->destY - current->data->y
}; };
if(Vector2Length(movement) < movementSpeed){ if(Vector2Length(movement) < movementSpeed){
current->data.hasDestination = 0; current->data->hasDestination = 0;
current->data.x = current->data.destX; current->data->x = current->data->destX;
current->data.y = current->data.destY; current->data->y = current->data->destY;
} }
else{ else{
movement = Vector2Normalize(movement); movement = Vector2Normalize(movement);
movement = Vector2Scale(movement, movementSpeed); movement = Vector2Scale(movement, movementSpeed);
current->data.x += movement.x; current->data->x += movement.x;
current->data.y += movement.y; current->data->y += movement.y;
// Change sprite according to direction // Change sprite according to direction
Vector2 nullvektor = {0,0}; Vector2 nullvektor = {0,0};
@ -168,46 +168,46 @@ void ListActAllSprites(Game *game){
if(angle <= 22.5 && angle >= -22.5){ if(angle <= 22.5 && angle >= -22.5){
// E // E
AnimationChangeAnimation(current->data.animationHandler, E); AnimationChangeAnimation(current->data->animationHandler, E);
} }
else if(angle > 0 && angle <= 67.5){ else if(angle > 0 && angle <= 67.5){
// NE // NE
AnimationChangeAnimation(current->data.animationHandler, NE); AnimationChangeAnimation(current->data->animationHandler, NE);
} }
else if(angle > 0 && angle <= 112.5){ else if(angle > 0 && angle <= 112.5){
// N // N
AnimationChangeAnimation(current->data.animationHandler, N); AnimationChangeAnimation(current->data->animationHandler, N);
} }
else if(angle > 0 && angle <= 157.5){ else if(angle > 0 && angle <= 157.5){
// NW // NW
AnimationChangeAnimation(current->data.animationHandler, NW); AnimationChangeAnimation(current->data->animationHandler, NW);
} }
else if(angle < 0 && angle >= -67.5){ else if(angle < 0 && angle >= -67.5){
// SE // SE
AnimationChangeAnimation(current->data.animationHandler, SE); AnimationChangeAnimation(current->data->animationHandler, SE);
} }
else if(angle < 0 && angle >= -112.5){ else if(angle < 0 && angle >= -112.5){
// S // S
AnimationChangeAnimation(current->data.animationHandler, S); AnimationChangeAnimation(current->data->animationHandler, S);
} }
else if(angle < 0 && angle >= -157.5){ else if(angle < 0 && angle >= -157.5){
// SW // SW
AnimationChangeAnimation(current->data.animationHandler, SW); AnimationChangeAnimation(current->data->animationHandler, SW);
} }
else{ else{
// W // W
AnimationChangeAnimation(current->data.animationHandler, W); AnimationChangeAnimation(current->data->animationHandler, W);
} }
} }
} }
SpriteUpdateAnimation(&current->data); SpriteUpdateAnimation(current->data);
// updating z-position according to the tile the sprite stands on // updating z-position according to the tile the sprite stands on
Tile *floorTile = IsometricMapGetTileFromWorldCoordinates(game->layers, current->data.x, current->data.y, 0); Tile *floorTile = IsometricMapGetTileFromWorldCoordinates(game->layers, current->data->x, current->data->y, 0);
Tile *topTile = IsometricMapGetMostUpperTile(game->layers, floorTile); Tile *topTile = IsometricMapGetMostUpperTile(game->layers, floorTile);
current->data.z = topTile->z; current->data->z = topTile->z;
current = current->next; current = current->next;
} }

@ -14,7 +14,7 @@ typedef struct List {
} List; } List;
typedef struct Node { typedef struct Node {
Sprite data; Sprite *data;
Node *next; Node *next;
Node *prev; Node *prev;

@ -1,12 +0,0 @@
#ifndef NODEDATA_H_
#define NODEDATA_H_
#include "../sprite.h"
typedef union NodeData {
int dataInt;
float dataFloat;
Sprite dataSprite;
} NodeData;
#endif

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -67,7 +67,7 @@ Game *GameInit()
{ {
((game->layers))[n] = IsometricMapInit(n); ((game->layers))[n] = IsometricMapInit(n);
} }
/*
for (n = 0; n < 10; n++) for (n = 0; n < 10; n++)
{ {
for (i = 0; i < game->layers[n]->width; i++) for (i = 0; i < game->layers[n]->width; i++)
@ -122,11 +122,11 @@ Game *GameInit()
} }
} }
} }
*/
n = 0; n = 0;
for (i = 0; i < 3; i++) for (i = 0; i < game->layers[0]->width; i++)
{ {
for (j = 0; j < 3; j++) for (j = 0; j < game->layers[0]->height; j++)
{ {
IsometricMapChangeTextureIdOfTile(game->layers, i, j, n, 0); IsometricMapChangeTextureIdOfTile(game->layers, i, j, n, 0);
} }

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.

@ -21,7 +21,7 @@ int main(){
// Hides the operating systems own cursor // Hides the operating systems own cursor
HideCursor(); HideCursor();
//SetTargetFPS(60); SetTargetFPS(60);
/* /*
Bucket *buckets[10]; Bucket *buckets[10];

BIN
main.o

Binary file not shown.

Binary file not shown.

BIN
spiel

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
tile.o

Binary file not shown.
Loading…
Cancel
Save