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;
}
|