- Compiler used : MS VISUAL STUDIO 2013
- Library used for graphics : SFML 2.3.2
This model yet does not have a lot of variety in terms of enemies and mario's super powers but it does have a large number of enemies and a considerably high difficulty level. Mario must score a total score of 25000 in order to win(since there's only one level for now)
- Most importantly, one must understand how to install SFML 2.3.2. First I had downloaded this version of SFML
- Next, I had to set the visual studio 2013 (Ultimate) configurations to x64, and declare location of this SFML as under:
- And added all the required .lib files shown under:
Here's a brief description of how I have implemented Mario and other game functionality:
- A virtual base class:
class Base // Virtual Base class for player and enemies
{
public: // Common data members for all things that will move
float dx, dy, currentFrame; // Displacement(dx & dy) and frame variables
FloatRect rect; // Rectangle that will hold objects and move in the map
Sprite sprite; // Object sprite
int power;
bool life, onGround; // OnGround checks if landed
Player_direction direction; // enum to get direction
RectangleShape power_indicator; // Power Indicator for Enemies and Mario
public:
virtual void update(float time) = 0; // This is the virtual update function
virtual void Collision(int num) = 0; // Virtual Collision function
virtual void operator --(int) = 0; // To reduce power
};
- Also the coins, player and all the enemies inherit from this class publically:
- If you have seen the video, you might be wondering how the bullets have been generated. For this I had to take some help from "subConcious bias"
Actually all of the bullets are stored in vector and updated & deleted using an iterator using ERASE REMOVE IDIOM. Bullet class is as following:
// Projectile.h
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <vector>
enum Player_direction{ stop, go_left, go_right }; // This for player's direction
class projectile
{
public:
// Data members
float velocity = 20; // Bullet speed
Player_direction direction; // 1. Left, 2. Right
sf::RectangleShape rect; // Bullets rectangle
bool hit; // Check if enemy was hit
// Methods
projectile();
void update();
};
// Projectile.cpp
#include "projectile.h"
projectile::projectile()
{
rect.setSize(sf::Vector2f(4, 2));
rect.setFillColor(sf::Color::Black);
rect.setPosition(0, 0);
hit = false;
direction = stop;
}
void projectile::update()
{
if (direction == 1)
rect.move(-velocity, 0); // Right
if (direction == 2)
rect.move(velocity, 0); // Left
}
- And what about the map. Well that is a tile map. I got that idea from here and the code that he provided:
The one in my game looks something like this
- Collisions were detected in a bit wise fashion again adapted from the last declared source (NO PLAGIARISM!)
void Collision(int num)
{
for (int i = rect.top / 16; i < (rect.top + rect.height) / 16; i++)
for (int j = rect.left / 16; j<(rect.left + rect.width) / 16; j++)
{
if ((TileMap1[i][j] == 'P') || (TileMap1[i][j] == 'k') || (TileMap1[i][j] == '0') || (TileMap1[i][j] == 'r') || (TileMap1[i][j] == 't') || (TileMap1[i][j] == 'c') || (TileMap1[i][j] == 'b') || (TileMap2[i][j] == 'u'))
{
if (dy>0 && num == 1)
{
rect.top = i * 16.f - rect.height;
dy = 0;
onGround = true;
}
if (dy<0 && num == 1)
{
rect.top = i * 16.f + 16.f;
dy = 0;
if (TileMap1[i][j] == 'k' || TileMap1[i][j] == 'b') // Wall breaking here
{
power--; // Reduce and balance power
if (power <= 0) { power = 0; life = false; }
TileMap1[i][j] = ' ';
wallbreak.play();
}
if (TileMap1[i][j] == 'c') // Pickables here
{
TileMap1[i][j] = ' '; // Clear it any way
if (rand() % 2 == 1 && reloadPlay)
{
Reload.play();
reloadPlay = false;
isGun = true;
}
else if (life) // Increase and balance power if it's not dead
power += 10;
}
}
if (dx>0 && num == 0)
{
rect.left = j * 16.f - rect.width;
}
if (dx<0 && num == 0)
{
rect.left = j * 16.f + 16.f;
}
}
if (TileMap2[i][j] == 'u') // Check for coin collect
{
TileMap2[i][j] = ' ';
coin_count++;
coin_collected.play();
}
}
}
As you can see, I have not developed all of this game by my self, some fractions such as the base class and bullets have been adopted from some other sources.
Oh yes! and don't forget to comment if you have anything to say regarding this blog and its contents.
Oh yes! and don't forget to comment if you have anything to say regarding this blog and its contents.
https://drive.google.com/file/d/0B85VdlLZ1OW6YkhlMUZBVkhhWDA/view?usp=sharing