MXVK Vulkan Framework 0.35.0
C++20 Vulkan rendering framework for practical 2D and 3D application development with SDL3.
Loading...
Searching...
No Matches
space.cpp File Reference
#include "mxvk/argz.hpp"
#include "mxvk/mxvk.hpp"
#include "mxvk/mxvk_exception.hpp"
#include <SDL3/SDL.h>
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <format>
#include <iostream>

Go to the source code of this file.

Classes

struct  Asteroid
struct  Particle
struct  Projectile
struct  Ship
class  SpaceRoxWindow
struct  Star

Macros

#define asteroids_ASSET_DIR   "."
#define M_PI   3.14159265358979323846

Enumerations

enum  GameState { STATE_COUNTDOWN , STATE_LAUNCH , STATE_PLAYING , STATE_GAMEOVER }

Functions

template<typename Func>
void bresenhamLine (int x0, int y0, int x1, int y1, Func plot)
int main (int argc, char **argv)

Variables

constexpr int ASTEROID_VERTICES = 8
constexpr int EXPLOSION_DURATION = 90
constexpr int FIRE_COOLDOWN = 5
constexpr int FIRE_DELAY = 3
constexpr int GAME_H = 360
constexpr int GAME_W = 640
constexpr int LARGE_ASTEROID_POINTS = 20
constexpr int MAX_ASTEROIDS = 30
constexpr int MAX_PARTICLES = 40
constexpr int MAX_PROJECTILES = 50
constexpr int MEDIUM_ASTEROID_POINTS = 50
constexpr float MIN_ASTEROID_RADIUS = 8.0f
constexpr int PROJECTILE_LIFETIME = 60
constexpr float PROJECTILE_SPEED = 5.0f
constexpr int SHOTS_PER_BURST = 5
constexpr int SMALL_ASTEROID_POINTS = 100
constexpr int STAR_COUNT = 800

Macro Definition Documentation

◆ asteroids_ASSET_DIR

#define asteroids_ASSET_DIR   "."

Definition at line 22 of file space.cpp.

◆ M_PI

#define M_PI   3.14159265358979323846

Definition at line 18 of file space.cpp.

Enumeration Type Documentation

◆ GameState

enum GameState
Enumerator
STATE_COUNTDOWN 
STATE_LAUNCH 
STATE_PLAYING 
STATE_GAMEOVER 

Definition at line 92 of file space.cpp.

@ STATE_GAMEOVER
Definition space.cpp:92
@ STATE_COUNTDOWN
Definition space.cpp:92
@ STATE_LAUNCH
Definition space.cpp:92
@ STATE_PLAYING
Definition space.cpp:92

Function Documentation

◆ bresenhamLine()

template<typename Func>
void bresenhamLine ( int x0,
int y0,
int x1,
int y1,
Func plot )

Definition at line 94 of file space.cpp.

94 {
95 int dx = abs(x1 - x0);
96 int dy = abs(y1 - y0);
97 int sx = (x0 < x1) ? 1 : -1;
98 int sy = (y0 < y1) ? 1 : -1;
99 int err = dx - dy;
100 while (true) {
101 plot(x0, y0);
102 if (x0 == x1 && y0 == y1)
103 break;
104 int e2 = 2 * err;
105 if (e2 > -dy) {
106 err -= dy;
107 x0 += sx;
108 }
109 if (e2 < dx) {
110 err += dx;
111 y0 += sy;
112 }
113 }
114}

◆ main()

int main ( int argc,
char ** argv )

Definition at line 1368 of file space.cpp.

1368 {
1369 Arguments args = proc_args(argc, argv);
1370 try {
1371 SpaceRoxWindow window(args.path, args.width, args.height, args.fullscreen, args.enable_vsync);
1372 window.loop();
1373 } catch (mxvk::Exception &e) {
1374 std::cerr << std::format("mxvk: Exception: {}\n", e.text());
1375 return EXIT_FAILURE;
1376 } catch (ArgException<std::string> &e) {
1377 std::cerr << std::format("mxvk: Argument Exception: {}\n", e.text());
1378 return EXIT_FAILURE;
1379 }
1380 return EXIT_SUCCESS;
1381}
Arguments proc_args(int &argc, char **argv)
Parse standard libmx2 command-line options from main()'s argv.
Definition argz.hpp:854
Exception thrown by Argz::proc() on unrecognised or malformed options.
Definition argz.hpp:169
String text() const
Definition argz.hpp:173
std::string text() const
Plain data structure returned by proc_args() with all common libmx2 CLI options.
Definition argz.hpp:718
bool fullscreen
Whether fullscreen mode was requested.
Definition argz.hpp:724
bool enable_vsync
Enable FIFO present mode / v-sync (--enable-vsync).
Definition argz.hpp:738
int height
Viewport height in pixels (default: 720).
Definition argz.hpp:721
std::string path
Asset root; proc_args() defaults it to the executable directory.
Definition argz.hpp:723
int width
Viewport width in pixels (default: 1280).
Definition argz.hpp:720

Variable Documentation

◆ ASTEROID_VERTICES

int ASTEROID_VERTICES = 8
constexpr

Definition at line 31 of file space.cpp.

◆ EXPLOSION_DURATION

int EXPLOSION_DURATION = 90
constexpr

Definition at line 37 of file space.cpp.

◆ FIRE_COOLDOWN

int FIRE_COOLDOWN = 5
constexpr

Definition at line 34 of file space.cpp.

◆ FIRE_DELAY

int FIRE_DELAY = 3
constexpr

Definition at line 36 of file space.cpp.

◆ GAME_H

int GAME_H = 360
constexpr

Definition at line 26 of file space.cpp.

◆ GAME_W

int GAME_W = 640
constexpr

Definition at line 25 of file space.cpp.

◆ LARGE_ASTEROID_POINTS

int LARGE_ASTEROID_POINTS = 20
constexpr

Definition at line 39 of file space.cpp.

◆ MAX_ASTEROIDS

int MAX_ASTEROIDS = 30
constexpr

Definition at line 29 of file space.cpp.

◆ MAX_PARTICLES

int MAX_PARTICLES = 40
constexpr

Definition at line 30 of file space.cpp.

◆ MAX_PROJECTILES

int MAX_PROJECTILES = 50
constexpr

Definition at line 28 of file space.cpp.

◆ MEDIUM_ASTEROID_POINTS

int MEDIUM_ASTEROID_POINTS = 50
constexpr

Definition at line 40 of file space.cpp.

◆ MIN_ASTEROID_RADIUS

float MIN_ASTEROID_RADIUS = 8.0f
constexpr

Definition at line 38 of file space.cpp.

◆ PROJECTILE_LIFETIME

int PROJECTILE_LIFETIME = 60
constexpr

Definition at line 33 of file space.cpp.

◆ PROJECTILE_SPEED

float PROJECTILE_SPEED = 5.0f
constexpr

Definition at line 32 of file space.cpp.

◆ SHOTS_PER_BURST

int SHOTS_PER_BURST = 5
constexpr

Definition at line 35 of file space.cpp.

◆ SMALL_ASTEROID_POINTS

int SMALL_ASTEROID_POINTS = 100
constexpr

Definition at line 41 of file space.cpp.

◆ STAR_COUNT

int STAR_COUNT = 800
constexpr

Definition at line 27 of file space.cpp.