parent
b5b08abb8a
commit
d8e98471e1
@ -0,0 +1,5 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"inputhandling.h": "c"
|
||||
}
|
||||
}
|
||||
@ -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