-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseCharacter.h
More file actions
55 lines (40 loc) · 1.6 KB
/
BaseCharacter.h
File metadata and controls
55 lines (40 loc) · 1.6 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
#include "raylib.h"
#ifndef BASE_CHARACTER_H
#define BASE_CHARACTER_H
class BaseCharacter{
public:
BaseCharacter();
virtual void tick(float deltaTime);
Vector2 getWorldPos(){ // Getter Method, with return type Vector2
return worldPos; // Accessor method, accesses value "worldpos" but prevents from changing.
}
// Class methods have access to class variables, even private ones!
void undoMovement(); // Tick (Like a clock) Function Call
Rectangle GetCollisionRec();
virtual Vector2 getScreenPos() = 0;
bool getAlive() { return alive; }
void setAlive(bool isAlive) { alive = isAlive; }
protected:
// Loading Textures
Texture2D texture{LoadTexture("characters/knight_idle_spritesheet.png")}; // Stationary knight spritesheet
Texture2D idle{LoadTexture("characters/knight_idle_spritesheet.png")}; // Stationary knight spritesheet
Texture2D run{LoadTexture("characters/knight_run_spritesheet.png")}; // Moving knight spritesheet
Vector2 screenPos{}; // Starting Position of the character on the screen/window (knightPos to screenPos)
Vector2 worldPos{}; // Moving position of the character in the world
Vector2 worldPosLastFrame{};
// 1: facing right, -1: facing left
float rightLeft = 1.0f;
// Animation variables/ Member variables of the class "Character"
float runningTime = 0;
float updateTime = 1.0 / 12.0;
int frame = 0;
int maxFrame = 6;
float speed = 4.0f;
float width{};
float height{};
float scale = 4.0f;
Vector2 velocity{};
private:
bool alive{true};
};
#endif