X-Git-Url: https://git.r.bdr.sh/rbdr/super-polarity/blobdiff_plain/ed603039c4a456b37aefe434a3b1a5352362d86b..8534e46e400268c5ceffb3b14f02cef39eedae8f:/src/actor.c diff --git a/src/actor.c b/src/actor.c new file mode 100644 index 0000000..32028a1 --- /dev/null +++ b/src/actor.c @@ -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 +#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