movey boy
This commit is contained in:
27
code/first.c
27
code/first.c
@@ -8,17 +8,22 @@
|
|||||||
|
|
||||||
#include "vulkan/core.h"
|
#include "vulkan/core.h"
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
#include "game/impl/player.c"
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
(void)argc;
|
(void)argc;
|
||||||
(void)argv;
|
(void)argv;
|
||||||
|
|
||||||
if (!SDL_Init(SDL_INIT_VIDEO)) {
|
if (!SDL_Init(SDL_INIT_VIDEO))
|
||||||
|
{
|
||||||
printf("[Error] :: Failed to initialise SDL3 (%s)\n", SDL_GetError());
|
printf("[Error] :: Failed to initialise SDL3 (%s)\n", SDL_GetError());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Window *window = SDL_CreateWindow("Ludum", 1280, 720, SDL_WINDOW_HIGH_PIXEL_DENSITY);
|
SDL_Window *window = SDL_CreateWindow("Ludum", 1280, 720, SDL_WINDOW_HIGH_PIXEL_DENSITY);
|
||||||
if (!window) {
|
if (!window)
|
||||||
|
{
|
||||||
printf("[Error] :: Failed to create window (%s)\n", SDL_GetError());
|
printf("[Error] :: Failed to create window (%s)\n", SDL_GetError());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -26,10 +31,19 @@ int main(int argc, char **argv) {
|
|||||||
Vk_Setup(window);
|
Vk_Setup(window);
|
||||||
|
|
||||||
bool running = true;
|
bool running = true;
|
||||||
while (running) {
|
Player player;
|
||||||
|
player.pos.x = 0;
|
||||||
|
player.pos.y = 0;
|
||||||
|
while (running)
|
||||||
|
{
|
||||||
SDL_Event e;
|
SDL_Event e;
|
||||||
while (SDL_PollEvent(&e)) {
|
while (SDL_PollEvent(&e))
|
||||||
if (e.type == SDL_EVENT_QUIT) { running = false; }
|
{
|
||||||
|
PlayerUpdate(&e, &player);
|
||||||
|
if (e.type == SDL_EVENT_QUIT)
|
||||||
|
{
|
||||||
|
running = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int w, h;
|
int w, h;
|
||||||
@@ -37,7 +51,6 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
Vk_Frame *frame = Vk_FrameBegin(window);
|
Vk_Frame *frame = Vk_FrameBegin(window);
|
||||||
VkCommandBuffer cmd = frame->cmd;
|
VkCommandBuffer cmd = frame->cmd;
|
||||||
|
|
||||||
VkImageMemoryBarrier2 colour_optimal = {0};
|
VkImageMemoryBarrier2 colour_optimal = {0};
|
||||||
colour_optimal.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2;
|
colour_optimal.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER_2;
|
||||||
colour_optimal.srcStageMask = VK_PIPELINE_STAGE_2_NONE;
|
colour_optimal.srcStageMask = VK_PIPELINE_STAGE_2_NONE;
|
||||||
|
|||||||
22
code/game/impl/player.c
Normal file
22
code/game/impl/player.c
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#include "../player.h"
|
||||||
|
|
||||||
|
void PlayerUpdate(SDL_Event *event, Player *player)
|
||||||
|
{
|
||||||
|
SDL_KeyboardEvent key = event->key;
|
||||||
|
if (key.key == SDLK_W)
|
||||||
|
{
|
||||||
|
player->pos.y += 10;
|
||||||
|
}
|
||||||
|
if (key.key == SDLK_A)
|
||||||
|
{
|
||||||
|
player->pos.x -= 10;
|
||||||
|
}
|
||||||
|
if (key.key == SDLK_D)
|
||||||
|
{
|
||||||
|
player->pos.x += 10;
|
||||||
|
}
|
||||||
|
if (key.key == SDLK_S)
|
||||||
|
{
|
||||||
|
player->pos.y -= 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
11
code/game/player.h
Normal file
11
code/game/player.h
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#include "core/types.h"
|
||||||
|
#include <SDL3/SDL_events.h>
|
||||||
|
#include "../core/macros.h"
|
||||||
|
|
||||||
|
typedef struct Player Player;
|
||||||
|
struct Player
|
||||||
|
{
|
||||||
|
V2f pos;
|
||||||
|
};
|
||||||
|
|
||||||
|
function void PlayerUpdate(SDL_Event *event, Player *player);
|
||||||
Reference in New Issue
Block a user