summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c218
1 files changed, 109 insertions, 109 deletions
diff --git a/main.c b/main.c
index c1bc2e0..0bc0ec7 100644
--- a/main.c
+++ b/main.c
@@ -1,109 +1,109 @@
-// Standard libraries ( not written by me )
-#include <stdio.h>
-#include <string.h>
-
-// SDL libraries ( not written by me )
-#include "SDL2/SDL.h"
-#include "SDL2/SDL_image.h"
-
-#ifdef __WIN32__
- // Work around a TCC<->SDL bug regarding the redefintion of main.
- // Note: the error messages from TCC make no sense
- #undef main
-#endif
-
-
-// Window dimensions
-#define SCREEN_WIDTH 640
-#define SCREEN_HEIGHT 480
-#define TILE_SIZE 32 // Width and height of 'squares' in the game
-
-#define SCREEN_WIDTH_SQUARES SCREEN_WIDTH / TILE_SIZE
-#define SCREEN_HEIGHT_SQUARES SCREEN_HEIGHT / TILE_SIZE
-
-// Modules of the game I have written ( in directory with this source file )
-#include "level.c" // Level structures, loading, other levely stuff
-#include "helpscreen.c" // Help-screen code
-#include "echidna_ai.c" // Echidna movement A
-#include "render.c" // Normal in-game rendering
-#include "game.c" // Normal in-game code
-
-/* error_sdl is called when SDL 'throws' an error
- * SDL can throw an error if the computer is for example incapable of displaying
- * the game, because it is too old ( ie made before the year 1998 ) */
-void error_sdl( char* reason )
-{
- // Print the error message and then close the game
- fprintf( stderr, "Error (SDL): %s: %s\n", reason, SDL_GetError() );
- exit(1);
-}
-
-int main(int argc, char *argv[])
-{
- // Initialisation
-
- /* First we need to tell SDL to create a window. A 'surface'
- * is created called surf_screen, 'surfaces' are simply images
- * of what we see on-screen.
- *
- * To make things appear on the screen, I copy ('blit') images
- * onto this surface at different locations
- */
-
- // Initialise SDL
- printf("Initialising SDL... ");
- if ( SDL_Init( SDL_INIT_VIDEO ) == -1 ) error_sdl("Could not initialise SDL");
- atexit(SDL_Quit);
-
- SDL_Window * sdlWindow = SDL_CreateWindow("EchidneaMenace", SDL_WINDOWPOS_UNDEFINED,
- SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_FULLSCREEN | SDL_WINDOW_OPENGL );
- SDL_Renderer *renderer = SDL_CreateRenderer(sdlWindow, -1, 0);
-
- printf("done\n");
-
- /// Menu
- printf(" ==== Entered menu\n");
-
- // Load the menu graphic into memory
- SDL_Surface *surf_title = IMG_Load( "titlescreen.png" );
- if (!surf_title) {
- error_sdl("could not get title surface\n");
- }
- SDL_Texture *surf_title_tex = SDL_CreateTextureFromSurface(renderer, surf_title);
- if (!surf_title_tex) {
- error_sdl("could not get title texture from surface\n");
- }
-
- // Need to draw before the while loop otherwise we only do the
- // initial drawing after a keydown-event
- SDL_RenderClear(renderer);
- SDL_RenderCopy(renderer, surf_title_tex, NULL, NULL);
- SDL_RenderPresent(renderer);
-
- // Events are variables used to store user input
- SDL_Event menuevent;
-
- while ( SDL_WaitEvent( &menuevent ) >= 0)
- {
- SDL_RenderClear(renderer);
- SDL_RenderCopy(renderer, surf_title_tex, NULL, NULL);
- SDL_RenderPresent(renderer);
-
- if ( menuevent.type == SDL_KEYDOWN )
- {
- // Menu choice selection
- if ( menuevent.key.keysym.sym == SDLK_p ) game_loop(renderer);
- else if ( menuevent.key.keysym.sym == SDLK_h ) help(renderer);
- else if ( menuevent.key.keysym.sym == SDLK_q || menuevent.key.keysym.sym == SDLK_ESCAPE ) exit(0);
- }
- }
-
- /* Technically the computer will never reach this point,
- * because the while statement above will run forever until the
- * user quits the game.
- *
- * The 'return' statement is still written here so the compiler
- * does not complain */
-
- return 0;
-}
+// Standard libraries ( not written by me )
+#include <stdio.h>
+#include <string.h>
+
+// SDL libraries ( not written by me )
+#include "SDL2/SDL.h"
+#include "SDL2/SDL_image.h"
+
+#ifdef __WIN32__
+ // Work around a TCC<->SDL bug regarding the redefintion of main.
+ // Note: the error messages from TCC make no sense
+ #undef main
+#endif
+
+
+// Window dimensions
+#define SCREEN_WIDTH 640
+#define SCREEN_HEIGHT 480
+#define TILE_SIZE 32 // Width and height of 'squares' in the game
+
+#define SCREEN_WIDTH_SQUARES SCREEN_WIDTH / TILE_SIZE
+#define SCREEN_HEIGHT_SQUARES SCREEN_HEIGHT / TILE_SIZE
+
+// Modules of the game I have written ( in directory with this source file )
+#include "level.c" // Level structures, loading, other levely stuff
+#include "helpscreen.c" // Help-screen code
+#include "echidna_ai.c" // Echidna movement A
+#include "render.c" // Normal in-game rendering
+#include "game.c" // Normal in-game code
+
+/* error_sdl is called when SDL 'throws' an error
+ * SDL can throw an error if the computer is for example incapable of displaying
+ * the game, because it is too old ( ie made before the year 1998 ) */
+void error_sdl( char* reason )
+{
+ // Print the error message and then close the game
+ fprintf( stderr, "Error (SDL): %s: %s\n", reason, SDL_GetError() );
+ exit(1);
+}
+
+int main(int argc, char *argv[])
+{
+ // Initialisation
+
+ /* First we need to tell SDL to create a window. A 'surface'
+ * is created called surf_screen, 'surfaces' are simply images
+ * of what we see on-screen.
+ *
+ * To make things appear on the screen, I copy ('blit') images
+ * onto this surface at different locations
+ */
+
+ // Initialise SDL
+ printf("Initialising SDL... ");
+ if ( SDL_Init( SDL_INIT_VIDEO ) == -1 ) error_sdl("Could not initialise SDL");
+ atexit(SDL_Quit);
+
+ SDL_Window * sdlWindow = SDL_CreateWindow("EchidneaMenace", SDL_WINDOWPOS_UNDEFINED,
+ SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_FULLSCREEN | SDL_WINDOW_OPENGL );
+ SDL_Renderer *renderer = SDL_CreateRenderer(sdlWindow, -1, 0);
+
+ printf("done\n");
+
+ /// Menu
+ printf(" ==== Entered menu\n");
+
+ // Load the menu graphic into memory
+ SDL_Surface *surf_title = IMG_Load( "titlescreen.png" );
+ if (!surf_title) {
+ error_sdl("could not get title surface\n");
+ }
+ SDL_Texture *surf_title_tex = SDL_CreateTextureFromSurface(renderer, surf_title);
+ if (!surf_title_tex) {
+ error_sdl("could not get title texture from surface\n");
+ }
+
+ // Need to draw before the while loop otherwise we only do the
+ // initial drawing after a keydown-event
+ SDL_RenderClear(renderer);
+ SDL_RenderCopy(renderer, surf_title_tex, NULL, NULL);
+ SDL_RenderPresent(renderer);
+
+ // Events are variables used to store user input
+ SDL_Event menuevent;
+
+ while ( SDL_WaitEvent( &menuevent ) >= 0)
+ {
+ SDL_RenderClear(renderer);
+ SDL_RenderCopy(renderer, surf_title_tex, NULL, NULL);
+ SDL_RenderPresent(renderer);
+
+ if ( menuevent.type == SDL_KEYDOWN )
+ {
+ // Menu choice selection
+ if ( menuevent.key.keysym.sym == SDLK_p ) game_loop(renderer);
+ else if ( menuevent.key.keysym.sym == SDLK_h ) help(renderer);
+ else if ( menuevent.key.keysym.sym == SDLK_q || menuevent.key.keysym.sym == SDLK_ESCAPE ) exit(0);
+ }
+ }
+
+ /* Technically the computer will never reach this point,
+ * because the while statement above will run forever until the
+ * user quits the game.
+ *
+ * The 'return' statement is still written here so the compiler
+ * does not complain */
+
+ return 0;
+}