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.
77 lines
2.4 KiB
77 lines
2.4 KiB
#include "inputHandler.h"
|
|
#include "raylib.h"
|
|
#include "sprite.h"
|
|
#include <stdio.h>
|
|
|
|
void mouseInput(InputHandler *inputHandler, 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){
|
|
DrawRect(inputHandler->rectStart, &(inputHandler->cursorPos));
|
|
}
|
|
|
|
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){
|
|
SpriteAdd(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)){
|
|
sprites->hasDestination = 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(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();
|
|
}
|
|
}
|
|
|
|
void DrawRect(Vector2 rectStart, Vector2 *mousePosition){
|
|
|
|
float width = GetMousePosition().x - rectStart.x;
|
|
float height = GetMousePosition().y - rectStart.y;
|
|
|
|
if(width < 0 && height >= 0){
|
|
width *= -1;
|
|
rectStart.x -= width;
|
|
}
|
|
else if(height < 0 && width >= 0){
|
|
height *= -1;
|
|
rectStart.y -= height;
|
|
}
|
|
else if(height < 0 && width < 0){
|
|
height *= -1;
|
|
width *= -1;
|
|
rectStart.x -= width;
|
|
rectStart.y -= height;
|
|
}
|
|
|
|
DrawRectangleLines(rectStart.x, rectStart.y, width, height, GREEN);
|
|
} |