extract game logic to separate file
This commit is contained in:
parent
ef8d4c3ad2
commit
3f9d68252e
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,2 +1,4 @@
|
||||
.vscode
|
||||
build/
|
||||
.cache/
|
||||
build/
|
||||
compile_commands.json
|
BIN
assets/enemy_1.pdf
Normal file
BIN
assets/enemy_1.pdf
Normal file
Binary file not shown.
265
assets/enemy_1.svg
Normal file
265
assets/enemy_1.svg
Normal file
@ -0,0 +1,265 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
version="1.1"
|
||||
id="svg1"
|
||||
width="35.000999"
|
||||
height="18.999001"
|
||||
viewBox="0 0 35.000999 18.999"
|
||||
sodipodi:docname="enemy_1.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="4.439152"
|
||||
inkscape:cx="23.878434"
|
||||
inkscape:cy="61.836134"
|
||||
inkscape:window-width="1918"
|
||||
inkscape:window-height="1038"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="20"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="g1">
|
||||
<inkscape:page
|
||||
x="0"
|
||||
y="0"
|
||||
inkscape:label="1"
|
||||
id="page1"
|
||||
width="35.000999"
|
||||
height="18.999001"
|
||||
margin="0"
|
||||
bleed="0" />
|
||||
</sodipodi:namedview>
|
||||
<g
|
||||
id="g1"
|
||||
inkscape:groupmode="layer"
|
||||
inkscape:label="1">
|
||||
<g
|
||||
id="g43"
|
||||
transform="matrix(0.97840269,0,0,0.97599299,-286.82338,-612.12844)">
|
||||
<path
|
||||
id="path2"
|
||||
d="m 77.8,130.5 h 1.162069"
|
||||
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,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path3"
|
||||
d="M 78.962051,125.5 H 77.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,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path4"
|
||||
d="m 77.5,129.5 v 0.8"
|
||||
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,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path5"
|
||||
d="m 77.5,130 h 1"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.09;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path6"
|
||||
d="M 78.890916,130.18825 78.962069,130.5"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.09;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path7"
|
||||
d="m 78.5,130 0.390916,0.18825"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.09;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path8"
|
||||
d="m 77.5,130.3 0.01878,0.0379 0.02355,0.0352 0.02792,0.0318 0.03182,0.0279 0.03518,0.0235 0.03794,0.0188 0.04006,0.0137 0.04149,0.008 0.04223,0.003 h 0.001"
|
||||
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,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path9"
|
||||
d="M 78,130.5 77.5,130"
|
||||
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,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path10"
|
||||
d="M 78.5,130.5 78,130"
|
||||
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,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path11"
|
||||
d="m 79.232051,126.5 v 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,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path12"
|
||||
d="M 79.232051,128.5 77.5,129.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,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path13"
|
||||
d="m 77.5,125.5 1.732051,1"
|
||||
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,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path14"
|
||||
d="m 77.5,129.5 0.03066,-0.0292 0.03021,-0.0297 0.02975,-0.0301 0.02928,-0.0306 0.0288,-0.0311 0.02832,-0.0315 0.02783,-0.0319 0.02733,-0.0324 0.02683,-0.0328 0.02632,-0.0332 0.02581,-0.0336 0.02528,-0.034 0.02475,-0.0344 0.02422,-0.0347 0.02368,-0.0351 0.02314,-0.0355 0.02259,-0.0358 0.02203,-0.0362 0.02147,-0.0365 0.0209,-0.0368 0.02033,-0.0372 0.01975,-0.0375 0.01917,-0.0378 0.01859,-0.0381 0.018,-0.0383 0.0174,-0.0386 0.0168,-0.0389 0.0162,-0.0391 0.0156,-0.0394 0.01499,-0.0396 0.01437,-0.0399 0.01376,-0.0401 0.01313,-0.0403 0.01251,-0.0405 0.01189,-0.0406 0.01126,-0.0408 0.01062,-0.041 0.01,-0.0412 0.0094,-0.0413 0.0087,-0.0414 0.0081,-0.0416 0.0074,-0.0417 0.0068,-0.0418 0.0061,-0.0419 0.0055,-0.042 0.0048,-0.0421 0.0042,-0.0421 0.0035,-0.0422 0.0029,-0.0423 0.0022,-0.0423 0.0016,-0.0423 9.27e-4,-0.0423 2.72e-4,-0.0423 -3.82e-4,-0.0423 -0.001,-0.0423 -0.0017,-0.0423 -0.0023,-0.0423 -0.003,-0.0422 -0.0036,-0.0422 -0.0043,-0.0421 -0.0049,-0.0421 -0.0056,-0.042 -0.0062,-0.0419 -0.0069,-0.0418 -0.0075,-0.0417 -0.0082,-0.0416 -0.0088,-0.0414 -0.0095,-0.0413 -0.0101,-0.0411 -0.01073,-0.041 -0.01136,-0.0408 -0.01199,-0.0406 -0.01262,-0.0404 -0.01324,-0.0402 -0.01386,-0.04 -0.01448,-0.0398 -0.01509,-0.0396 -0.0157,-0.0393 -0.0163,-0.0391 -0.01691,-0.0388 -0.0175,-0.0386 -0.0181,-0.0383 -0.01869,-0.038 -0.01927,-0.0377 -0.01985,-0.0374 -0.02043,-0.0371 -0.021,-0.0368 -0.02156,-0.0365 -0.02212,-0.0361 -0.02268,-0.0358 -0.02323,-0.0354 -0.02377,-0.0351 -0.02431,-0.0347 -0.02484,-0.0343 -0.02537,-0.0339 -0.02589,-0.0335 -0.02641,-0.0331 -0.02692,-0.0327 -0.02742,-0.0323 -0.02791,-0.0318 -0.0284,-0.0314 -0.02888,-0.031 -0.02936,-0.0305 -0.02983,-0.0301 -0.03029,-0.0296 L 77.5,125.5"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.09;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path15"
|
||||
d="m 78.366025,127.5 0.866026,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,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path16"
|
||||
d="m 78.366025,127.5 0.866026,-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,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path17"
|
||||
d="m 78.799038,127 0.433013,0.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,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path18"
|
||||
d="M 79.232051,127.5 78.799038,128"
|
||||
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,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path19"
|
||||
d="M 78.366025,127.5 H 77.3"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.09;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path20"
|
||||
d="M 77.15,127.24019 77.6,127.5"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.09;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path21"
|
||||
d="m 77.6,127.5 -0.45,0.25981"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.09;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path22"
|
||||
d="M 77.15,127.24019 79.232051,126.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,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path23"
|
||||
d="M 77.15,127.75981 79.232051,128.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,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path24"
|
||||
d="m 77.15,127.75981 0.01976,-0.0375 0.01663,-0.0389 0.01338,-0.0402 0.01005,-0.0411 0.0067,-0.0418 0.0032,-0.0422 -2.54e-4,-0.0423 -0.0037,-0.0422 -0.0072,-0.0417 -0.01055,-0.041 -0.01387,-0.04 -0.01709,-0.0387 -0.01705,-0.0319"
|
||||
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,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path25"
|
||||
d="M 78.962069,130.5 80.5,129.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,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path26"
|
||||
d="M 78.962051,125.5 80.5,126"
|
||||
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,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path27"
|
||||
d="m 80.5,126 0.3,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,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path28"
|
||||
d="m 80.5,129.5 0.3,-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,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path29"
|
||||
d="m 80.8,126.5 h 1.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,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path30"
|
||||
d="m 82.5,126.5 -0.6,-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,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path31"
|
||||
d="m 81.9,126.1 h 3.6"
|
||||
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,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path32"
|
||||
d="m 85.5,126.1 1,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,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path33"
|
||||
d="m 80.8,128.8 h 1.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,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path34"
|
||||
d="m 82.5,128.8 -0.6,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,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path35"
|
||||
d="m 81.9,129.2 h 3.6"
|
||||
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,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path36"
|
||||
d="m 85.5,129.2 1,-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,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path37"
|
||||
d="m 86.5,128.8 v -2.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,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path38"
|
||||
d="m 80.6,128.5 h 1.9"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.09;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path39"
|
||||
d="m 82.5,128.5 0.3,-0.3"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.09;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path40"
|
||||
d="m 80.6,128.5 0.3,-0.3"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.09;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path41"
|
||||
d="m 80.9,128.2 h 1.9"
|
||||
style="fill:none;stroke:#ffffff;stroke-width:0.09;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
transform="matrix(3.7775238,0,0,-3.7799327,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path42"
|
||||
d="m 80.6,128.5 2.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,1.8887619,1120.75)" />
|
||||
<path
|
||||
id="path43"
|
||||
d="m 81.55,128.5 1.25,-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,1.8887619,1120.75)" />
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 16 KiB |
4828
misc/enemy_1.dxf
Normal file
4828
misc/enemy_1.dxf
Normal file
File diff suppressed because it is too large
Load Diff
@ -7,3 +7,8 @@ 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;
|
||||
|
||||
#define WIDTH_RATIO 15
|
||||
#define HEIGHT_RATIO 41.53846153846154
|
||||
#define MIN_INPUT_DELAY_MOVEMENT 0
|
||||
#define MIN_INPUT_DELAY_FIRE 200
|
||||
|
136
src/game_logic.cpp
Normal file
136
src/game_logic.cpp
Normal file
@ -0,0 +1,136 @@
|
||||
#include "const.hpp"
|
||||
#include "main.hpp"
|
||||
#include "projectiles.hpp"
|
||||
#include "types.hpp"
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
// returns true on win and false on lose
|
||||
bool play_level() {
|
||||
ship_type player_ship = []() -> ship_type {
|
||||
SDL_Texture *player_ship_texture = nullptr;
|
||||
|
||||
SDL_IOStream *texture_file = SDL_IOFromFile("assets/player_ship.svg", "r");
|
||||
|
||||
float ship_width = static_cast<float>(static_cast<double>(mode->w) /
|
||||
static_cast<double>(WIDTH_RATIO));
|
||||
float ship_height = static_cast<float>(static_cast<double>(mode->h) /
|
||||
static_cast<double>(HEIGHT_RATIO));
|
||||
|
||||
SDL_Surface *player_ship_surface =
|
||||
IMG_LoadSizedSVG_IO(texture_file, ship_width, ship_height);
|
||||
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, ship_width, ship_height};
|
||||
|
||||
SDL_FPoint gun_offset = {ship_width * 0.9f, ship_height * 0.9f};
|
||||
|
||||
return {player_ship_rect, gun_offset, player_ship_texture};
|
||||
}();
|
||||
bool running = true;
|
||||
Uint64 lastFrameTime = SDL_GetTicksNS();
|
||||
float deltaTime = 0.0f;
|
||||
|
||||
Uint8 player_ship_speed = 1;
|
||||
std::vector<projectile> projectiles;
|
||||
std::vector<ship_type> enemies;
|
||||
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_MOVEMENT)) {
|
||||
if (player_ship.rect.y + player_ship.rect.h < mode->h) {
|
||||
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_MOVEMENT)) {
|
||||
if (player_ship.rect.y > 0) {
|
||||
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_MOVEMENT)) {
|
||||
if (player_ship.rect.x + player_ship.rect.w < mode->w) {
|
||||
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_MOVEMENT)) {
|
||||
if (player_ship.rect.x > 0) {
|
||||
player_ship.rect.x -= player_ship_speed;
|
||||
}
|
||||
last_toggle_direction[3] = SDL_GetTicks();
|
||||
}
|
||||
|
||||
const SDL_MouseButtonFlags mousestate =
|
||||
SDL_GetMouseState(nullptr, nullptr);
|
||||
static Uint32 last_fire = 0;
|
||||
if ((mousestate & SDL_BUTTON_LMASK || keystate[SDL_SCANCODE_SPACE]) &&
|
||||
SDL_GetTicks() - last_fire > MIN_INPUT_DELAY_FIRE) {
|
||||
projectiles.push_back(
|
||||
spawn_projectile({player_ship.rect.x + player_ship.gun_offset.x,
|
||||
player_ship.rect.y + player_ship.gun_offset.y},
|
||||
1, 0, 3, "assets/basic_projectile.svg", nullptr));
|
||||
last_fire = SDL_GetTicks();
|
||||
}
|
||||
}
|
||||
|
||||
SDL_SetRenderDrawColor(main_sdl_session.renderer, 0, 0, 0, 255);
|
||||
SDL_RenderClear(main_sdl_session.renderer);
|
||||
|
||||
for (projectile &p : projectiles) {
|
||||
if (p.rect.x > mode->w || p.rect.y > mode->h) {
|
||||
projectiles.erase(projectiles.begin() + (&p - projectiles.data()));
|
||||
} else { // TODO colision detection
|
||||
step_projectile(p);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
2
src/game_logic.hpp
Normal file
2
src/game_logic.hpp
Normal file
@ -0,0 +1,2 @@
|
||||
#pragma once
|
||||
bool play_level();
|
133
src/main.cpp
133
src/main.cpp
@ -1,5 +1,4 @@
|
||||
#include "const.hpp"
|
||||
#include "projectiles.hpp"
|
||||
#include "game_logic.hpp"
|
||||
#include "types.hpp"
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_events.h>
|
||||
@ -12,23 +11,14 @@
|
||||
#include <SDL3/SDL_timer.h>
|
||||
#include <SDL3/SDL_video.h>
|
||||
#include <SDL3_image/SDL_image.h>
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
sdl_session main_sdl_session;
|
||||
SDL_DisplayMode *mode;
|
||||
|
||||
#define WIDTH_RATIO 15
|
||||
#define HEIGHT_RATIO 41.53846153846154
|
||||
#define MIN_INPUT_DELAY_MOVEMENT 0
|
||||
#define MIN_INPUT_DELAY_FIRE 200
|
||||
const SDL_DisplayMode *mode;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
|
||||
const SDL_DisplayMode *mode =
|
||||
SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay());
|
||||
mode = SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay());
|
||||
|
||||
main_sdl_session.window =
|
||||
SDL_CreateWindow("Vector Blow", mode->w, mode->h, SDL_WINDOW_FULLSCREEN);
|
||||
@ -36,123 +26,8 @@ int main(int argc, char *argv[]) {
|
||||
main_sdl_session.renderer =
|
||||
SDL_CreateRenderer(main_sdl_session.window, "gpu,vulcan");
|
||||
|
||||
player_ship_type player_ship = [&mode]() -> player_ship_type {
|
||||
SDL_Texture *player_ship_texture = nullptr;
|
||||
play_level();
|
||||
|
||||
SDL_IOStream *texture_file = SDL_IOFromFile("assets/player_ship.svg", "r");
|
||||
|
||||
float ship_width = static_cast<float>(static_cast<double>(mode->w) /
|
||||
static_cast<double>(WIDTH_RATIO));
|
||||
float ship_height = static_cast<float>(static_cast<double>(mode->h) /
|
||||
static_cast<double>(HEIGHT_RATIO));
|
||||
|
||||
SDL_Surface *player_ship_surface =
|
||||
IMG_LoadSizedSVG_IO(texture_file, ship_width, ship_height);
|
||||
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, ship_width, ship_height};
|
||||
|
||||
SDL_FPoint gun_offset = {ship_width * 0.9f, ship_height * 0.9f};
|
||||
|
||||
return {player_ship_rect, gun_offset, player_ship_texture};
|
||||
}();
|
||||
bool running = true;
|
||||
Uint64 lastFrameTime = SDL_GetTicksNS();
|
||||
float deltaTime = 0.0f;
|
||||
|
||||
Uint8 player_ship_speed = 1;
|
||||
std::vector<projectile> projectiles;
|
||||
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_MOVEMENT)) {
|
||||
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_MOVEMENT)) {
|
||||
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_MOVEMENT)) {
|
||||
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_MOVEMENT)) {
|
||||
player_ship.rect.x -= player_ship_speed;
|
||||
last_toggle_direction[3] = SDL_GetTicks();
|
||||
}
|
||||
|
||||
const SDL_MouseButtonFlags mousestate =
|
||||
SDL_GetMouseState(nullptr, nullptr);
|
||||
static Uint32 last_fire = 0;
|
||||
if ((mousestate & SDL_BUTTON_LMASK || keystate[SDL_SCANCODE_SPACE]) &&
|
||||
SDL_GetTicks() - last_fire > MIN_INPUT_DELAY_FIRE) {
|
||||
projectiles.push_back(
|
||||
spawn_projectile({player_ship.rect.x + player_ship.gun_offset.x,
|
||||
player_ship.rect.y + player_ship.gun_offset.y},
|
||||
1, 0, 3, "assets/basic_projectile.svg", nullptr));
|
||||
last_fire = SDL_GetTicks();
|
||||
}
|
||||
}
|
||||
|
||||
SDL_SetRenderDrawColor(main_sdl_session.renderer, 0, 0, 0, 255);
|
||||
SDL_RenderClear(main_sdl_session.renderer);
|
||||
|
||||
for (projectile &p : projectiles) {
|
||||
if (p.rect.x > mode->w || p.rect.y > mode->h) {
|
||||
projectiles.erase(projectiles.begin() + (&p - projectiles.data()));
|
||||
} else { // TODO colision detection
|
||||
step_projectile(p);
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
|
@ -1,3 +1,4 @@
|
||||
#pragma once
|
||||
#include "types.hpp"
|
||||
extern sdl_session main_sdl_session;
|
||||
extern sdl_session main_sdl_session;
|
||||
extern SDL_DisplayMode *mode;
|
@ -1,5 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#include "types.hpp"
|
||||
#include <cmath>
|
||||
|
||||
|
@ -5,6 +5,14 @@
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
|
||||
enum enemy_ai_type {
|
||||
RANDOM,
|
||||
FLYER,
|
||||
GUNNER,
|
||||
ACE,
|
||||
BOSS,
|
||||
};
|
||||
|
||||
struct Angle {
|
||||
private:
|
||||
float value{0};
|
||||
@ -105,12 +113,19 @@ struct sdl_session {
|
||||
SDL_Renderer *renderer;
|
||||
};
|
||||
|
||||
struct player_ship_type {
|
||||
struct ship_type {
|
||||
SDL_FRect rect;
|
||||
SDL_FPoint gun_offset;
|
||||
SDL_Texture *texture;
|
||||
};
|
||||
|
||||
struct enemy_type {
|
||||
ship_type ship;
|
||||
enemy_ai_type type;
|
||||
Uint32 last_shot;
|
||||
Uint32 reload_time;
|
||||
};
|
||||
|
||||
struct projectile {
|
||||
SDL_FRect rect;
|
||||
SDL_Texture *texture;
|
||||
|
Loading…
x
Reference in New Issue
Block a user