From 794f8fc43659a33b11e648a8f93289ddd5c64804 Mon Sep 17 00:00:00 2001 From: JailDoctor Date: Sat, 25 Sep 2021 20:26:37 +0200 Subject: [PATCH] mouse support, solved some funcs clash on linux, started sprite editor --- .gitignore | 1 + .vscode/launch.json | 29 ----------------------------- .vscode/settings.json | 8 -------- .vscode/tasks.json | 32 -------------------------------- main.cpp | 13 +++++++++++-- mini.cpp | 31 ++++++++++++++++++++++++++----- mini.h | 9 ++++++++- 7 files changed, 46 insertions(+), 77 deletions(-) delete mode 100644 .vscode/launch.json delete mode 100644 .vscode/settings.json delete mode 100644 .vscode/tasks.json diff --git a/.gitignore b/.gitignore index 596e6d0..3e96560 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ mini.exe +mini diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index e66abde..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "g++.exe - Compilar y depurar el archivo activo", - "type": "cppdbg", - "request": "launch", - "program": "${fileDirname}\\mini.exe", - "args": [], - "stopAtEntry": false, - "cwd": "${fileDirname}", - "environment": [], - "externalConsole": false, - "MIMode": "gdb", - "miDebuggerPath": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe", - "setupCommands": [ - { - "description": "Habilitar la impresión con sangría para gdb", - "text": "-enable-pretty-printing", - "ignoreFailures": true - } - ], - "preLaunchTask": "C/C++: g++.exe compilar archivo activo" - } - ] -} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index bd284c1..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "files.associations": { - "cmath": "cpp", - "*.tcc": "cpp", - "cinttypes": "cpp", - "cstdlib": "cpp" - } -} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index 2d3ceec..0000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "type": "cppbuild", - "label": "C/C++: g++.exe compilar archivo activo", - "command": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe", - "args": [ - "-g", - "*.cpp", - "./lua/*.c", - "-lmingw32", - "-lSDL2main", - "-lSDL2", - //"-mwindows", - "-o", - "${fileDirname}\\mini.exe" - ], - "options": { - "cwd": "${fileDirname}" - }, - "problemMatcher": [ - "$gcc" - ], - "group": { - "kind": "build", - "isDefault": true - }, - "detail": "compilador: \"C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe\"" - } - ] -} \ No newline at end of file diff --git a/main.cpp b/main.cpp index b1f6ed3..b28d833 100644 --- a/main.cpp +++ b/main.cpp @@ -8,8 +8,17 @@ void do_terminal() { } void do_sprite_editor() { - cls(); - sspr(0, 0, 8, 8, 8, 8, 64, 64); + cls(14); + palt(0, false); + rectfill(0, 0, 160, 7, 2); + rectfill(0, 115, 160, 119, 2); + sspr(0, 0, 128, 32, 0, 83); + sspr(0, 0, 8, 8, 8, 16, 64, 64); + rect(8, 16, 72, 80, 0); + spr(17, mouseX(), mouseY()); + if (mouseButton(1) && mouseX()>=8 && mouseY()>=8 && mouseX()<72 && mouseY()<72) { + sset((mouseX()-8)/8, (mouseY()-16)/8); + } } void loop() { diff --git a/mini.cpp b/mini.cpp index 59d173a..e8efd31 100644 --- a/mini.cpp +++ b/mini.cpp @@ -58,6 +58,9 @@ int debug_cursor = 0; const Uint8 *keys; Uint8 key_just_pressed = 0; +int mouse_x, mouse_y; +Uint32 mouse_buttons; + void reinit() { ds::pen_color = 6; ds::cam[0] = ds::cam[1] = 0; @@ -130,7 +133,9 @@ int main(int argc,char*argv[]){ } } keys = SDL_GetKeyboardState(NULL); - + mouse_buttons = SDL_GetMouseState(&mouse_x, &mouse_y); + mouse_x /= 4; mouse_y /= 4; + if (lua_is_playing()) { lua_call_update(); } else { @@ -595,6 +600,18 @@ bool btnp(uint8_t i) { return key_just_pressed == i; } +int mouseX() { + return mouse_x; +} + +int mouseY() { + return mouse_y; +} + +bool mouseButton(uint8_t i) { + return mouse_buttons & SDL_BUTTON(i); +} + float time() { return float(SDL_GetTicks())/1000.0f; } @@ -603,10 +620,6 @@ float time() { return SDL_fabsf(x); }*/ -float ceil(float x) { - return SDL_ceilf(x); -} - float flr(float x) { return SDL_floorf(x); } @@ -615,6 +628,12 @@ float sgn(float x) { return x >= 0 ? 1 : -1; } +#ifndef __LINUX__ + +float ceil(float x) { + return SDL_ceilf(x); +} + float sin(float x) { return SDL_sinf(x); } @@ -631,6 +650,8 @@ float sqrt(float x) { return SDL_sqrtf(x); } +#endif + float max(float x, float y) { return SDL_max(x, y); } diff --git a/mini.h b/mini.h index 5650c65..30d1ab4 100644 --- a/mini.h +++ b/mini.h @@ -181,17 +181,24 @@ void map(uint8_t celx, uint8_t cely, int sx, int sy, uint8_t celw, uint8_t celh, bool btn(uint8_t i); bool btnp(uint8_t i); +int mouseX(); +int mouseY(); +bool mouseButton(uint8_t i); + float time(); //float abs(float x); -float ceil(float x); + float flr(float x); float sgn(float x); +#ifndef __LINUX__ +float ceil(float x); float sin(float x); float cos(float x); float atan2(float dx, float dy); float sqrt(float x); +#endif float max(float x, float y); float mid(float x, float y, float z);