Skip to content

Commit

Permalink
Beginnings of battle system
Browse files Browse the repository at this point in the history
  • Loading branch information
Hydrocharged committed Apr 4, 2022
1 parent 16d0a53 commit 5803b18
Show file tree
Hide file tree
Showing 34 changed files with 1,186 additions and 203 deletions.
Binary file added assets/enemies/bird/color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/enemies/bird/gray.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/enemies/dragon/color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/enemies/dragon/gray.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/enemies/snake/color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/enemies/snake/gray.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/stats/evasion.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
93 changes: 44 additions & 49 deletions include/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,59 +6,54 @@

#ifndef CHARACTER_H
#define CHARACTER_H
#include <string>
#include "context.h"
#include "rune.h"

class Character;
class StatusEffectInstance;

struct CharacterInstance {
explicit CharacterInstance(Character& parent) : Parent(parent) {}

Character& Parent;
int MaxHealth = 0;
int CurrentHealth = 0;
int PhysicalAttack = 0;
int SpecialAttack = 0;
int PhysicalArmor = 0;
int SpecialArmor = 0;
int Speed = 0;
int Evasion = 0;
double CritChance = 0;
double CritMultiplier = 0;
double DebuffResistance = 0;
double FireResistance = 0;
double WaterResistance = 0;
double ElectricResistance = 0;
double WindResistance = 0;
};

class Character {
public:
Character();
~Character();

/*
Thinking of keeping track of buffs and debuffs in two ways:
1. We can have a vector of strings and include and remove whatever buff/debuff applied to the character when they
receive buff/debuff.
2. We can create functions, such as
isPoisoned() {
if (poisoned == true) { return true; }
return false;
}
And call them every round. Both are very scalable, I think that the functions while more work upfront are better
in the long run, if we are just considering runtime because the second option is constant time O(1) compared to
O(n) n being the size of the vector arrays created
*/
// std::vector<std::string> buffs;
// std::vector<std::string> debuffs;

// Need to create a structure to the list of runes a character holds
// RUNE is some data structure holding the rest of the runes data
// std::map<runeName, RUNE> runeList;
Character() : instance(*this) {}
virtual int Level(Context& ctx) = 0;
virtual double FireResistance(Context& ctx) = 0;
virtual double WaterResistance(Context& ctx) = 0;
virtual double ElectricResistance(Context& ctx) = 0;
virtual double WindResistance(Context& ctx) = 0;
virtual CharacterInstance& Instance(Context& ctx) = 0;

private:
unsigned int level; // Character Level
unsigned int healthPoints; // The amount of damage a character can handle before dying
unsigned int physicalArmor; // Flat reduction against physical attacks
unsigned int specialArmor; // Flat reduction against special (magical) attacks
int speed; // Determines who attacks first
/* Percentage resistances corresponding to the variable title - for ex. fireResistance is a percentage resistance
against fire attacks */
int fireResistance, waterResistance, electricResistance, windResistance;
public:
int Health = 0;
int CurrentHealth = 0;
int PhysicalAttack = 0;
int SpecialAttack = 0;
int PhysicalArmor = 0;
int SpecialArmor = 0;
int Speed = 0;

protected:
CharacterInstance instance;
};

Character::Character() {
// Set all variables to their start
level = 0;
healthPoints = 500;
physicalArmor = 50;
specialArmor = 25;
speed = 20;
fireResistance = 0;
waterResistance = 0;
electricResistance = 0;
windResistance = 0;
}

Character::~Character() {
// No Memory Leaked
}

#endif //CHARACTER_H
124 changes: 64 additions & 60 deletions include/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,61 +9,17 @@
#include "raylib/raylib.h"
#include "vector"

class Context;
class Component;

struct Colors_ {
Color Background = Color{30, 30, 30, 255};
Color Slider = Color{0, 136, 182, 255};
Color SliderHover = Color{0, 190, 253, 255};
Color Button = Color{255, 255, 255, 50};
Color ButtonHover = Color{255, 255, 255, 100};
Color InputStepper = Color{255, 255, 255, 100};
Color InputStepperHover = Color{0, 190, 253, 255};

Color RarityCommon = Color{255, 255, 255, 255};
Color RarityUncommon = Color{30, 255, 0, 255};
Color RarityRare = Color{0, 112, 221, 255};
Color RarityEpic = Color{163, 53, 238, 255};
Color RarityLegendary = Color{255, 128, 0, 255};

Color ExperienceBar = Color{30, 180, 30, 255};
Color HealthBar = Color{180, 30, 30, 255};
};

struct Mouse_ {
friend class Context;

public:
int X() { return x; }
int Y() { return y; }
bool IsDown() { return down; }
bool HasClicked() { return clicked; }

private:
int x = -2147483648;
int y = -2147483648;
bool down = false;
bool clicked = false;
};

struct Screen_ {
friend class Context;

public:
int Width() const { return width; };
int Height() const { return height; };
bool HasResized() const { return width != prevWidth || height != prevHeight; }

private:
int width = 0;
int height = 0;
int prevWidth = 0;
int prevHeight = 0;
};
class State;

