]> git.r.bdr.sh - rbdr/super-polarity/blobdiff - src/actor.c
Add some basic actorstuffs
[rbdr/super-polarity] / src / actor.c
diff --git a/src/actor.c b/src/actor.c
new file mode 100644 (file)
index 0000000..32028a1
--- /dev/null
@@ -0,0 +1,44 @@
+//
+//  actor.c
+//  Super Polarity
+//
+//  Created by Ruben Beltran del Rio on 8/14/13.
+//  Copyright (c) 2013 Abuguet. All rights reserved.
+//
+
+#include <stdio.h>
+#include "actor.h"
+
+SDL_Renderer *renderer;
+
+void actorUpdate(Actor *this, Uint32 dt) {
+    this->textureBox.x = this->pos.x;
+    this->textureBox.y = this->pos.y;
+    this->angle = (Uint32)(this->angle + dt / 5) % 360;
+}
+
+void actorDraw(Actor *this) {
+    SDL_RenderCopyEx(renderer, this->texture, NULL, &this->textureBox, this->angle, NULL, SDL_FLIP_NONE);
+}
+
+// This constructor is pretty much dumb. So, don't take it as anything final.
+Actor* createActor () {
+    Actor *actor = malloc(sizeof(Actor*));
+    actor->pos.x = 0;
+    actor->pos.y = 0;
+    actor->update = actorUpdate;
+    actor->draw = actorDraw;
+    actor->angle = 0.0;
+    
+    // Load the surface.
+    SDL_Surface *benSurface;
+    benSurface = IMG_Load("data/img/static/ben.png");
+    actor->texture = SDL_CreateTextureFromSurface(renderer, benSurface);
+    actor->textureBox.x = 230;
+    actor->textureBox.y = 150;
+    actor->textureBox.w = 180;
+    actor->textureBox.h = 180;
+    SDL_FreeSurface(benSurface);
+    
+    return actor;
+}
\ No newline at end of file