Text based adventure side-scroller. Works and would like input

I am working on a side-scroller that is currently in text mode. I'll make this short because there are a lot of notes in main.cpp for you to refer to.

I'm not looking for someone to read all this code. I am looking for someone to give a peek at the style of coding and perhaps give some suggestions. Such as more effective ways get the job done.

So if you have time and are really bored I would appreciate some input. Even if its a very small comment - every suggestion counts! :)

I'd like to warn the user that this is basically an engine and there's not much to it. Just 3 characters to start with that are surrounded by a rectangle border. This is NOT a full or playable game. Just a hollow environment to test the game.

Here's what the game looks like:

Board y: 18                     *                Mode: Play
Board x: 2                      *
Section: 0                      *
Object: 0                       *
Ar Size[0]: 81                  *               O              O
Ar Size[1]: 60                  *              ===            ===
                                *  O            |              |
                                * ---          / \            / \
                                *  |        _________      _________
  0: 14                         * / \        o     o        o     o
 90: 7                          *************************************
180: 0 
270: 1
Disp Section: 0 to 1
Sections: 4
Section Size: 30
Move Seq#: 0  @ 0
Move Rep#: 0  @ 0  Actual: 0  



I only have enough room for main, so will post it here:

// main.cpp
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
145
146
147
148
149
150
151
152
// main.cpp
#include <iostream>
#include <ncurses.h>
#include <vector>
#include <algorithm>
#include <functional>
#include "game.h"
#include "drawscreen.h"

/*	
 *		This program is free software: you can redistribute it and/or modify
 *	it under the terms of the GNU General Public License as published by
 *	the Free Software Foundation, either version 3 of the License, or
 *	(at your option) any later version.
 *
 *		This program is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU General Public License for more details.
 * 
 *		You should have received a copy of the GNU General Public License
 *	along with this program.  If not, see <http://www.gnu.org/licenses/>. */

/*
 * 	These dependancies must be installed to compile this program in ubuntu:
 *	sudo apt-get install build-essential ncurses-dev
 *	
 *	Compile & run on linux:
 *	g++ -Wall main.cpp game.cpp drawscreen.cpp -lncurses -std=c++11
 * 
 *  Run:
 *	./a.out 
 */


/*	
 * 	Gameplay:
 * 
 * a = left
 * d = right
 * s = down / stop jumping
 * w = jump
 * 
 * up/down/left/right arrows also steers character but  is unrestrained
 * and allows to go through objects. this is used for background and
 * see-through objects and is not yet fully implimented
 * 
 *	e = edit mode
 *
 *	edit mode allows one to move around the board without gravity effects 
 *	on particular character
 * 
 *	r = record moves
 * 
 * 	when 'r' is pressed the game starts recording your moves. press
 *	'r' again to go back into play mode and playback the moves. note
 *	that while playing moves you cannot control the character. to
 * 	regain control simply press 'r' twice. this will record 0 moves
 *	and allow movement freedom.
 *
 * 	1-9 = switch to player number < keypressed >
 * 
 *	you can automatically switch to any other player or enemy by
 * 	pressing their player number button
 * 
 *	q / esc = quit game
 *
 * 
 *	bugs - there is a bug that causes the characters to sink into
 *	the platform when entering and leaving other sections. temp fix
 * 	can be implimented by uncommenting line 140/141 in drawscreen.cpp
 *	
 * 
 * 	Benefits of game:
 *  
 *  - NOTES!!! - Almost every line of code has notes, not on 'what' is
 *	  happening, but 'why' it has to happen :)
 * 	- 0 number of errors or warnings  in compile (g++ -wall mode)
 *	- debugging stats on screen during gameplay
 *  - sectioned areas for speed and large maps
 *	- infinit player ability
 *  - easily upgradable to graphics (have done before with SDL)
 *  - collision detection can detect collision at any speed/skip rate
 *  - all direction distance detection on dashboard
 * 	- easy to add split / dual screens / dual/triple... games
 * 	- all objects / characters treated the same. whatever a player
 * 	  can do, all objects can do, eg.. enemies, and even a brick, can jump.
 *    as well, enemies, player, and a brick can fly...
 * 	- can morpth or take over control of any other player or object
 * 	- encapsulated data; no #defines, static, and other global variables
 *
 * 
 * 
 * 	Please note that I am a beginner programmer and this is my
 * 	second C++ game. I have not made a map or implimented any other
 *  features as I feel it would be better focus on the basics.
 * 
 *  Comments regarding programming style are programming tips are
 *  welcomed and encouraged. Please refrain from giving ideas
 *  regarding gameplay and gameplay options, such as, "You should make
 *  more platforms and make a level system." I am not looking for such
 *  input.
 * 
 *  
 */

int main()
{
	
	// create draw object
	DrawScreen drawGame;
	
	// create game object vector
	std::vector<std::vector<Game> > obj;
	
	// create game character objects
	Game::initialiseGame(obj, drawGame);
	
	// run game
	while (drawGame.keepPlaying())
	{
		// get key presses
		drawGame.grabKeys();
		
		// draw objects
		drawGame.drawboard(obj);
		
		// calculate the lowest and highest section within range
		register int lowSection, highSection;
		drawGame.sectionLowTohigh(obj, lowSection, highSection);

		// move objects		
		for(int currentSection = lowSection;
			currentSection <= highSection; ++currentSection)
		{
			for(unsigned int i = 0; i < obj[currentSection].size(); ++i)
				obj[currentSection][i].moveCharacter(obj, drawGame, currentSection, i);
		}
		
		// draw all data to screen
		refresh();
		
	}

	// delete objects in memory
	obj.clear();

	// shut down ncurses and exit
	endwin();
	
	return 0;
}




Files can be downloaded here:

// main.cpp
http://ubuntuone.com/1CiZ31g97AaDENypwBqZnS

// game.cpp
http://ubuntuone.com/4D6mPykpKgnsbQJlypytek

// drawscreen.cpp
http://ubuntuone.com/2nAsdUl3u0B3UY3rZAksGJ

// game.h
http://ubuntuone.com/2y3fQXIXxf5vg94kMd76N2

// drawscreen.h
http://ubuntuone.com/0ZnGCqppPGLHD9PE63dEEO


:)
This looks so cool. Can you put a compiled version up on mediafire or somewhere? I would love to test this out but my compiler doesn't want to compile this :(
Last edited on
Hi Jayhawker07,

What OS are you using? What compiler?

This game was made under Linux and unfortunately the ncurses library that allows the text to be manipulated in the terminal is only available for that platform. However, later on I will be using the SDL graphics library that is cross platform, and I'll be supplying code for both Linux and Windows.

Anyways, if by chance you do run Linux then here is the executable file compiled under Ubuntu:

//a.out
http://ubuntuone.com/5WTowZbcNEDHnIAEFYz3C8

Run with the command: ./a.out
Topic archived. No new replies allowed.