From 5cf871caed4f6330b8e40f6fcde830491d8166c7 Mon Sep 17 00:00:00 2001 From: JailDoctor Date: Sun, 4 Jun 2023 18:27:39 +0200 Subject: [PATCH] =?UTF-8?q?-=20Afegit=20soport=20per=20a=20ratol=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/jinput.cpp | 18 ++++++++++++++++++ source/jinput.h | 5 +++++ source/main.cpp | 25 +++++++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/source/jinput.cpp b/source/jinput.cpp index dc87457..600a598 100644 --- a/source/jinput.cpp +++ b/source/jinput.cpp @@ -46,4 +46,22 @@ namespace input keypressed = key; } + int mouseX() + { + int x; + SDL_GetMouseState(&x, NULL); + return x; + } + + int mouseY() + { + int y; + SDL_GetMouseState(NULL, &y); + return y; + } + + bool mouseBtn(int btn) + { + return (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(btn)); + } } diff --git a/source/jinput.h b/source/jinput.h index 0f2ee2a..c3c4db4 100644 --- a/source/jinput.h +++ b/source/jinput.h @@ -27,4 +27,9 @@ namespace input void updateKey(uint8_t key); void updateKeypressed(uint8_t key); + + int mouseX(); + int mouseY(); + bool mouseBtn(int btn); + } \ No newline at end of file diff --git a/source/main.cpp b/source/main.cpp index e913df1..c6237eb 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -46,6 +46,24 @@ void game::init() int sx=1, sy=0; + void print(int x, int y, int num) + { + int digits=0; + bool sign = num < 0; + num = SDL_abs(num); + int n = num; + while (n>0) {n=n/10;digits++;} + if (sign) digits++; + x=x+digits*4; + if (num==0) draw::draw(x+4,y,5,7,0,120); + while (num>0) + { + draw::draw(x,y,5,7,(num%10)*5,120); + num=num/10; + x=x-4; + } + if (sign) draw::draw(x,y,5,7,50,120); + } bool game::loop() { @@ -54,6 +72,7 @@ bool game::loop() ii++;if(ii>3)ii=0; restart(); } + actor::update(actor::getFirst()); actor::reorder(); @@ -62,6 +81,12 @@ bool game::loop() actor::draw(actor::getFirst()); room::draw2(); //draw::draw(148+sx*2-sy*2, 67+sx+sy,24,24,24,0); + + print(0,0,input::mouseX()/3); + print(0,20,input::mouseY()/3); + print(0,30,input::mouseBtn(1)?1:0); + print(0,40,input::mouseBtn(2)?1:0); + print(0,50,input::mouseBtn(3)?1:0); draw::render(); return true;