#include <stdio.h>
#include <time.h>
+#include <math.h>
#include "SDL2/SDL.h"
#include "SDL2_image/SDL_image.h"
+#include "actor.h"
+#include "actor_manager.h"
+
// TODO: Move these guys to a config header file
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
SDL_Window *window;
SDL_Renderer *renderer;
-SDL_Surface *benHead;
+SDL_Texture *benHead;
+SDL_Rect benRect;
+bool focus;
+
+ActorManager *actorManager;
void init () {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
// Set linear quality for scaling, and the "logical" window size.
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
SDL_RenderSetLogicalSize(renderer, SCREEN_WIDTH, SCREEN_HEIGHT);
+}
+
+void close () {
+ SDL_DestroyTexture(benHead);
+ SDL_DestroyRenderer(renderer);
+ SDL_DestroyWindow(window);
+ SDL_Quit();
+}
+
+
+void initActorManager () {
+ Actor *actor;
+ Actor *otherActor;
+
+ //test the Actor Manager.
+ actorManager = createActorManager();
+
+ actor = createActor();
+ actor->pos.x = 55;
+ actor->pos.y = 24;
+ actorManager->addActor(actorManager, actor);
+
+ otherActor = createActor();
+ otherActor->pos.x=100;
+ otherActor->pos.y=100;
+ actorManager->addActor(actorManager, otherActor);
- // Load the surface.
- // benHead = IMG_Load("data/img/static/ben.png");
}
-void render (SDL_Renderer *renderer) {
+void loadAssets() {
+ initActorManager();
+}
+
+void draw (SDL_Renderer *renderer) {
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_RenderClear(renderer);
+
+ actorManager->draw(actorManager);
+
SDL_RenderPresent(renderer);
}
-int mainC(int argc, const char * argv[])
+void update (Uint32 dt) {
+ actorManager->update(actorManager, dt);
+}
+
+int main(int argc, const char * argv[])
{
// SDL Initialization. TODO: Should have an initializer.
- Uint32 startFrame;
- Uint32 endFrame;
+ Uint32 startFrame = 0;
+ Uint32 endFrame = 0;
+ Uint32 lastTime = 0;
+ Uint32 dt;
Uint32 delay;
int done;
+
+ init();
+ loadAssets();
done = 0;
+ focus = true;
// Event Loop.
while (!done) {
startFrame = SDL_GetTicks();
+ dt = startFrame - lastTime;
+ lastTime = startFrame;
+
SDL_Event event;
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
done = 1;
}
+ if (event.type == SDL_WINDOWEVENT) {
+ if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) {
+ focus = false;
+ }
+ if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) {
+ focus = true;
+ }
+ }
}
- render(renderer);
+ if (focus) {
+ update(dt);
+ draw(renderer);
+ }
endFrame = SDL_GetTicks();
SDL_Delay(delay);
}
- SDL_Quit();
+ close();
return 0;
}