5 // Created by Ruben Beltran del Rio on 8/13/13.
6 // Copyright (c) 2013 Abuguet. All rights reserved.
14 #include "SDL2_image/SDL_image.h"
17 #include "actor_manager.h"
19 // TODO: Move these guys to a config header file
20 #define SCREEN_WIDTH 640
21 #define SCREEN_HEIGHT 480
25 SDL_Renderer
*renderer
;
30 ActorManager
*actorManager
;
33 if (SDL_Init(SDL_INIT_VIDEO
) < 0) {
34 printf("Could not initialize SDL");
38 // Load the window and renderer
39 window
= SDL_CreateWindow("Super Polarity", SDL_WINDOWPOS_CENTERED
, SDL_WINDOWPOS_CENTERED
, 0, 0, SDL_WINDOW_OPENGL
| SDL_WINDOW_FULLSCREEN_DESKTOP
);
41 renderer
= SDL_CreateRenderer(window
, -1, 0);
43 // Set linear quality for scaling, and the "logical" window size.
44 SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY
, "linear");
45 SDL_RenderSetLogicalSize(renderer
, SCREEN_WIDTH
, SCREEN_HEIGHT
);
49 SDL_DestroyTexture(benHead
);
50 SDL_DestroyRenderer(renderer
);
51 SDL_DestroyWindow(window
);
56 void initActorManager () {
60 //test the Actor Manager.
61 actorManager
= createActorManager();
63 actor
= createActor();
66 actorManager
->addActor(actorManager
, actor
);
68 otherActor
= createActor();
69 otherActor
->pos
.x
=100;
70 otherActor
->pos
.y
=100;
71 actorManager
->addActor(actorManager
, otherActor
);
79 void draw (SDL_Renderer
*renderer
) {
80 SDL_SetRenderDrawColor(renderer
, 255, 255, 255, 255);
81 SDL_RenderClear(renderer
);
83 actorManager
->draw(actorManager
);
85 SDL_RenderPresent(renderer
);
88 void update (Uint32 dt
) {
89 actorManager
->update(actorManager
, dt
);
92 int main(int argc
, const char * argv
[])
95 // SDL Initialization. TODO: Should have an initializer.
96 Uint32 startFrame
= 0;
112 startFrame
= SDL_GetTicks();
113 dt
= startFrame
- lastTime
;
114 lastTime
= startFrame
;
117 while (SDL_PollEvent(&event
)) {
118 if (event
.type
== SDL_QUIT
) {
121 if (event
.type
== SDL_WINDOWEVENT
) {
122 if (event
.window
.event
== SDL_WINDOWEVENT_FOCUS_LOST
) {
125 if (event
.window
.event
== SDL_WINDOWEVENT_FOCUS_GAINED
) {
136 endFrame
= SDL_GetTicks();
138 /* see if we have time to sleep */
139 delay
= 1000 / FPS
- (endFrame
- startFrame
);
140 if (delay
> 1000 / FPS
) {