Permalink
Browse files

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...
1 parent 5269344 commit 7914f8bfe3c0dc1255a87e209e587da38d7d00bf @Ballaw committed Mar 9, 2012
View
@@ -1,2 +1,5 @@
# emacs autosave files
-[#]*[#]
+[#]*[#]
+# temporary files
+*~
+~*
View
Binary file not shown.
View
@@ -3,18 +3,18 @@ CFLAGS=-Wall
INCLUDE_DIR=-I./inc
AR=
LIBS=-lSDL -lSDL_image
-SOURCES=./src/demo.cpp
+SOURCES=./src/Astral_OnEvent.cpp ./src/Astral_OnLoop.cpp ./src/Astral_OnCleanup.cpp ./src/Astral_OnInit.cpp ./src/Astral_OnRender.cpp ./src/Astral.cpp
ASOBJECTS=$(ASSOURCES:.s=.o)
OBJECTS=$(SOURCES:.cpp=.o)
-TARGET=demo
+TARGET=Astral
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(CC) -o $(TARGET) $(OBJECTS) $(LIBS)
-%.o: %.cc
- $(CC) -c -o $@ $< $(INCLUDE_DIR) $(CFLAGS)
+.cpp.o:
+ $(CC) -c $(CFLAGS) $(INCLUDE_DIR) -o $@ $<
clean:
rm -rf $(OBJECTS) $(TARGET)
View
@@ -0,0 +1,26 @@
+#ifndef _Astral_H_
+#define _ASTRAL_H_
+
+#include "SDL/SDL.h"
+
+class Astral {
+ private:
+
+ bool Running;
+ SDL_Surface* Display_Surf;
+
+ public:
+
+ Astral();
+ int OnExecute();
+
+ public:
+
+ bool OnInit();
+ void OnEvent(SDL_Event* Event);
+ void OnLoop();
+ void OnRender();
+ void OnCleanup();
+};
+
+#endif
View
@@ -0,0 +1,2 @@
+# object files
+*.o
View
@@ -0,0 +1,32 @@
+#include "Astral.h"
+
+Astral::Astral() {
+ Display_Surf = NULL;
+ Running = true;
+}
+
+int Astral::OnExecute() {
+ if(OnInit() == false) {
+ return -1;
+ }
+
+ SDL_Event Event;
+
+ while(Running) {
+ while(SDL_PollEvent(&Event)) {
+ OnEvent(&Event);
+ }
+ OnLoop();
+ OnRender();
+ }
+
+ OnCleanup();
+
+ return 0;
+}
+
+int main(int argc, char * argv[]) {
+ Astral AstralEnv;
+
+ return AstralEnv.OnExecute();
+}
@@ -0,0 +1,5 @@
+#include "Astral.h"
+
+void Astral::OnCleanup() {
+ SDL_Quit();
+}
@@ -0,0 +1,7 @@
+#include "Astral.h"
+
+void Astral::OnEvent(SDL_Event* Event) {
+ if(Event->type == SDL_QUIT) {
+ Running = false;
+ }
+}
View
@@ -0,0 +1,13 @@
+#include "Astral.h"
+
+bool Astral::OnInit() {
+ if(SDL_Init(SDL_INIT_EVERYTHING) < 0) {
+ return false;
+ }
+
+ if((Display_Surf = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF)) == NULL) {
+ return false;
+ }
+
+ return true;
+}
@@ -0,0 +1,4 @@
+#include "Astral.h"
+
+void Astral::OnLoop() {
+}
@@ -0,0 +1,4 @@
+#include "Astral.h"
+
+void Astral::OnRender() {
+}
View
Binary file not shown.

0 comments on commit 7914f8b

Please sign in to comment.