init
This commit is contained in:
commit
de460abd29
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
.vscode
|
||||
build/
|
40
Makefile
Normal file
40
Makefile
Normal file
@ -0,0 +1,40 @@
|
||||
CPPC = g++
|
||||
COMMON_CPPC_FLAGS = -std=c++23 -Wall -Wextra -lSDL3 -lSDL3_image `pkg-config --cflags --libs sdl3` -Wno-write-strings
|
||||
CPPC_FLAGS = -O3 $(COMMON_CPPC_FLAGS)
|
||||
DEBUG_FLAGS = -ggdb $(COMMON_CPPC_FLAGS)
|
||||
DEBUG_ASANITIZE = -fsanitize=address -ggdb -fno-omit-frame-pointer $(COMMON_CPPC_FLAGS)
|
||||
|
||||
SRC_PATH := src
|
||||
OBJ_PATH := build/obj
|
||||
BIN_PATH := build/bin
|
||||
BIN_NAME := Vector_blow
|
||||
|
||||
SRC_FILES := $(shell find $(SRC_PATH) -name '*.cpp')
|
||||
OBJ_FILES := $(patsubst $(SRC_PATH)/%.cpp,$(OBJ_PATH)/%.o,$(SRC_FILES))
|
||||
|
||||
all: make-build-dir $(BIN_PATH)/$(BIN_NAME)
|
||||
|
||||
|
||||
debug: CPPC_FLAGS = $(DEBUG_FLAGS)
|
||||
debug: make-build-dir $(BIN_PATH)/$(BIN_NAME)
|
||||
|
||||
asan: CPPC_FLAGS = $(DEBUG_ASANITIZE)
|
||||
asan: make-build-dir $(BIN_PATH)/$(BIN_NAME)
|
||||
|
||||
make-build-dir:
|
||||
mkdir -p $(OBJ_PATH)
|
||||
mkdir -p $(BIN_PATH)
|
||||
|
||||
|
||||
$(BIN_PATH)/$(BIN_NAME): $(OBJ_FILES)
|
||||
$(CPPC) $(CPPC_FLAGS) $^ -o $@
|
||||
|
||||
|
||||
$(OBJ_PATH)/%.o: $(SRC_PATH)/%.cpp
|
||||
$(CPPC) $(CPPC_FLAGS) -c $< -o $@
|
||||
|
||||
|
||||
clean:
|
||||
rm -fr build
|
||||
|
||||
.PHONY: all clean debug asan
|
BIN
assets/player_ship.pdf
Normal file
BIN
assets/player_ship.pdf
Normal file
Binary file not shown.
262
assets/player_ship.svg
Normal file
262
assets/player_ship.svg
Normal file
@ -0,0 +1,262 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
version="1.1"
|
||||
id="svg1"
|
||||
width="128"
|
||||
height="26"
|
||||
viewBox="0 0 128 25.999998"
|
||||
sodipodi:docname="player_ship.svg"
|
||||
inkscape:version="1.4.2 (ebf0e940d0, 2025-05-08)"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg">
|
||||
<defs
|
||||
id="defs1" />
|
||||
<sodipodi:namedview
|
||||
id="namedview1"
|
||||
pagecolor="#000000"
|
||||
bordercolor="#999999"
|
||||
borderopacity="1"
|
||||
inkscape:showpageshadow="2"
|
||||
inkscape:pageopacity="0"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#d1d1d1"
|
||||
inkscape:zoom="9.36"
|
||||
inkscape:cx="93.536325"
|
||||
inkscape:cy="25.267094"
|
||||
inkscape:window-width="1918"
|
||||
inkscape:window-height="1038"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="20"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="g1"
|
||||
showguides="true">
|
||||
<inkscape:page
|
||||
x="0"
|
||||
y="0"
|
||||
inkscape:label="1"
|
||||
id="page1"
|
||||
width="128"
|
||||
height="25.999998"
|
||||
margin="0"
|
||||
bleed="0" />
|
||||
</sodipodi:namedview>
|
||||
<g
|
||||
id="g1"
|
||||
inkscape:groupmode="layer"
|
||||
inkscape:label="1">
|
||||
<g
|
||||
id="g42"
|
||||
inkscape:label="ship"
|
||||
transform="matrix(1.9849534,0,0,1.9084402,-723.31193,-1058.1333)">
|
||||
<path
|
||||
id="path2"
|
||||
d="m 96.55,147 v 1.5"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path3"
|
||||
d="m 96.55,148.5 1,0.25"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path4"
|
||||
d="m 97.55,148.75 -0.5,1.5"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path5"
|
||||
d="m 97.05,150.25 h 2"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path6"
|
||||
d="m 99.05,150.25 1.5,-1.5"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path7"
|
||||
d="m 100.55,148.75 3,0.4"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path8"
|
||||
d="m 103.55,149.15 v -0.4"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path9"
|
||||
d="m 103.55,148.75 h 2"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path10"
|
||||
d="m 105.55,148.75 0.9,-0.7"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path11"
|
||||
d="m 106.45,148.05 h 3.5"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path12"
|
||||
d="m 109.95,148.05 -0.5,-0.5"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path13"
|
||||
d="m 109.45,147.55 h 3"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path14"
|
||||
d="m 112.45,147.55 1,-0.5"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path15"
|
||||
d="M 110.45,146.75 H 97.55"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path16"
|
||||
d="m 97.55,146.75 -1,0.25"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path17"
|
||||
d="m 110.45,146.75 0.75,0.075"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path18"
|
||||
d="m 111.2,146.825 0.75,0.075"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path19"
|
||||
d="m 111.95,146.9 0.75,0.075"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path20"
|
||||
d="m 112.7,146.975 0.75,0.075"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path21"
|
||||
d="m 106.45,148.05 -0.2,-0.3"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.05;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path22"
|
||||
d="m 106.25,147.75 h -2.5"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.05;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path23"
|
||||
d="m 103.75,147.75 v 1"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.05;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path24"
|
||||
d="m 108.55,148.05 -0.2,-0.3"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.05;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path25"
|
||||
d="m 108.35,147.75 h -0.7"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.05;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path26"
|
||||
d="m 107.65,147.75 0.2,0.3"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.05;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path27"
|
||||
d="m 108.25,147.75 0.2,0.3"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.05;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path28"
|
||||
d="m 108.15,147.75 0.2,0.3"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.05;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path29"
|
||||
d="m 108.05,147.75 0.2,0.3"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.05;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path30"
|
||||
d="m 107.95,147.75 0.2,0.3"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.05;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path31"
|
||||
d="m 107.85,147.75 0.2,0.3"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.05;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path32"
|
||||
d="m 107.75,147.75 0.2,0.3"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.05;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path33"
|
||||
d="m 103.55,148.95 h 0.3"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.05;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path34"
|
||||
d="m 104.05,148.75 -0.004,0.042 -0.0132,0.0402 -0.0214,0.0365 -0.0285,0.0312 -0.0345,0.0245 -0.0388,0.0167 -0.0415,0.008 -0.0177,7.8e-4"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.05;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path35"
|
||||
d="m 97.55,148.75 h 3"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path36"
|
||||
d="m 97.55,147.75 h 3"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path37"
|
||||
d="m 99.05,147.45 h -2"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path38"
|
||||
d="m 97.55,147.75 -0.5,-0.3"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path39"
|
||||
d="m 99.05,147.45 1.5,0.3"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path40"
|
||||
d="m 110.825,146.7875 h 1.8"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.05;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path41"
|
||||
d="m 112.625,146.7875 v 0.1782"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.05;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
<path
|
||||
id="path42"
|
||||
d="m 112.625,146.8766 -1.05,-0.0141"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.05;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,0,1122.64)" />
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 14 KiB |
4802
misc/player_ship.dxf
Normal file
4802
misc/player_ship.dxf
Normal file
File diff suppressed because it is too large
Load Diff
13
src/const.hpp
Normal file
13
src/const.hpp
Normal file
@ -0,0 +1,13 @@
|
||||
#include <SDL3/SDL_stdinc.h>
|
||||
|
||||
#ifndef CONST_NS
|
||||
#define CONST_NS
|
||||
|
||||
constexpr int SCREEN_WIDTH = 1600;
|
||||
constexpr int SCREEN_HEIGHT = 1200;
|
||||
constexpr int WORLD_WIDTH = 20000;
|
||||
constexpr int WORLD_HEIGHT = 200000;
|
||||
constexpr int TARGET_FPS = 120;
|
||||
constexpr Uint64 TARGET_FRAME_TIME_NS = 1'000'000'000 / TARGET_FPS;
|
||||
|
||||
#endif
|
127
src/main.cpp
Normal file
127
src/main.cpp
Normal file
@ -0,0 +1,127 @@
|
||||
#include "const.hpp"
|
||||
#include "types.hpp"
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_events.h>
|
||||
#include <SDL3/SDL_iostream.h>
|
||||
#include <SDL3/SDL_render.h>
|
||||
#include <SDL3/SDL_scancode.h>
|
||||
#include <SDL3/SDL_stdinc.h>
|
||||
#include <SDL3/SDL_surface.h>
|
||||
#include <SDL3/SDL_video.h>
|
||||
#include <SDL3_image/SDL_image.h>
|
||||
#include <cstring>
|
||||
|
||||
sdl_session main_sdl_session;
|
||||
|
||||
#define WIDTH_RATIO 15
|
||||
#define HEIGHT_RATIO 41.53846153846154
|
||||
#define MIN_INPUT_DELAY 0
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
|
||||
const SDL_DisplayMode *mode =
|
||||
SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay());
|
||||
|
||||
main_sdl_session.window =
|
||||
SDL_CreateWindow("Vector Blow", mode->w, mode->h, SDL_WINDOW_FULLSCREEN);
|
||||
|
||||
main_sdl_session.renderer =
|
||||
SDL_CreateRenderer(main_sdl_session.window, "gpu,vulcan");
|
||||
|
||||
SDL_Texture *player_ship_texture = nullptr;
|
||||
{
|
||||
SDL_IOStream *texture_file = SDL_IOFromFile("assets/player_ship.svg", "r");
|
||||
SDL_Surface *player_ship_surface = IMG_LoadSizedSVG_IO(
|
||||
texture_file,
|
||||
static_cast<int>(static_cast<double>(mode->w) /
|
||||
static_cast<double>(WIDTH_RATIO)),
|
||||
static_cast<int>(static_cast<double>(mode->h) /
|
||||
static_cast<double>(HEIGHT_RATIO)));
|
||||
|
||||
SDL_CloseIO(texture_file);
|
||||
|
||||
player_ship_texture = SDL_CreateTextureFromSurface(
|
||||
main_sdl_session.renderer, player_ship_surface);
|
||||
SDL_DestroySurface(player_ship_surface);
|
||||
}
|
||||
|
||||
SDL_FRect player_ship_rect = {
|
||||
0, 0,
|
||||
static_cast<float>(static_cast<double>(mode->w) /
|
||||
static_cast<double>(WIDTH_RATIO)),
|
||||
static_cast<float>(static_cast<double>(mode->h) /
|
||||
static_cast<double>(HEIGHT_RATIO))};
|
||||
|
||||
bool running = true;
|
||||
Uint64 lastFrameTime = SDL_GetTicksNS();
|
||||
float deltaTime = 0.0f;
|
||||
|
||||
Uint8 player_ship_speed = 1;
|
||||
while (running) {
|
||||
const Uint64 frameStart = SDL_GetTicksNS();
|
||||
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_EVENT_QUIT:
|
||||
running = false;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const bool *keystate = SDL_GetKeyboardState(NULL);
|
||||
static Uint32 last_toggle_direction[4];
|
||||
std::memset(last_toggle_direction, 0, sizeof(last_toggle_direction));
|
||||
if ((keystate[SDL_SCANCODE_DOWN] || keystate[SDL_SCANCODE_S]) &&
|
||||
(SDL_GetTicks() - last_toggle_direction[0] > MIN_INPUT_DELAY)) {
|
||||
player_ship_rect.y += player_ship_speed;
|
||||
last_toggle_direction[0] = SDL_GetTicks();
|
||||
}
|
||||
if ((keystate[SDL_SCANCODE_UP] || keystate[SDL_SCANCODE_W]) &&
|
||||
(SDL_GetTicks() - last_toggle_direction[1] > MIN_INPUT_DELAY)) {
|
||||
player_ship_rect.y -= player_ship_speed;
|
||||
last_toggle_direction[1] = SDL_GetTicks();
|
||||
}
|
||||
if ((keystate[SDL_SCANCODE_RIGHT] || keystate[SDL_SCANCODE_D]) &&
|
||||
(SDL_GetTicks() - last_toggle_direction[2] > MIN_INPUT_DELAY)) {
|
||||
player_ship_rect.x += player_ship_speed;
|
||||
last_toggle_direction[2] = SDL_GetTicks();
|
||||
}
|
||||
if ((keystate[SDL_SCANCODE_LEFT] || keystate[SDL_SCANCODE_A]) &&
|
||||
(SDL_GetTicks() - last_toggle_direction[3] > MIN_INPUT_DELAY)) {
|
||||
player_ship_rect.x -= player_ship_speed;
|
||||
last_toggle_direction[3] = SDL_GetTicks();
|
||||
}
|
||||
|
||||
SDL_SetRenderDrawColor(main_sdl_session.renderer, 0, 0, 0, 255);
|
||||
SDL_RenderClear(main_sdl_session.renderer);
|
||||
|
||||
SDL_RenderTexture(main_sdl_session.renderer, player_ship_texture, nullptr,
|
||||
&player_ship_rect);
|
||||
|
||||
SDL_RenderPresent(main_sdl_session.renderer);
|
||||
|
||||
const Uint64 frameTime = SDL_GetTicksNS() - frameStart;
|
||||
if (frameTime < TARGET_FRAME_TIME_NS) {
|
||||
const Uint64 sleepTime = TARGET_FRAME_TIME_NS - frameTime;
|
||||
if (sleepTime >= 2'000'000) {
|
||||
SDL_DelayNS(sleepTime - 2'000'000);
|
||||
}
|
||||
while (SDL_GetTicksNS() - frameStart < TARGET_FRAME_TIME_NS) {
|
||||
}
|
||||
}
|
||||
|
||||
deltaTime = (SDL_GetTicksNS() - lastFrameTime) / 1e9f;
|
||||
lastFrameTime = SDL_GetTicksNS();
|
||||
}
|
||||
|
||||
SDL_DestroyTexture(player_ship_texture);
|
||||
SDL_DestroyRenderer(main_sdl_session.renderer);
|
||||
SDL_DestroyWindow(main_sdl_session.window);
|
||||
SDL_Quit();
|
||||
|
||||
return 0;
|
||||
}
|
85
src/types.hpp
Normal file
85
src/types.hpp
Normal file
@ -0,0 +1,85 @@
|
||||
#include "const.hpp"
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3_image/SDL_image.h>
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <optional>
|
||||
|
||||
#ifndef TYPES_NS
|
||||
#define TYPES_NS
|
||||
|
||||
struct Angle {
|
||||
private:
|
||||
float value{0};
|
||||
|
||||
void normalize() {
|
||||
value = std::fmod(value, 360);
|
||||
if (value < 0)
|
||||
value += 360; // Handle negative values
|
||||
}
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Angle(int val = 0) : value(val) { normalize(); }
|
||||
|
||||
// Assignment operator
|
||||
Angle &operator=(int val) {
|
||||
value = val;
|
||||
normalize();
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Compound assignment
|
||||
Angle &operator+=(int rhs) {
|
||||
value += rhs;
|
||||
normalize();
|
||||
return *this;
|
||||
}
|
||||
|
||||
Angle &operator-=(int rhs) {
|
||||
value -= rhs;
|
||||
normalize();
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Type conversion
|
||||
operator int() const { return value; }
|
||||
|
||||
// Stream output
|
||||
friend std::ostream &operator<<(std::ostream &os, const Angle &a) {
|
||||
return os << a.value;
|
||||
}
|
||||
};
|
||||
|
||||
struct basic_cords {
|
||||
float x;
|
||||
float y;
|
||||
};
|
||||
|
||||
struct Entity {
|
||||
SDL_FRect position;
|
||||
SDL_FRect Tposition;
|
||||
bool gotoT = false;
|
||||
SDL_Texture *texture;
|
||||
SDL_Rect srcRect;
|
||||
float speed;
|
||||
Angle angle = 0;
|
||||
|
||||
basic_cords Central_position(std::optional<float> x = std::nullopt,
|
||||
std::optional<float> y = std::nullopt) {
|
||||
if (x != std::nullopt) {
|
||||
position.x = *x - position.w / 2;
|
||||
}
|
||||
if (y != std::nullopt) {
|
||||
position.y = *y - position.h / 2;
|
||||
}
|
||||
|
||||
return {position.x + position.w / 2, position.y + position.h / 2};
|
||||
}
|
||||
};
|
||||
|
||||
struct sdl_session {
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
};
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user