commit
ac26ea6e60
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"inputhandling.h": "c"
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1 +1,18 @@
|
|||||||
# Aufbauspiel jaja
|
# Aufbauspiel jaja
|
||||||
|
|
||||||
|
[[_TOC_]]
|
||||||
|
|
||||||
|
## Ackermatch gegen die Natur?
|
||||||
|
|
||||||
|
KI Gegner ist erstmal zu aufwändig, ein wenig Ackern muss man aber immer!
|
||||||
|
|
||||||
|
Fantasy Welt oder Realistisch?
|
||||||
|
|
||||||
|
## Isometrie in RayLib
|
||||||
|
[Projection Orthogonal -> Isometric](https://gamedevelopment.tutsplus.com/tutorials/creating-isometric-worlds-a-primer-for-game-developers--gamedev-6511)
|
||||||
|
|
||||||
|
## TODO
|
||||||
|
|
||||||
|
- Bug with movement of sprite
|
||||||
|
- Drawn Rectangle problems with negative width/height
|
||||||
|
- Selecting Sprites for moving all selected to the same destination
|
||||||
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.5 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
@ -0,0 +1,72 @@
|
|||||||
|
struct InputHandler{
|
||||||
|
int pressed;
|
||||||
|
Vector2 rectStart;
|
||||||
|
int clicked;
|
||||||
|
Vector2 cursorPos;
|
||||||
|
} InputHandler;
|
||||||
|
|
||||||
|
//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
|
||||||
|
|
||||||
|
/*
|
||||||
|
cursor.x = GetMousePosition().x - texture.width / 2;
|
||||||
|
cursor.y = GetMousePosition().y - texture.height / 2;
|
||||||
|
*/
|
||||||
|
|
||||||
|
void mouseInput(struct InputHandler *inputHandler, struct Sprite *sprites, int *spriteAmount, Texture2D *texture, Camera2D *camera){
|
||||||
|
|
||||||
|
inputHandler->cursorPos.x = GetMousePosition().x;
|
||||||
|
inputHandler->cursorPos.y = GetMousePosition().y;
|
||||||
|
|
||||||
|
if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT)){
|
||||||
|
if(inputHandler->pressed == 0){
|
||||||
|
inputHandler->rectStart.x = GetMousePosition().x;
|
||||||
|
inputHandler->rectStart.y = GetMousePosition().y;
|
||||||
|
inputHandler->pressed = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(inputHandler->pressed){
|
||||||
|
float width = GetMousePosition().x - inputHandler->rectStart.x;
|
||||||
|
float height = GetMousePosition().y - inputHandler->rectStart.y;
|
||||||
|
if(width + height > 1){
|
||||||
|
//TODO: Fallunterscheidung für negative width / height?
|
||||||
|
// Auslagern in eigene Funktion
|
||||||
|
DrawRectangleLines(inputHandler->rectStart.x, inputHandler->rectStart.y, width, height, GREEN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(IsMouseButtonReleased(MOUSE_BUTTON_LEFT)){
|
||||||
|
inputHandler->pressed = 0;
|
||||||
|
float width = GetMousePosition().x - inputHandler->rectStart.x;
|
||||||
|
float height = GetMousePosition().y - inputHandler->rectStart.y;
|
||||||
|
if(width + height <= 1){
|
||||||
|
printf("Klick\n");
|
||||||
|
addSprite(sprites, spriteAmount, texture, inputHandler->cursorPos.x + (*camera).target.x - (texture->width)/2, inputHandler->cursorPos.y + (*camera).target.y - (texture->height)/2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(IsMouseButtonPressed(MOUSE_BUTTON_RIGHT)){
|
||||||
|
inputHandler->clicked = 1;
|
||||||
|
sprites->clicked = 1;
|
||||||
|
sprites->destX = inputHandler->cursorPos.x + (*camera).target.x - (texture->width)/2;
|
||||||
|
sprites->destY = inputHandler->cursorPos.y + (*camera).target.y - (texture->height)/2;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void keyboardInput(struct InputHandler *inputHandler, Camera2D *camera){
|
||||||
|
if(IsKeyDown(KEY_W)){
|
||||||
|
(*camera).target.y -= 100.0f * GetFrameTime();
|
||||||
|
}
|
||||||
|
if(IsKeyDown(KEY_S)){
|
||||||
|
(*camera).target.y += 100.0f * GetFrameTime();
|
||||||
|
}
|
||||||
|
if(IsKeyDown(KEY_D)){
|
||||||
|
(*camera).target.x += 100.0f * GetFrameTime();
|
||||||
|
}
|
||||||
|
if(IsKeyDown(KEY_A)){
|
||||||
|
(*camera).target.x -= 100.0f * GetFrameTime();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in new issue