|
|
|
|
@ -4,6 +4,7 @@
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <math.h>
|
|
|
|
|
#include "../List/list.h"
|
|
|
|
|
|
|
|
|
|
//TODO: Macht es Sinn ein einzelnes "Game" struct zu haben, das alle möglichen Pointer hat zu allen arrays, camera, textures etc?
|
|
|
|
|
// Man hat einen Übergabeparameter mit dem man dann alles verändern kann, man muss nicht alles was man verändern will einzeln übergeben
|
|
|
|
|
@ -51,7 +52,7 @@ Vector2 GetRectangle(Vector2 rectStart){
|
|
|
|
|
return rectStart;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void mouseInput(InputHandler *inputHandler, Sprite *sprites, int *spriteAmount, Texture2D *texture, Camera2D *camera){
|
|
|
|
|
void mouseInput(InputHandler *inputHandler, List *sprites, Texture2D *texture, Camera2D *camera){
|
|
|
|
|
|
|
|
|
|
inputHandler->cursorPos.x = GetMousePosition().x;
|
|
|
|
|
inputHandler->cursorPos.y = GetMousePosition().y;
|
|
|
|
|
@ -75,7 +76,8 @@ void mouseInput(InputHandler *inputHandler, Sprite *sprites, int *spriteAmount,
|
|
|
|
|
|
|
|
|
|
// Add Sprite
|
|
|
|
|
if(width + height <= 1){
|
|
|
|
|
SpriteAdd(sprites, spriteAmount, texture, inputHandler->cursorPos.x + (*camera).target.x - (texture->width)/2, inputHandler->cursorPos.y + (*camera).target.y - (texture->height)/2);
|
|
|
|
|
//SpriteAdd(sprites, spriteAmount, texture, inputHandler->cursorPos.x + (*camera).target.x - (texture->width)/2, inputHandler->cursorPos.y + (*camera).target.y - (texture->height)/2);
|
|
|
|
|
ListInsertBack(sprites, SpriteCreate(texture, inputHandler->cursorPos.x + (*camera).target.x - (texture->width)/2, inputHandler->cursorPos.y + (*camera).target.y - (texture->height)/2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Berechnung, welche Sprites ausgewählt wurden
|
|
|
|
|
@ -85,33 +87,37 @@ void mouseInput(InputHandler *inputHandler, Sprite *sprites, int *spriteAmount,
|
|
|
|
|
|
|
|
|
|
printf("Auswahl: x: %f, y: %f, w: %f, h: %f\n", rect.x, rect.y, width, height);
|
|
|
|
|
|
|
|
|
|
int k;
|
|
|
|
|
float deltaX;
|
|
|
|
|
float deltaY;
|
|
|
|
|
for(k = 0; k < *spriteAmount; k++){
|
|
|
|
|
deltaX = (sprites+k)->x - (rect.x + camera->target.x);
|
|
|
|
|
deltaY = (sprites+k)->y - (rect.y + camera->target.y);
|
|
|
|
|
Node *current = sprites->head;
|
|
|
|
|
while (current != 0){
|
|
|
|
|
deltaX = current->data.x + current->data.texture->width/2 - (rect.x + camera->target.x);
|
|
|
|
|
deltaY = current->data.y + current->data.texture->height/2 - (rect.y + camera->target.y);
|
|
|
|
|
|
|
|
|
|
printf("deltaX: %f, deltaY: %f\n", deltaX, deltaY);
|
|
|
|
|
|
|
|
|
|
if(deltaX > 0 && deltaX < width && deltaY > 0 && deltaY < height){
|
|
|
|
|
(sprites + k)->selected = 1;
|
|
|
|
|
printf("%d selected\n", k);
|
|
|
|
|
current->data.selected = 1;
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
(sprites + k)->selected = 0;
|
|
|
|
|
current->data.selected = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
current = current->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(IsMouseButtonPressed(MOUSE_BUTTON_RIGHT)){
|
|
|
|
|
int i;
|
|
|
|
|
for(i=0;i<*spriteAmount;i++){
|
|
|
|
|
if((sprites+i)->selected){
|
|
|
|
|
(sprites+i)->hasDestination = 1;
|
|
|
|
|
(sprites+i)->destX = inputHandler->cursorPos.x + (*camera).target.x - (texture->width)/2;
|
|
|
|
|
(sprites+i)->destY = inputHandler->cursorPos.y + (*camera).target.y - (texture->height)/2;
|
|
|
|
|
Node *current = sprites->head;
|
|
|
|
|
|
|
|
|
|
while (current != 0){
|
|
|
|
|
if(current->data.selected){
|
|
|
|
|
current->data.hasDestination = 1;
|
|
|
|
|
current->data.destX = inputHandler->cursorPos.x + (*camera).target.x - (texture->width)/2;
|
|
|
|
|
current->data.destY = inputHandler->cursorPos.y + (*camera).target.y - (texture->height)/2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
current = current->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|