|
|
|
@ -60,11 +60,16 @@ void mouseInput(InputHandler *inputHandler, List *sprites, Texture2D *texture, C
|
|
|
|
inputHandler->cursorPos.y = GetMousePosition().y;
|
|
|
|
inputHandler->cursorPos.y = GetMousePosition().y;
|
|
|
|
|
|
|
|
|
|
|
|
// resetting last selected Tile to grass texture
|
|
|
|
// resetting last selected Tile to grass texture
|
|
|
|
int n = 9;
|
|
|
|
|
|
|
|
if(inputHandler->selectedLayer != -1){
|
|
|
|
if(inputHandler->selectedLayer != -1){
|
|
|
|
IsometricMapChangeTextureIdOfTile(layers[inputHandler->selectedLayer], (int) inputHandler->cursorWorldPos.x, (int) inputHandler->cursorWorldPos.y, 0);
|
|
|
|
IsometricMapChangeTextureIdOfTile(layers[inputHandler->selectedLayer], (int) inputHandler->cursorWorldTile.x, (int) inputHandler->cursorWorldTile.y, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// TODO: n=2 no good style, but Segmentation fault when > layerAmount
|
|
|
|
/*
|
|
|
|
|
|
|
|
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]));
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
int n = 9;
|
|
|
|
for(n = 9; n >= 0 ; n--){
|
|
|
|
for(n = 9; n >= 0 ; n--){
|
|
|
|
if(layers[n] != 0){
|
|
|
|
if(layers[n] != 0){
|
|
|
|
float tileWidthHalf = layers[n]->tileTextures[0].width / 2;
|
|
|
|
float tileWidthHalf = layers[n]->tileTextures[0].width / 2;
|
|
|
|
@ -77,11 +82,11 @@ void mouseInput(InputHandler *inputHandler, List *sprites, Texture2D *texture, C
|
|
|
|
Tile *selectedTile = IsometricMapGetTileFromWorldCoordinates(layers[n], inputHandler->cursorWorldPos.x, inputHandler->cursorWorldPos.y);
|
|
|
|
Tile *selectedTile = IsometricMapGetTileFromWorldCoordinates(layers[n], inputHandler->cursorWorldPos.x, inputHandler->cursorWorldPos.y);
|
|
|
|
|
|
|
|
|
|
|
|
if(selectedTile != 0){
|
|
|
|
if(selectedTile != 0){
|
|
|
|
inputHandler->cursorWorldPos.x = selectedTile->x;
|
|
|
|
inputHandler->cursorWorldTile.x = selectedTile->x;
|
|
|
|
inputHandler->cursorWorldPos.y = selectedTile->y;
|
|
|
|
inputHandler->cursorWorldTile.y = selectedTile->y;
|
|
|
|
// setting currently selected tile to tower
|
|
|
|
|
|
|
|
inputHandler->selectedLayer = n;
|
|
|
|
inputHandler->selectedLayer = n;
|
|
|
|
IsometricMapChangeTextureIdOfTile(layers[n], (int) inputHandler->cursorWorldPos.x, (int) inputHandler->cursorWorldPos.y, 1);
|
|
|
|
// setting currently selected tile to tower
|
|
|
|
|
|
|
|
IsometricMapChangeTextureIdOfTile(layers[n], inputHandler->cursorWorldTile.x, inputHandler->cursorWorldTile.y, 1);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -106,23 +111,25 @@ void mouseInput(InputHandler *inputHandler, List *sprites, Texture2D *texture, C
|
|
|
|
|
|
|
|
|
|
|
|
if(IsMouseButtonReleased(MOUSE_BUTTON_LEFT)){
|
|
|
|
if(IsMouseButtonReleased(MOUSE_BUTTON_LEFT)){
|
|
|
|
inputHandler->pressed = 0;
|
|
|
|
inputHandler->pressed = 0;
|
|
|
|
// Cursorsprite is rechanged to normal
|
|
|
|
// Cursorsprite is changed back to normal
|
|
|
|
inputHandler->cursorSprite->texture = (inputHandler->cursorTextures);
|
|
|
|
inputHandler->cursorSprite->texture = (inputHandler->cursorTextures);
|
|
|
|
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(width + height <= 1){
|
|
|
|
if(width + height <= 1){
|
|
|
|
ListInsertBack(sprites, SpriteCreate(texture, inputHandler->cursorPos.x + (*camera).target.x - (texture->width)/2, inputHandler->cursorPos.y + (*camera).target.y - (texture->height)/2));
|
|
|
|
ListInsertBack(sprites, SpriteCreate(texture, inputHandler->cursorWorldPos.x, inputHandler->cursorWorldPos.y));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Berechnung, welche Sprites ausgewählt wurden
|
|
|
|
// Berechnung, welche Sprites ausgewählt wurden, scuffed
|
|
|
|
Vector2 rect = GetRectangle(inputHandler->rectStart);
|
|
|
|
Vector2 rect = GetRectangle(inputHandler->rectStart);
|
|
|
|
width = abs(width);
|
|
|
|
width = abs(width);
|
|
|
|
height = abs(height);
|
|
|
|
height = abs(height);
|
|
|
|
|
|
|
|
|
|
|
|
printf("Auswahl: x: %f, y: %f, w: %f, h: %f\n", rect.x, rect.y, width, height);
|
|
|
|
printf("Auswahl: x: %f, y: %f, w: %f, h: %f\n", rect.x, rect.y, width, height);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: update to World Coordinates
|
|
|
|
float deltaX;
|
|
|
|
float deltaX;
|
|
|
|
float deltaY;
|
|
|
|
float deltaY;
|
|
|
|
Node *current = sprites->head;
|
|
|
|
Node *current = sprites->head;
|
|
|
|
@ -149,8 +156,8 @@ void mouseInput(InputHandler *inputHandler, List *sprites, Texture2D *texture, C
|
|
|
|
while (current != 0){
|
|
|
|
while (current != 0){
|
|
|
|
if(current->data.selected){
|
|
|
|
if(current->data.selected){
|
|
|
|
current->data.hasDestination = 1;
|
|
|
|
current->data.hasDestination = 1;
|
|
|
|
current->data.destX = inputHandler->cursorPos.x + (*camera).target.x - (texture->width)/2;
|
|
|
|
current->data.destX = inputHandler->cursorWorldPos.x;
|
|
|
|
current->data.destY = inputHandler->cursorPos.y + (*camera).target.y - (texture->height)/2;
|
|
|
|
current->data.destY = inputHandler->cursorWorldPos.y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
current = current->next;
|
|
|
|
current = current->next;
|
|
|
|
@ -159,16 +166,17 @@ void mouseInput(InputHandler *inputHandler, List *sprites, Texture2D *texture, C
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void keyboardInput(InputHandler *inputHandler, Camera2D *camera){
|
|
|
|
void keyboardInput(InputHandler *inputHandler, Camera2D *camera){
|
|
|
|
|
|
|
|
float camSpeed = 1000.0f;
|
|
|
|
if(IsKeyDown(KEY_W)){
|
|
|
|
if(IsKeyDown(KEY_W)){
|
|
|
|
(*camera).target.y -= 1000.0f * GetFrameTime();
|
|
|
|
(*camera).target.y -= camSpeed * GetFrameTime();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(IsKeyDown(KEY_S)){
|
|
|
|
if(IsKeyDown(KEY_S)){
|
|
|
|
(*camera).target.y += 1000.0f * GetFrameTime();
|
|
|
|
(*camera).target.y += camSpeed * GetFrameTime();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(IsKeyDown(KEY_D)){
|
|
|
|
if(IsKeyDown(KEY_D)){
|
|
|
|
(*camera).target.x += 1000.0f * GetFrameTime();
|
|
|
|
(*camera).target.x += camSpeed * GetFrameTime();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(IsKeyDown(KEY_A)){
|
|
|
|
if(IsKeyDown(KEY_A)){
|
|
|
|
(*camera).target.x -= 1000.0f * GetFrameTime();
|
|
|
|
(*camera).target.x -= camSpeed * GetFrameTime();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|