Reimplemented placing sprites

main
JanEhehalt 3 years ago
parent ce2abb9ccd
commit bcfb4e7515

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

@ -19,7 +19,7 @@ int main(){
int pressed = 0; int pressed = 0;
Vector2 rectStart = {0,0}; Vector2 rectStart = {0,0};
texture = LoadTexture("amulet.png"); texture = LoadTexture("assets/amulet.png");
int j = 0; int j = 0;
struct Sprite cursor = {&texture, 450, 225}; struct Sprite cursor = {&texture, 450, 225};
@ -54,7 +54,7 @@ int main(){
cursor.x = GetMousePosition().x - texture.width / 2; cursor.x = GetMousePosition().x - texture.width / 2;
cursor.y = GetMousePosition().y - texture.height / 2; cursor.y = GetMousePosition().y - texture.height / 2;
/* /*
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)){ if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)){
printf("Klick\n"); printf("Klick\n");
addSprite(sprites, &j, &texture, cursor.x + camera.target.x, cursor.y + camera.target.y); addSprite(sprites, &j, &texture, cursor.x + camera.target.x, cursor.y + camera.target.y);
@ -63,8 +63,8 @@ int main(){
if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT)){ if(IsMouseButtonPressed(MOUSE_BUTTON_LEFT)){
if(pressed == 0){ if(pressed == 0){
rectStart.x = cursor.x; rectStart.x = GetMousePosition().x;
rectStart.y = cursor.y; rectStart.y = GetMousePosition().y;
pressed = 1; pressed = 1;
} }
} }
@ -72,14 +72,23 @@ int main(){
if(pressed){ if(pressed){
float width = GetMousePosition().x - rectStart.x; float width = GetMousePosition().x - rectStart.x;
float height = GetMousePosition().y - rectStart.y; float height = GetMousePosition().y - rectStart.y;
if(width + height > 1){
//TODO: Fallunterscheidung für negative width / height?
// Auslagern in eigene Funktion
DrawRectangleLines(rectStart.x, rectStart.y, width, height, GREEN); DrawRectangleLines(rectStart.x, rectStart.y, width, height, GREEN);
} }
}
if(IsMouseButtonReleased(MOUSE_BUTTON_LEFT)){ if(IsMouseButtonReleased(MOUSE_BUTTON_LEFT)){
pressed = 0; pressed = 0;
float width = GetMousePosition().x - rectStart.x;
float height = GetMousePosition().y - rectStart.y;
if(width + height <= 1){
printf("Klick\n");
addSprite(sprites, &j, &texture, cursor.x + camera.target.x, cursor.y + camera.target.y);
}
} }
if(IsMouseButtonPressed(MOUSE_BUTTON_RIGHT)){ if(IsMouseButtonPressed(MOUSE_BUTTON_RIGHT)){

BIN
main.o

Binary file not shown.

BIN
spiel

Binary file not shown.
Loading…
Cancel
Save