Project categories

Project site header
Category
Games
Platform
PC
Language
C++
Type
nCode project
Team members
1
Date
2010
State
Completed

Description

This game was made for learning purposes, and is a PC version of the DS game 'New Mario Bros'. There was a special effort not only on functionality, but on every detailed I had time to code: GUI, control of player, camera movement, scene animations... The final result resembles the DS version, even still lacks some features. Not to say, but the code, images and explanations on the site are not about Nintendo's game, but from my version.

All the programming was done in C++, except for the LUA bindings used for the AI system. About the rendering, it was done directly through OpenGL. However, the code was refactorized during development and I ended with two libraries plus the game: a core library, a small 2D tile-based engine for platform games and the game itself.

The core library has the following components:

  • Rendering functions and utilities.
  • Integrated shader support.
  • Input devices: mouse, keyboard and joystick.
  • Texture manger and font managers.
  • Simple math and geometry library with 2-dimensional components: 2d vectors, points, squares and operations between them.
  • State machine component.
  • Sound engine.
  • Graphical console for debug purposes.

The 2D engine has the following features:

  • Collision system for map and game entities
  • Complete tile system, allowing animated and breakable tiles.
  • Levels: a level is made by a set of maps.
  • Levels and maps stored as external resources: allows configuration for each map, enemy's locations and tile's configurations.
  • Configurable layers for maps: tile maps and parallax images supported (both can be animated).
  • Enemies and items support.
  • Basic GUI system: handles basic events and allows transition effects.

In the game we can find the following features:

  • Two complete levels
  • Multiplayer mode: two players in a local network
  • LUA bindings for AI of enemies: exported world state functions, AI specific functions, and base enemy class, allowing completely new enemies created just from LUA.
  • Configurable character controls.
  • Fine tuned character and camera movements.

Images

Video

Code sample

The following code shows the class for the maps used in the game.

weapon.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#ifndef ENGINE2D_LEVEL_MAP
#define ENGINE2D_LEVEL_MAP
 
#include <vector>
#include <string>
 
#include "Point2D.h"
 
#include "TileMap.h"
#include "ParallaxImage.h"
#include "MapLayer.h"
#include "BlockManager.h"
#include "EnemyManager.h"
#include "ItemManager.h"
 
 
 
 
 
 
namespace engine2d
{
 
 
class Scene;
 
 
 
/*!
    The class represents a level map. It is composed of several (0 or more) backgrounds,
    a foreground and an interaction layers.
*/
class LevelMap
{
public:
    LevelMap(void);
    virtual ~LevelMap(void);
 
    void Unload ();
 
    bool Update (Scene* scene, const double time_step);
 
    void DrawBackground (const core::Point2D& world_position);
    void DrawInteraction (const core::Point2D& world_position);
    void DrawForeground (const core::Point2D& world_position);
 
    void DrawDebug (const core::Point2D& world_position);
 
    TileMap& GetForegroundMap ()
    {
        return foreground_layer;
    }
 
    TileMap& GetInteractionMap ()
    {
        return interaction_layer;
    }
 
    std::vector <MapLayer*>& GetBackgroundLayers ()
    {
        return backgrounds;
    }
 
    void GetBackgroundColor (float& red, float& green, float& blue) const
    {
        red = this->red;
        green = this->green;
        blue = this->blue;
    }
 
    EnemyManager& GetEnemyManager ()
    {
        return enemy_manager;
    }
 
    ItemManager& GetItemManager ()
    {
        return item_manager;
    }
 
    BlockManager& GetBlockManager ()
    {
        return block_manager;
    }
 
    const std::string& GetMusic ()
    {
        return music;
    }
 
    void SetMusic (std::string& music_file)
    {
        music = music_file;
    }
 
    const core::Point2D& GetStartPosition ()
    {
        return start_position;
    }
 
    void SetStartPosition (const core::Point2D& position)
    {
        start_position = position;
    }
 
    void SetBackgroundColor (const float red, const float green, const float blue)
    {
        this->red = red;
        this->green = green;
        this->blue = blue;
    }
 
 
private:
    core::Point2D start_position;     //! Player start position in the map
 
    float red, green, blue;     //! Color components for the background
 
    std::vector <MapLayer*> backgrounds;  //! Vector of background (in draw order)
    TileMap interaction_layer;              //! Foreground tilemap
    TileMap foreground_layer;               //! Foreground tilemap
 
    std::string music;          //! Music of the level
 
    BlockManager block_manager;     //! Handles the blocks in the map
    EnemyManager enemy_manager;     //! Handles the enemies in the map
    ItemManager item_manager;       //! Handles the items in the map
 
private:
    void DrawMap (TileMap& map, int time, float worldx, float worldy);
    void DrawParallaxImage (ParallaxImage& parallax, int elapsed_time, float worldx, float worldy);
 
    double elapsed_time;
};
 
 
 
} // End of namespace engien2d
 
 
 
#endif
 
 

Links

RakNet
Multiplayer game network engine, used for the 2-player game mode.
FMOD
Sound library used for the game.
LUA
Scripting language used for the AI system.
luabind
Library used for C++/LUA binding.
VGMaps
Tile maps for the levels of the game.

NOTE! This site uses cookies and similar technologies.

This site uses cookies and similar technologies. If you not change browser settings, you agree to it. Learn more

I understand