Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updated states for new statemanager

  • Loading branch information...
commit 82d9ccf19c9dad7fc54921da399b19e5941b5e0d 1 parent 0dd1ae3
@niksaak authored
Showing with 24 additions and 11 deletions.
  1. +10 −5 src/main.c
  2. +13 −6 src/state_main.c
  3. +1 −0  src/state_main.h
View
15 src/main.c
@@ -1,19 +1,24 @@
+#ifdef _WIN32
+#include <windows.h>
+#endif
+
#include "engine/engine.h"
-#include "states.h"
+#include "state_main.h"
#include "main.h"
int main(int argc, char** argv)
{
- state_t state = state_main(); // TODO: move this to init_states() or something
+ register_state("main", state_main());
+ init_states();
- state.init(); // init our main-and-only (MANLY) gamestate
- swstate(&state);
+ swstate("main");
scrstart("TEST", 512, 512, false); // window appearifies here
gameloop(scrget());
scrstop();
- state.deinit();
+ deinit_states();
+ clear_registry();
return 0;
}
View
19 src/state_main.c
@@ -2,9 +2,8 @@
#include <SDL/SDL.h>
#include <SDL/SDL_gfxPrimitives.h>
-#include "entities/entities.h"
+#include "entities/entity.h"
#include "engine/engine.h"
-#include "states.h"
typedef struct EntityStack {
Uint16 top;
@@ -89,8 +88,16 @@ static void do_world(cpFloat step)
(ran_domo(1, 500) - 250) / 100.0)));
pcount++;
break;
- default:
+ case SDL_KEYUP:
+ switch(e.key.keysym.sym)
+ {
+ case SDLK_SPACE:
+ swstate("second");
+ break;
+ default: break;
+ }
break;
+ default: break;
}
}
}
@@ -141,9 +148,9 @@ static void deinit()
cpSpaceFree(space);
}
-state_t state_main()
+state_t* state_main()
{
- state_t s;
+ static state_t s = {0};
s.init = &init;
s.wake = &wake;
@@ -152,6 +159,6 @@ state_t state_main()
s.sleep = &sleep;
s.deinit = &deinit;
- return s;
+ return &s;
}
View
1  src/state_main.h
@@ -0,0 +1 @@
+extern state_t* state_main();
Please sign in to comment.
Something went wrong with that request. Please try again.