SCC.150 Assembler Emulator
A compiler for a simple assembler language
 All Data Structures Files Functions
moonlander.h
Go to the documentation of this file.
1 #ifndef MOONLANDER_H_
2 #define MOONLANDER_H_
3 
29 #include <stdbool.h>
30 #include <ncurses.h>
31 #include <stdlib.h>
32 #include <time.h>
33 #include <math.h>
34 
35 // I almost think I should start looking into enums, rather than the
36 // world's lengthiest macro lists all the time.
37 // Macros for ship jet directions.
38 #define NONE 0
39 #define UP 1
40 #define RIGHT 2
41 #define DOWN 3
42 #define LEFT 4
43 
44 // Macros for the components of the landscape.
45 #define LEFT_INCLINE 0
46 #define STRAIGHT_UP 1
47 #define STRAIGHT_DOWN 2
48 #define RIGHT_DECLINE 3
49 #define PLATEAU 4
50 
51 // Macros for the type of game end.
52 #define NONE 0
53 #define CRASH 1
54 #define LAND 2
55 #define QUIT 3
56 
57 // Macros for setting difficulty.
58 #define STARTING_FUEL 900
59 #define CHANCE_OF_LANDING_PAD 3
60 
61 // Macros for the ship.
62 #define TERMINAL_VELOCITY 0.9f
63 
64 // Global variables aren't the best, but I feel like I can
65 // get away with a few here; it saves so very much fannying
66 // around with pointers.
67 bool end = false;
68 unsigned int endType = NONE;
69 struct timespec_t s;
70 // Dirty cheat(s).
71 bool invincible = false;
72 
73 // The bits and bobs that make up the landscape.
74 typedef struct _win_landscape_struct {
75  chtype li, su, sd, rd, pl;
77 
78 // The landscape 'class'
79 typedef struct _WIN_landscape_struct {
80  int startx, starty;
81  int height, width;
82  int landingPoints;
83  WIN_LANDSCAPE graphics;
84 }LANDSCAPE;
85 
86 // Same again, but with the ship.
87 typedef struct _win_ship_struct {
88  chtype bod;
89 }WIN_SHIP;
90 
91 // And the ship 'class'
92 typedef struct _WIN_ship_struct {
93  int startx, starty;
94  int lastx, lasty;
95  int fuel;
96  float xF, yF;
97  int x, y;
98  int height, width;
99  float xMomentum, yMomentum;
100  WIN_SHIP graphics;
101 }SHIP;
102 
103 // I don't profess to know how `nanosleep()` works, but I nicked this
104 // off of SO and it seems to do the job, even if Geany gives me an
105 // 'implicit declaration' warning.
106 struct timespec_t {
107  time_t tv_sec; /* seconds */
108  long tv_nsec; /* nanoseconds */
109 };
110 
111 // Initialisation functions.
112 void initialisencurses();
113 void initialiseShip(SHIP* ship);
114 void initialiseLandscape(LANDSCAPE* landscape);
115 
116 // Creation functions.
117 void createShip(SHIP* ship);
118 bool createLandscape();
119 
120 // Physics application functions.
121 void applyJet(SHIP* ship, unsigned int dir);
122 void applyGravity(SHIP* ship);
123 void applyFriction(SHIP* ship);
124 
125 // Ship movement function. Includes collision detection.
126 void moveShip(SHIP* ship, size_t lASize, unsigned int landscapeArray[],
127  size_t sASize, unsigned int safeArray[]);
128 
129 // Introduction display function.
130 void displayIntro();
131 
132 // Arcane magic.
133 double getScore(SHIP* ship, unsigned int time);
134 
135 #endif /* MOONLANDER_H_ */
void createShip(SHIP *ship)
Definition: moonlander.c:295
bool createLandscape(LANDSCAPE *landscape, unsigned int landscapeArray[], unsigned int safeArray[])
Definition: moonlander.c:318
Definition: moonlander.h:92
void applyJet(SHIP *ship, unsigned int dir)
Definition: moonlander.c:443
void moveShip(SHIP *ship, size_t lASize, unsigned int landscapeArray[], size_t sASize, unsigned int safeArray[])
Definition: moonlander.c:507
void displayIntro()
Definition: moonlander.c:602
double getScore(SHIP *ship, unsigned int time)
Definition: moonlander.c:642
void initialiseLandscape(LANDSCAPE *landscape)
Definition: moonlander.c:274
void applyFriction(SHIP *ship)
Definition: moonlander.c:482
Definition: moonlander.h:106
void initialiseShip(SHIP *ship)
Definition: moonlander.c:248
Definition: moonlander.h:87
void applyGravity(SHIP *ship)
Definition: moonlander.c:473
Definition: moonlander.h:74
void initialisencurses()
Definition: moonlander.c:226
Definition: moonlander.h:79