added gamepad stuffies

This commit is contained in:
DaniTheSkunk 2023-01-20 08:30:34 +00:00
parent fdfb5b8032
commit cd9a5251e0
7 changed files with 72 additions and 11 deletions

View File

@ -1,19 +1,27 @@
#include <gsa.h>
void init() {
sprites[0].tile = 2;
sprites[0].x = 10;
sprites[0].y = 10;
i32 x, y;
sprites[1].tile = 3;
sprites[1].x = 10;
sprites[1].y = 100;
for(y = 0; y < 11; ++y) {
for(x = 0; x < 19; ++x) {
maps[0].tiles[x][y] = 0x1000;
}
}
maps[0].tiles[20][1] = 1;
for(y = 0; y < 11; y += 2) {
maps[0].tiles[0][y] = 0x1101;
maps[0].tiles[1][y] = 0x1102;
maps[0].tiles[0][y + 1] = 0x1201;
maps[0].tiles[1][y + 1] = 0x1202;
maps[0].tiles[17][y] = 0x1101;
maps[0].tiles[18][y] = 0x1102;
maps[0].tiles[17][y + 1] = 0x1201;
maps[0].tiles[18][y + 1] = 0x1202;
}
}
void tick() {
sprites[0].x += 1;
sprites[1].x += 0;
maps[0].scrollx += 1;
}

BIN
gfx.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 21 KiB

22
include/gamepad.h Normal file
View File

@ -0,0 +1,22 @@
#ifndef GUARD_F8BB6BA29F6FB6745AF8B6E15CD1C086
#define GUARD_F8BB6BA29F6FB6745AF8B6E15CD1C086
#include "gamepad.h"
#include "types.h"
#define SW_MAX_GAMEPADS 4
#define SW_MAX_GAMEPAD_AXES 4
#define SW_MAX_GAMEPAD_BUTTONS 14
struct sw_gamepad {
f32 axes[SW_MAX_GAMEPAD_AXES];
bool button_down;
bool button_pressed;
};
extern struct sw_gamepad sw_gamepads[SW_MAX_GAMEPADS];
void sw_gamepad_static_init();
void sw_gamepad_tick();
#endif /* GUARD_F8BB6BA29F6FB6745AF8B6E15CD1C086 */

View File

@ -44,6 +44,7 @@ skunk_sources = [
'src/error.c',
'src/file.c',
'src/framebuffer.c',
'src/gamepad.c',
'src/gsa.c',
'src/image32.c',
'src/image8.c',

28
src/gamepad.c Normal file
View File

@ -0,0 +1,28 @@
#include "gamepad.h"
#include "GLFW/glfw3.h"
#include "string.h"
struct sw_gamepad sw_gamepads[SW_MAX_GAMEPADS];
void sw_gamepad_static_init() {
memset(sw_gamepads, 0, sizeof(sw_gamepads));
}
void sw_gamepad_tick() {
i32 i, j;
GLFWgamepadstate state;
for(i = 0; i < SW_MAX_GAMEPADS; ++i) {
if(glfwGetGamepadState(i, &state)) {
for(j = 0; j < SW_MAX_GAMEPAD_AXES; ++j) {
sw_gamepads[i].axes[j] = state.axes[j];
}
for(j = 0; j < SW_MAX_GAMEPAD_BUTTONS; ++j) {
bool down = state.buttons[j];
sw_gamepads[i].button_pressed =
!sw_gamepads[i].button_pressed && down;
sw_gamepads[i].button_down = down;
}
}
}
}

View File

@ -44,7 +44,7 @@ static struct sw_shaderprogram program;
static u32 vbo, vao;
#define MAX_RENDER_VERTS 60
#define MAX_RENDER_VERTS 10000
struct render_vert {
f32 x, y, tx, ty;

View File

@ -7,6 +7,7 @@
#include "GLFW/glfw3.h"
#include "error.h"
#include "framebuffer.h"
#include "gamepad.h"
#include "scaler.h"
#include "shaders.h"
#include "vec2i.h"
@ -52,8 +53,9 @@ struct sw_window *sw_window_create(struct sw_vec2i size, char *title) {
sw_log("setup ogl defaults");
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
/* glEnable(GL_DEPTH_TEST); */
sw_gamepad_static_init();
sw_shaders_static_init();
sw_framebuffer_static_init(); /* TODO: move elsewhere */
win->_scaler_fb = sw_framebuffer_create(size);