Clone the repo and run "make all" in the terminal
Textures can be loaded once and used all over the codebase using a singleton design of the TexturesHandler
wrapper class
First include the class:
#include "TexturesHandler.hpp"
Then, to get the texture see this example:
sf::Texture* texture = LOADTEXTURE("textures/stone_wall.png");
this->sprite = new sf::Sprite();
sprite->setTexture(*texture);
For a real example, take a look at the Cat.cpp class.
A time factor constant can be obtained based on how much time passed between the current and the last frame. This can be used to adjust things like the speed of entities, etc..
Include file
#include "Utility.h"
Access time factor using:
UTIL_CLASS.getTimeFactor();
Real example from the Entity.cpp class.
// Move the entity to new position
int factor = UTIL_CLASS.getTimeFactor();
this->position.set(this->position.getX() + (movement_speed*factor), this->position.getY());
We're using the Criterion framework for testing in this project: https://github.com/Snaipe/Criterion
To install on ubuntu run:
sudo apt-get install libcriterion-dev
In the folder test
create <Class>.test.cpp
file where <Class>
is the name of the class being tested in that file.
touch test/ExampleClass.test.cpp
In this file, all the testing for the class should be implemented in the following format.
#include "../src/ExampleClass.h"
#include <criterion/criterion.h>
#include <criterion/logging.h>
#include <stdio.h>
// This will assess a certain functionality in the class
Test(example_class_suite, test_1) {
cr_log_info("This is a test log: %d", 123);
ExampleClass cls = new ExampleClass();
// Assert conditions (must be true for the current test to pass)
cr_assert(
// Condition
cls.attribute == 321,
// Error message if condition doesn't pass
"ERROR: The attribute 'attribute' is not 321!"
);
// Another assertion example
cr_assert(cls.getNumber() == 10, "Error: Number is not 10!");
}
// This will assess another part
Test(example_class_suite, test_2) {
// ...
}
For a real example check the test/Vector.test.cpp
file.
Run the command:
make <Class>.test
For our example class test, we would run
make ExampleClass.test
To run all test files execute:
make test
- Each class will have a test file.
- Each test file will test every single method the class has.
- Each test file will test different functionalities the class should have.
- If a Class A depends on Class B through an association, the test file for Class A must test that relation.