class Context {
public:
Context();
~Context();
void Initialize();
void Update();
void Draw();

struct Menus {
friend class Context;

Expand All @@ -88,16 +44,64 @@ class Context {
void initialize(Context& ctx);
};

Context();
~Context();
void Initialize();
void Update();
void Draw();
const Colors_ Colors;
Screen_ Screen;
Mouse_ Mouse;
Menus Menu;
struct {
Color Background = Color{30, 30, 30, 255};
Color Slider = Color{0, 136, 182, 255};
Color SliderHover = Color{0, 190, 253, 255};
Color Button = Color{255, 255, 255, 50};
Color ButtonHover = Color{255, 255, 255, 100};
Color InputStepper = Color{255, 255, 255, 100};
Color InputStepperHover = Color{0, 190, 253, 255};
Color EnemyBackground = Color{255, 255, 255, 15};

Color RarityCommon = Color{255, 255, 255, 255};
Color RarityUncommon = Color{30, 255, 0, 255};
Color RarityRare = Color{0, 112, 221, 255};
Color RarityEpic = Color{163, 53, 238, 255};
Color RarityLegendary = Color{255, 128, 0, 255};

Color ExperienceBar = Color{30, 180, 30, 255};
Color HealthBar = Color{180, 30, 30, 255};

Color ElementFire = Color{194, 0, 0, 255};
Color ElementWater = Color{41, 121, 255, 255};
Color ElementElectric = Color{255, 167, 38, 255};
Color ElementWind = Color{135, 222, 66, 255};
} Colors;

struct {
friend class Context;

public:
int Width() const { return width; };
int Height() const { return height; };
bool HasResized() const { return width != prevWidth || height != prevHeight; }

private:
int width = 0;
int height = 0;
int prevWidth = 0;
int prevHeight = 0;
} Screen;

struct {
friend class Context;

public:
int X() { return x; }
int Y() { return y; }
bool IsDown() { return down; }
bool HasClicked() { return clicked; }

private:
int x = -2147483648;
int y = -2147483648;
bool down = false;
bool clicked = false;
} Mouse;

Menus Menu;
State* GameState;
float Volume = 1;
};

Expand Down
28 changes: 20 additions & 8 deletions include/enemy.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,32 @@

#ifndef ENEMY_H
#define ENEMY_H
#include "context.h"
#include "character.h"

class Enemy : public Character {
public:
Enemy();
Enemy(Context& ctx, double currentTime, bool isBoss);
~Enemy();
};
int Level(Context& ctx) override;
double FireResistance(Context& ctx) override;
double WaterResistance(Context& ctx) override;
double ElectricResistance(Context& ctx) override;
double WindResistance(Context& ctx) override;
CharacterInstance& Instance(Context& ctx) override;
Component* GenerateComponent(Context& ctx, const Component::Options& options);
Sprite* GetSprite(Context& ctx, const Component::Options& options);

Enemy::Enemy() {
// No separate variables yet;
}
std::string Name;
double EncounterTime;
bool IsBoss;

Enemy::~Enemy() {
// Nothing to destroy yet;
}
private:
SpriteName spriteName;
double fireResistance;
double waterResistance;
double electricResistance;
double windResistance;
};

#endif //ENEMY_H
25 changes: 25 additions & 0 deletions include/gui/border.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright © 2022 Daylon Wilkins & Maxwell Chow
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

#ifndef BORDER_H
#define BORDER_H
#include "context.h"
#include "component.h"

class Border : public Component {
public:
Border(Context& ctx, const Component::Options& options, float thicknessScale);
int Width(Context& ctx) override;
int Height(Context& ctx) override;

protected:
void Draw(Context& ctx) override;

private:
float thicknessScale;
};

#endif //BORDER_H
5 changes: 3 additions & 2 deletions include/gui/progressbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@

class ProgressBar : public Component {
public:
ProgressBar(Context& ctx, const Component::Options& options, float* trackedValue);
ProgressBar(Context& ctx, const Component::Options& options, int* maxValue, int* currentValue);
int Width(Context& ctx) override;
int Height(Context& ctx) override;

protected:
void Draw(Context& ctx) override;

private:
float* trackedValue;
int* maxValue;
int* currentValue;
};

#endif //PROGRESSBAR_H
4 changes: 4 additions & 0 deletions include/gui/sprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ enum SpriteName {
SpearGoblin,
BearBaby,
Golem,
Dragon,
Bird,
Snake,

// Runes
NoneRune,
Expand Down Expand Up @@ -49,6 +52,7 @@ enum SpriteName {
PhysicalArmor,
SpecialArmor,
Speed,
Evasion,
FireResistance,
WaterResistance,
ElectricResistance,
Expand Down
1 change: 1 addition & 0 deletions include/gui/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "label.h"
#include "wrappedlabel.h"
#include "verticalpanel.h"
#include "border.h"
#include "sprite.h"
#include "slider.h"
#include "inputstepper.h"
Expand Down
30 changes: 30 additions & 0 deletions include/player.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright © 2022 Daylon Wilkins & Maxwell Chow
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

#ifndef PLAYER_H
#define PLAYER_H
#include "character.h"

class Player : public Character {
public:
Player();
~Player();
int Level(Context& ctx) override;
double FireResistance(Context& ctx) override;
double WaterResistance(Context& ctx) override;
double ElectricResistance(Context& ctx) override;
double WindResistance(Context& ctx) override;
CharacterInstance& Instance(Context& ctx) override;

int Experience;
int Evasion;
Rune Runes[6];

private:
int level;
};

#endif //PLAYER_H
Loading

0 comments on commit 5803b18

Please sign in to comment.