Commit a20e9ab7 authored by Aapeli's avatar Aapeli

Imported project source code

parent 89552234
echo "Starting build..."
cd src/
make windows_i686 linux_release linux_debug
echo "Creating binary folders..."
cd ..
cp -r windows-binary-skel windows-binary
cp -r windows-binary-all-dlls-skel windows-binary-dll
cp -r linux-binary-skel linux-binary
echo "Copying binaries..."
cp src/release/AapeliBlox.exe windows-binary
cp src/release/AapeliBlox.exe windows-binary-dll
cp src/release/AapeliBlox linux-binary
echo "Compressing binaries..."
cd windows-binary
zip AapeliBlox.zip *
cp AapeliBlox.zip ../
cd ..
rm windows-binary/ -r
cd windows-binary-dll
zip AapeliBlox-dll.zip *
cp AapeliBlox-dll.zip ../
cd ..
rm windows-binary-dll/ -r
cd linux-binary
tar -cvzf AapeliBlox.tar.gz *
cp AapeliBlox.tar.gz ../
cd ..
rm linux-binary/ -r
echo "Done."
Copyright (c) 2010 by vernon adams (vern@newtypography.co.uk),
with Reserved Font Name Bangers.
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
This diff is collapsed.
Copyright (c) 2011, Raph Levien (firstname.lastname@gmail.com), Copyright (c) 2012, Cyreal (cyreal.org)
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
AapeliBlox v1.0
===============
Copyright (c) 2014 Aapeli Vuorinen.
Free download for Linux and Windows at http://aape.li/blox.
About
=====
A small game where you form rows out of dropping blocks.
Installation
============
AapeliBlox requires the SFML libraries to be installed. Please
refer to your distribution in regard to how to install these.
On Ubuntu, this can be done by executing the command:
sudo apt-get install libsfml-graphics2 \
libsfml-system2 libsfml-window2
Technical details
=================
AapeliBlox uses the following great libraries/fonts:
SFML, Copyright (c) Laurent Gomila; Inconsolata, Copyright (c)
2011 Raph Levien (OFL 1.1); Bangers, Copyright (c) 2010 Vernon
Adams (OFL 1.1); and Chewy (Apache License 2.0).
If you contact me, I might give you the source code.
License
=======
This software is provided 'as-is', without any express or
implied warranty. In no event will the author be held liable
for any damages arising from the use of this software.
This software may be redistributed as permitted by law, given
that this file is included in every distribution.
make windows_i686 windows_i686_static1 windows_i686_static2 windows_i686_static3 linux_debug linux_release
#include <SFML/Graphics.hpp>
#include "classes.hpp"
namespace AapeliBlox {
Move::Move (int sx, int sy, int srotation, bool sjump) {
x = sx; y = sy; rotation = srotation; jump = sjump; lastMove = 0;
}
void Move::restart (void) {
lastMove = 0;
}
Vector::Vector (int sx, int sy) {
x = sx; y = sy;
}
Block::Block (sf::Color scolor, bool visible, bool sisUndoBlock) {
color = scolor; isBlock = visible; isUndoBlock = sisUndoBlock;
}
ShapeBlock::ShapeBlock (sf::Color scolor, int sx, int sy) {
x = sx; y = sy; color = scolor;
}
void Shape::updateExtrema (void) {
minx = 0; maxx = 0;
for (int i = 0; i < 4; i++) {
minx = std::min(minx, blocks[i].x);
maxx = std::max(maxx, blocks[i].x);
}
}
Shape::Shape (sf::Color scolor,
int x1, int y1,
int x2, int y2,
int x3, int y3,
int x4, int y4,
bool sevenWide,
bool soddThick,
int soriginx,
int soriginy) {
color = scolor;
blocks[0] = Vector(x1, y1);
blocks[1] = Vector(x2, y2);
blocks[2] = Vector(x3, y3);
blocks[3] = Vector(x4, y4);
evenWide = sevenWide;
oddThick = soddThick;
originx = soriginx;
originy = soriginy;
updateExtrema();
}
/** Rotate either 0, 90, 180, 270, etc degrees */
void Shape::rotate (int rotation) {
while (rotation < 0) {
rotation += 4;
}
int c = 0; int s = 0;
switch (rotation % 4) {
case 0:
c = 1; break;
case 1:
s = -1; break;
case 2:
c = -1; break;
case 3:
s = 1; break;
}
for (int i = 0; i < 4; i++) {
int x = blocks[i].x - originx;
int y = blocks[i].y - originy;
blocks[i].x = x * c - y * s;
blocks[i].y = x * s + y * c;
}
updateExtrema();
}
}
#ifndef CLASSES_HPP
#define CLASSES_HPP
#include <SFML/Graphics.hpp>
namespace AapeliBlox {
// Small helper class for moves
struct Move {
int x, y, rotation;
bool jump;
double lastMove;
Move (int sx = 0, int sy = 0, int srotation = 0, bool sjump = false);
void restart (void);
};
const int blockSide = 30;
struct Vector {
int x, y;
Vector (int sx = 0, int sy = 0);
};
struct Block {
sf::Color color;
bool isBlock;
bool isUndoBlock;
Block (sf::Color scolor = sf::Color::White, bool visible = false, bool sisUndoBlock = false);
};
struct ShapeBlock {
sf::Color color;
int x, y;
ShapeBlock (sf::Color scolor = sf::Color::White, int sx = 0, int sy = 0);
};
struct Shape {
bool evenWide;
bool oddThick;
int minx, maxx;
int originx, originy;
sf::Color color;
Vector blocks[4];
Shape (sf::Color scolor = sf::Color(255,255,255,0),
int x1 = 0, int y1 = 0,
int x2 = 0, int y2 = 1,
int x3 = 0, int y3 = 2,
int x4 = 0, int y4 = 3,
bool sevenWide = false,
bool soddThick = false,
int soriginx = 0,
int soriginy = 0);
void rotate (int rotation);
private:
void updateExtrema (void);
};
}
#endif //CLASSES_HPP
This diff is collapsed.
#ifndef GAME_HPP
#define GAME_HPP
#include <string>
#include <SFML/Graphics.hpp>
#include "classes.hpp"
#include "random.hpp"
#include "menus.hpp"
namespace AapeliBlox {
enum gameType {
undoGame,
timeTrial,
normal
};
class Game {
enum endType {
undoNoBlocks,
undoTimeOver,
timeTrialOver,
tooManyBlocks
};
states& gameState;
// Global game settings
int blockTowerWidth, blockTowerHeight, blockTowerVisibleHeight, blockSide, totalPoints, featureWidth;
int nextBlockHeight, textPaddingx, textPaddingy, featurePadding, undoHeight, gameTime, gameTimeMins, secsInMin;
Vector min, max, features, featuresNextBlock, featuresYourScore, featuresTimer;
Vector featuresNextBlockDimensions, featuresYourScoreDimensions, featuresTimerDimensions;
bool drawGhost;
// Some colors
sf::Color empty, undo;
Block emptyBlock, undoBlock;
// Time between each drop
double dropInterval, effectInterval;
// Timers
sf::Clock drop, effects, gameTimer;
std::string gameTimePretty;
int effectsPoints;
// We need a random number generator
RandomNumberGenerator& RNG;
// Vector to store blocks in
std::vector<std::vector<Block>> blocks;
sf::VertexArray blockVertexArray;
int colorIntensity;
std::vector<Shape> shapes;
// Grid data
sf::Color gridLineColor;
sf::VertexArray grid;
// Current block data
Shape currentShape;
Shape currentShapeGhost;
Shape nextShape;
Vector nextShapeLocation;
sf::VertexArray nextGrid, nextVertexArray;
Vector currentLocation;
Vector currentLocationGhost;
sf::VertexArray featureOutline, featureBoxes;
sf::Color featureOutlineColor, featureBoxColor;
Move left, right, down, jump, rotateLeft, rotateRight;
sf::Clock moveTimer;
double minMoveInterval;
// Point calcuation
std::vector<int> points;
std::vector<int> weights;
// Font stuff
// We need a font to display text with
// make it a pointer, so it's faster
sf::Font &sFont, &dFont;
sf::Text scoreText;
sf::Text scoreTextNumbers;
sf::Text nextShapeText;
sf::Text timerText;
sf::Text timerTextNumbers;
sf::Color textColor;
gameType curGameType;
MenuEntry &scoreEntry, &endEntry, &timeEntry;
void drawBlock (int x, int y, sf::Color& color);
void drawShape (Shape& sh, Vector& loc);
void drawNext (void);
void drawPoints (void);
void drawTimer (void);
void drawFeatureBox (int x, int y, int width, int height);
void placeGhost (void);
void checkRows (void);
bool canBlockGo (Shape shape, Vector location);
bool canBlockRotate (Shape shape, Vector location, int rotation);
void dissolveCurrentBlock (void);
void placeBlock (void);
void move (Move& doMove);
void centerText (sf::Text& text, int x, int y);
void doEffects (void);
void createUndoMap (void);
void calculatePoints (void);
void endGameLogic (endType type);
public:
Game (states& sgameState,
RandomNumberGenerator& sRNG,
sf::Font& sdFont,
sf::Font& ssFont,
MenuEntry& sscoreEntry,
MenuEntry& sendEntry,
MenuEntry& stimeEntry,
int sblockTowerWidth = 10,
int sblockTowerHeight = 22,
int sblockSide = 30,
int sminx = 50,
int sminy = 50,
int sfeaturewidth = 200,
int sfeaturepadding = 20,
bool sdrawGhost = true,
double sdropInterval = 0.5,
int blockColor = 254,
double sminMoveInterval = 0.1,
sf::Color empty = sf::Color(255, 0, 255, 150),
sf::Color undo = sf::Color(23, 47, 66, 255));
void newGame (gameType newGameType);
void spawnNewBlock (void);
void gameLogic (void);
void draw (sf::RenderWindow& window);
void inputLeft (void);
void inputRight (void);
void inputDown (void);
void inputRotateLeft (void);
void inputRotateRight (void);
void inputJump (void);
int getPoints (void);
void restart (void);
};
}
#endif //GAME_HPP
#include <vector>
#include <algorithm>
#include <SFML/Graphics.hpp>
#include "classes.hpp"
#include "random.hpp"
#include "game.hpp"
#include "menu.hpp"
#include "menus.hpp"
#include "resources/Inconsolata.hpp"
#include "resources/Bangers.hpp"
#include "resources/Chewy.hpp"
#include "resources/bloxIcon.hpp"
using namespace AapeliBlox;
int main(void)
{
// Current state
states gameState = inMainMenu;
int gameWidth = 522;
int gameHeight = 603;
int padding = 20;
int width = gameWidth + 2 * padding;
int height = gameHeight + 2 * padding;
sf::ContextSettings settings;
settings.antialiasingLevel = 2;
sf::RenderWindow window(sf::VideoMode(width, height), "AapeliBlox", sf::Style::Close, settings);
window.setIcon(bloxIcon.width, bloxIcon.height, bloxIcon.pixel_data);
std::random_device rRandomDevice;
RandomNumberGenerator myRNG(rRandomDevice(), 10);
sf::Font scoreFont;
scoreFont.loadFromMemory(Inconsolata_ttf, Inconsolata_ttf_len);
sf::Font menuFont;
menuFont.loadFromMemory(Bangers_ttf, Bangers_ttf_len);
sf::Font chewy;
chewy.loadFromMemory(Chewy_ttf, Chewy_ttf_len);
MenuHandler menus(gameState, menuFont, width, height);
Game myGame(gameState, myRNG, menuFont, scoreFont, menus.getEndScoreEntry(), menus.getEndTextEntry(), menus.getEndTimeEntry(), 10, 22, 30, 20, 20,
200, 20, true, 0.5, 200, 0.1, sf::Color(255, 0, 255, 150),
sf::Color(23, 47, 66, 255));
gameState = inMainMenu;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
switch (event.type) {
case sf::Event::Closed:
window.close(); break;
case sf::Event::LostFocus:
if (gameState == inGame) {
gameState = inContinueMenu;
}
case sf::Event::MouseMoved:
if (gameState != inGame) {
menus.mouseMoved(event.mouseMove.x, event.mouseMove.y);
}
break;
case sf::Event::MouseButtonPressed:
if (event.mouseButton.button == sf::Mouse::Left && gameState != inGame) {
menus.mouseClicked(event.mouseButton.x, event.mouseButton.y);
}
break;
case sf::Event::KeyPressed:
if (gameState != inGame) {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) { menus.inputUp(); }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { menus.inputDown(); }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Return)) { menus.inputEnter(); }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) { menus.inputEsc(); }
} else {
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) { myGame.inputLeft(); }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) { myGame.inputRight(); }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { myGame.inputDown(); }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) { myGame.inputRotateRight(); }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::X)) { myGame.inputRotateRight(); }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Z)) { myGame.inputRotateLeft(); }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) { myGame.inputJump(); }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::P)) { gameState = inContinueMenu; }
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)) { gameState = inContinueMenu; }
}
default: break;
}
}
if (gameState != inGame) {
switch (menus.processSelection()) {
case goToNewGameMenu:
gameState = inNewGameMenu; break;
case goToAboutBox:
gameState = inAboutBox; break;
case goToMainMenu:
gameState = inMainMenu; break;
case continueGame:
gameState = inGame; break;
case doQuit:
window.close(); break;
case newGameUndo:
myRNG.reSeed(rRandomDevice());
myGame.newGame(undoGame); break;
case newGameTimeTrial:
myRNG.reSeed(rRandomDevice());
myGame.newGame(timeTrial); break;
case newGameNormal:
myRNG.reSeed(rRandomDevice());
myGame.newGame(normal); break;
case newGameRestart:
myGame.restart(); break;
default: break;
}
}
// Clear the buffer
window.clear(sf::Color(255, 255, 255, 255));
myGame.gameLogic();
myGame.draw(window);
menus.draw(window);
// Display everything
window.display();
}
// All good. Quit.
return 0;
}
wincc = i686-w64-mingw32-g++
winext = .exe
linuxcc = g++
name = AapeliBlox
optimize =-O2
errors = # Change to -Wall for all warnings
hcon = -mwindows # Hide console
windows_i686:
$(wincc) *.cpp -o release/$(name)$(winext) -lsfml-graphics -lsfml-window -lsfml-system $(errors) -std=c++11 $(optimize) -static $(hcon)
linux_release:
$(linuxcc) *.cpp -o release/$(name) -lsfml-graphics -lsfml-window -lsfml-system $(errors) -std=c++11 $(optimize)
linux_debug:
$(linuxcc) *.cpp -o release/$(name).debug -lsfml-graphics -lsfml-window -lsfml-system $(errors) -std=c++11 -ggdb
#include <vector>
#include <string>
#include <algorithm>
#include <SFML/Graphics.hpp>
#include "menu.hpp"