Hello I am mrki from Croatia.
Currently I am working as teacher but in free time I like coding. My favorite languages are PHP and MySQL. Currently I am working on sportbook project and later I have idea making lottery system.
I like sport (Real Madrid and Dinamo Zagreb fan), play tennis and...
hi! I'm in high school and going down daily ADHD hyper fixations with learning how to do insanely specific things coding-wise. Stack overflow was scary so I'm here instead.
Hello coders! I wanted to share a brief introduction to API(s)!
I recently helped with a thread that was asking a bit about API(s). Funny enough I heard about API(s) before but never actually knew what it meant. That is until now.
So what’s an API? An API is an abbreviation...
Lovely to be part of this community. I'm not from a development background so please go easy on me if my requests and questions come across as very basic!
I was a UX/UI designer by trade, and happy to help with provisional UI mockups, etc. where needed on request, or to collaborate...
Improving the game
There is a great amount of improvements that we could make to the game. It can however get complex pretty fast, so it is important to be comfortable with the basics of the programming language used before really getting into big projects.
Learning to code in C++...
Lighting and shadows
Simulating lighting and shadows can greatly improve the visuals of a video game. It may however get very complex. For the sake of simplicity, here, we will only handle the display of shadows (And in a simple way).
Representation of colors
Colors are often...
Buying and using potions
Until now, there was no mean for the player to obtain gold. We will give the character a gold coin for each monster slayed.
In the section of code executed when the player kills a monster, we will add the following code:
// Increases the amount of gold by...
Adding a merchant and building
Adding the castle
We will add a small castle at the bottom left of the window. We load its texture and create its sprite:
Making the monsters attack
Storing information about the player
To keep track of the health and the amount of gold and potions the player has, we define 3 variables:
int playerGoldAmount = 0, playerPotionAmount = 0, playerHealthAmount = 3;
How the monsters attack
The monsters attack by casting...
The class used to display text is sf::Text.
Similarly to how an object of type sf::Sprite needs a texture, an object of type sf::Text requires a font.
A font specifies the shape of the characters (And other information) and an object of type...
Making the character attack
Keeping track of whether a monster is alive or not
A variable of type 'bool' can either equal 'true' or 'false'. Here, we define an array of 'bool' values indicating if a monster is dead or not:
In the loop where we assign the texture to the...
Displaying the monsters
There are 3 textures for the monsters. To simulate an animation, we will alternate between them every 0.333 seconds.
Handling the collisions
Currently, collisions are not tested. The player can walk over the trees and stones. Let us resolve that.
Testing the collision between two sprites
The class sf::FloatRect is almost the same as sf::IntRect. The only difference is that its members (Representing its...
Adding the character
The sprite and texture
Testing if a key is pressed
Adding trees and stones
Adding the trees
When we have to create many variables of the same type, defining them individually may be inconvenient. In that case, it is better to create an array. An array is simply a group of variables which are individually accessed by their index within the array, rather than by...
Drawing into the window
The class sf::Texture is used to store pictures in the memory of the graphic card, ready to be drawn.
Its method loadFromFile loads the picture from the file located at the path received in argument. Note that, in C++, text is surrounded by quotes.
Opening the window
The object sf::RenderWindow
The following line of code defines an object of type sf::RenderWindow, which opens a window at its creation.
sf::RenderWindow win(sf::VideoMode(800, 600), "Introduction to coding", sf::Style::Close);
Above, we also provide arguments to the...
Introduction to coding
About this tutorial
The purpose of this tutorial is to introduce how coding works, with the C++ language here, by creating and explaining, step by step, the code of a small 2D game. In other words, the goal is to provide an overview of programming with the C++...
I'm @Daniel. I'm a Moderator here at CF.org and a person who's into Computers, Programming, Mathematics and Physics. This is my second Hello World post as my first one was in my opinion, more of just a rant detailing why I came back to CF. So, I figured that I'd give myself a more...