]> git.r.bdr.sh - rbdr/super-polarity/blame - src/actor.c
Proper merge for gitignore
[rbdr/super-polarity] / src / actor.c
CommitLineData
8534e46e
BB
1//
2// actor.c
3// Super Polarity
4//
5// Created by Ruben Beltran del Rio on 8/14/13.
6// Copyright (c) 2013 Abuguet. All rights reserved.
7//
8
9#include <stdio.h>
10#include "actor.h"
11
12SDL_Renderer *renderer;
13
14void actorUpdate(Actor *this, Uint32 dt) {
15 this->textureBox.x = this->pos.x;
16 this->textureBox.y = this->pos.y;
17 this->angle = (Uint32)(this->angle + dt / 5) % 360;
18}
19
20void actorDraw(Actor *this) {
21 SDL_RenderCopyEx(renderer, this->texture, NULL, &this->textureBox, this->angle, NULL, SDL_FLIP_NONE);
22}
23
24// This constructor is pretty much dumb. So, don't take it as anything final.
25Actor* createActor () {
26 Actor *actor = malloc(sizeof(Actor*));
27 actor->pos.x = 0;
28 actor->pos.y = 0;
29 actor->update = actorUpdate;
30 actor->draw = actorDraw;
31 actor->angle = 0.0;
32
33 // Load the surface.
34 SDL_Surface *benSurface;
35 benSurface = IMG_Load("data/img/static/ben.png");
36 actor->texture = SDL_CreateTextureFromSurface(renderer, benSurface);
37 actor->textureBox.x = 230;
38 actor->textureBox.y = 150;
39 actor->textureBox.w = 180;
40 actor->textureBox.h = 180;
41 SDL_FreeSurface(benSurface);
42
43 return actor;
44}