aboutsummaryrefslogtreecommitdiff
path: root/games/skully_escape/monster.c
blob: 643d0a7311eecd7f2b9071c8200b318530f00289 (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
45
46
47
48
49
50
51
52
53
54
/***********************************************************************************
*
*   KING GAME JAM - GRAY TEAM
*
*   <Game title>
*   <Game description>
*
*   This game has been created using raylib (www.raylib.com)
*   raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
*   Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
*
************************************************************************************/

#include "raylib.h"
#include "monster.h"

void UpdateMonster(Monster *monster)
{
    if (!monster->active)
    {
        if (CheckCollisionPointRec(GetMousePosition(), monster->bounds)) monster->selected = true;
        else monster->selected = false;
    }
    else if (monster->spooky)
    {
        monster->framesCounter++;
        monster->currentSeq = 0;
        
        if (monster->framesCounter > 7)
        {
            monster->currentFrame++;
            monster->framesCounter = 0;
            
            if (monster->currentFrame > monster->numFrames - 1) monster->currentFrame = 1;
        }
    }
    
    monster->frameRec.x = monster->currentFrame*monster->texture.width/monster->numFrames;
    monster->frameRec.y = monster->currentSeq*monster->texture.height;
}

void DrawMonster(Monster monster, int scroll)
{
    Vector2 scrollPos = { monster.position.x - scroll, monster.position.y };
    
    if (monster.selected) DrawTextureRec(monster.texture, monster.frameRec, scrollPos, RED);
    else DrawTextureRec(monster.texture, monster.frameRec, scrollPos, WHITE);
}

void UnloadMonster(Monster monster)
{
    UnloadTexture(monster.texture);
}