Skip to content

Instantly share code, notes, and snippets.

View murilobnt's full-sized avatar
:octocat:

Murilo Bento murilobnt

:octocat:
  • Brazil
View GitHub Profile
@murilobnt
murilobnt / 0superclass.hpp
Last active November 18, 2022 00:06
Example of abstraction in C++
#ifndef SUPERCLASS_HPP_
#define SUPERCLASS_HPP_
// PLEASE IGNORE THE 0 IN THE FILENAME. THIS IS ONLY FOR IT TO SHOW IN THE RIGHT ORDER
// IN THE GIST.
class SuperClass {
public:
SuperClass(int id);
virtual void print_itself() = 0; // Abstract method, a pure virtual function.
@murilobnt
murilobnt / first.cpp
Created November 23, 2019 20:35
Weird C++ increment operator behaviour. Two different outputs for the same statement.
#include <iostream>
void test(int &i){}
int main(){
int i = 0;
std::cout << "++i + i++: " << ++i + i++ << std::endl;
}
// Compilation:
#include "game_scene.hpp"
void GameScene::start() {
gs::TextureLoader::set_texture_from_file(texture, "assets/player_t.png");
player = Player(texture, sf::Vector2f(400, 300));
time_handlers.push_back(player.get_time_handler());
}
void GameScene::update() {
player.control_entity(get_delta_time());
#include "game.hpp"
Game::Game() : window(sf::VideoMode(800, 600), "SFML works!") {
tex.loadFromFile("assets/player_t.png");
player = Player(tex, sf::seconds(1.f / 10.f));
player.get_sprite().setPosition(sf::Vector2f(400, 300));
}
void Game::run() {
while (window.isOpen()) {
#include <SFML/Graphics.hpp>
int main() {
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML works!");
sf::Clock clock;
sf::Texture tex;
sf::Time elapsed;
sf::Time animation_time = sf::Time::Zero;
int animation_loop_state;
sf::Time animation_framerate(sf::seconds(1.f / 10.f));
@murilobnt
murilobnt / inheritance.cpp
Created March 8, 2019 03:39
C++ class inheritance example
// Okay, so suppose we want to create a mechanism to print a string
// in anywhere we want just by creating another class that implements the thing
// we want to do. Here, we'll be checking inheritance and abstract classes.
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
@murilobnt
murilobnt / main.cpp
Last active March 14, 2019 03:33
SFML sample implementation using the gs2d_engine
#include "gs2d/core.hpp"
#include "my_scene.hpp"
int main() {
gs::App app(200, 200, "Sample SFML");
app.app_start(new MyScene());
}