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.
105 lines
3.5 KiB
105 lines
3.5 KiB
#include "sprite.h"
|
|
#include "raylib.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include "IsometricMap/isometricMap.h"
|
|
#include "Textures/textureIDs.h"
|
|
#include "Textures/animationHandler.h"
|
|
#include "Textures/animation.h"
|
|
#include "Textures/textureatlas.h"
|
|
#include "IsometricMap/tile.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;
|
|
if(sprite->selected){
|
|
DrawTexture(*sprite->texture, pos.x, pos.y, (Color){255, 255, 255, 200});
|
|
//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, (Color){255, 255, 255, 200});
|
|
//DrawTexture(*sprite->texture, sprite->x, sprite->y, BLACK);
|
|
}
|
|
else{
|
|
DrawTexture(*sprite->texture, sprite->x, sprite->y, WHITE);
|
|
}
|
|
}
|
|
|
|
void SpriteUpdateAnimation(Sprite *sprite){
|
|
AnimationUpdate(sprite->animationHandler);
|
|
sprite->texture = sprite->animationHandler->currentFrame->texture;
|
|
}
|
|
|
|
Sprite * SpriteCreate(TextureAtlas *atlas, int textureID, int x, int y){
|
|
Sprite *newSprite = (Sprite *) malloc(sizeof(Sprite));
|
|
|
|
//AnimationHandler create
|
|
//Animation **animations = atlas->workerAnimations;
|
|
Animation **animations = 0;
|
|
|
|
if(textureID == worker){
|
|
animations = atlas->workerAnimations;
|
|
}
|
|
else if(textureID == cursor){
|
|
animations = atlas->cursorAnimation;
|
|
}
|
|
else{
|
|
printf("\n\n\n\n\n\n\n\nSpriteCreate mit falscher ID aufgerufen oder ID nicht bekannt!!!\n\n\n\n\n\n\n\n");
|
|
}
|
|
|
|
AnimationHandler *newHandler = AnimationHandlerInit(animations);
|
|
|
|
newSprite->animationHandler = newHandler;
|
|
newSprite->texture = newSprite->animationHandler->currentFrame->texture;
|
|
newSprite->x = x - newSprite->texture->width / 2;
|
|
newSprite->y = y - newSprite->texture->height / 2;
|
|
newSprite->destX = x;
|
|
newSprite->destY = y;
|
|
newSprite->hasDestination = 0;
|
|
newSprite->selected = 0;
|
|
|
|
return newSprite;
|
|
}
|