MXVK Vulkan Framework 0.24.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.

92 {
97};
@ STATE_GAMEOVER
Definition space.cpp:96
@ STATE_COUNTDOWN
Definition space.cpp:93
@ STATE_LAUNCH
Definition space.cpp:94
@ STATE_PLAYING
Definition space.cpp:95

Function Documentation

◆ bresenhamLine()

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

Definition at line 100 of file space.cpp.

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

◆ main()

int main ( int argc,
char ** argv )

Definition at line 1408 of file space.cpp.

1408 {
1409 Arguments args = proc_args(argc, argv);
1410 try {
1411 SpaceRoxWindow window(args.path, args.width, args.height, args.fullscreen, args.enable_vsync);
1412 window.loop();
1413 } catch (mxvk::Exception &e) {
1414 std::cerr << std::format("mxvk: Exception: {}\n", e.text());
1415 return EXIT_FAILURE;
1416 } catch (ArgException<std::string> &e) {
1417 std::cerr << std::format("mxvk: Argument Exception: {}\n", e.text());
1418 return EXIT_FAILURE;
1419 }
1420 return EXIT_SUCCESS;
1421}
Arguments proc_args(int &argc, char **argv)
Parse standard libmx2 command-line options from main()'s argv.
Definition argz.hpp:872
Exception thrown by Argz::proc() on unrecognised or malformed options.
Definition argz.hpp:178
String text() const
Definition argz.hpp:182
std::string text() const
Plain data structure returned by proc_args() with all common libmx2 CLI options.
Definition argz.hpp:730
bool fullscreen
Whether fullscreen mode was requested.
Definition argz.hpp:736
bool enable_vsync
Enable FIFO present mode / v-sync (--enable-vsync).
Definition argz.hpp:750
int height
Viewport height in pixels (default: 720).
Definition argz.hpp:733
std::string path
Asset root; proc_args() defaults it to the executable directory.
Definition argz.hpp:735
int width
Viewport width in pixels (default: 1280).
Definition argz.hpp:732

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.