You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
2.3 KiB
71 lines
2.3 KiB
#include "sprite.h"
|
|
#include "raylib.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include "IsometricMap/isometricMap.h"
|
|
#include "IsometricMap/tile.h"
|
|
|
|
void SpriteAdd(Sprite *sprites, int *spriteAmount, Texture2D *texture, int x, int y){
|
|
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->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
|
|
// nvm, Isometric map muss mit reingerechnet werden
|
|
pos.x -= camera->target.x;
|
|
pos.y -= camera->target.y;
|
|
if(sprite->selected){
|
|
DrawTexture(*sprite->texture, pos.x, pos.y, BLACK);
|
|
//DrawTexture(*sprite->texture, sprite->x, sprite->y, BLACK);
|
|
}
|
|
else{
|
|
DrawTexture(*sprite->texture, pos.x, pos.y, WHITE);
|
|
}
|
|
//printf("%f %f \n", sprite->x, sprite->y);
|
|
}
|
|
|
|
void DrawSpriteToScreen(Sprite *sprite){
|
|
|
|
if(sprite->selected){
|
|
DrawTexture(*sprite->texture, sprite->x, sprite->y, WHITE);
|
|
//DrawTexture(*sprite->texture, sprite->x, sprite->y, BLACK);
|
|
}
|
|
else{
|
|
DrawTexture(*sprite->texture, sprite->x, sprite->y, WHITE);
|
|
}
|
|
}
|
|
|
|
Sprite * SpriteCreate(Texture2D *texture, int x, int y){
|
|
Sprite *newSprite = (Sprite *) malloc(sizeof(Sprite));
|
|
|
|
newSprite->texture = texture;
|
|
newSprite->x = x - texture->width / 2;
|
|
newSprite->y = y - texture->height / 2;
|
|
newSprite->destX = x;
|
|
newSprite->destY = y;
|
|
newSprite->hasDestination = 0;
|
|
newSprite->selected = 0;
|
|
|
|
return newSprite;
|
|
}
|