-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseCharacter.cpp
More file actions
70 lines (62 loc) · 1.62 KB
/
BaseCharacter.cpp
File metadata and controls
70 lines (62 loc) · 1.62 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "BaseCharacter.h"
#include "raymath.h"
BaseCharacter::BaseCharacter()
{}
void BaseCharacter::Tick(float DeltaTime)
{
WorldPosLastFrame = WorldPos;
// Update animation frame
RunningTime += GetFrameTime();
if (RunningTime >= UpdateTime)
{
Frame++;
RunningTime = 0.f;
if (Frame > MaxFrame) { Frame = 0; }
}
// Define the movement of the map
if (Vector2Length(Velocity) != 0.0)
{
// set WorldPos = WorldPos + Direction
WorldPos = Vector2Add(WorldPos, Vector2Scale(Vector2Normalize(Velocity), Speed));
Velocity.x < 0.f ? RightLeft = -1.f : RightLeft = 1.f;
Texture = Run; // Texture state is running
}
else
{
Texture = Idle; // Texture state is idle
}
Velocity = {}; // zeroing out the velocity after it move
// Draw BaseCharacter on the game
Rectangle Source{ // Source/Origin where the BaseCharacter is actually
Width * Frame,
0.f,
Width * RightLeft,
Height
};
Rectangle Destination{ // Destination where the BaseCharacter is gonna be
GetScreenPos().x,
GetScreenPos().y,
Width * Scale,
Height * Scale
};
DrawTexturePro(Texture, Source, Destination, Vector2{}, 0.f, WHITE);
}
void BaseCharacter::UnDoMovement()
{
WorldPos = WorldPosLastFrame;
}
Rectangle BaseCharacter::GetCollisionRec()
{
return Rectangle{
GetScreenPos().x,
GetScreenPos().y,
Width * Scale,
Height * Scale
};
}
void BaseCharacter::UnloadTextures()
{
UnloadTexture(Texture);
UnloadTexture(Run);
UnloadTexture(Idle);
}