mouse support, solved some funcs clash on linux, started sprite editor

This commit is contained in:
2021-09-25 20:26:37 +02:00
parent 9dbd952359
commit 794f8fc436
7 changed files with 46 additions and 77 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
mini.exe mini.exe
mini

29
.vscode/launch.json vendored
View File

@@ -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"
}
]
}

View File

@@ -1,8 +0,0 @@
{
"files.associations": {
"cmath": "cpp",
"*.tcc": "cpp",
"cinttypes": "cpp",
"cstdlib": "cpp"
}
}

32
.vscode/tasks.json vendored
View File

@@ -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\""
}
]
}

View File

@@ -8,8 +8,17 @@ void do_terminal() {
} }
void do_sprite_editor() { void do_sprite_editor() {
cls(); cls(14);
sspr(0, 0, 8, 8, 8, 8, 64, 64); 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() { void loop() {

View File

@@ -58,6 +58,9 @@ int debug_cursor = 0;
const Uint8 *keys; const Uint8 *keys;
Uint8 key_just_pressed = 0; Uint8 key_just_pressed = 0;
int mouse_x, mouse_y;
Uint32 mouse_buttons;
void reinit() { void reinit() {
ds::pen_color = 6; ds::pen_color = 6;
ds::cam[0] = ds::cam[1] = 0; ds::cam[0] = ds::cam[1] = 0;
@@ -130,6 +133,8 @@ int main(int argc,char*argv[]){
} }
} }
keys = SDL_GetKeyboardState(NULL); keys = SDL_GetKeyboardState(NULL);
mouse_buttons = SDL_GetMouseState(&mouse_x, &mouse_y);
mouse_x /= 4; mouse_y /= 4;
if (lua_is_playing()) { if (lua_is_playing()) {
lua_call_update(); lua_call_update();
@@ -595,6 +600,18 @@ bool btnp(uint8_t i) {
return key_just_pressed == 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() { float time() {
return float(SDL_GetTicks())/1000.0f; return float(SDL_GetTicks())/1000.0f;
} }
@@ -603,10 +620,6 @@ float time() {
return SDL_fabsf(x); return SDL_fabsf(x);
}*/ }*/
float ceil(float x) {
return SDL_ceilf(x);
}
float flr(float x) { float flr(float x) {
return SDL_floorf(x); return SDL_floorf(x);
} }
@@ -615,6 +628,12 @@ float sgn(float x) {
return x >= 0 ? 1 : -1; return x >= 0 ? 1 : -1;
} }
#ifndef __LINUX__
float ceil(float x) {
return SDL_ceilf(x);
}
float sin(float x) { float sin(float x) {
return SDL_sinf(x); return SDL_sinf(x);
} }
@@ -631,6 +650,8 @@ float sqrt(float x) {
return SDL_sqrtf(x); return SDL_sqrtf(x);
} }
#endif
float max(float x, float y) { float max(float x, float y) {
return SDL_max(x, y); return SDL_max(x, y);
} }

9
mini.h
View File

@@ -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 btn(uint8_t i);
bool btnp(uint8_t i); bool btnp(uint8_t i);
int mouseX();
int mouseY();
bool mouseButton(uint8_t i);
float time(); float time();
//float abs(float x); //float abs(float x);
float ceil(float x);
float flr(float x); float flr(float x);
float sgn(float x); float sgn(float x);
#ifndef __LINUX__
float ceil(float x);
float sin(float x); float sin(float x);
float cos(float x); float cos(float x);
float atan2(float dx, float dy); float atan2(float dx, float dy);
float sqrt(float x); float sqrt(float x);
#endif
float max(float x, float y); float max(float x, float y);
float mid(float x, float y, float z); float mid(float x, float y, float z);