Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

made game environment object 'Astral' - the game's 5 stages (init, ev…

…ent handling, loop/updates, render, cleanup) are methods of the Astral game object
  • Loading branch information...
commit 7914f8bfe3c0dc1255a87e209e587da38d7d00bf 1 parent 5269344
authored
5 .gitignore
... ... @@ -1,2 +1,5 @@
1 1 # emacs autosave files
2   -[#]*[#]
  2 +[#]*[#]
  3 +# temporary files
  4 +*~
  5 +~*
BIN  Astral
Binary file not shown
8 Makefile
@@ -3,18 +3,18 @@ CFLAGS=-Wall
3 3 INCLUDE_DIR=-I./inc
4 4 AR=
5 5 LIBS=-lSDL -lSDL_image
6   -SOURCES=./src/demo.cpp
  6 +SOURCES=./src/Astral_OnEvent.cpp ./src/Astral_OnLoop.cpp ./src/Astral_OnCleanup.cpp ./src/Astral_OnInit.cpp ./src/Astral_OnRender.cpp ./src/Astral.cpp
7 7 ASOBJECTS=$(ASSOURCES:.s=.o)
8 8 OBJECTS=$(SOURCES:.cpp=.o)
9   -TARGET=demo
  9 +TARGET=Astral
10 10
11 11 all: $(TARGET)
12 12
13 13 $(TARGET): $(OBJECTS)
14 14 $(CC) -o $(TARGET) $(OBJECTS) $(LIBS)
15 15
16   -%.o: %.cc
17   - $(CC) -c -o $@ $< $(INCLUDE_DIR) $(CFLAGS)
  16 +.cpp.o:
  17 + $(CC) -c $(CFLAGS) $(INCLUDE_DIR) -o $@ $<
18 18
19 19 clean:
20 20 rm -rf $(OBJECTS) $(TARGET)
26 inc/Astral.h
... ... @@ -0,0 +1,26 @@
  1 +#ifndef _Astral_H_
  2 +#define _ASTRAL_H_
  3 +
  4 +#include "SDL/SDL.h"
  5 +
  6 +class Astral {
  7 + private:
  8 +
  9 + bool Running;
  10 + SDL_Surface* Display_Surf;
  11 +
  12 + public:
  13 +
  14 + Astral();
  15 + int OnExecute();
  16 +
  17 + public:
  18 +
  19 + bool OnInit();
  20 + void OnEvent(SDL_Event* Event);
  21 + void OnLoop();
  22 + void OnRender();
  23 + void OnCleanup();
  24 +};
  25 +
  26 +#endif
2  src/.gitignore
... ... @@ -0,0 +1,2 @@
  1 +# object files
  2 +*.o
32 src/Astral.cpp
... ... @@ -0,0 +1,32 @@
  1 +#include "Astral.h"
  2 +
  3 +Astral::Astral() {
  4 + Display_Surf = NULL;
  5 + Running = true;
  6 +}
  7 +
  8 +int Astral::OnExecute() {
  9 + if(OnInit() == false) {
  10 + return -1;
  11 + }
  12 +
  13 + SDL_Event Event;
  14 +
  15 + while(Running) {
  16 + while(SDL_PollEvent(&Event)) {
  17 + OnEvent(&Event);
  18 + }
  19 + OnLoop();
  20 + OnRender();
  21 + }
  22 +
  23 + OnCleanup();
  24 +
  25 + return 0;
  26 +}
  27 +
  28 +int main(int argc, char * argv[]) {
  29 + Astral AstralEnv;
  30 +
  31 + return AstralEnv.OnExecute();
  32 +}
5 src/Astral_OnCleanup.cpp
... ... @@ -0,0 +1,5 @@
  1 +#include "Astral.h"
  2 +
  3 +void Astral::OnCleanup() {
  4 + SDL_Quit();
  5 +}
7 src/Astral_OnEvent.cpp
... ... @@ -0,0 +1,7 @@
  1 +#include "Astral.h"
  2 +
  3 +void Astral::OnEvent(SDL_Event* Event) {
  4 + if(Event->type == SDL_QUIT) {
  5 + Running = false;
  6 + }
  7 +}
13 src/Astral_OnInit.cpp
... ... @@ -0,0 +1,13 @@
  1 +#include "Astral.h"
  2 +
  3 +bool Astral::OnInit() {
  4 + if(SDL_Init(SDL_INIT_EVERYTHING) < 0) {
  5 + return false;
  6 + }
  7 +
  8 + if((Display_Surf = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF)) == NULL) {
  9 + return false;
  10 + }
  11 +
  12 + return true;
  13 +}
4 src/Astral_OnLoop.cpp
... ... @@ -0,0 +1,4 @@
  1 +#include "Astral.h"
  2 +
  3 +void Astral::OnLoop() {
  4 +}
4 src/Astral_OnRender.cpp
... ... @@ -0,0 +1,4 @@
  1 +#include "Astral.h"
  2 +
  3 +void Astral::OnRender() {
  4 +}
BIN  src/demo.o
Binary file not shown

0 comments on commit 7914f8b

Please sign in to comment.
Something went wrong with that request. Please try again.