aboutsummaryrefslogtreecommitdiff
path: root/src/actor.c
blob: 32028a1ea2c5378249fdff09b2aa72a773ec83ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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;
}