| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1 |
/* |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2 |
=========================================================================== |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3 |
blockattack - Block Attack - Rise of the Blocks |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
4 |
Copyright (C) 2005-2012 Poul Sander |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
5 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
6 |
This program is free software: you can redistribute it and/or modify |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
7 |
it under the terms of the GNU General Public License as published by |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
8 |
the Free Software Foundation, either version 2 of the License, or |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
9 |
(at your option) any later version. |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
10 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
11 |
This program is distributed in the hope that it will be useful, |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
14 |
GNU General Public License for more details. |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
15 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
16 |
You should have received a copy of the GNU General Public License |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
17 |
along with this program. If not, see http://www.gnu.org/licenses/ |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
18 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
19 |
Source information and contacts persons can be found at |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
20 |
http://blockattack.sf.net |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
21 |
=========================================================================== |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
22 |
*/ |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
23 |
|
| 215ca7b3 |
sago007 |
2009-03-06 16:37 |
24 |
#include "common.h" |
| 26ddb424 |
sago007 |
2011-06-09 20:06 |
25 |
#include "global.hpp" |
| 9b99cf7a |
sago007 |
2015-12-04 20:22 |
26 |
#include "scopeHelpers.hpp" |
| 215ca7b3 |
sago007 |
2009-03-06 16:37 |
27 |
|
| 27ae0175 |
sago007 |
2009-01-30 06:02 |
28 |
#include <string.h> |
| 27ae0175 |
sago007 |
2009-01-30 06:02 |
29 |
|
| 27ae0175 |
sago007 |
2009-01-30 06:02 |
30 |
|
| 1572de2b |
sago007 |
2008-09-11 18:15 |
31 |
#ifndef VERSION_NUMBER |
| b37fa2db |
sago007 |
2015-12-04 20:44 |
32 |
#define VERSION_NUMBER "version 1.5.0 BETA" |
| 1572de2b |
sago007 |
2008-09-11 18:15 |
33 |
#endif |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
34 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
35 |
//If DEBUG is defined: AI info and FPS will be written to screen |
| 1572de2b |
sago007 |
2008-09-11 18:15 |
36 |
#ifndef DEBUG |
| 571b4d47 |
sago007 |
2015-12-05 16:02 |
37 |
#define DEBUG 1 |
| 1572de2b |
sago007 |
2008-09-11 18:15 |
38 |
#endif |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
39 |
|
| 2e57d791 |
sago007 |
2009-06-04 17:48 |
40 |
#define WITH_SDL 1 |
| 2e57d791 |
sago007 |
2009-06-04 17:48 |
41 |
|
| c6bde3e3 |
sago007 |
2015-12-22 16:56 |
42 |
#include "sago/SagoSpriteHolder.hpp" |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
43 |
#include <iostream> |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
44 |
#include <stdlib.h> |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
45 |
#include <time.h> //Used for srand() |
| 769a41a0 |
sago007 |
2008-09-24 12:54 |
46 |
#include <sstream> //Still used by itoa2 |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
47 |
#include <string> |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
48 |
#include "SDL.h" //The SDL libary, used for most things |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
49 |
#include <SDL_mixer.h> //Used for sound & music |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
50 |
#include <SDL_image.h> //To load PNG images! |
| 41f02ab2 |
sago007 |
2009-05-10 21:40 |
51 |
#include <physfs.h> //Abstract file system. To use containers |
| 41f02ab2 |
sago007 |
2009-05-10 21:40 |
52 |
#include "physfs_stream.hpp" //To use C++ style file streams |
| 925b7e58 |
sago007 |
2011-04-25 16:35 |
53 |
#include "Libs/NFont.h" |
| 47529580 |
sago007 |
2008-12-09 02:34 |
54 |
//#include "ttfont.h" //To use True Type Fonts in SDL |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
55 |
//#include "config.h" |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
56 |
#include <vector> |
| 95bc02ff |
sago007 |
2009-03-15 02:46 |
57 |
#include <SDL/SDL_timer.h> |
| 925b7e58 |
sago007 |
2011-04-25 16:35 |
58 |
#include <SDL/SDL_video.h> |
| 925b7e58 |
sago007 |
2011-04-25 16:35 |
59 |
#include <SDL/SDL_ttf.h> |
| 605138b3 |
sago007 |
2012-04-14 15:12 |
60 |
#include "CppSdlImageHolder.hpp" |
| b7590374 |
sago007 |
2011-05-19 16:15 |
61 |
#include "MenuSystem.h" |
| 055218be |
sago007 |
2015-08-22 18:44 |
62 |
#include "puzzlehandler.hpp" |
| f3a1637d |
sago007 |
2015-11-14 21:32 |
63 |
#include <memory> |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
64 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
65 |
//if SHAREDIR is not used we look in current directory |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
66 |
#ifndef SHAREDIR |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
67 |
#define SHAREDIR "." |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
68 |
#endif |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
69 |
|
| c9dd376f |
sago007 |
2012-01-20 17:13 |
70 |
#ifndef LOCALEDIR |
| c9dd376f |
sago007 |
2012-01-20 17:13 |
71 |
#define LOCALEDIR SHAREDIR"/locale" |
| c9dd376f |
sago007 |
2012-01-20 17:13 |
72 |
#endif |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
73 |
|
| c9dd376f |
sago007 |
2012-01-20 17:13 |
74 |
#ifndef PACKAGE |
| c9dd376f |
sago007 |
2012-01-20 17:13 |
75 |
#define PACKAGE "blockattack_roftb" |
| c9dd376f |
sago007 |
2012-01-20 17:13 |
76 |
#endif |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
77 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
78 |
#include "highscore.h" //Stores highscores |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
79 |
#include "ReadKeyboard.h" //Reads text from keyboard |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
80 |
#include "joypad.h" //Used for joypads |
| acd79baf |
sago007 |
2015-11-22 19:37 |
81 |
#include "listFiles.h" //Used to show files on screen |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
82 |
#include "stats.h" //Saves general stats |
| bc9ea011 |
sago007 |
2009-04-12 17:43 |
83 |
//#include "uploadReplay.h" //Takes care of everything libcurl related |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
84 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
85 |
#include "common.h" |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
86 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
87 |
/******************************************************************************* |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
88 |
* All variables and constant has been moved to mainVars.hpp for the overview. * |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
89 |
*******************************************************************************/ |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
90 |
#include "mainVars.hpp" |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
91 |
|
| 90e6c797 |
sago007 |
2015-11-22 21:46 |
92 |
using namespace std; |
| 90e6c797 |
sago007 |
2015-11-22 21:46 |
93 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
94 |
|
| 4b0c248f |
sago007 |
2010-11-10 21:13 |
95 |
static void UnloadImages(); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
96 |
static int InitImages(sago::SagoSpriteHolder& holder); |
| 866417ca |
sago007 |
2009-05-10 21:35 |
97 |
|
| 866417ca |
sago007 |
2009-05-10 21:35 |
98 |
static string oldThemePath = "default"; |
| 41f02ab2 |
sago007 |
2009-05-10 21:40 |
99 |
static bool loaded = false; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
100 |
|
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
101 |
void loadTheme(sago::SagoSpriteHolder& holder, const string& themeName) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
102 |
if (loaded) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
103 |
UnloadImages(); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
104 |
} |
| 866417ca |
sago007 |
2009-05-10 21:35 |
105 |
#if defined(__unix__) |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
106 |
string home = (string)getenv("HOME")+(string)"/.gamesaves/blockattack"; |
| 866417ca |
sago007 |
2009-05-10 21:35 |
107 |
#elif defined(_WIN32) |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
108 |
string home = (string)getMyDocumentsPath()+(string)"/My Games/blockattack"; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
109 |
#endif |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
110 |
//Remove old theme |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
111 |
PHYSFS_removeFromSearchPath(oldThemePath.c_str()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
112 |
//Look in blockattack.data |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
113 |
PHYSFS_addToSearchPath(((string)SHAREDIR+"/blockattack.data").c_str(), 1); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
114 |
//Look in folder |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
115 |
PHYSFS_addToSearchPath( ((string) PHYSFS_getBaseDir()+"/data").c_str(), 1); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
116 |
//Look in home folder |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
117 |
#if defined(__unix__) || defined(_WIN32) |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
118 |
PHYSFS_addToSearchPath(home.c_str(), 1); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
119 |
#endif |
| b1592756 |
sago007 |
2015-11-15 16:18 |
120 |
if (themeName == Config::getInstance()->getString("themename")) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
121 |
//If this is a theme different from the saved one. Remember it! |
| b1592756 |
sago007 |
2015-11-15 16:18 |
122 |
Config::getInstance()->setString("themename", themeName); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
123 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
124 |
if (themeName.compare("default")==0 || (themeName.compare("start")==0)) { |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
125 |
InitImages(holder); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
126 |
loaded =true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
127 |
return; //Nothing more to do |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
128 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
129 |
oldThemePath = "themes/"+themeName; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
130 |
PHYSFS_addToSearchPath(oldThemePath.c_str(),0); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
131 |
#if defined(__unix__) || defined(_WIN32) |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
132 |
PHYSFS_addToSearchPath((home+(string)"/"+oldThemePath).c_str(), 0); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
133 |
#endif |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
134 |
InitImages(holder); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
135 |
loaded = true; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
136 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
137 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
138 |
|
| 078900fe |
sago007 |
2015-12-05 15:31 |
139 |
long NFont_OpenFont(SDL_Renderer* dest, NFont* target, const char* path,int ptsize, SDL_Color color, int style=TTF_STYLE_NORMAL) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
140 |
if (!PHYSFS_exists(path)) { |
| 56241205 |
sago007 |
2012-08-05 11:15 |
141 |
cerr << "Error: File not in blockattack.data: " << path << endl; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
142 |
return -1; //file doesn't exist |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
143 |
} |
| 925b7e58 |
sago007 |
2011-04-25 16:35 |
144 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
145 |
if (!(TTF_WasInit())) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
146 |
TTF_Init(); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
147 |
} |
| 925b7e58 |
sago007 |
2011-04-25 16:35 |
148 |
|
| 56241205 |
sago007 |
2012-08-05 11:15 |
149 |
PHYSFS_file* myfile = PHYSFS_openRead(path); |
| 925b7e58 |
sago007 |
2011-04-25 16:35 |
150 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
151 |
// Get the lenght of the file |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
152 |
unsigned int m_size = PHYSFS_fileLength(myfile); |
| 925b7e58 |
sago007 |
2011-04-25 16:35 |
153 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
154 |
// Get the file data. |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
155 |
char* m_data = new char[m_size]; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
156 |
int length_read = PHYSFS_read (myfile, m_data, 1, m_size); |
| 925b7e58 |
sago007 |
2011-04-25 16:35 |
157 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
158 |
if (length_read != (int)m_size) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
159 |
delete [] m_data; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
160 |
m_data = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
161 |
PHYSFS_close(myfile); |
| 56241205 |
sago007 |
2012-08-05 11:15 |
162 |
cerr << "Error: Curropt data file!" << endl; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
163 |
return -3; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
164 |
} |
| 925b7e58 |
sago007 |
2011-04-25 16:35 |
165 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
166 |
PHYSFS_close(myfile); |
| 925b7e58 |
sago007 |
2011-04-25 16:35 |
167 |
|
| 925b7e58 |
sago007 |
2011-04-25 16:35 |
168 |
// And this is how you load from a memory buffer with SDL |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
169 |
SDL_RWops* rw = SDL_RWFromMem (m_data, m_size); |
| 925b7e58 |
sago007 |
2011-04-25 16:35 |
170 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
171 |
//The above might fail an return null. |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
172 |
if (!rw) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
173 |
delete [] m_data; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
174 |
m_data = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
175 |
PHYSFS_close(myfile); |
| 56241205 |
sago007 |
2012-08-05 11:15 |
176 |
cerr << "Error: Curropt data file!" << endl; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
177 |
return -2; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
178 |
} |
| 925b7e58 |
sago007 |
2011-04-25 16:35 |
179 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
180 |
TTF_Font* font; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
181 |
font=TTF_OpenFontRW(rw, 1, ptsize); |
| 078900fe |
sago007 |
2015-12-05 15:31 |
182 |
TTF_SetFontStyle(font, style); |
| 925b7e58 |
sago007 |
2011-04-25 16:35 |
183 |
|
| 078900fe |
sago007 |
2015-12-05 15:31 |
184 |
target->load(dest, font, color); |
| 925b7e58 |
sago007 |
2011-04-25 16:35 |
185 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
186 |
TTF_CloseFont(font); //Once loaded we don't care anymore! |
| 925b7e58 |
sago007 |
2011-04-25 16:35 |
187 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
188 |
return 0; |
| 925b7e58 |
sago007 |
2011-04-25 16:35 |
189 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
190 |
|
| 41f02ab2 |
sago007 |
2009-05-10 21:40 |
191 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
192 |
Mix_Music* Mix_LoadMUS2(string path) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
193 |
if (!PHYSFS_exists(path.c_str())) { |
| 56241205 |
sago007 |
2012-08-05 11:15 |
194 |
cerr << "Warning: File not in blockattack.data: " << path << endl; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
195 |
return nullptr; //file doesn't exist |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
196 |
} |
| adaf31bf |
sago007 |
2009-05-05 16:01 |
197 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
198 |
PHYSFS_file* myfile = PHYSFS_openRead(path.c_str()); |
| adaf31bf |
sago007 |
2009-05-05 16:01 |
199 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
200 |
// Get the lenght of the file |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
201 |
unsigned int m_size = PHYSFS_fileLength(myfile); |
| adaf31bf |
sago007 |
2009-05-05 16:01 |
202 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
203 |
// Get the file data. |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
204 |
char* m_data = new char[m_size]; |
| adaf31bf |
sago007 |
2009-05-05 16:01 |
205 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
206 |
int length_read = PHYSFS_read (myfile, m_data, 1, m_size); |
| adaf31bf |
sago007 |
2009-05-05 16:01 |
207 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
208 |
if (length_read != (int)m_size) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
209 |
delete [] m_data; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
210 |
m_data = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
211 |
PHYSFS_close(myfile); |
| 56241205 |
sago007 |
2012-08-05 11:15 |
212 |
cerr << "Error: Curropt data file!" << endl; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
213 |
return nullptr; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
214 |
} |
| adaf31bf |
sago007 |
2009-05-05 16:01 |
215 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
216 |
PHYSFS_close(myfile); |
| adaf31bf |
sago007 |
2009-05-05 16:01 |
217 |
|
| adaf31bf |
sago007 |
2009-05-05 16:01 |
218 |
// And this is how you load from a memory buffer with SDL |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
219 |
SDL_RWops* rw = SDL_RWFromMem (m_data, m_size); |
| adaf31bf |
sago007 |
2009-05-05 16:01 |
220 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
221 |
//The above might fail an return null. |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
222 |
if (!rw) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
223 |
delete [] m_data; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
224 |
m_data = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
225 |
PHYSFS_close(myfile); |
| 56241205 |
sago007 |
2012-08-05 11:15 |
226 |
cerr << "Error: Curropt data file!" << endl; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
227 |
return nullptr; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
228 |
} |
| adaf31bf |
sago007 |
2009-05-05 16:01 |
229 |
|
| 078900fe |
sago007 |
2015-12-05 15:31 |
230 |
Mix_Music* ret = Mix_LoadMUS_RW(rw, SDL_TRUE); |
| adaf31bf |
sago007 |
2009-05-05 16:01 |
231 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
232 |
return ret; |
| adaf31bf |
sago007 |
2009-05-05 16:01 |
233 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
234 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
235 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
236 |
Mix_Chunk* Mix_LoadWAV2(const char* path) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
237 |
if (!PHYSFS_exists(path)) { |
| 56241205 |
sago007 |
2012-08-05 11:15 |
238 |
cerr << "Warning: File not in blockattack.data: " << path << endl; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
239 |
return nullptr; //file doesn't exist |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
240 |
} |
| adaf31bf |
sago007 |
2009-05-05 16:01 |
241 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
242 |
PHYSFS_file* myfile = PHYSFS_openRead(path); |
| adaf31bf |
sago007 |
2009-05-05 16:01 |
243 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
244 |
// Get the lenght of the file |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
245 |
unsigned int m_size = PHYSFS_fileLength(myfile); |
| adaf31bf |
sago007 |
2009-05-05 16:01 |
246 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
247 |
// Get the file data. |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
248 |
char* m_data = new char[m_size]; |
| adaf31bf |
sago007 |
2009-05-05 16:01 |
249 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
250 |
int length_read = PHYSFS_read (myfile, m_data, 1, m_size); |
| adaf31bf |
sago007 |
2009-05-05 16:01 |
251 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
252 |
if (length_read != (int)m_size) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
253 |
delete [] m_data; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
254 |
m_data = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
255 |
PHYSFS_close(myfile); |
| 56241205 |
sago007 |
2012-08-05 11:15 |
256 |
cerr << "Error: Curropt data file!" << endl; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
257 |
return nullptr; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
258 |
} |
| adaf31bf |
sago007 |
2009-05-05 16:01 |
259 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
260 |
PHYSFS_close(myfile); |
| adaf31bf |
sago007 |
2009-05-05 16:01 |
261 |
|
| adaf31bf |
sago007 |
2009-05-05 16:01 |
262 |
// And this is how you load from a memory buffer with SDL |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
263 |
SDL_RWops* rw = SDL_RWFromMem (m_data, m_size); |
| adaf31bf |
sago007 |
2009-05-05 16:01 |
264 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
265 |
//The above might fail an return null. |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
266 |
if (!rw) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
267 |
delete [] m_data; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
268 |
m_data = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
269 |
PHYSFS_close(myfile); |
| 56241205 |
sago007 |
2012-08-05 11:15 |
270 |
cerr << "Error: Curropt data file!" << endl; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
271 |
return nullptr; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
272 |
} |
| adaf31bf |
sago007 |
2009-05-05 16:01 |
273 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
274 |
Mix_Chunk* ret = Mix_LoadWAV_RW(rw,true); //the second argument tells the function to three RWops |
| adaf31bf |
sago007 |
2009-05-05 16:01 |
275 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
276 |
return ret; |
| adaf31bf |
sago007 |
2009-05-05 16:01 |
277 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
278 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
279 |
//Load all image files to memory |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
280 |
static int InitImages(sago::SagoSpriteHolder& holder) { |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
281 |
bricks[0] = holder.GetSprite("blue"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
282 |
bricks[1] = holder.GetSprite("green"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
283 |
bricks[2] = holder.GetSprite("purple"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
284 |
bricks[3] = holder.GetSprite("red"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
285 |
bricks[4] = holder.GetSprite("turkish"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
286 |
bricks[5] = holder.GetSprite("yellow"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
287 |
bricks[6] = holder.GetSprite("grey"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
288 |
bomb = holder.GetSprite("block_bomb"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
289 |
backgroundImage = holder.GetSprite("background"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
290 |
bHighScore = holder.GetSprite("b_highscore"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
291 |
bBack = holder.GetSprite("b_back"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
292 |
bForward = holder.GetSprite("b_forward"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
293 |
blackLine = holder.GetSprite("black_line"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
294 |
stageBobble = holder.GetSprite("i_stage_clear_limit"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
295 |
crossover = holder.GetSprite("crossover"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
296 |
balls[0] = holder.GetSprite("ball_blue"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
297 |
balls[1] = holder.GetSprite("ball_green"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
298 |
balls[2] = holder.GetSprite("ball_purple"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
299 |
balls[3] = holder.GetSprite("ball_red"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
300 |
balls[4] = holder.GetSprite("ball_turkish"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
301 |
balls[5] = holder.GetSprite("ball_yellow"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
302 |
balls[6] = holder.GetSprite("ball_gray"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
303 |
cursor = holder.GetSprite("cursor"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
304 |
ready = holder.GetSprite("ready"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
305 |
explosion[0] = holder.GetSprite("explosion0"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
306 |
explosion[2] = holder.GetSprite("explosion1"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
307 |
explosion[3] = holder.GetSprite("explosion2"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
308 |
explosion[4] = holder.GetSprite("explosion3"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
309 |
counter[0] = holder.GetSprite("counter_1"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
310 |
counter[1] = holder.GetSprite("counter_2"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
311 |
counter[2] = holder.GetSprite("counter_3"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
312 |
iGameOver = holder.GetSprite("i_game_over"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
313 |
iWinner = holder.GetSprite("i_winner"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
314 |
iDraw = holder.GetSprite("i_draw"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
315 |
iLoser = holder.GetSprite("i_loser"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
316 |
//iChainFrame = holder.GetSprite("chain_frame"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
317 |
dialogBox = holder.GetSprite("dialogbox"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
318 |
iLevelCheck = holder.GetSprite("i_level_check"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
319 |
iLevelCheckBox = holder.GetSprite("i_level_check_box"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
320 |
iLevelCheckBoxMarked = holder.GetSprite("i_level_check_box_marked"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
321 |
iCheckBoxArea = holder.GetSprite("i_check_box_area"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
322 |
boardBackBack = holder.GetSprite("board_back_back"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
323 |
garbageTL = holder.GetSprite("garbage_tl"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
324 |
garbageT = holder.GetSprite("garbage_t"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
325 |
garbageTR = holder.GetSprite("garbage_tr"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
326 |
garbageR = holder.GetSprite("garbage_r"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
327 |
garbageBR = holder.GetSprite("garbage_br"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
328 |
garbageB = holder.GetSprite("garbage_b"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
329 |
garbageBL = holder.GetSprite("garbage_bl"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
330 |
garbageL = holder.GetSprite("garbage_l"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
331 |
garbageFill = holder.GetSprite("garbage_fill"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
332 |
garbageML = holder.GetSprite("garbage_ml"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
333 |
garbageM = holder.GetSprite("garbage_m"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
334 |
garbageMR = holder.GetSprite("garbage_mr"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
335 |
garbageGM = holder.GetSprite("garbage_gm"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
336 |
garbageGML = holder.GetSprite("garbage_gml"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
337 |
garbageGMR = holder.GetSprite("garbage_gmr"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
338 |
smiley[0] = holder.GetSprite("smileys0"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
339 |
smiley[1] = holder.GetSprite("smileys1"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
340 |
smiley[2] = holder.GetSprite("smileys2"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
341 |
smiley[3] = holder.GetSprite("smileys3"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
342 |
transCover = holder.GetSprite("trans_cover"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
343 |
bSkip = holder.GetSprite("b_skip"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
344 |
bNext = holder.GetSprite("b_next"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
345 |
bRetry = holder.GetSprite("b_retry"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
346 |
mouse = holder.GetSprite("mouse"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
347 |
menuMarked = holder.GetSprite("menu_marked"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
348 |
menuUnmarked = holder.GetSprite("menu_unmarked"); |
| 6332acb6 |
sago007 |
2015-12-19 17:51 |
349 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
350 |
SDL_Color nf_button_color, nf_standard_blue_color, nf_standard_small_color; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
351 |
memset(&nf_button_color,0,sizeof(SDL_Color)); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
352 |
nf_button_color.b = 255; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
353 |
nf_button_color.g = 255; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
354 |
nf_button_color.r = 255; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
355 |
nf_standard_blue_color.b = 255; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
356 |
nf_standard_blue_color.g = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
357 |
nf_standard_blue_color.r = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
358 |
nf_standard_small_color.b = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
359 |
nf_standard_small_color.g = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
360 |
nf_standard_small_color.r = 200; |
| 078900fe |
sago007 |
2015-12-05 15:31 |
361 |
NFont_OpenFont(screen, &nf_button_font,"fonts/FreeSerif.ttf",24,nf_button_color); |
| 078900fe |
sago007 |
2015-12-05 15:31 |
362 |
NFont_OpenFont(screen, &nf_standard_blue_font,"fonts/FreeSerif.ttf",30,nf_standard_blue_color); |
| 078900fe |
sago007 |
2015-12-05 15:31 |
363 |
NFont_OpenFont(screen, &nf_standard_small_font,"fonts/FreeSerif.ttf",16,nf_standard_small_color); |
| 078900fe |
sago007 |
2015-12-05 15:31 |
364 |
NFont_OpenFont(screen, &nf_scoreboard_font,"fonts/PenguinAttack.ttf",20,nf_button_color); //should draw to boardBackBack |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
365 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
366 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
367 |
//Loads the sound if sound present |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
368 |
if (!NoSound) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
369 |
//And here the music: |
| 56241205 |
sago007 |
2012-08-05 11:15 |
370 |
bgMusic = Mix_LoadMUS2("music/bgMusic.ogg"); |
| 56241205 |
sago007 |
2012-08-05 11:15 |
371 |
highbeatMusic = Mix_LoadMUS2("music/highbeat.ogg"); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
372 |
//the music... we just hope it exists, else the user won't hear anything |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
373 |
//Same goes for the sounds |
| 56241205 |
sago007 |
2012-08-05 11:15 |
374 |
boing = Mix_LoadWAV2("sound/pop.ogg"); |
| 56241205 |
sago007 |
2012-08-05 11:15 |
375 |
applause = Mix_LoadWAV2("sound/applause.ogg"); |
| 56241205 |
sago007 |
2012-08-05 11:15 |
376 |
photoClick = Mix_LoadWAV2("sound/cameraclick.ogg"); |
| 56241205 |
sago007 |
2012-08-05 11:15 |
377 |
typingChunk = Mix_LoadWAV2("sound/typing.ogg"); |
| 56241205 |
sago007 |
2012-08-05 11:15 |
378 |
counterChunk = Mix_LoadWAV2("sound/counter.ogg"); |
| 56241205 |
sago007 |
2012-08-05 11:15 |
379 |
counterFinalChunk = Mix_LoadWAV2("sound/counterFinal.ogg"); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
380 |
} //All sound has been loaded or not |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
381 |
return 0; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
382 |
} //InitImages() |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
383 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
384 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
385 |
//Unload images and fonts and sounds |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
386 |
void UnloadImages() { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
387 |
if (verboseLevel) { |
| 56241205 |
sago007 |
2012-08-05 11:15 |
388 |
cout << "Unloading data..." << endl; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
389 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
390 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
391 |
|
| 444cec07 |
sago007 |
2012-05-05 16:42 |
392 |
|
| 444cec07 |
sago007 |
2012-05-05 16:42 |
393 |
static stringstream converter; |
| 444cec07 |
sago007 |
2012-05-05 16:42 |
394 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
395 |
//Function to convert numbers to string (2 diget) |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
396 |
static string itoa2(int num) { |
| 444cec07 |
sago007 |
2012-05-05 16:42 |
397 |
converter.str(std::string()); |
| 444cec07 |
sago007 |
2012-05-05 16:42 |
398 |
converter.clear(); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
399 |
if (num<10) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
400 |
converter << "0"; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
401 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
402 |
converter << num; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
403 |
return converter.str(); |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
404 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
405 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
406 |
/*Draws a image from on a given Surface. Takes source image, destination surface and coordinates*/ |
| c6bde3e3 |
sago007 |
2015-12-22 16:56 |
407 |
void DrawIMG(sago::SagoSprite &sprite, SDL_Renderer* target, int x, int y) { |
| c6bde3e3 |
sago007 |
2015-12-22 16:56 |
408 |
sprite.Draw(target,1,x,y); |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
409 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
410 |
|
| c6bde3e3 |
sago007 |
2015-12-22 16:56 |
411 |
void DrawIMG_Bounded(sago::SagoSprite &sprite, SDL_Renderer* target, int x, int y, int minx, int miny, int maxx, int maxy) { |
| c6bde3e3 |
sago007 |
2015-12-22 16:56 |
412 |
SDL_Rect bounds; |
| c6bde3e3 |
sago007 |
2015-12-22 16:56 |
413 |
bounds.x = minx; |
| c6bde3e3 |
sago007 |
2015-12-22 16:56 |
414 |
bounds.y = miny; |
| c6bde3e3 |
sago007 |
2015-12-22 16:56 |
415 |
bounds.w = maxx-minx; |
| c6bde3e3 |
sago007 |
2015-12-22 16:56 |
416 |
bounds.h = maxy-miny; |
| c6bde3e3 |
sago007 |
2015-12-22 16:56 |
417 |
sprite.DrawBounded(target,1,x,y,bounds); |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
418 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
419 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
420 |
/*Draws a part of an image on a surface of choice*/ |
| c6bde3e3 |
sago007 |
2015-12-22 16:56 |
421 |
/*void DrawIMG(sago::SagoSprite &sprite, Renderer* target, int x, int y, int w, int h, int x2, int y2) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
422 |
SDL_Rect dest; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
423 |
dest.x = x; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
424 |
dest.y = y; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
425 |
SDL_Rect dest2; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
426 |
dest2.x = x2; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
427 |
dest2.y = y2; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
428 |
dest2.w = w; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
429 |
dest2.h = h; |
| c6bde3e3 |
sago007 |
2015-12-22 16:56 |
430 |
sprite.Draw() |
| c6bde3e3 |
sago007 |
2015-12-22 16:56 |
431 |
|
| c6bde3e3 |
sago007 |
2015-12-22 16:56 |
432 |
}*/ |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
433 |
|
| cf54d8c3 |
sago007 |
2012-05-03 20:52 |
434 |
|
| 6332acb6 |
sago007 |
2015-12-19 17:51 |
435 |
void NFont_Write(SDL_Renderer* target, int x, int y, const string& text) { |
| 6332acb6 |
sago007 |
2015-12-19 17:51 |
436 |
nf_standard_blue_font.draw(target, x, y, "%s", text.c_str()); |
| 925b7e58 |
sago007 |
2011-04-25 16:35 |
437 |
} |
| 925b7e58 |
sago007 |
2011-04-25 16:35 |
438 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
439 |
void ResetFullscreen() { |
| 26ddb424 |
sago007 |
2011-06-09 20:06 |
440 |
#if defined(WIN32) |
| acd79baf |
sago007 |
2015-11-22 19:37 |
441 |
if (bFullscreen) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
442 |
screen=SDL_SetVideoMode(xsize,ysize,32,SDL_SWSURFACE|SDL_FULLSCREEN|SDL_ANYFORMAT); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
443 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
444 |
else { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
445 |
screen=SDL_SetVideoMode(xsize,ysize,32,SDL_SWSURFACE|SDL_ANYFORMAT); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
446 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
447 |
DrawIMG(background, screen, 0, 0); |
| 26ddb424 |
sago007 |
2011-06-09 20:06 |
448 |
#else |
| 6332acb6 |
sago007 |
2015-12-19 17:51 |
449 |
//TODO: Find SDL2 alternative |
| 6332acb6 |
sago007 |
2015-12-19 17:51 |
450 |
//SDL_WM_ToggleFullScreen(screen); //Will only work in Linux |
| 26ddb424 |
sago007 |
2011-06-09 20:06 |
451 |
#endif |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
452 |
SDL_ShowCursor(SDL_DISABLE); |
| 78d03b38 |
sago007 |
2008-11-13 19:56 |
453 |
} |
| 78d03b38 |
sago007 |
2008-11-13 19:56 |
454 |
|
| 78d03b38 |
sago007 |
2008-11-13 19:56 |
455 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
456 |
//The small things that are faaling when you clear something |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
457 |
class aBall { |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
458 |
private: |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
459 |
double x; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
460 |
double y; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
461 |
double velocityY; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
462 |
double velocityX; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
463 |
int color; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
464 |
unsigned long int lastTime; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
465 |
public: |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
466 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
467 |
aBall() { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
468 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
469 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
470 |
//constructor: |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
471 |
aBall(int X, int Y, bool right, int coulor) { |
| 9d59a0e2 |
sago007 |
2013-11-15 23:05 |
472 |
double tal = 1.0+((double)rand()/((double)RAND_MAX)); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
473 |
velocityY = -tal*startVelocityY; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
474 |
lastTime = currentTime; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
475 |
x = (double)X; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
476 |
y = (double)Y; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
477 |
color = coulor; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
478 |
if (right) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
479 |
velocityX = tal*VelocityX; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
480 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
481 |
else { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
482 |
velocityX = -tal*VelocityX; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
483 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
484 |
} //constructor |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
485 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
486 |
void update() { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
487 |
double timePassed = (((double)(currentTime-lastTime))/1000.0); //time passed in seconds |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
488 |
x = x+timePassed*velocityX; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
489 |
y = y+timePassed*velocityY; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
490 |
velocityY = velocityY + gravity*timePassed; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
491 |
if (y<1.0) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
492 |
velocityY=10.0; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
493 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
494 |
if ((velocityY>minVelocity) && (y>(double)(768-ballSize)) && (y<768.0)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
495 |
velocityY = -0.70*velocityY; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
496 |
y = 768.0-ballSize; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
497 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
498 |
lastTime = currentTime; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
499 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
500 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
501 |
int getX() { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
502 |
return (int)x; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
503 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
504 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
505 |
int getY() { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
506 |
return (int)y; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
507 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
508 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
509 |
int getColor() { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
510 |
return color; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
511 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
512 |
}; //aBall |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
513 |
|
| 4b0c248f |
sago007 |
2010-11-10 21:13 |
514 |
static const int maxNumberOfBalls = 6*12*2*2; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
515 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
516 |
class ballManeger { |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
517 |
public: |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
518 |
aBall ballArray[maxNumberOfBalls]; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
519 |
bool ballUsed[maxNumberOfBalls]; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
520 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
521 |
ballManeger() { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
522 |
for (int i=0; i<maxNumberOfBalls; i++) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
523 |
ballUsed[i] = false; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
524 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
525 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
526 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
527 |
//Adds a ball to the screen at given coordiantes, traveling right or not with color |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
528 |
int addBall(int x, int y,bool right,int color) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
529 |
int ballNumber = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
530 |
//Find a free ball |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
531 |
while ((ballUsed[ballNumber])&&(ballNumber<maxNumberOfBalls)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
532 |
ballNumber++; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
533 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
534 |
//Could not find a free ball, return -1 |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
535 |
if (ballNumber==maxNumberOfBalls) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
536 |
return -1; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
537 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
538 |
currentTime = SDL_GetTicks(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
539 |
ballArray[ballNumber] = aBall(x,y,right,color); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
540 |
ballUsed[ballNumber] = true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
541 |
return 1; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
542 |
} //addBall |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
543 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
544 |
void update() { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
545 |
currentTime = SDL_GetTicks(); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
546 |
for (int i = 0; i<maxNumberOfBalls; i++) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
547 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
548 |
if (ballUsed[i]) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
549 |
ballArray[i].update(); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
550 |
if (ballArray[i].getY()>800 || ballArray[i].getX()>xsize || ballArray[i].getX()<-ballSize) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
551 |
ballUsed[i] = false; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
552 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
553 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
554 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
555 |
} //update |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
556 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
557 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
558 |
}; //theBallManeger |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
559 |
|
| 4b0c248f |
sago007 |
2010-11-10 21:13 |
560 |
static ballManeger theBallManeger; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
561 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
562 |
//a explosions, non moving |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
563 |
class anExplosion { |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
564 |
private: |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
565 |
int x; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
566 |
int y; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
567 |
Uint8 frameNumber; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
568 |
#define frameLength 80 |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
569 |
//How long an image in an animation should be showed |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
570 |
#define maxFrame 4 |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
571 |
//How many images there are in the animation |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
572 |
unsigned long int placeTime; //Then the explosion occored |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
573 |
public: |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
574 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
575 |
anExplosion() { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
576 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
577 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
578 |
//constructor: |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
579 |
anExplosion(int X, int Y) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
580 |
placeTime = currentTime; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
581 |
x = X; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
582 |
y = Y; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
583 |
frameNumber=0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
584 |
} //constructor |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
585 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
586 |
//true if animation has played and object should be removed from the screen |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
587 |
bool removeMe() { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
588 |
frameNumber = (currentTime-placeTime)/frameLength; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
589 |
return (!(frameNumber<maxFrame)); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
590 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
591 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
592 |
int getX() { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
593 |
return (int)x; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
594 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
595 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
596 |
int getY() { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
597 |
return (int)y; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
598 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
599 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
600 |
int getFrame() { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
601 |
return frameNumber; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
602 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
603 |
}; //nExplosion |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
604 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
605 |
class explosionManeger { |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
606 |
public: |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
607 |
anExplosion explosionArray[maxNumberOfBalls]; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
608 |
bool explosionUsed[maxNumberOfBalls]; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
609 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
610 |
explosionManeger() { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
611 |
for (int i=0; i<maxNumberOfBalls; i++) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
612 |
explosionUsed[i] = false; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
613 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
614 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
615 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
616 |
int addExplosion(int x, int y) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
617 |
int explosionNumber = 0; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
618 |
while ((explosionUsed[explosionNumber])&&(explosionNumber<maxNumberOfBalls)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
619 |
explosionNumber++; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
620 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
621 |
if (explosionNumber==maxNumberOfBalls) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
622 |
return -1; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
623 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
624 |
currentTime = SDL_GetTicks(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
625 |
explosionArray[explosionNumber] = anExplosion(x,y); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
626 |
explosionUsed[explosionNumber] = true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
627 |
return 1; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
628 |
} //addBall |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
629 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
630 |
void update() { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
631 |
currentTime = SDL_GetTicks(); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
632 |
for (int i = 0; i<maxNumberOfBalls; i++) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
633 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
634 |
if (explosionUsed[i]) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
635 |
if (explosionArray[i].removeMe()) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
636 |
explosionUsed[i] = false; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
637 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
638 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
639 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
640 |
} //update |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
641 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
642 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
643 |
}; //explosionManeger |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
644 |
|
| 4b0c248f |
sago007 |
2010-11-10 21:13 |
645 |
static explosionManeger theExplosionManeger; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
646 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
647 |
//text pop-up |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
648 |
class textMessage { |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
649 |
private: |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
650 |
int x; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
651 |
int y; |
| 571b4d47 |
sago007 |
2015-12-05 16:02 |
652 |
string textt; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
653 |
unsigned long int time; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
654 |
unsigned long int placeTime; //Then the text was placed |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
655 |
public: |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
656 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
657 |
textMessage() { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
658 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
659 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
660 |
//constructor: |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
661 |
textMessage(int X, int Y,const char* Text,unsigned int Time) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
662 |
placeTime = currentTime; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
663 |
x = X; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
664 |
y = Y; |
| 571b4d47 |
sago007 |
2015-12-05 16:02 |
665 |
textt = Text; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
666 |
time = Time; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
667 |
} //constructor |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
668 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
669 |
//true if the text has expired |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
670 |
bool removeMe() { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
671 |
return currentTime-placeTime>time; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
672 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
673 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
674 |
int getX() { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
675 |
return x; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
676 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
677 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
678 |
int getY() { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
679 |
return y; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
680 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
681 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
682 |
const char* getText() { |
| 571b4d47 |
sago007 |
2015-12-05 16:02 |
683 |
return textt.c_str(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
684 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
685 |
}; //text popup |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
686 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
687 |
class textManeger { |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
688 |
public: |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
689 |
textMessage textArray[maxNumberOfBalls]; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
690 |
bool textUsed[maxNumberOfBalls]; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
691 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
692 |
textManeger() { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
693 |
for (int i=0; i<maxNumberOfBalls; i++) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
694 |
textUsed[i] = false; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
695 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
696 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
697 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
698 |
int addText(int x, int y,string Text,unsigned int Time) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
699 |
int textNumber = 0; |
| 571b4d47 |
sago007 |
2015-12-05 16:02 |
700 |
while (textNumber<maxNumberOfBalls && textUsed[textNumber]) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
701 |
textNumber++; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
702 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
703 |
if (textNumber==maxNumberOfBalls) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
704 |
return -1; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
705 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
706 |
currentTime = SDL_GetTicks(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
707 |
textArray[textNumber] = textMessage(x,y,Text.c_str(),Time); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
708 |
textUsed[textNumber] = true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
709 |
return 1; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
710 |
} //addText |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
711 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
712 |
void update() { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
713 |
currentTime = SDL_GetTicks(); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
714 |
for (int i = 0; i<maxNumberOfBalls; i++) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
715 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
716 |
if (textUsed[i]) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
717 |
if (textArray[i].removeMe()) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
718 |
textUsed[i] = false; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
719 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
720 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
721 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
722 |
} //update |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
723 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
724 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
725 |
}; //textManeger |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
726 |
|
| 4b0c248f |
sago007 |
2010-11-10 21:13 |
727 |
static textManeger theTextManeger; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
728 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
729 |
//Here comes the Block Game object |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
730 |
#include "BlockGame.hpp" |
| 17916a2e |
sago007 |
2010-11-07 11:26 |
731 |
#include "BlockGame.cpp" |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
732 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
733 |
class BlockGameSdl : public BlockGame { |
| 6b1dc7a6 |
sago007 |
2010-11-08 21:03 |
734 |
public: |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
735 |
BlockGameSdl(int tx, int ty) { |
| 229e212d |
sago007 |
2015-08-22 17:14 |
736 |
topx = tx; |
| 229e212d |
sago007 |
2015-08-22 17:14 |
737 |
topy = ty; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
738 |
} |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
739 |
|
| c6bde3e3 |
sago007 |
2015-12-22 16:56 |
740 |
void DrawImgBoard(sago::SagoSprite& img, int x, int y) const { |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
741 |
DrawIMG(img, screen, x+topx, y+topy); |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
742 |
} |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
743 |
|
| c6bde3e3 |
sago007 |
2015-12-22 16:56 |
744 |
void DrawImgBoardBounded(sago::SagoSprite& img, int x, int y) const { |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
745 |
DrawIMG_Bounded(img, screen, x+topx, y+topy, topx, topy, topx + backBoard.GetWidth(), topy + backBoard.GetHeight()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
746 |
} |
| 46cfd6b2 |
sago007 |
2015-12-06 15:36 |
747 |
|
| 46cfd6b2 |
sago007 |
2015-12-06 15:36 |
748 |
void PrintTextCenteredBoard(int x, int y, const char* text) { |
| c6bde3e3 |
sago007 |
2015-12-22 16:56 |
749 |
nf_button_font.draw(screen, x+topx+60, y+topy+10, NFont::CENTER, "%s", text); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
750 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
751 |
|
| 58dd05a0 |
sago007 |
2015-08-22 17:49 |
752 |
int GetTopX() const { |
| 229e212d |
sago007 |
2015-08-22 17:14 |
753 |
return topx; |
| 229e212d |
sago007 |
2015-08-22 17:14 |
754 |
} |
| 58dd05a0 |
sago007 |
2015-08-22 17:49 |
755 |
int GetTopY() const { |
| 229e212d |
sago007 |
2015-08-22 17:14 |
756 |
return topy; |
| 229e212d |
sago007 |
2015-08-22 17:14 |
757 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
758 |
|
| 313ecd1b |
sago007 |
2015-08-22 20:38 |
759 |
void AddText(int x, int y, const std::string& text, int time) const override { |
| 229e212d |
sago007 |
2015-08-22 17:14 |
760 |
theTextManeger.addText(topx-10+x*bsize, topy+12*bsize-y*bsize, text, time); |
| 229e212d |
sago007 |
2015-08-22 17:14 |
761 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
762 |
|
| 313ecd1b |
sago007 |
2015-08-22 20:38 |
763 |
void AddBall(int x, int y, bool right, int color) const override { |
| b37fa2db |
sago007 |
2015-12-04 20:44 |
764 |
theBallManeger.addBall(topx+40+x*bsize, topy+bsize*12-y*bsize, right, color); |
| 229e212d |
sago007 |
2015-08-22 17:14 |
765 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
766 |
|
| acd79baf |
sago007 |
2015-11-22 19:37 |
767 |
void AddExplosion(int x, int y) const override { |
| 229e212d |
sago007 |
2015-08-22 17:14 |
768 |
theExplosionManeger.addExplosion(topx-10+x*bsize, topy+bsize*12-10-y*bsize); |
| 229e212d |
sago007 |
2015-08-22 17:14 |
769 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
770 |
|
| 313ecd1b |
sago007 |
2015-08-22 20:38 |
771 |
void PlayerWonEvent() const override { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
772 |
if (!SoundEnabled) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
773 |
return; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
774 |
} |
| 313ecd1b |
sago007 |
2015-08-22 20:38 |
775 |
Mix_PlayChannel(1, applause, 0); |
| 313ecd1b |
sago007 |
2015-08-22 20:38 |
776 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
777 |
|
| 027b5cfd |
sago007 |
2015-08-23 14:27 |
778 |
void DrawEvent() const override { |
| 027b5cfd |
sago007 |
2015-08-23 14:27 |
779 |
Mix_HaltChannel(1); |
| 027b5cfd |
sago007 |
2015-08-23 14:27 |
780 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
781 |
|
| 313ecd1b |
sago007 |
2015-08-22 20:38 |
782 |
void BlockPopEvent() const override { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
783 |
if (!SoundEnabled) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
784 |
return; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
785 |
} |
| 313ecd1b |
sago007 |
2015-08-22 20:38 |
786 |
Mix_PlayChannel(0, boing, 0); |
| 313ecd1b |
sago007 |
2015-08-22 20:38 |
787 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
788 |
|
| 313ecd1b |
sago007 |
2015-08-22 20:38 |
789 |
void LongChainDoneEvent() const override { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
790 |
if (!SoundEnabled) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
791 |
return; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
792 |
} |
| 313ecd1b |
sago007 |
2015-08-22 20:38 |
793 |
Mix_PlayChannel(1, applause, 0); |
| 313ecd1b |
sago007 |
2015-08-22 20:38 |
794 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
795 |
|
| 313ecd1b |
sago007 |
2015-08-22 20:38 |
796 |
void TimeTrialEndEvent() const override { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
797 |
if (!NoSound && SoundEnabled) { |
| 313ecd1b |
sago007 |
2015-08-22 20:38 |
798 |
Mix_PlayChannel(1,counterFinalChunk,0); |
| 313ecd1b |
sago007 |
2015-08-22 20:38 |
799 |
} |
| 313ecd1b |
sago007 |
2015-08-22 20:38 |
800 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
801 |
|
| 313ecd1b |
sago007 |
2015-08-22 20:38 |
802 |
void EndlessHighscoreEvent() const override { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
803 |
if (!SoundEnabled) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
804 |
return; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
805 |
} |
| 313ecd1b |
sago007 |
2015-08-22 20:38 |
806 |
Mix_PlayChannel(1, applause, 0); |
| 313ecd1b |
sago007 |
2015-08-22 20:38 |
807 |
} |
| 6b1dc7a6 |
sago007 |
2010-11-08 21:03 |
808 |
private: |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
809 |
//Draws all the bricks to the board (including garbage) |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
810 |
void PaintBricks() const { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
811 |
for (int i=0; ((i<13)&&(i<30)); i++) |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
812 |
for (int j=0; j<6; j++) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
813 |
if ((board[j][i]%10 != -1) && (board[j][i]%10 < 7) && ((board[j][i]/1000000)%10==0)) { |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
814 |
DrawImgBoardBounded(bricks[board[j][i]%10], j*bsize, bsize*12-i*bsize-pixels); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
815 |
if ((board[j][i]/BLOCKWAIT)%10==1) { |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
816 |
DrawImgBoard(bomb, j*bsize, bsize*12-i*bsize-pixels); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
817 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
818 |
if ((board[j][i]/BLOCKHANG)%10==1) { |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
819 |
DrawImgBoardBounded(ready, j*bsize, bsize*12-i*bsize-pixels); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
820 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
821 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
822 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
823 |
if ((board[j][i]/1000000)%10==1) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
824 |
int left, right, over, under; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
825 |
int number = board[j][i]; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
826 |
if (j<1) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
827 |
left = -1; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
828 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
829 |
else { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
830 |
left = board[j-1][i]; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
831 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
832 |
if (j>5) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
833 |
right = -1; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
834 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
835 |
else { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
836 |
right = board[j+1][i]; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
837 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
838 |
if (i>28) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
839 |
over = -1; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
840 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
841 |
else { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
842 |
over = board[j][i+1]; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
843 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
844 |
if (i<1) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
845 |
under = -1; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
846 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
847 |
else { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
848 |
under = board[j][i-1]; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
849 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
850 |
if ((left == number)&&(right == number)&&(over == number)&&(under == number)) { |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
851 |
DrawImgBoardBounded(garbageFill, j*bsize, bsize*12-i*bsize-pixels); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
852 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
853 |
if ((left != number)&&(right == number)&&(over == number)&&(under == number)) { |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
854 |
DrawImgBoardBounded(garbageL, j*bsize, bsize*12-i*bsize-pixels); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
855 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
856 |
if ((left == number)&&(right != number)&&(over == number)&&(under == number)) { |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
857 |
DrawImgBoardBounded(garbageR, j*bsize, bsize*12-i*bsize-pixels); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
858 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
859 |
if ((left == number)&&(right == number)&&(over != number)&&(under == number)) { |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
860 |
DrawImgBoardBounded(garbageT, j*bsize, bsize*12-i*bsize-pixels); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
861 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
862 |
if ((left == number)&&(right == number)&&(over == number)&&(under != number)) { |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
863 |
DrawImgBoardBounded(garbageB, j*bsize, bsize*12-i*bsize-pixels); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
864 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
865 |
if ((left != number)&&(right == number)&&(over != number)&&(under == number)) { |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
866 |
DrawImgBoardBounded(garbageTL, j*bsize, bsize*12-i*bsize-pixels); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
867 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
868 |
if ((left != number)&&(right == number)&&(over == number)&&(under != number)) { |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
869 |
DrawImgBoardBounded(garbageBL, j*bsize, bsize*12-i*bsize-pixels); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
870 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
871 |
if ((left == number)&&(right != number)&&(over != number)&&(under == number)) { |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
872 |
DrawImgBoardBounded(garbageTR, j*bsize, bsize*12-i*bsize-pixels); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
873 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
874 |
if ((left == number)&&(right != number)&&(over == number)&&(under != number)) { |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
875 |
DrawImgBoardBounded(garbageBR, j*bsize, bsize*12-i*bsize-pixels); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
876 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
877 |
if ((left == number)&&(right != number)&&(over != number)&&(under != number)) { |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
878 |
DrawImgBoardBounded(garbageMR, j*bsize, bsize*12-i*bsize-pixels); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
879 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
880 |
if ((left == number)&&(right == number)&&(over != number)&&(under != number)) { |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
881 |
DrawImgBoardBounded(garbageM, j*bsize, bsize*12-i*bsize-pixels); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
882 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
883 |
if ((left != number)&&(right == number)&&(over != number)&&(under != number)) { |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
884 |
DrawImgBoardBounded(garbageML, j*bsize, bsize*12-i*bsize-pixels); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
885 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
886 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
887 |
if ((board[j][i]/1000000)%10==2) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
888 |
if (j==0) { |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
889 |
DrawImgBoardBounded(garbageGML, j*bsize, bsize*12-i*bsize-pixels); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
890 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
891 |
else if (j==5) { |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
892 |
DrawImgBoardBounded(garbageGMR, j*bsize, bsize*12-i*bsize-pixels); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
893 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
894 |
else { |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
895 |
DrawImgBoardBounded(garbageGM, j*bsize, bsize*12-i*bsize-pixels); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
896 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
897 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
898 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
899 |
const int j = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
900 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
901 |
int garbageSize=0; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
902 |
for (int i=0; i<20; i++) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
903 |
if ((board[j][i]/1000000)%10==1) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
904 |
int left, right, over, under; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
905 |
int number = board[j][i]; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
906 |
if (j<1) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
907 |
left = -1; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
908 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
909 |
else { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
910 |
left = board[j-1][i]; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
911 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
912 |
if (j>5) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
913 |
right = -1; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
914 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
915 |
else { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
916 |
right = board[j+1][i]; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
917 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
918 |
if (i>28) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
919 |
over = -1; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
920 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
921 |
else { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
922 |
over = board[j][i+1]; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
923 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
924 |
if (i<1) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
925 |
under = -1; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
926 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
927 |
else { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
928 |
under = board[j][i-1]; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
929 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
930 |
if (((left != number)&&(right == number)&&(over != number)&&(under == number))&&(garbageSize>0)) { |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
931 |
DrawImgBoardBounded(smiley[board[j][i]%4], 2*bsize, 12*bsize-i*bsize-pixels+(bsize/2)*garbageSize); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
932 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
933 |
if (!((left != number)&&(right == number)&&(over == number)&&(under == number))) { //not in garbage |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
934 |
garbageSize=0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
935 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
936 |
else { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
937 |
garbageSize++; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
938 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
939 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
940 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
941 |
} |
| 571b4d47 |
sago007 |
2015-12-05 16:02 |
942 |
for (int i=0; i<6; i++) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
943 |
if (board[i][0]!=-1) { |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
944 |
DrawImgBoardBounded(transCover, i*bsize, 12*bsize-pixels); //Make the appering blocks transperant |
| acd79baf |
sago007 |
2015-11-22 19:37 |
945 |
} |
| 571b4d47 |
sago007 |
2015-12-05 16:02 |
946 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
947 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
948 |
} |
| 6b1dc7a6 |
sago007 |
2010-11-08 21:03 |
949 |
public: |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
950 |
//Draws everything |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
951 |
void DoPaintJob() { |
| c699a9f9 |
sago007 |
2015-12-05 17:22 |
952 |
DrawIMG(boardBackBack,screen,this->GetTopX()-60,this->GetTopY()-68); |
| 46cfd6b2 |
sago007 |
2015-12-06 15:36 |
953 |
|
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
954 |
nf_scoreboard_font.draw(screen, this->GetTopX()+310,this->GetTopY()-68+148,_("Score:") ); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
955 |
nf_scoreboard_font.draw(screen, this->GetTopX()+310,this->GetTopY()-68+197,_("Time:") ); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
956 |
nf_scoreboard_font.draw(screen, this->GetTopX()+310,this->GetTopY()-68+246,_("Chain:") ); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
957 |
nf_scoreboard_font.draw(screen, this->GetTopX()+310,this->GetTopY()-68+295,_("Speed:") ); |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
958 |
DrawImgBoard(backBoard, 0, 0); |
| cf54d8c3 |
sago007 |
2012-05-03 20:52 |
959 |
|
| cf54d8c3 |
sago007 |
2012-05-03 20:52 |
960 |
PaintBricks(); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
961 |
if (stageClear) { |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
962 |
DrawImgBoard(blackLine, 0, bsize*(12+2)+bsize*(stageClearLimit-linesCleared)-pixels-1); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
963 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
964 |
if (puzzleMode&&(!bGameOver)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
965 |
//We need to write nr. of moves left! |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
966 |
strHolder = "Moves left: " + itoa(MovesLeft); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
967 |
nf_standard_blue_font.draw(screen, topx+5, topy+5, "%s",strHolder.c_str()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
968 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
969 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
970 |
if (puzzleMode && stageButtonStatus == SBpuzzleMode) { |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
971 |
DrawImgBoard(bRetry, cordRetryButton.x, cordRetryButton.y); |
| 46cfd6b2 |
sago007 |
2015-12-06 15:36 |
972 |
PrintTextCenteredBoard(cordRetryButton.x, cordRetryButton.y, _("Retry")); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
973 |
if (Level<PuzzleGetNumberOfPuzzles()-1) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
974 |
if (hasWonTheGame) { |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
975 |
DrawImgBoard(bNext,cordNextButton.x, cordNextButton.y); |
| 46cfd6b2 |
sago007 |
2015-12-06 15:36 |
976 |
PrintTextCenteredBoard(cordNextButton.x, cordNextButton.y, _("Next")); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
977 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
978 |
else { |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
979 |
DrawImgBoard(bSkip,cordNextButton.x, cordNextButton.y); |
| 46cfd6b2 |
sago007 |
2015-12-06 15:36 |
980 |
PrintTextCenteredBoard(cordNextButton.x, cordNextButton.y, _("Skip")); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
981 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
982 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
983 |
else { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
984 |
strHolder = "Last puzzle"; |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
985 |
nf_standard_blue_font.draw(screen, topx+5, topy+5, "%s",strHolder.c_str()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
986 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
987 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
988 |
if (stageClear && stageButtonStatus == SBstageClear) { |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
989 |
DrawImgBoard(bRetry, cordRetryButton.x, cordRetryButton.y); |
| 46cfd6b2 |
sago007 |
2015-12-06 15:36 |
990 |
PrintTextCenteredBoard(cordRetryButton.x, cordRetryButton.y, _("Retry")); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
991 |
if (Level<50-1) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
992 |
if (hasWonTheGame) { |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
993 |
DrawImgBoard(bNext,cordNextButton.x, cordNextButton.y); |
| 46cfd6b2 |
sago007 |
2015-12-06 15:36 |
994 |
PrintTextCenteredBoard(cordNextButton.x, cordNextButton.y, _("Next")); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
995 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
996 |
else { |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
997 |
DrawImgBoard(bSkip,cordNextButton.x, cordNextButton.y); |
| 46cfd6b2 |
sago007 |
2015-12-06 15:36 |
998 |
PrintTextCenteredBoard(cordNextButton.x, cordNextButton.y, _("Skip")); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
999 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1000 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1001 |
else { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1002 |
strHolder = "Last stage"; |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
1003 |
nf_standard_blue_font.draw(screen, topx+5, topy+5, "%s",strHolder.c_str()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1004 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1005 |
} |
| 6b1dc7a6 |
sago007 |
2010-11-08 21:03 |
1006 |
|
| 6b1dc7a6 |
sago007 |
2010-11-08 21:03 |
1007 |
#if DEBUG |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1008 |
if (AI_Enabled&&(!bGameOver)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1009 |
strHolder = "AI_status: " + itoa(AIstatus)+ ", "+ itoa(AIlineToClear); |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
1010 |
//NFont_Write( 5, 5, strHolder.c_str()); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
1011 |
nf_standard_blue_font.draw(screen, topx+5, topy+5, "%s",strHolder.c_str()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1012 |
} |
| 6b1dc7a6 |
sago007 |
2010-11-08 21:03 |
1013 |
#endif |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1014 |
if (!bGameOver) { |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
1015 |
DrawImgBoard(cursor,cursorx*bsize-4,11*bsize-cursory*bsize-pixels-4); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1016 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1017 |
if (ticks<gameStartedAt) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1018 |
int currentCounter = abs((int)ticks-(int)gameStartedAt)/1000; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1019 |
if ( (currentCounter!=lastCounter) && (SoundEnabled)&&(!NoSound)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1020 |
Mix_PlayChannel(1,counterChunk,0); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1021 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1022 |
lastCounter = currentCounter; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1023 |
switch (currentCounter) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1024 |
case 2: |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
1025 |
DrawImgBoard(counter[2], 2*bsize, 5*bsize); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1026 |
break; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1027 |
case 1: |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
1028 |
DrawImgBoard(counter[1], 2*bsize, 5*bsize); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1029 |
break; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1030 |
case 0: |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
1031 |
DrawImgBoard(counter[0], 2*bsize, 5*bsize); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1032 |
break; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1033 |
default: |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1034 |
break; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1035 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1036 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1037 |
else { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1038 |
if (SoundEnabled&&(!NoSound)&&(timetrial)&&(ticks>gameStartedAt+10000)&&(!bGameOver)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1039 |
int currentCounter = (ticks-(int)gameStartedAt)/1000; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1040 |
if (currentCounter!=lastCounter) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1041 |
if (currentCounter>115 && currentCounter<120) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1042 |
Mix_PlayChannel(1,counterChunk,0); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1043 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1044 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1045 |
lastCounter = currentCounter; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1046 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1047 |
else { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1048 |
if ( (0==lastCounter) && (SoundEnabled)&&(!NoSound)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1049 |
Mix_PlayChannel(1,counterFinalChunk,0); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1050 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1051 |
lastCounter = -1; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1052 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1053 |
} |
| 6b1dc7a6 |
sago007 |
2010-11-08 21:03 |
1054 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1055 |
if ((bGameOver)&&(!editorMode)) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1056 |
if (hasWonTheGame) { |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
1057 |
DrawImgBoard(iWinner, 0, 5*bsize); |
| 80b830cd |
sago007 |
2012-08-19 17:51 |
1058 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1059 |
else { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1060 |
if (bDraw) { |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
1061 |
DrawImgBoard(iDraw, 0, 5*bsize); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1062 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1063 |
else { |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
1064 |
DrawImgBoard(iGameOver, 0, 5*bsize); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1065 |
} |
| 80b830cd |
sago007 |
2012-08-19 17:51 |
1066 |
} |
| 80b830cd |
sago007 |
2012-08-19 17:51 |
1067 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1068 |
} |
| 6b1dc7a6 |
sago007 |
2010-11-08 21:03 |
1069 |
|
| 6b1dc7a6 |
sago007 |
2010-11-08 21:03 |
1070 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1071 |
void Update(int newtick) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1072 |
BlockGame::Update(newtick); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1073 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1074 |
|
| 229e212d |
sago007 |
2015-08-22 17:14 |
1075 |
private: |
| 229e212d |
sago007 |
2015-08-22 17:14 |
1076 |
int topx, topy; |
| 6b1dc7a6 |
sago007 |
2010-11-08 21:03 |
1077 |
}; |
| 6b1dc7a6 |
sago007 |
2010-11-08 21:03 |
1078 |
|
| 6b1dc7a6 |
sago007 |
2010-11-08 21:03 |
1079 |
|
| 6b1dc7a6 |
sago007 |
2010-11-08 21:03 |
1080 |
|
| 6b1dc7a6 |
sago007 |
2010-11-08 21:03 |
1081 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1082 |
//writeScreenShot saves the screen as a bmp file, it uses the time to get a unique filename |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1083 |
void writeScreenShot() { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1084 |
if (verboseLevel) { |
| 56241205 |
sago007 |
2012-08-05 11:15 |
1085 |
cout << "Saving screenshot" << endl; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1086 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1087 |
int rightNow = (int)time(nullptr); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1088 |
/*#if defined(__unix__) |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1089 |
char buf[514]; |
| f306e3ca |
sago007 |
2015-12-04 21:16 |
1090 |
snprintf( buf, sizeof(buf), "%s/.gamesaves/blockattack/screenshots/screenshot%i.bmp", getenv("HOME"), rightNow ); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1091 |
#elif defined(__win32__) |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1092 |
char buf[MAX_PATH]; |
| f306e3ca |
sago007 |
2015-12-04 21:16 |
1093 |
snprintf( buf, sizeof(buf), "%s\\My Games\\blockattack\\screenshots\\screenshot%i.bmp", (getMyDocumentsPath()).c_str(), rightNow ); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1094 |
#else |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1095 |
char buf[MAX_PATH]; |
| f306e3ca |
sago007 |
2015-12-04 21:16 |
1096 |
snprintf( buf, sizeof(buf), "screenshot%i.bmp", rightNow ); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1097 |
#endif*/ |
| 215ca7b3 |
sago007 |
2009-03-06 16:37 |
1098 |
#if defined(__unix__) |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1099 |
string buf = (string)getenv("HOME")+"/.gamesaves/blockattack/screenshots/screenshot"+itoa(rightNow)+".bmp"; |
| 215ca7b3 |
sago007 |
2009-03-06 16:37 |
1100 |
#elif defined(__win32__) |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1101 |
string buf = getMyDocumentsPath()+"\\My Games\\blockattack\\screenshots\\screenshot"+itoa(rightNow)+".bmp"; |
| 215ca7b3 |
sago007 |
2009-03-06 16:37 |
1102 |
#else |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1103 |
string buf = "screenshot"+itoa(rightNow)+".bmp"; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1104 |
#endif |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
1105 |
//SDL_SaveBMP( screen, buf.c_str() ); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
1106 |
//TODO: Write screenshot |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
1107 |
if (!NoSound) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1108 |
if (SoundEnabled) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1109 |
Mix_PlayChannel(1,photoClick,0); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1110 |
} |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
1111 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1112 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1113 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1114 |
//Function to return the name of a key, to be displayed... |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
1115 |
static string getKeyName(SDL_Keycode key) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1116 |
string keyname(SDL_GetKeyName(key)); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1117 |
return keyname; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1118 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1119 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1120 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1121 |
//Dialogbox |
| f6707482 |
sago007 |
2015-12-04 22:55 |
1122 |
bool OpenDialogbox(int x, int y, std::string& name) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1123 |
bool done = false; //We are done! |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1124 |
bool accept = false; //New name is accepted! (not Cancelled) |
| f6707482 |
sago007 |
2015-12-04 22:55 |
1125 |
ReadKeyboard rk = ReadKeyboard(name.c_str()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1126 |
string strHolder; |
| c699a9f9 |
sago007 |
2015-12-05 17:22 |
1127 |
DrawIMG(backgroundImage,screen,0,0); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1128 |
while (!done && !Config::getInstance()->isShuttingDown()) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1129 |
DrawIMG(dialogBox,screen,x,y); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1130 |
NFont_Write(screen, x+40,y+76,rk.GetString()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1131 |
strHolder = rk.GetString(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1132 |
strHolder.erase((int)rk.CharsBeforeCursor()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1133 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1134 |
if (((SDL_GetTicks()/600)%2)==1) { |
| e55d039f |
sago007 |
2015-12-04 22:22 |
1135 |
NFont_Write(screen, x+40+nf_standard_blue_font.getWidth( "%s", strHolder.c_str()),y+76,"|"); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1136 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1137 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1138 |
SDL_Event event; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1139 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1140 |
while ( SDL_PollEvent(&event) ) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1141 |
if ( event.type == SDL_QUIT ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1142 |
Config::getInstance()->setShuttingDown(5); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1143 |
done = true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1144 |
accept = false; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1145 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1146 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1147 |
if ( event.type == SDL_KEYDOWN ) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1148 |
if ( (event.key.keysym.sym == SDLK_RETURN)||(event.key.keysym.sym == SDLK_KP_ENTER) ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1149 |
done = true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1150 |
accept = true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1151 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1152 |
else if ( (event.key.keysym.sym == SDLK_ESCAPE) ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1153 |
done = true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1154 |
accept = false; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1155 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1156 |
else if (!(event.key.keysym.sym == SDLK_BACKSPACE)) { |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
1157 |
if ((rk.ReadKey(event))&&(SoundEnabled)&&(!NoSound)) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1158 |
Mix_PlayChannel(1,typingChunk,0); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1159 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1160 |
} |
| 9b99cf7a |
sago007 |
2015-12-04 20:22 |
1161 |
else if (event.key.keysym.sym == SDLK_BACKSPACE) { |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
1162 |
if ((rk.ReadKey(event))&&(SoundEnabled)&&(!NoSound)) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1163 |
Mix_PlayChannel(1,typingChunk,0); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1164 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1165 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1166 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1167 |
|
| acd79baf |
sago007 |
2015-11-22 19:37 |
1168 |
} //while(event) |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1169 |
|
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
1170 |
SDL_RenderPresent(screen); //Update screen |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1171 |
} //while(!done) |
| f6707482 |
sago007 |
2015-12-04 22:55 |
1172 |
name = rk.GetString(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1173 |
bScreenLocked = false; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1174 |
showDialog = false; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1175 |
return accept; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1176 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1177 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1178 |
//Draws the highscores |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1179 |
void DrawHighscores(int x, int y, bool endless) { |
| c699a9f9 |
sago007 |
2015-12-05 17:22 |
1180 |
DrawIMG(backgroundImage,screen,0,0); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1181 |
if (endless) { |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
1182 |
nf_standard_blue_font.draw(screen, x+100,y+100, "%s",_("Endless:") ); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1183 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1184 |
else { |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
1185 |
nf_standard_blue_font.draw(screen, x+100,y+100, "%s",_("Time Trial:") ); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1186 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1187 |
for (int i =0; i<10; i++) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1188 |
char playerScore[32]; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1189 |
char playerName[32]; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1190 |
if (endless) { |
| f306e3ca |
sago007 |
2015-12-04 21:16 |
1191 |
snprintf(playerScore, sizeof(playerScore), "%i", theTopScoresEndless.getScoreNumber(i)); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1192 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1193 |
else { |
| f306e3ca |
sago007 |
2015-12-04 21:16 |
1194 |
snprintf(playerScore, sizeof(playerScore), "%i", theTopScoresTimeTrial.getScoreNumber(i)); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1195 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1196 |
if (endless) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1197 |
strcpy(playerName,theTopScoresEndless.getScoreName(i)); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1198 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1199 |
else { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1200 |
strcpy(playerName,theTopScoresTimeTrial.getScoreName(i)); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1201 |
} |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
1202 |
nf_standard_blue_font.draw(screen, x+420,y+150+i*35, "%s",playerScore); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
1203 |
nf_standard_blue_font.draw(screen, x+60,y+150+i*35, "%s",playerName); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1204 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1205 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1206 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1207 |
void DrawStats() { |
| c699a9f9 |
sago007 |
2015-12-05 17:22 |
1208 |
DrawIMG(backgroundImage,screen,0,0); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1209 |
int y = 5; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1210 |
const int y_spacing = 30; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1211 |
NFont_Write(screen, 10,y,_("Stats") ); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1212 |
y+=y_spacing*2; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1213 |
NFont_Write(screen, 10,y,_("Chains") ); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1214 |
for (int i=2; i<13; i++) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1215 |
y+=y_spacing; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1216 |
NFont_Write(screen, 10,y,(itoa(i)+"X").c_str()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1217 |
string numberAsString = itoa(Stats::getInstance()->getNumberOf("chainX"+itoa(i))); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1218 |
NFont_Write(screen, 300,y,numberAsString.c_str()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1219 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1220 |
y+=y_spacing*2; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1221 |
NFont_Write(screen, 10,y,_("Lines Pushed: ") ); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1222 |
string numberAsString = itoa(Stats::getInstance()->getNumberOf("linesPushed")); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1223 |
NFont_Write(screen, 300,y,numberAsString.c_str()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1224 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1225 |
y+=y_spacing; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1226 |
NFont_Write(screen, 10,y, _("Puzzles solved: ") ); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1227 |
numberAsString = itoa(Stats::getInstance()->getNumberOf("puzzlesSolved")); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1228 |
NFont_Write(screen, 300,y,numberAsString.c_str()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1229 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1230 |
y+=y_spacing*2; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1231 |
NFont_Write(screen, 10,y, _("Run time: ") ); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1232 |
commonTime ct = TimeHandler::peekTime("totalTime",TimeHandler::ms2ct(SDL_GetTicks())); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1233 |
y+=y_spacing; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1234 |
NFont_Write(screen, 10,y,((string)( _("Days: ")+itoa(ct.days))).c_str()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1235 |
y+=y_spacing; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1236 |
NFont_Write(screen, 10,y,((string)( _("Hours: ")+itoa(ct.hours))).c_str()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1237 |
y+=y_spacing; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1238 |
NFont_Write(screen, 10,y,((string)( _("Minutes: ")+itoa(ct.minutes))).c_str()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1239 |
y+=y_spacing; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1240 |
NFont_Write(screen, 10,y,((string)( _("Seconds: ")+itoa(ct.seconds))).c_str()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1241 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1242 |
y-=y_spacing*4; //Four rows back |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1243 |
const int x_offset3 = xsize/3+10; //Ofset for three rows |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1244 |
NFont_Write(screen, x_offset3,y, _("Play time: ") ); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1245 |
ct = TimeHandler::getTime("playTime"); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1246 |
y+=y_spacing; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1247 |
NFont_Write(screen, x_offset3,y,((string)( _("Days: ")+itoa(ct.days))).c_str()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1248 |
y+=y_spacing; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1249 |
NFont_Write(screen, x_offset3,y,((string)( _("Hours: ")+itoa(ct.hours))).c_str()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1250 |
y+=y_spacing; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1251 |
NFont_Write(screen, x_offset3,y,((string)( _("Minutes: ")+itoa(ct.minutes))).c_str()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1252 |
y+=y_spacing; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1253 |
NFont_Write(screen, x_offset3,y,((string)( _("Seconds: ")+itoa(ct.seconds))).c_str()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1254 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1255 |
const int x_offset = xsize/2+10; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1256 |
y = 5+y_spacing*2; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1257 |
NFont_Write(screen, x_offset,y, _("VS CPU (win/loss)") ); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1258 |
for (int i=0; i<7; i++) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1259 |
y += y_spacing; |
| e68d08eb |
sago007 |
2013-11-15 22:33 |
1260 |
NFont_Write(screen, x_offset,y,string("AI "+itoa(i+1)).c_str()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1261 |
numberAsString = itoa(Stats::getInstance()->getNumberOf("defeatedAI"+itoa(i))); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1262 |
string numberAsString2 = itoa(Stats::getInstance()->getNumberOf("defeatedByAI"+itoa(i))); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1263 |
string toPrint = numberAsString + "/" + numberAsString2; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1264 |
NFont_Write(screen, x_offset+230,y,toPrint.c_str()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1265 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1266 |
} |
| 47529580 |
sago007 |
2008-12-09 02:34 |
1267 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1268 |
void OpenScoresDisplay() { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1269 |
int mousex,mousey; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1270 |
bool done = false; //We are done! |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1271 |
int page = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1272 |
const int numberOfPages = 3; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1273 |
//button coodinates: |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1274 |
const int scoreX = buttonXsize*2; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1275 |
const int scoreY = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1276 |
const int backX = 20; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1277 |
const int backY = ysize-buttonYsize-20; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1278 |
const int nextX = xsize-buttonXsize-20; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1279 |
const int nextY = backY; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1280 |
while (!done && !Config::getInstance()->isShuttingDown()) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1281 |
switch (page) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1282 |
case 0: |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1283 |
//Highscores, endless |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1284 |
DrawHighscores(100,100,true); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1285 |
break; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1286 |
case 1: |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1287 |
//Highscores, Time Trial |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1288 |
DrawHighscores(100,100,false); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1289 |
break; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1290 |
case 2: |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1291 |
default: |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1292 |
DrawStats(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1293 |
}; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1294 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1295 |
//Draw buttons: |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1296 |
DrawIMG(bHighScore,screen,scoreX,scoreY); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1297 |
DrawIMG(bBack,screen,backX,backY); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
1298 |
nf_button_font.draw(screen, backX+60,backY+10, NFont::CENTER ,_("Back")); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1299 |
DrawIMG(bNext,screen,nextX,nextY); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
1300 |
nf_button_font.draw(screen, nextX+60,nextY+10, NFont::CENTER,_("Next")); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1301 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1302 |
//Draw page number |
| 53001fa2 |
sago007 |
2015-11-08 15:13 |
1303 |
string pageXofY = (boost::format(_("Page %1% of %2%") )%(page+1)%numberOfPages).str(); |
| e55d039f |
sago007 |
2015-12-04 22:22 |
1304 |
NFont_Write(screen, xsize/2-nf_standard_blue_font.getWidth( "%s", pageXofY.c_str())/2,ysize-60,pageXofY.c_str()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1305 |
|
| 571b4d47 |
sago007 |
2015-12-05 16:02 |
1306 |
SDL_Delay(1); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1307 |
SDL_Event event; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1308 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1309 |
SDL_GetMouseState(&mousex,&mousey); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1310 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1311 |
while ( SDL_PollEvent(&event) ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1312 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1313 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1314 |
if ( event.type == SDL_QUIT ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1315 |
Config::getInstance()->setShuttingDown(5); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1316 |
done = true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1317 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1318 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1319 |
if ( event.type == SDL_KEYDOWN ) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1320 |
if ( (event.key.keysym.sym == SDLK_RIGHT)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1321 |
page++; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1322 |
if (page>=numberOfPages) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1323 |
page = 0; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1324 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1325 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1326 |
else if ( (event.key.keysym.sym == SDLK_LEFT)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1327 |
page--; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1328 |
if (page<0) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1329 |
page = numberOfPages-1; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1330 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1331 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1332 |
else { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1333 |
done = true; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1334 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1335 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1336 |
if ( event.key.keysym.sym == SDLK_F9 ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1337 |
writeScreenShot(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1338 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1339 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1340 |
if ( (event.key.keysym.sym == SDLK_RETURN)||(event.key.keysym.sym == SDLK_KP_ENTER) ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1341 |
done = true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1342 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1343 |
else if ( (event.key.keysym.sym == SDLK_ESCAPE) ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1344 |
done = true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1345 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1346 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1347 |
|
| acd79baf |
sago007 |
2015-11-22 19:37 |
1348 |
} //while(event) |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1349 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1350 |
// If the mouse button is released, make bMouseUp equal true |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1351 |
if (!SDL_GetMouseState(nullptr, nullptr)&SDL_BUTTON(1)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1352 |
bMouseUp=true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1353 |
} |
| 7ca669ac |
sago007 |
2008-12-09 16:30 |
1354 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1355 |
if (SDL_GetMouseState(nullptr,nullptr)&SDL_BUTTON(1) && bMouseUp) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1356 |
bMouseUp = false; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1357 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1358 |
//The Score button: |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1359 |
if ((mousex>scoreX) && (mousex<scoreX+buttonXsize) && (mousey>scoreY) && (mousey<scoreY+buttonYsize)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1360 |
done =true; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1361 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1362 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1363 |
//The back button: |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1364 |
if ((mousex>backX) && (mousex<backX+buttonXsize) && (mousey>backY) && (mousey<backY+buttonYsize)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1365 |
page--; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1366 |
if (page<0) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1367 |
page = numberOfPages-1; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1368 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1369 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1370 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1371 |
//The next button: |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1372 |
if ((mousex>nextX) && (mousex<nextX+buttonXsize) && (mousey>nextY) && (mousey<nextY+buttonYsize)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1373 |
page++; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1374 |
if (page>=numberOfPages) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1375 |
page = 0; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1376 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1377 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1378 |
} |
| 7ca669ac |
sago007 |
2008-12-09 16:30 |
1379 |
|
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
1380 |
mouse.Draw(screen, SDL_GetTicks(), mousex, mousey); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
1381 |
SDL_RenderPresent(screen); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1382 |
} |
| 6b1dc7a6 |
sago007 |
2010-11-08 21:03 |
1383 |
|
| 6b1dc7a6 |
sago007 |
2010-11-08 21:03 |
1384 |
|
| 81d9c25d |
sago007 |
2008-11-24 09:50 |
1385 |
} |
| 81d9c25d |
sago007 |
2008-11-24 09:50 |
1386 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1387 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1388 |
//Open a puzzle file |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1389 |
bool OpenFileDialogbox(int x, int y, char* name) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1390 |
bool done = false; //We are done! |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1391 |
int mousex, mousey; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1392 |
ListFiles lf = ListFiles(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1393 |
string folder = (string)SHAREDIR+(string)"/puzzles"; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1394 |
if (verboseLevel) { |
| 56241205 |
sago007 |
2012-08-05 11:15 |
1395 |
cout << "Looking in " << folder << endl; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1396 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1397 |
lf.setDirectory(folder.c_str()); |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1398 |
#ifdef __unix__ |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1399 |
string homeFolder = (string)getenv("HOME")+(string)"/.gamesaves/blockattack/puzzles"; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1400 |
lf.setDirectory2(homeFolder.c_str()); |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1401 |
#endif |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1402 |
while (!done && !Config::getInstance()->isShuttingDown()) { |
| c699a9f9 |
sago007 |
2015-12-05 17:22 |
1403 |
DrawIMG(backgroundImage,screen,0,0); |
| c699a9f9 |
sago007 |
2015-12-05 17:22 |
1404 |
DrawIMG(bForward,screen,x+460,y+420); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
1405 |
nf_button_font.draw(screen, x+20+60, y+420+10, NFont::CENTER, _("Forward")); |
| c699a9f9 |
sago007 |
2015-12-05 17:22 |
1406 |
DrawIMG(bBack,screen,x+20,y+420); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
1407 |
nf_button_font.draw(screen, x+20+60, y+420+10, NFont::CENTER, _("Back")); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1408 |
const int nrOfFiles = 10; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1409 |
for (int i=0; i<nrOfFiles; i++) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1410 |
NFont_Write(screen, x+10,y+10+36*i,lf.getFileName(i).c_str()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1411 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1412 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1413 |
SDL_Event event; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1414 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1415 |
while ( SDL_PollEvent(&event) ) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1416 |
if ( event.type == SDL_QUIT ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1417 |
Config::getInstance()->setShuttingDown(5); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1418 |
done = true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1419 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1420 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1421 |
if ( event.type == SDL_KEYDOWN ) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1422 |
if ( (event.key.keysym.sym == SDLK_ESCAPE) ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1423 |
done = true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1424 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1425 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1426 |
if ( (event.key.keysym.sym == SDLK_RIGHT) ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1427 |
lf.forward(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1428 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1429 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1430 |
if ( (event.key.keysym.sym == SDLK_LEFT) ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1431 |
lf.back(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1432 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1433 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1434 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1435 |
} //while(event) |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1436 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1437 |
SDL_GetMouseState(&mousex,&mousey); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1438 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1439 |
// If the mouse button is released, make bMouseUp equal true |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1440 |
if (!SDL_GetMouseState(nullptr, nullptr)&SDL_BUTTON(1)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1441 |
bMouseUp=true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1442 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1443 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1444 |
if (SDL_GetMouseState(nullptr,nullptr)&SDL_BUTTON(1) && bMouseUp) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1445 |
bMouseUp = false; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1446 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1447 |
//The Forward Button: |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1448 |
if ( (mousex>x+460) && (mousex<x+460+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1449 |
lf.forward(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1450 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1451 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1452 |
//The back button: |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1453 |
if ( (mousex>x+20) && (mousex<x+20+buttonXsize) && (mousey>y+420) && (mousey<y+420+40) ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1454 |
lf.back(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1455 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1456 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1457 |
for (int i=0; i<10; i++) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1458 |
if ( (mousex>x+10) && (mousex<x+480) && (mousey>y+10+i*36) && (mousey<y+10+i*36+32) ) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1459 |
if (lf.fileExists(i)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1460 |
strncpy(name,lf.getFileName(i).c_str(),28); //Problems occurs then larger than 28 (maybe 29) |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1461 |
done=true; //The user have, clicked the purpose of this function is now complete |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1462 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1463 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1464 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1465 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1466 |
|
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
1467 |
mouse.Draw(screen, SDL_GetTicks(), mousex, mousey); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
1468 |
SDL_RenderPresent(screen); //Update screen |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1469 |
} |
| 80b830cd |
sago007 |
2012-08-19 17:51 |
1470 |
return true; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1471 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1472 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1473 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1474 |
//Draws the balls and explosions |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1475 |
static void DrawBalls() { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1476 |
for (int i = 0; i< maxNumberOfBalls; i++) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1477 |
if (theBallManeger.ballUsed[i]) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1478 |
DrawIMG(balls[theBallManeger.ballArray[i].getColor()],screen,theBallManeger.ballArray[i].getX(),theBallManeger.ballArray[i].getY()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1479 |
} //if used |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1480 |
if (theExplosionManeger.explosionUsed[i]) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1481 |
DrawIMG(explosion[theExplosionManeger.explosionArray[i].getFrame()],screen,theExplosionManeger.explosionArray[i].getX(),theExplosionManeger.explosionArray[i].getY()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1482 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1483 |
if (theTextManeger.textUsed[i]) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1484 |
//cout << "Printing text: " << theTextManeger.textArray[i].getText() << endl; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1485 |
int x = theTextManeger.textArray[i].getX()-12; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1486 |
int y = theTextManeger.textArray[i].getY()-12; |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
1487 |
//DrawIMG(iChainBack,screen,x,y); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
1488 |
|
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
1489 |
nf_standard_small_font.draw(screen, x+12,y+7, NFont::CENTER, "%s",theTextManeger.textArray[i].getText()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1490 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1491 |
} //for |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1492 |
} //DrawBalls |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1493 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1494 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1495 |
//draws everything |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1496 |
void DrawEverything(int xsize, int ysize,BlockGameSdl* theGame, BlockGameSdl* theGame2) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1497 |
SDL_ShowCursor(SDL_DISABLE); |
| c699a9f9 |
sago007 |
2015-12-05 17:22 |
1498 |
DrawIMG(backgroundImage,screen,0,0); |
| ae0f6c7a |
sago007 |
2015-12-05 16:58 |
1499 |
theGame->DoPaintJob(); |
| c699a9f9 |
sago007 |
2015-12-05 17:22 |
1500 |
theGame2->DoPaintJob(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1501 |
string strHolder; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1502 |
strHolder = itoa(theGame->GetScore()+theGame->GetHandicap()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1503 |
NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+100,strHolder.c_str()); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1504 |
if (theGame->GetAIenabled()) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1505 |
NFont_Write(screen, theGame->GetTopX()+10,theGame->GetTopY()-34,_("AI") ); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1506 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1507 |
else if (editorMode) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1508 |
NFont_Write(screen, theGame->GetTopX()+10,theGame->GetTopY()-34,_("Playing field") ); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1509 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1510 |
else if (!singlePuzzle) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1511 |
NFont_Write(screen, theGame->GetTopX()+10,theGame->GetTopY()-34,player1name); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1512 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1513 |
if (theGame->isTimeTrial()) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1514 |
int tid = (int)SDL_GetTicks()-theGame->GetGameStartedAt(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1515 |
int minutes; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1516 |
int seconds; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1517 |
if (tid>=0) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1518 |
minutes = (2*60*1000-(abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))/60/1000; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1519 |
seconds = ((2*60*1000-(abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))%(60*1000))/1000; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1520 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1521 |
else { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1522 |
minutes = ((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))/60/1000; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1523 |
seconds = (((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))%(60*1000))/1000; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1524 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1525 |
if (theGame->isGameOver()) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1526 |
minutes=0; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1527 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1528 |
if (theGame->isGameOver()) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1529 |
seconds=0; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1530 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1531 |
if (seconds>9) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1532 |
strHolder = itoa(minutes)+":"+itoa(seconds); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1533 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1534 |
else { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1535 |
strHolder = itoa(minutes)+":0"+itoa(seconds); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1536 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1537 |
//if ((SoundEnabled)&&(!NoSound)&&(tid>0)&&(seconds<5)&&(minutes == 0)&&(seconds>1)&&(!(Mix_Playing(6)))) Mix_PlayChannel(6,heartBeat,0); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1538 |
NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+150,strHolder.c_str()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1539 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1540 |
else { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1541 |
int minutes = ((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))/60/1000; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1542 |
int seconds = (((abs((int)SDL_GetTicks()-(int)theGame->GetGameStartedAt())))%(60*1000))/1000; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1543 |
if (theGame->isGameOver()) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1544 |
minutes=(theGame->GetGameEndedAt()/1000/60)%100; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1545 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1546 |
if (theGame->isGameOver()) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1547 |
seconds=(theGame->GetGameEndedAt()/1000)%60; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1548 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1549 |
if (seconds>9) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1550 |
strHolder = itoa(minutes)+":"+itoa(seconds); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1551 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1552 |
else { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1553 |
strHolder = itoa(minutes)+":0"+itoa(seconds); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1554 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1555 |
NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+150,strHolder.c_str()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1556 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1557 |
strHolder = itoa(theGame->GetChains()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1558 |
NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+200,strHolder.c_str()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1559 |
//drawspeedLevel: |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1560 |
strHolder = itoa(theGame->GetSpeedLevel()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1561 |
NFont_Write(screen, theGame->GetTopX()+310,theGame->GetTopY()+250,strHolder.c_str()); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1562 |
if ((theGame->isStageClear()) &&(theGame->GetTopY()+700+50*(theGame->GetStageClearLimit()-theGame->GetLinesCleared())-theGame->GetPixels()-1<600+theGame->GetTopY())) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1563 |
oldBubleX = theGame->GetTopX()+280; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1564 |
oldBubleY = theGame->GetTopY()+650+50*(theGame->GetStageClearLimit()-theGame->GetLinesCleared())-theGame->GetPixels()-1; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1565 |
DrawIMG(stageBobble,screen,theGame->GetTopX()+280,theGame->GetTopY()+650+50*(theGame->GetStageClearLimit()-theGame->GetLinesCleared())-theGame->GetPixels()-1); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1566 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1567 |
//player1 finnish, player2 start |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1568 |
//DrawIMG(boardBackBack,screen,theGame2->GetTopX()-60,theGame2->GetTopY()-68); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1569 |
if (!editorMode) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1570 |
/* |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1571 |
*If single player mode (and not VS) |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1572 |
*/ |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1573 |
if (!twoPlayers && !theGame->isGameOver()) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1574 |
//Blank player2's board: |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1575 |
DrawIMG(backBoard,screen,theGame2->GetTopX(),theGame2->GetTopY()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1576 |
//Write a description: |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1577 |
if (theGame->isTimeTrial()) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1578 |
NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+10,"Time Trial"); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1579 |
NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160,"Objective:"); |
| cf54d8c3 |
sago007 |
2012-05-03 20:52 |
1580 |
string infostring = _("Score as much as \npossible in 2 minutes"); |
| cf54d8c3 |
sago007 |
2012-05-03 20:52 |
1581 |
NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32,infostring); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1582 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1583 |
else if (theGame->isStageClear()) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1584 |
NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+10,"Stage Clear"); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1585 |
NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160,"Objective:"); |
| cf54d8c3 |
sago007 |
2012-05-03 20:52 |
1586 |
string infostring = _("You must clear a \nnumber of lines.\nSpeed is rapidly \nincreased."); |
| cf54d8c3 |
sago007 |
2012-05-03 20:52 |
1587 |
NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32,infostring); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1588 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1589 |
else if (theGame->isPuzzleMode()) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1590 |
NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+10,"Puzzle"); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1591 |
NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160,"Objective:"); |
| cf54d8c3 |
sago007 |
2012-05-03 20:52 |
1592 |
string infostring = _("Clear the entire board \nwith a limited number \nof moves."); |
| cf54d8c3 |
sago007 |
2012-05-03 20:52 |
1593 |
NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32,infostring); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1594 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1595 |
else { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1596 |
NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+10,"Endless"); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1597 |
NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160,"Objective:"); |
| cf54d8c3 |
sago007 |
2012-05-03 20:52 |
1598 |
string infostring = _("Score as much as \npossible. No time limit."); |
| cf54d8c3 |
sago007 |
2012-05-03 20:52 |
1599 |
NFont_Write(screen, theGame2->GetTopX()+7,theGame2->GetTopY()+160+32,infostring); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1600 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1601 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1602 |
//Write the keys that are in use |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1603 |
int y = theGame2->GetTopY()+400; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1604 |
NFont_Write(screen, theGame2->GetTopX()+7,y,_("Movement keys:") ); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1605 |
NFont_Write(screen, theGame2->GetTopX()+7,y+40,(getKeyName(keySettings[0].left)+", "+getKeyName(keySettings[0].right)+"," ).c_str() ); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1606 |
NFont_Write(screen, theGame2->GetTopX()+7,y+76,(getKeyName(keySettings[0].up)+", "+getKeyName(keySettings[0].down)).c_str() ); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1607 |
NFont_Write(screen, theGame2->GetTopX()+7,y+120,( _("Switch: ")+getKeyName(keySettings[0].change) ).c_str() ); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1608 |
if (theGame->isPuzzleMode()) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1609 |
NFont_Write(screen, theGame2->GetTopX()+7,y+160,( _("Restart: ")+getKeyName(keySettings[0].push) ).c_str() ); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1610 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1611 |
else { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1612 |
NFont_Write(screen, theGame2->GetTopX()+7,y+160,( _("Push line: ")+getKeyName(keySettings[0].push) ).c_str() ); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1613 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1614 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1615 |
strHolder = itoa(theGame2->GetScore()+theGame2->GetHandicap()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1616 |
NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+100,strHolder.c_str()); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1617 |
if (theGame2->GetAIenabled()) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1618 |
NFont_Write(screen, theGame2->GetTopX()+10,theGame2->GetTopY()-34,_("AI") ); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1619 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1620 |
else { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1621 |
NFont_Write(screen, theGame2->GetTopX()+10,theGame2->GetTopY()-34,theGame2->name); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1622 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1623 |
if (theGame2->isTimeTrial()) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1624 |
int tid = (int)SDL_GetTicks()-theGame2->GetGameStartedAt(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1625 |
int minutes; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1626 |
int seconds; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1627 |
if (tid>=0) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1628 |
minutes = (2*60*1000-(abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())))/60/1000; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1629 |
seconds = ((2*60*1000-(abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())))%(60*1000))/1000; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1630 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1631 |
else { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1632 |
minutes = ((abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())))/60/1000; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1633 |
seconds = (((abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())))%(60*1000))/1000; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1634 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1635 |
if (theGame2->isGameOver()) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1636 |
minutes=0; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1637 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1638 |
if (theGame2->isGameOver()) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1639 |
seconds=0; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1640 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1641 |
if (seconds>9) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1642 |
strHolder = itoa(minutes)+":"+itoa(seconds); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1643 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1644 |
else { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1645 |
strHolder = itoa(minutes)+":0"+itoa(seconds); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1646 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1647 |
//if ((SoundEnabled)&&(!NoSound)&&(tid>0)&&(seconds<5)&&(minutes == 0)&&(seconds>1)&&(!(Mix_Playing(6)))) Mix_PlayChannel(6,heartBeat,0); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1648 |
NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+150,strHolder.c_str()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1649 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1650 |
else { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1651 |
int minutes = (abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt()))/60/1000; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1652 |
int seconds = (abs((int)SDL_GetTicks()-(int)theGame2->GetGameStartedAt())%(60*1000))/1000; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1653 |
if (theGame2->isGameOver()) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1654 |
minutes=(theGame2->GetGameEndedAt()/1000/60)%100; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1655 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1656 |
if (theGame2->isGameOver()) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1657 |
seconds=(theGame2->GetGameEndedAt()/1000)%60; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1658 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1659 |
if (seconds>9) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1660 |
strHolder = itoa(minutes)+":"+itoa(seconds); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1661 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1662 |
else { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1663 |
strHolder = itoa(minutes)+":0"+itoa(seconds); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1664 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1665 |
NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+150,strHolder.c_str()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1666 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1667 |
strHolder = itoa(theGame2->GetChains()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1668 |
NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+200,strHolder.c_str()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1669 |
strHolder = itoa(theGame2->GetSpeedLevel()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1670 |
NFont_Write(screen, theGame2->GetTopX()+310,theGame2->GetTopY()+250,strHolder.c_str()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1671 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1672 |
//player2 finnish |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1673 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1674 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1675 |
DrawBalls(); |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1676 |
|
| 1572de2b |
sago007 |
2008-09-11 18:15 |
1677 |
#if DEBUG |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1678 |
Frames++; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1679 |
if (SDL_GetTicks() >= Ticks + 1000) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1680 |
if (Frames > 999) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1681 |
Frames=999; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1682 |
} |
| f306e3ca |
sago007 |
2015-12-04 21:16 |
1683 |
snprintf(FPS, sizeof(FPS), "%lu fps", Frames); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1684 |
Frames = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1685 |
Ticks = SDL_GetTicks(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1686 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1687 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1688 |
//NFont_Write(screen, 800,4,FPS); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
1689 |
nf_standard_blue_font.draw(screen, 800, 4, "%s", FPS); |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1690 |
#endif |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1691 |
|
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
1692 |
//SDL_RenderPresent(screen); Update screen is now called outside DrawEvrything, bacause the mouse needs to be painted |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1693 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1694 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1695 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1696 |
//The function that allows the player to choose PuzzleLevel |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1697 |
int PuzzleLevelSelect(int Type) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1698 |
const int xplace = 200; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1699 |
const int yplace = 300; |
| a5a3aa4f |
sago007 |
2015-08-23 15:31 |
1700 |
int levelNr = 0; |
| a5a3aa4f |
sago007 |
2015-08-23 15:31 |
1701 |
int mousex, mousey; |
| a5a3aa4f |
sago007 |
2015-08-23 15:31 |
1702 |
int oldmousex = 0; |
| a5a3aa4f |
sago007 |
2015-08-23 15:31 |
1703 |
int oldmousey = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1704 |
bool levelSelected = false; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1705 |
bool tempBool; |
| a5a3aa4f |
sago007 |
2015-08-23 15:31 |
1706 |
int nrOfLevels = 0; |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1707 |
Uint32 tempUInt32; |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1708 |
Uint32 totalScore = 0; |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1709 |
Uint32 totalTime = 0; |
| cc6724c9 |
sago007 |
2012-04-16 21:11 |
1710 |
int selected = 0; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1711 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1712 |
//Loads the levels, if they havn't been loaded: |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1713 |
if (Type == 0) { |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1714 |
LoadPuzzleStages(); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1715 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1716 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1717 |
//Keeps track of background; |
| 80b830cd |
sago007 |
2012-08-19 17:51 |
1718 |
SDL_GetTicks(); |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1719 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1720 |
if (Type == 0) { |
| 055218be |
sago007 |
2015-08-22 18:44 |
1721 |
nrOfLevels = PuzzleGetNumberOfPuzzles(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1722 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1723 |
if (Type == 1) { |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1724 |
ifstream stageFile(stageClearSavePath.c_str(),ios::binary); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1725 |
if (stageFile) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1726 |
for (int i = 0; i<nrOfStageLevels; i++) { |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1727 |
stageFile.read(reinterpret_cast<char*>(&tempBool),sizeof(bool)); |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1728 |
stageCleared[i]=tempBool; |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1729 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1730 |
if (!stageFile.eof()) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1731 |
for (int i=0; i<nrOfStageLevels; i++) { |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1732 |
tempUInt32 = 0; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1733 |
if (!stageFile.eof()) { |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1734 |
stageFile.read(reinterpret_cast<char*>(&tempUInt32),sizeof(Uint32)); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1735 |
} |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1736 |
stageScores[i]=tempUInt32; |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1737 |
totalScore+=tempUInt32; |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1738 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1739 |
for (int i=0; i<nrOfStageLevels; i++) { |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1740 |
tempUInt32 = 0; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1741 |
if (!stageFile.eof()) { |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1742 |
stageFile.read(reinterpret_cast<char*>(&tempUInt32),sizeof(Uint32)); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1743 |
} |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1744 |
stageTimes[i]=tempUInt32; |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1745 |
totalTime += tempUInt32; |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1746 |
} |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1747 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1748 |
else { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1749 |
for (int i=0; i<nrOfStageLevels; i++) { |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1750 |
stageScores[i]=0; |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1751 |
stageTimes[i]=0; |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1752 |
} |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1753 |
} |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1754 |
stageFile.close(); |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1755 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1756 |
else { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1757 |
for (int i=0; i<nrOfStageLevels; i++) { |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1758 |
stageCleared[i]= false; |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1759 |
stageScores[i]=0; |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1760 |
stageTimes[i]=0; |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1761 |
} |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1762 |
} |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1763 |
nrOfLevels = nrOfStageLevels; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1764 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1765 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1766 |
while (!levelSelected) { |
| 80b830cd |
sago007 |
2012-08-19 17:51 |
1767 |
SDL_GetTicks(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1768 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1769 |
|
| c699a9f9 |
sago007 |
2015-12-05 17:22 |
1770 |
DrawIMG(backgroundImage, screen, 0, 0); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1771 |
DrawIMG(iCheckBoxArea,screen,xplace,yplace); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1772 |
if (Type == 0) { |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1773 |
NFont_Write(screen, xplace+12,yplace+2,_("Select Puzzle") ); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1774 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1775 |
if (Type == 1) { |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1776 |
NFont_Write(screen, xplace+12,yplace+2, _("Stage Clear Level Select") ); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1777 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1778 |
//Now drow the fields you click in (and a V if clicked): |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1779 |
for (int i = 0; i < nrOfLevels; i++) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1780 |
DrawIMG(iLevelCheckBox,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1781 |
if (i==selected) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1782 |
DrawIMG(iLevelCheckBoxMarked,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1783 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1784 |
if (Type == 0 && PuzzleIsCleared(i)) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1785 |
DrawIMG(iLevelCheck,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1786 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1787 |
if (Type == 1 && stageCleared.at(i)==true) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1788 |
DrawIMG(iLevelCheck,screen,xplace+10+(i%10)*50, yplace+60+(i/10)*50); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1789 |
} |
| ed33b751 |
sago007 |
2012-04-17 10:48 |
1790 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1791 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1792 |
SDL_Event event; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1793 |
while ( SDL_PollEvent(&event) ) |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1794 |
if ( event.type == SDL_KEYDOWN ) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1795 |
if ( event.key.keysym.sym == SDLK_ESCAPE ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1796 |
levelNr = -1; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1797 |
levelSelected = true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1798 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1799 |
if ( event.key.keysym.sym == SDLK_RETURN || event.key.keysym.sym == SDLK_KP_ENTER ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1800 |
levelNr = selected; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1801 |
levelSelected = true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1802 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1803 |
if ( event.key.keysym.sym == SDLK_RIGHT ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1804 |
++selected; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1805 |
if (selected >= nrOfLevels) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1806 |
selected = 0; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1807 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1808 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1809 |
if ( event.key.keysym.sym == SDLK_LEFT ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1810 |
--selected; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1811 |
if (selected < 0) { |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1812 |
selected = nrOfLevels-1; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1813 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1814 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1815 |
if ( event.key.keysym.sym == SDLK_DOWN ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1816 |
selected+=10; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1817 |
if (selected >= nrOfLevels) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1818 |
selected-=10; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1819 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1820 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1821 |
if ( event.key.keysym.sym == SDLK_UP ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1822 |
selected-=10; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1823 |
if (selected < 0) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1824 |
selected+=10; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1825 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1826 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1827 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1828 |
|
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
1829 |
SDL_GetKeyboardState(nullptr); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1830 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1831 |
SDL_GetMouseState(&mousex,&mousey); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1832 |
if (mousex != oldmousex || mousey != oldmousey) { |
| ed33b751 |
sago007 |
2012-04-17 10:48 |
1833 |
int tmpSelected = -1; |
| ed33b751 |
sago007 |
2012-04-17 10:48 |
1834 |
int j; |
| 42f05434 |
sago007 |
2012-04-19 20:25 |
1835 |
for (j = 0; (tmpSelected == -1) && ( (j<nrOfLevels/10)||((j<nrOfLevels/10+1)&&(nrOfLevels%10 != 0)) ); j++) |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1836 |
if ((60+j*50<mousey-yplace)&&(mousey-yplace<j*50+92)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1837 |
tmpSelected = j*10; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1838 |
} |
| ed33b751 |
sago007 |
2012-04-17 10:48 |
1839 |
if (tmpSelected != -1) |
| 42f05434 |
sago007 |
2012-04-19 20:25 |
1840 |
for (int k = 0; (( (!(nrOfLevels%10) || k<nrOfLevels-10*(j-1)) )&&(k<10)); k++) |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1841 |
if ((10+k*50<mousex-xplace)&&(mousex-xplace<k*50+42)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1842 |
tmpSelected +=k; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1843 |
selected = tmpSelected; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1844 |
} |
| ed33b751 |
sago007 |
2012-04-17 10:48 |
1845 |
} |
| ed33b751 |
sago007 |
2012-04-17 10:48 |
1846 |
oldmousey = mousey; |
| ed33b751 |
sago007 |
2012-04-17 10:48 |
1847 |
oldmousex= mousex; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1848 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1849 |
// If the mouse button is released, make bMouseUp equal true |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1850 |
if (!SDL_GetMouseState(nullptr, nullptr)&SDL_BUTTON(1)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1851 |
bMouseUp=true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1852 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1853 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1854 |
if (SDL_GetMouseState(nullptr,nullptr)&SDL_BUTTON(1) && bMouseUp) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1855 |
bMouseUp = false; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1856 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1857 |
int levelClicked = -1; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1858 |
int i; |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1859 |
for (i = 0; (i<nrOfLevels/10)||((i<nrOfLevels/10+1)&&(nrOfLevels%10 != 0)); i++) |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1860 |
if ((60+i*50<mousey-yplace)&&(mousey-yplace<i*50+92)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1861 |
levelClicked = i*10; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1862 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1863 |
i++; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1864 |
if (levelClicked != -1) |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1865 |
for (int j = 0; ((j<nrOfStageLevels%(i*10))&&(j<10)); j++) |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1866 |
if ((10+j*50<mousex-xplace)&&(mousex-xplace<j*50+42)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1867 |
levelClicked +=j; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1868 |
levelSelected = true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1869 |
levelNr = levelClicked; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1870 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1871 |
} |
| 80b830cd |
sago007 |
2012-08-19 17:51 |
1872 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1873 |
if (Type == 1) { |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1874 |
string scoreString = _("Best score: 0"); |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1875 |
string timeString = _("Time used: -- : --"); |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1876 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1877 |
if (stageScores.at(selected)>0) { |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1878 |
scoreString = _("Best score: ")+itoa(stageScores.at(selected)); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1879 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1880 |
if (stageTimes.at(selected)>0) { |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1881 |
timeString = _("Time used: ")+itoa(stageTimes.at(selected)/1000/60)+" : "+itoa2((stageTimes.at(selected)/1000)%60); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1882 |
} |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1883 |
|
| aede0664 |
sago007 |
2012-04-19 19:45 |
1884 |
NFont_Write(screen, 200,200,scoreString.c_str()); |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1885 |
NFont_Write(screen, 200,250,timeString.c_str()); |
| 53001fa2 |
sago007 |
2015-11-08 15:13 |
1886 |
string totalString = (boost::format("Total score: %1% in %2%:%3%")%totalScore%(totalTime/1000/60)%((totalTime/1000)%60)).str(); //"Total score: " +itoa(totalScore) + " in " + itoa(totalTime/1000/60) + " : " + itoa2((totalTime/1000)%60); |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1887 |
NFont_Write(screen, 200,600,totalString.c_str()); |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1888 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1889 |
|
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
1890 |
mouse.Draw(screen, SDL_GetTicks(), mousex, mousey); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
1891 |
SDL_RenderPresent(screen); //draws it all to the screen |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1892 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1893 |
} |
| c699a9f9 |
sago007 |
2015-12-05 17:22 |
1894 |
DrawIMG(backgroundImage, screen, 0, 0); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1895 |
return levelNr; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1896 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1897 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1898 |
//This function will promt for the user to select another file for puzzle mode |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1899 |
void changePuzzleLevels() { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1900 |
char theFileName[30]; |
| 055218be |
sago007 |
2015-08-22 18:44 |
1901 |
strcpy(theFileName, PuzzleGetName().c_str()); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1902 |
for (int i=PuzzleGetName().length(); i<30; i++) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1903 |
theFileName[i]=' '; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1904 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1905 |
theFileName[29]=0; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1906 |
if (OpenFileDialogbox(200,100,theFileName)) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1907 |
for (int i=28; ((theFileName[i]==' ')&&(i>0)); i--) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1908 |
theFileName[i]=0; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1909 |
} |
| 055218be |
sago007 |
2015-08-22 18:44 |
1910 |
PuzzleSetName(theFileName); |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1911 |
#if defined(__unix__) |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1912 |
string home = getenv("HOME"); |
| 055218be |
sago007 |
2015-08-22 18:44 |
1913 |
PuzzleSetSavePath(home+"/.gamesaves/blockattack/"+PuzzleGetName()+".save"); |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1914 |
#elif defined(_WIN32) |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1915 |
string home = getMyDocumentsPath(); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1916 |
if (&home!=nullptr) { |
| 055218be |
sago007 |
2015-08-22 18:44 |
1917 |
PuzzleSetSavePath(home+"/My Games/blockattack/"+PuzzleGetName()+".save"); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1918 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1919 |
else { |
| 055218be |
sago007 |
2015-08-22 18:44 |
1920 |
PuzzleSetSavePath(PuzzleGetName()+".save"); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1921 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1922 |
#else |
| 055218be |
sago007 |
2015-08-22 18:44 |
1923 |
PuzzleSetSavePath(PuzzleGetName()+".save"); |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1924 |
#endif |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1925 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1926 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1927 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
1928 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1929 |
static BlockGameSdl* player1; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1930 |
static BlockGameSdl* player2; |
| 30f910dd |
sago007 |
2010-11-10 21:02 |
1931 |
|
| dfdb7d66 |
sago007 |
2015-11-29 19:21 |
1932 |
static bool registerEndlessHighscore = false; |
| dfdb7d66 |
sago007 |
2015-11-29 19:21 |
1933 |
static bool registerTTHighscorePlayer1 = false; |
| dfdb7d66 |
sago007 |
2015-11-29 19:21 |
1934 |
static bool registerTTHighscorePlayer2 = false; |
| dfdb7d66 |
sago007 |
2015-11-29 19:21 |
1935 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1936 |
static void StartSinglePlayerEndless() { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1937 |
//1 player - endless |
| 229e212d |
sago007 |
2015-08-22 17:14 |
1938 |
player1->NewGame(SDL_GetTicks()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1939 |
player1->putStartBlocks(time(0)); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1940 |
twoPlayers =false; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1941 |
player2->SetGameOver(); |
| 8f632c05 |
sago007 |
2015-08-22 16:21 |
1942 |
player1->name = player1name; |
| 8f632c05 |
sago007 |
2015-08-22 16:21 |
1943 |
player2->name = player2name; |
| dfdb7d66 |
sago007 |
2015-11-29 19:21 |
1944 |
registerEndlessHighscore = true; |
| 30f910dd |
sago007 |
2010-11-10 21:02 |
1945 |
} |
| 30f910dd |
sago007 |
2010-11-10 21:02 |
1946 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1947 |
static void StartSinglePlayerTimeTrial() { |
| 229e212d |
sago007 |
2015-08-22 17:14 |
1948 |
player1->NewTimeTrialGame(SDL_GetTicks()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1949 |
twoPlayers =false; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1950 |
player2->SetGameOver(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1951 |
//vsMode = false; |
| 8f632c05 |
sago007 |
2015-08-22 16:21 |
1952 |
player1->name = player1name; |
| 8f632c05 |
sago007 |
2015-08-22 16:21 |
1953 |
player2->name = player2name; |
| dfdb7d66 |
sago007 |
2015-11-29 19:21 |
1954 |
registerTTHighscorePlayer1 = true; |
| 4f1d27f1 |
sago007 |
2011-03-18 15:53 |
1955 |
} |
| 4f1d27f1 |
sago007 |
2011-03-18 15:53 |
1956 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1957 |
static int StartSinglePlayerPuzzle(int level) { |
| aede0664 |
sago007 |
2012-04-19 19:45 |
1958 |
int myLevel = PuzzleLevelSelect(0); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1959 |
if (myLevel == -1) { |
| 67a32395 |
sago007 |
2012-04-19 18:40 |
1960 |
return 1; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1961 |
} |
| 229e212d |
sago007 |
2015-08-22 17:14 |
1962 |
player1->NewPuzzleGame(myLevel,SDL_GetTicks()); |
| c699a9f9 |
sago007 |
2015-12-05 17:22 |
1963 |
DrawIMG(backgroundImage, screen, 0, 0); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1964 |
twoPlayers = false; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1965 |
player2->SetGameOver(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1966 |
//vsMode = true; |
| 8f632c05 |
sago007 |
2015-08-22 16:21 |
1967 |
player1->name = player1name; |
| 8f632c05 |
sago007 |
2015-08-22 16:21 |
1968 |
player2->name = player2name; |
| 67a32395 |
sago007 |
2012-04-19 18:40 |
1969 |
return 0; |
| b7590374 |
sago007 |
2011-05-19 16:15 |
1970 |
} |
| b7590374 |
sago007 |
2011-05-19 16:15 |
1971 |
|
| 4f1d27f1 |
sago007 |
2011-03-18 15:53 |
1972 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1973 |
static void StarTwoPlayerTimeTrial() { |
| 229e212d |
sago007 |
2015-08-22 17:14 |
1974 |
player1->NewTimeTrialGame(SDL_GetTicks()); |
| 229e212d |
sago007 |
2015-08-22 17:14 |
1975 |
player2->NewTimeTrialGame(SDL_GetTicks()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1976 |
int theTime = time(0); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1977 |
player1->putStartBlocks(theTime); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1978 |
player2->putStartBlocks(theTime); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1979 |
twoPlayers = true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1980 |
player1->setGameSpeed(player1Speed); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1981 |
player2->setGameSpeed(player2Speed); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1982 |
player1->setHandicap(player1handicap); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1983 |
player2->setHandicap(player2handicap); |
| dfdb7d66 |
sago007 |
2015-11-29 19:21 |
1984 |
registerTTHighscorePlayer1 = true; |
| dfdb7d66 |
sago007 |
2015-11-29 19:21 |
1985 |
registerTTHighscorePlayer2 = true; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1986 |
if (player1AI) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1987 |
player1->setAIlevel(player1AIlevel); |
| dfdb7d66 |
sago007 |
2015-11-29 19:21 |
1988 |
registerTTHighscorePlayer1 = false; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1989 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1990 |
if (player2AI) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1991 |
player2->setAIlevel(player2AIlevel); |
| dfdb7d66 |
sago007 |
2015-11-29 19:21 |
1992 |
registerTTHighscorePlayer2 = false; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
1993 |
} |
| 8f632c05 |
sago007 |
2015-08-22 16:21 |
1994 |
player1->name = player1name; |
| 8f632c05 |
sago007 |
2015-08-22 16:21 |
1995 |
player2->name = player2name; |
| 4f1d27f1 |
sago007 |
2011-03-18 15:53 |
1996 |
} |
| 4f1d27f1 |
sago007 |
2011-03-18 15:53 |
1997 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
1998 |
static void StartTwoPlayerVs() { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
1999 |
//2 player - VsMode |
| 229e212d |
sago007 |
2015-08-22 17:14 |
2000 |
player1->NewVsGame(player2,SDL_GetTicks()); |
| 229e212d |
sago007 |
2015-08-22 17:14 |
2001 |
player2->NewVsGame(player1,SDL_GetTicks()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2002 |
//vsMode = true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2003 |
twoPlayers = true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2004 |
player1->setGameSpeed(player1Speed); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2005 |
player2->setGameSpeed(player2Speed); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2006 |
player1->setHandicap(player1handicap); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2007 |
player2->setHandicap(player2handicap); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2008 |
if (player1AI) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2009 |
player1->setAIlevel(player1AIlevel); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2010 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2011 |
if (player2AI) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2012 |
player2->setAIlevel(player2AIlevel); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2013 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2014 |
int theTime = time(0); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2015 |
player1->putStartBlocks(theTime); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2016 |
player2->putStartBlocks(theTime); |
| 8f632c05 |
sago007 |
2015-08-22 16:21 |
2017 |
player1->name = player1name; |
| 8f632c05 |
sago007 |
2015-08-22 16:21 |
2018 |
player2->name = player2name; |
| 4f1d27f1 |
sago007 |
2011-03-18 15:53 |
2019 |
} |
| 4f1d27f1 |
sago007 |
2011-03-18 15:53 |
2020 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
2021 |
//The main function, quite big... too big |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2022 |
int main(int argc, char* argv[]) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2023 |
//We first create the folder there we will save (only on UNIX systems) |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2024 |
//we call the external command "mkdir"... the user might have renamed this, but we hope he hasn't |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
2025 |
#if defined(__unix__) |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2026 |
//Compiler warns about unused result. The users envisonment should normally give the user all the information he needs |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2027 |
if (system("mkdir -p ~/.gamesaves/blockattack/screenshots")) { |
| 56241205 |
sago007 |
2012-08-05 11:15 |
2028 |
cerr << "mkdir error creating ~/.gamesaves/blockattack/screenshots" << endl; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2029 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2030 |
if (system("mkdir -p ~/.gamesaves/blockattack/replays")) { |
| 56241205 |
sago007 |
2012-08-05 11:15 |
2031 |
cerr << "mkdir error creating ~/.gamesaves/blockattack/replays" << endl; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2032 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2033 |
if (system("mkdir -p ~/.gamesaves/blockattack/puzzles")) { |
| 56241205 |
sago007 |
2012-08-05 11:15 |
2034 |
cerr << "mkdir error creating ~/.gamesaves/blockattack/puzzles" << endl; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2035 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
2036 |
#elif defined(_WIN32) |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2037 |
//Now for Windows NT/2k/xp/2k3 etc. |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2038 |
string tempA = getMyDocumentsPath()+"\\My Games"; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2039 |
CreateDirectory(tempA.c_str(),nullptr); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2040 |
tempA = getMyDocumentsPath()+"\\My Games\\blockattack"; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2041 |
CreateDirectory(tempA.c_str(),nullptr); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2042 |
tempA = getMyDocumentsPath()+"\\My Games\\blockattack\\replays"; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2043 |
CreateDirectory(tempA.c_str(),nullptr); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2044 |
tempA = getMyDocumentsPath()+"\\My Games\\blockattack\\screenshots"; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2045 |
CreateDirectory(tempA.c_str(),nullptr); |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
2046 |
#endif |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2047 |
highPriority = false; //if true the game will take most resources, but increase framerate. |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2048 |
bFullscreen = false; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2049 |
//Set default Config variables: |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2050 |
Config::getInstance()->setDefault("themename","default"); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2051 |
setlocale (LC_ALL, ""); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2052 |
bindtextdomain (PACKAGE, LOCALEDIR); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2053 |
textdomain (PACKAGE); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2054 |
if (argc > 1) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2055 |
int argumentNr = 1; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2056 |
while (argc>argumentNr) { |
| 56241205 |
sago007 |
2012-08-05 11:15 |
2057 |
const char helpString[] = "--help"; |
| 56241205 |
sago007 |
2012-08-05 11:15 |
2058 |
const char priorityString[] = "-priority"; |
| 56241205 |
sago007 |
2012-08-05 11:15 |
2059 |
const char singlePuzzleString[] = "-SP"; |
| 56241205 |
sago007 |
2012-08-05 11:15 |
2060 |
const char noSoundAtAll[] = "-nosound"; |
| 56241205 |
sago007 |
2012-08-05 11:15 |
2061 |
const char selectTheme[] = "-theme"; |
| 56241205 |
sago007 |
2012-08-05 11:15 |
2062 |
const char verbose[] = "-v"; |
| f306e3ca |
sago007 |
2015-12-04 21:16 |
2063 |
if (strequals(argv[argumentNr],helpString)) { |
| f306e3ca |
sago007 |
2015-12-04 21:16 |
2064 |
cout << "Block Attack Help" << endl << helpString << " " << _("Displays this message") << |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2065 |
endl << "-priority " << _("Starts game in high priority") << endl << |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2066 |
"-nosound " << _("No sound will be played at all, and sound hardware will not be loaded (use this if game crashes because of sound)") << endl << |
| b37fa2db |
sago007 |
2015-12-04 20:44 |
2067 |
"-theme <" << _("THEMENAME") << "> " << _("Changes to the theme <THEMENAME> on startup") << endl; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
2068 |
#ifdef WIN32 |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2069 |
system("Pause"); |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
2070 |
#endif |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2071 |
return 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2072 |
} |
| f306e3ca |
sago007 |
2015-12-04 21:16 |
2073 |
if (strequals(argv[argumentNr],priorityString)) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2074 |
if (verboseLevel) { |
| 56241205 |
sago007 |
2012-08-05 11:15 |
2075 |
cout << "Priority mode" << endl; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2076 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2077 |
highPriority = true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2078 |
} |
| f306e3ca |
sago007 |
2015-12-04 21:16 |
2079 |
if (strequals(argv[argumentNr],singlePuzzleString)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2080 |
singlePuzzle = true; //We will just have one puzzle |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2081 |
if (argv[argumentNr+1][1]!=0) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2082 |
singlePuzzleNr = (argv[argumentNr+1][1]-'0')+(argv[argumentNr+1][0]-'0')*10; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2083 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2084 |
else { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2085 |
singlePuzzleNr = (argv[argumentNr+1][0]-'0'); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2086 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2087 |
singlePuzzleFile = argv[argumentNr+2]; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2088 |
argumentNr+=2; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2089 |
if (verboseLevel) { |
| 56241205 |
sago007 |
2012-08-05 11:15 |
2090 |
cout << "SinglePuzzleMode, File: " << singlePuzzleFile << " and Level: " << singlePuzzleNr << endl; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2091 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2092 |
} |
| f306e3ca |
sago007 |
2015-12-04 21:16 |
2093 |
if (strequals(argv[argumentNr],noSoundAtAll)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2094 |
NoSound = true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2095 |
} |
| f306e3ca |
sago007 |
2015-12-04 21:16 |
2096 |
if (strequals(argv[argumentNr],selectTheme)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2097 |
argumentNr++; //Go to themename (the next argument) |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2098 |
if (verboseLevel) { |
| 56241205 |
sago007 |
2012-08-05 11:15 |
2099 |
cout << "Theme set to \"" << argv[argumentNr] << '"' << endl; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2100 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2101 |
Config::getInstance()->setString("themename",argv[argumentNr]); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2102 |
} |
| f306e3ca |
sago007 |
2015-12-04 21:16 |
2103 |
if (strequals(argv[argumentNr],verbose)) { |
| 56241205 |
sago007 |
2012-08-05 11:15 |
2104 |
verboseLevel++; |
| 56241205 |
sago007 |
2012-08-05 11:15 |
2105 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2106 |
argumentNr++; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2107 |
} //while |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2108 |
} //if |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2109 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2110 |
SoundEnabled = true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2111 |
MusicEnabled = true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2112 |
bScreenLocked = false; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2113 |
twoPlayers = false; //true if two players splitscreen |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2114 |
theTopScoresEndless = Highscore(1); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2115 |
theTopScoresTimeTrial = Highscore(2); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2116 |
drawBalls = true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2117 |
puzzleLoaded = false; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2118 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2119 |
theBallManeger = ballManeger(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2120 |
theExplosionManeger = explosionManeger(); |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
2121 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2122 |
//We now set the paths were we are saving, we are using the keyword __unix__ . I hope that all UNIX systems has a home folder |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
2123 |
#if defined(__unix__) |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2124 |
string home = getenv("HOME"); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2125 |
string optionsPath = home+"/.gamesaves/blockattack/options.dat"; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
2126 |
#elif defined(_WIN32) |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2127 |
string home = getMyDocumentsPath(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2128 |
string optionsPath; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2129 |
if (&home!=nullptr) { //Null if no APPDATA dir exists (win 9x) |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2130 |
optionsPath = home+"/My Games/blockattack/options.dat"; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2131 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2132 |
else { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2133 |
optionsPath = "options.dat"; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2134 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
2135 |
#else |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2136 |
string optionsPath = "options.dat"; |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
2137 |
#endif |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
2138 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2139 |
#if defined(__unix__) |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2140 |
stageClearSavePath = home+"/.gamesaves/blockattack/stageClear.SCsave"; |
| 055218be |
sago007 |
2015-08-22 18:44 |
2141 |
PuzzleSetSavePath(home+"/.gamesaves/blockattack/puzzle.levels.save"); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2142 |
#elif defined(_WIN32) |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2143 |
if (&home!=nullptr) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2144 |
stageClearSavePath = home+"/My Games/blockattack/stageClear.SCsave"; |
| 055218be |
sago007 |
2015-08-22 18:44 |
2145 |
PuzzleSetSavePath(home+"/My Games/blockattack/puzzle.levels.save"); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2146 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2147 |
else { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2148 |
stageClearSavePath = "stageClear.SCsave"; |
| 055218be |
sago007 |
2015-08-22 18:44 |
2149 |
PuzzleSetSavePath("puzzle.levels.save"); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2150 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
2151 |
#else |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2152 |
stageClearSavePath = "stageClear.SCsave"; |
| 055218be |
sago007 |
2015-08-22 18:44 |
2153 |
PuzzleSetSavePath("puzzle.levels.save"); |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
2154 |
#endif |
| 055218be |
sago007 |
2015-08-22 18:44 |
2155 |
PuzzleSetName("puzzle.levels"); |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
2156 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2157 |
//Init SDL |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2158 |
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { |
| 56241205 |
sago007 |
2012-08-05 11:15 |
2159 |
cerr << "Unable to init SDL: " << SDL_GetError() << endl; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2160 |
exit(1); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2161 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2162 |
atexit(SDL_Quit); //quits SDL when the game stops for some reason (like you hit exit or Esc) |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
2163 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2164 |
SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE); |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
2165 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2166 |
Joypad_init(); //Prepare the joysticks |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2167 |
Joypad joypad1 = Joypad(); //Creates a joypad |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2168 |
Joypad joypad2 = Joypad(); //Creates a joypad |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
2169 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2170 |
theTextManeger = textManeger(); |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
2171 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2172 |
//Open Audio |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2173 |
if (!NoSound) //If sound has not been disabled, then load the sound system |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2174 |
if (Mix_OpenAudio(44100, AUDIO_S16SYS, 2, 2048) < 0) { |
| 56241205 |
sago007 |
2012-08-05 11:15 |
2175 |
cerr << "Warning: Couldn't set 44100 Hz 16-bit audio - Reason: " << SDL_GetError() << endl |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2176 |
<< "Sound will be disabled!" << endl; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2177 |
NoSound = true; //Tries to stop all sound from playing/loading |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2178 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2179 |
|
| 078900fe |
sago007 |
2015-12-05 15:31 |
2180 |
//SDL_WM_SetCaption("Block Attack - Rise of the Blocks", nullptr); //Sets title line |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
2181 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2182 |
if (verboseLevel) { |
| 56241205 |
sago007 |
2012-08-05 11:15 |
2183 |
//Copyright notice: |
| 56241205 |
sago007 |
2012-08-05 11:15 |
2184 |
cout << "Block Attack - Rise of the Blocks (" << VERSION_NUMBER << ")" << endl << "http://blockattack.sf.net" << endl << "Copyright 2004-2011 Poul Sander" << endl << |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2185 |
"A SDL based game (see www.libsdl.org)" << endl << |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2186 |
"The game is availeble under the GPL, see COPYING for details." << endl; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2187 |
#if defined(_WIN32) |
| 56241205 |
sago007 |
2012-08-05 11:15 |
2188 |
cout << "Windows build" << endl; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2189 |
#elif defined(__linux__) |
| 56241205 |
sago007 |
2012-08-05 11:15 |
2190 |
cout << "Linux build" << endl; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2191 |
#elif defined(__unix__) |
| 56241205 |
sago007 |
2012-08-05 11:15 |
2192 |
cout << "Unix build" << endl; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2193 |
#else |
| 56241205 |
sago007 |
2012-08-05 11:15 |
2194 |
cout << "Alternative build" << endl; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2195 |
#endif |
| 56241205 |
sago007 |
2012-08-05 11:15 |
2196 |
cout << "-------------------------------------------" << endl; |
| 56241205 |
sago007 |
2012-08-05 11:15 |
2197 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2198 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2199 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2200 |
keySettings[0].up= SDLK_UP; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2201 |
keySettings[0].down = SDLK_DOWN; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2202 |
keySettings[0].left = SDLK_LEFT; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2203 |
keySettings[0].right = SDLK_RIGHT; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2204 |
keySettings[0].change = SDLK_RCTRL; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2205 |
keySettings[0].push = SDLK_RSHIFT; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2206 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2207 |
keySettings[2].up= SDLK_w; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2208 |
keySettings[2].down = SDLK_s; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2209 |
keySettings[2].left = SDLK_a; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2210 |
keySettings[2].right = SDLK_d; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2211 |
keySettings[2].change = SDLK_LCTRL; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2212 |
keySettings[2].push = SDLK_LSHIFT; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2213 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2214 |
player1keys=0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2215 |
player2keys=2; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2216 |
|
| f6707482 |
sago007 |
2015-12-04 22:55 |
2217 |
player1name = "Player 1"; |
| f6707482 |
sago007 |
2015-12-04 22:55 |
2218 |
player2name = "Player 2"; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2219 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2220 |
Config* configSettings = Config::getInstance(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2221 |
//configSettings->setString("aNumber"," A string"); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2222 |
//configSettings->save(); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2223 |
if (configSettings->exists("fullscreen")) { //Test if an configFile exists |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2224 |
bFullscreen = (bool)configSettings->getInt("fullscreen"); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2225 |
MusicEnabled = (bool)configSettings->getInt("musicenabled"); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2226 |
SoundEnabled = (bool)configSettings->getInt("soundenabled"); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2227 |
mouseplay1 = (bool)configSettings->getInt("mouseplay1"); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2228 |
mouseplay2 = (bool)configSettings->getInt("mouseplay2"); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2229 |
joyplay1 = (bool)configSettings->getInt("joypad1"); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2230 |
joyplay2 = (bool)configSettings->getInt("joypad2"); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2231 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2232 |
if (configSettings->exists("player1keyup")) { |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
2233 |
keySettings[0].up = (SDL_Keycode)configSettings->getInt("player1keyup"); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2234 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2235 |
if (configSettings->exists("player1keydown")) { |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
2236 |
keySettings[0].down = (SDL_Keycode)configSettings->getInt("player1keydown"); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2237 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2238 |
if (configSettings->exists("player1keyleft")) { |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
2239 |
keySettings[0].left = (SDL_Keycode)configSettings->getInt("player1keyleft"); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2240 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2241 |
if (configSettings->exists("player1keyright")) { |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
2242 |
keySettings[0].right = (SDL_Keycode)configSettings->getInt("player1keyright"); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2243 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2244 |
if (configSettings->exists("player1keychange")) { |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
2245 |
keySettings[0].change = (SDL_Keycode)configSettings->getInt("player1keychange"); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2246 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2247 |
if (configSettings->exists("player1keypush")) { |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
2248 |
keySettings[0].push = (SDL_Keycode)configSettings->getInt("player1keypush"); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2249 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2250 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2251 |
if (configSettings->exists("player2keyup")) { |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
2252 |
keySettings[2].up = (SDL_Keycode)configSettings->getInt("player2keyup"); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2253 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2254 |
if (configSettings->exists("player2keydown")) { |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
2255 |
keySettings[2].down = (SDL_Keycode)configSettings->getInt("player2keydown"); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2256 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2257 |
if (configSettings->exists("player2keyleft")) { |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
2258 |
keySettings[2].left = (SDL_Keycode)configSettings->getInt("player2keyleft"); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2259 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2260 |
if (configSettings->exists("player2keyright")) { |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
2261 |
keySettings[2].right = (SDL_Keycode)configSettings->getInt("player2keyright"); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2262 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2263 |
if (configSettings->exists("player2keychange")) { |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
2264 |
keySettings[2].change = (SDL_Keycode)configSettings->getInt("player2keychange"); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2265 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2266 |
if (configSettings->exists("player2keypush")) { |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
2267 |
keySettings[2].push = (SDL_Keycode)configSettings->getInt("player2keypush"); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2268 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2269 |
if (configSettings->exists("player1name")) { |
| f6707482 |
sago007 |
2015-12-04 22:55 |
2270 |
player1name = configSettings->getString("player1name"); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2271 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2272 |
if (configSettings->exists("player2name")) { |
| f6707482 |
sago007 |
2015-12-04 22:55 |
2273 |
player2name = configSettings->getString("player2name"); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2274 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2275 |
if (verboseLevel) { |
| 56241205 |
sago007 |
2012-08-05 11:15 |
2276 |
cout << "Data loaded from config file" << endl; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2277 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2278 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2279 |
else { |
| f6707482 |
sago007 |
2015-12-04 22:55 |
2280 |
if (verboseLevel) { |
| f6707482 |
sago007 |
2015-12-04 22:55 |
2281 |
cout << "Unable to load options file, using default values" << endl; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2282 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2283 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
2284 |
|
| 1572de2b |
sago007 |
2008-09-11 18:15 |
2285 |
#if NETWORK |
| b45d8841 |
sago007 |
2012-04-23 19:30 |
2286 |
Config::getInstance()->setDefault("portv4","42200"); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2287 |
strcpy(serverAddress, "192.168.0.2 \0"); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2288 |
if (configSettings->exists("address0")) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2289 |
strcpy(serverAddress, " \0"); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2290 |
strncpy(serverAddress,configSettings->getString("address0").c_str(),sizeof(serverAddress)-1); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2291 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
2292 |
#endif |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
2293 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2294 |
if (singlePuzzle) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2295 |
xsize=300; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2296 |
ysize=600; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2297 |
} |
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
2298 |
|
| 89c4a3a6 |
sago007 |
2008-08-29 14:32 |
2299 |
|
| 078900fe |
sago007 |
2015-12-05 15:31 |
2300 |
// "Block Attack - Rise of the Blocks" |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2301 |
//Open video |
| 078900fe |
sago007 |
2015-12-05 15:31 |
2302 |
int createWindowParams = 0; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2303 |
if ((bFullscreen)&&(!singlePuzzle)) { |
| 078900fe |
sago007 |
2015-12-05 15:31 |
2304 |
createWindowParams |= SDL_WINDOW_FULLSCREEN_DESKTOP; |
| 078900fe |
sago007 |
2015-12-05 15:31 |
2305 |
} |
| 078900fe |
sago007 |
2015-12-05 15:31 |
2306 |
|
| 078900fe |
sago007 |
2015-12-05 15:31 |
2307 |
SDL_Window *sdlWindow = SDL_CreateWindow("Block Attack - Rise of the BlocksMy Game Window", |
| 078900fe |
sago007 |
2015-12-05 15:31 |
2308 |
SDL_WINDOWPOS_UNDEFINED, |
| 078900fe |
sago007 |
2015-12-05 15:31 |
2309 |
SDL_WINDOWPOS_UNDEFINED, |
| 078900fe |
sago007 |
2015-12-05 15:31 |
2310 |
xsize, ysize, |
| 078900fe |
sago007 |
2015-12-05 15:31 |
2311 |
createWindowParams ); |
| 078900fe |
sago007 |
2015-12-05 15:31 |
2312 |
dieOnNullptr(sdlWindow, "Unable to create window"); |
| 078900fe |
sago007 |
2015-12-05 15:31 |
2313 |
SDL_Renderer *renderer = SDL_CreateRenderer(sdlWindow, -1, 0); |
| 078900fe |
sago007 |
2015-12-05 15:31 |
2314 |
dieOnNullptr(renderer, "Unable to create render"); |
| b7590374 |
sago007 |
2011-05-19 16:15 |
2315 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2316 |
//Init the file system abstraction layer |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2317 |
PHYSFS_init(argv[0]); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
2318 |
PHYSFS_addToSearchPath( ((string) PHYSFS_getBaseDir()+"/data").c_str(), 1); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2319 |
//Load default theme |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
2320 |
sago::SagoDataHolder d(renderer); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
2321 |
sago::SagoSpriteHolder spriteholder(d); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
2322 |
loadTheme(spriteholder, Config::getInstance()->getString("themename")); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2323 |
//Now sets the icon: |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
2324 |
//SDL_Surface* icon = IMG_Load2("gfx/icon.png"); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
2325 |
//SDL_WM_SetIcon(icon,nullptr); |
| b7590374 |
sago007 |
2011-05-19 16:15 |
2326 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2327 |
if (verboseLevel) { |
| 56241205 |
sago007 |
2012-08-05 11:15 |
2328 |
cout << "Images loaded" << endl; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2329 |
} |
| b7590374 |
sago007 |
2011-05-19 16:15 |
2330 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2331 |
//InitMenues(); |
| b7590374 |
sago007 |
2011-05-19 16:15 |
2332 |
|
| acd79baf |
sago007 |
2015-11-22 19:37 |
2333 |
BlockGameSdl theGame = BlockGameSdl(50,100); //creates game objects |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2334 |
BlockGameSdl theGame2 = BlockGameSdl(xsize-500,100); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2335 |
player1 = &theGame; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2336 |
player2 = &theGame2; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2337 |
/*if (singlePuzzle) |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2338 |
{ |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2339 |
theGame.GetTopY()=0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2340 |
theGame.GetTopX()=0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2341 |
theGame2.GetTopY()=10000; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2342 |
theGame2.GetTopX()=10000; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2343 |
}*/ |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2344 |
theGame.SetGameOver(); //sets the game over in the beginning |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2345 |
theGame2.SetGameOver(); |
| b7590374 |
sago007 |
2011-05-19 16:15 |
2346 |
|
| b7590374 |
sago007 |
2011-05-19 16:15 |
2347 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2348 |
//Takes names from file instead |
| 8f632c05 |
sago007 |
2015-08-22 16:21 |
2349 |
theGame.name = player1name; |
| 8f632c05 |
sago007 |
2015-08-22 16:21 |
2350 |
theGame2.name = player2name; |
| b7590374 |
sago007 |
2011-05-19 16:15 |
2351 |
|
| 69862ef6 |
sago007 |
2015-08-22 17:24 |
2352 |
if (singlePuzzle) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2353 |
LoadPuzzleStages(); |
| 229e212d |
sago007 |
2015-08-22 17:14 |
2354 |
theGame.NewPuzzleGame(singlePuzzleNr, SDL_GetTicks()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2355 |
} |
| c699a9f9 |
sago007 |
2015-12-05 17:22 |
2356 |
DrawIMG(backgroundImage, screen, 0, 0); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2357 |
DrawEverything(xsize,ysize,&theGame,&theGame2); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
2358 |
SDL_RenderPresent(screen); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2359 |
//game loop |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2360 |
MainMenu(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2361 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2362 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2363 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2364 |
//Saves options |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2365 |
if (!editorMode) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2366 |
configSettings->setInt("fullscreen",(int)bFullscreen); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2367 |
configSettings->setInt("musicenabled",(int)MusicEnabled); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2368 |
configSettings->setInt("soundenabled",(int)SoundEnabled); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2369 |
configSettings->setInt("mouseplay1",(int)mouseplay1); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2370 |
configSettings->setInt("mouseplay2",(int)mouseplay2); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2371 |
configSettings->setInt("joypad1",(int)joyplay1); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2372 |
configSettings->setInt("joypad2",(int)joyplay2); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2373 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2374 |
configSettings->setInt("player1keyup",(int)keySettings[0].up); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2375 |
configSettings->setInt("player1keydown",(int)keySettings[0].down); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2376 |
configSettings->setInt("player1keyleft",(int)keySettings[0].left); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2377 |
configSettings->setInt("player1keyright",(int)keySettings[0].right); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2378 |
configSettings->setInt("player1keychange",(int)keySettings[0].change); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2379 |
configSettings->setInt("player1keypush",(int)keySettings[0].push); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2380 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2381 |
configSettings->setInt("player2keyup",(int)keySettings[2].up); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2382 |
configSettings->setInt("player2keydown",(int)keySettings[2].down); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2383 |
configSettings->setInt("player2keyleft",(int)keySettings[2].left); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2384 |
configSettings->setInt("player2keyright",(int)keySettings[2].right); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2385 |
configSettings->setInt("player2keychange",(int)keySettings[2].change); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2386 |
configSettings->setInt("player2keypush",(int)keySettings[2].push); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2387 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2388 |
configSettings->setString("player1name",player1name); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2389 |
configSettings->setString("player2name",player2name); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2390 |
configSettings->save(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2391 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2392 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2393 |
//calculate uptime: |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2394 |
//int hours, mins, secs, |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2395 |
commonTime ct = TimeHandler::ms2ct(SDL_GetTicks()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2396 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2397 |
if (verboseLevel) { |
| 56241205 |
sago007 |
2012-08-05 11:15 |
2398 |
cout << boost::format("Block Attack - Rise of the Blocks ran for: %1% hours %2% mins and %3% secs") % ct.hours % ct.minutes % ct.seconds << endl; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2399 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2400 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2401 |
ct = TimeHandler::addTime("totalTime",ct); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2402 |
if (verboseLevel) { |
| 56241205 |
sago007 |
2012-08-05 11:15 |
2403 |
cout << "Total run time is now: " << ct.days << " days " << ct.hours << " hours " << ct.minutes << " mins and " << ct.seconds << " secs" << endl; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2404 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2405 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2406 |
Stats::getInstance()->save(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2407 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2408 |
Config::getInstance()->save(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2409 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2410 |
//Frees memory from music and fonts |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2411 |
//This is done after writing of configurations and stats since it often crashes the program :( |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2412 |
UnloadImages(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2413 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2414 |
//Close file system Apstraction layer! |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2415 |
PHYSFS_deinit(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2416 |
return 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2417 |
} |
| b7590374 |
sago007 |
2011-05-19 16:15 |
2418 |
|
| b7590374 |
sago007 |
2011-05-19 16:15 |
2419 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2420 |
int runGame(int gametype, int level) { |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
2421 |
const Uint8* keys; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2422 |
int mousex, mousey; //Mouse coordinates |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2423 |
bScreenLocked = false; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2424 |
theTopScoresEndless = Highscore(1); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2425 |
theTopScoresTimeTrial = Highscore(2); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2426 |
drawBalls = true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2427 |
puzzleLoaded = false; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2428 |
bool weWhereConnected = false; |
| a5a3aa4f |
sago007 |
2015-08-23 15:31 |
2429 |
bool bNearDeath = false; //Play music faster or louder while tru |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2430 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2431 |
//Things used for repeating keystrokes: |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2432 |
bool repeatingS[2] = {false,false}; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2433 |
bool repeatingW[2] = {false,false}; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2434 |
bool repeatingN[2] = {false,false}; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2435 |
bool repeatingE[2] = {false,false}; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2436 |
const int startRepeat = 200; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2437 |
const int repeatDelay = 100; //Repeating |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2438 |
unsigned long timeHeldP1N = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2439 |
unsigned long timeHeldP1S = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2440 |
unsigned long timeHeldP1E = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2441 |
unsigned long timeHeldP1W = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2442 |
unsigned long timeHeldP2N = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2443 |
unsigned long timeHeldP2S = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2444 |
unsigned long timeHeldP2E = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2445 |
unsigned long timeHeldP2W = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2446 |
unsigned long timesRepeatedP1N = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2447 |
unsigned long timesRepeatedP1S = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2448 |
unsigned long timesRepeatedP1E = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2449 |
unsigned long timesRepeatedP1W = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2450 |
unsigned long timesRepeatedP2N = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2451 |
unsigned long timesRepeatedP2S = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2452 |
unsigned long timesRepeatedP2E = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2453 |
unsigned long timesRepeatedP2W = 0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2454 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2455 |
theBallManeger = ballManeger(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2456 |
theExplosionManeger = explosionManeger(); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2457 |
BlockGameSdl theGame = BlockGameSdl(50,100); //creates game objects |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2458 |
BlockGameSdl theGame2 = BlockGameSdl(xsize-500,100); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2459 |
player1 = &theGame; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2460 |
player2 = &theGame2; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2461 |
theGame.DoPaintJob(); //Makes sure what there is something to paint |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2462 |
theGame2.DoPaintJob(); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2463 |
theGame.SetGameOver(); //sets the game over in the beginning |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2464 |
theGame2.SetGameOver(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2465 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2466 |
//Takes names from file instead |
| 8f632c05 |
sago007 |
2015-08-22 16:21 |
2467 |
theGame.name = player1name; |
| 8f632c05 |
sago007 |
2015-08-22 16:21 |
2468 |
theGame2.name = player2name; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2469 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2470 |
Joypad joypad1 = Joypad(); //Creates a joypad |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2471 |
Joypad joypad2 = Joypad(); //Creates a joypad |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2472 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2473 |
if (singlePuzzle) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2474 |
LoadPuzzleStages(); |
| 229e212d |
sago007 |
2015-08-22 17:14 |
2475 |
theGame.NewPuzzleGame(singlePuzzleNr, SDL_GetTicks()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2476 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2477 |
//game loop |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2478 |
int done = 0; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2479 |
if (verboseLevel) { |
| 56241205 |
sago007 |
2012-08-05 11:15 |
2480 |
cout << "Starting game loop" << endl; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2481 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2482 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2483 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2484 |
bool mustsetupgame = true; |
| dfdb7d66 |
sago007 |
2015-11-29 19:21 |
2485 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2486 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2487 |
while (done == 0) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2488 |
if (mustsetupgame) { |
| dfdb7d66 |
sago007 |
2015-11-29 19:21 |
2489 |
registerEndlessHighscore = false; |
| dfdb7d66 |
sago007 |
2015-11-29 19:21 |
2490 |
registerTTHighscorePlayer1 = false; |
| dfdb7d66 |
sago007 |
2015-11-29 19:21 |
2491 |
registerTTHighscorePlayer2 = false; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2492 |
switch (gametype) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2493 |
case 1: |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2494 |
StartSinglePlayerTimeTrial(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2495 |
break; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2496 |
case 2: { |
| aede0664 |
sago007 |
2012-04-19 19:45 |
2497 |
int myLevel = PuzzleLevelSelect(1); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2498 |
if (myLevel == -1) { |
| aede0664 |
sago007 |
2012-04-19 19:45 |
2499 |
return 1; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2500 |
} |
| 229e212d |
sago007 |
2015-08-22 17:14 |
2501 |
theGame.NewStageGame(myLevel,SDL_GetTicks()); |
| c699a9f9 |
sago007 |
2015-12-05 17:22 |
2502 |
DrawIMG(backgroundImage, screen, 0, 0); |
| aede0664 |
sago007 |
2012-04-19 19:45 |
2503 |
twoPlayers =false; |
| aede0664 |
sago007 |
2012-04-19 19:45 |
2504 |
theGame2.SetGameOver(); |
| 8f632c05 |
sago007 |
2015-08-22 16:21 |
2505 |
theGame.name = player1name; |
| 8f632c05 |
sago007 |
2015-08-22 16:21 |
2506 |
theGame2.name = player2name; |
| aede0664 |
sago007 |
2012-04-19 19:45 |
2507 |
} |
| aede0664 |
sago007 |
2012-04-19 19:45 |
2508 |
break; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2509 |
case 3: |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2510 |
if (StartSinglePlayerPuzzle(level)) { |
| 67a32395 |
sago007 |
2012-04-19 18:40 |
2511 |
return 1; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2512 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2513 |
break; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2514 |
case 4: { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2515 |
//1 player - Vs mode |
| 67a32395 |
sago007 |
2012-04-19 18:40 |
2516 |
int theAIlevel = level; //startSingleVs(); |
| 229e212d |
sago007 |
2015-08-22 17:14 |
2517 |
theGame.NewVsGame(&theGame2, SDL_GetTicks()); |
| 229e212d |
sago007 |
2015-08-22 17:14 |
2518 |
theGame2.NewVsGame(&theGame, SDL_GetTicks()); |
| c699a9f9 |
sago007 |
2015-12-05 17:22 |
2519 |
DrawIMG(backgroundImage, screen, 0, 0); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2520 |
twoPlayers = true; //Single player, but AI plays |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2521 |
theGame2.setAIlevel((Uint8)theAIlevel); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2522 |
int theTime = time(0); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2523 |
theGame.putStartBlocks(theTime); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2524 |
theGame2.putStartBlocks(theTime); |
| 8f632c05 |
sago007 |
2015-08-22 16:21 |
2525 |
theGame.name = player1name; |
| 8f632c05 |
sago007 |
2015-08-22 16:21 |
2526 |
theGame2.name = player2name; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2527 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2528 |
break; |
| b0222eff |
sago007 |
2012-04-22 15:06 |
2529 |
case 10: |
| b0222eff |
sago007 |
2012-04-22 15:06 |
2530 |
StarTwoPlayerTimeTrial(); |
| b0222eff |
sago007 |
2012-04-22 15:06 |
2531 |
break; |
| b0222eff |
sago007 |
2012-04-22 15:06 |
2532 |
case 11: |
| b0222eff |
sago007 |
2012-04-22 15:06 |
2533 |
StartTwoPlayerVs(); |
| b0222eff |
sago007 |
2012-04-22 15:06 |
2534 |
break; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2535 |
case 0: |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2536 |
default: |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2537 |
StartSinglePlayerEndless(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2538 |
break; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2539 |
}; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2540 |
mustsetupgame = false; |
| c699a9f9 |
sago007 |
2015-12-05 17:22 |
2541 |
DrawIMG(backgroundImage, screen, 0, 0); |
| 67a32395 |
sago007 |
2012-04-19 18:40 |
2542 |
DrawEverything(xsize,ysize,&theGame,&theGame2); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
2543 |
SDL_RenderPresent(screen); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2544 |
} |
| b7590374 |
sago007 |
2011-05-19 16:15 |
2545 |
|
| acd79baf |
sago007 |
2015-11-22 19:37 |
2546 |
if (!(highPriority)) { |
| 571b4d47 |
sago007 |
2015-12-05 16:02 |
2547 |
SDL_Delay(1); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2548 |
} |
| c699a9f9 |
sago007 |
2015-12-05 17:22 |
2549 |
DrawIMG(backgroundImage, screen, 0, 0); |
| b7590374 |
sago007 |
2011-05-19 16:15 |
2550 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2551 |
//updates the balls and explosions: |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2552 |
theBallManeger.update(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2553 |
theExplosionManeger.update(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2554 |
theTextManeger.update(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2555 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2556 |
if (!bScreenLocked) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2557 |
SDL_Event event; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2558 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2559 |
while ( SDL_PollEvent(&event) ) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2560 |
if ( event.type == SDL_QUIT ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2561 |
Config::getInstance()->setShuttingDown(5); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2562 |
done = 1; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2563 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2564 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2565 |
if ( event.type == SDL_KEYDOWN ) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2566 |
if ( event.key.keysym.sym == SDLK_ESCAPE || ( event.key.keysym.sym == SDLK_RETURN && theGame.isGameOver() ) ) { |
| 1a156b60 |
sago007 |
2015-08-22 17:29 |
2567 |
done=1; |
| c699a9f9 |
sago007 |
2015-12-05 17:22 |
2568 |
DrawIMG(backgroundImage, screen, 0, 0); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2569 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2570 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2571 |
if ((!editorMode)&&(!editorModeTest)&&(!theGame.GetAIenabled())) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2572 |
//player1: |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2573 |
if ( event.key.keysym.sym == keySettings[player1keys].up ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2574 |
theGame.MoveCursor('N'); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2575 |
repeatingN[0]=true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2576 |
timeHeldP1N=SDL_GetTicks(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2577 |
timesRepeatedP1N=0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2578 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2579 |
if ( event.key.keysym.sym == keySettings[player1keys].down ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2580 |
theGame.MoveCursor('S'); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2581 |
repeatingS[0]=true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2582 |
timeHeldP1S=SDL_GetTicks(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2583 |
timesRepeatedP1S=0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2584 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2585 |
if ( (event.key.keysym.sym == keySettings[player1keys].left) ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2586 |
theGame.MoveCursor('W'); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2587 |
repeatingW[0]=true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2588 |
timeHeldP1W=SDL_GetTicks(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2589 |
timesRepeatedP1W=0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2590 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2591 |
if ( (event.key.keysym.sym == keySettings[player1keys].right) ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2592 |
theGame.MoveCursor('E'); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2593 |
repeatingE[0]=true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2594 |
timeHeldP1E=SDL_GetTicks(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2595 |
timesRepeatedP1E=0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2596 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2597 |
if ( event.key.keysym.sym == keySettings[player1keys].push ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2598 |
theGame.PushLine(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2599 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2600 |
if ( event.key.keysym.sym == keySettings[player1keys].change ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2601 |
theGame.SwitchAtCursor(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2602 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2603 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2604 |
if (!editorMode && !theGame2.GetAIenabled()) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2605 |
//player2: |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2606 |
if ( event.key.keysym.sym == keySettings[player2keys].up ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2607 |
theGame2.MoveCursor('N'); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2608 |
repeatingN[1]=true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2609 |
timeHeldP2N=SDL_GetTicks(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2610 |
timesRepeatedP2N=0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2611 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2612 |
if ( event.key.keysym.sym == keySettings[player2keys].down ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2613 |
theGame2.MoveCursor('S'); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2614 |
repeatingS[1]=true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2615 |
timeHeldP2S=SDL_GetTicks(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2616 |
timesRepeatedP2S=0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2617 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2618 |
if ( (event.key.keysym.sym == keySettings[player2keys].left) ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2619 |
theGame2.MoveCursor('W'); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2620 |
repeatingW[1]=true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2621 |
timeHeldP2W=SDL_GetTicks(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2622 |
timesRepeatedP2W=0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2623 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2624 |
if ( (event.key.keysym.sym == keySettings[player2keys].right) ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2625 |
theGame2.MoveCursor('E'); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2626 |
repeatingE[1]=true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2627 |
timeHeldP2E=SDL_GetTicks(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2628 |
timesRepeatedP2E=0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2629 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2630 |
if ( event.key.keysym.sym == keySettings[player2keys].push ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2631 |
theGame2.PushLine(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2632 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2633 |
if ( event.key.keysym.sym == keySettings[player2keys].change ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2634 |
theGame2.SwitchAtCursor(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2635 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2636 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2637 |
//common: |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2638 |
if ((!singlePuzzle)&&(!editorMode)) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2639 |
if ( event.key.keysym.sym == SDLK_F2 ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2640 |
/*#if NETWORK |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2641 |
if ((!showOptions)&&(!networkActive)){ |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2642 |
#else |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2643 |
if ((!showOptions)){ |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2644 |
#endif |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2645 |
StartSinglePlayerEndless(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2646 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2647 |
*/ |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2648 |
mustsetupgame = true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2649 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2650 |
if ( event.key.keysym.sym == SDLK_F10 ) { |
| ca486238 |
sago007 |
2015-08-23 15:12 |
2651 |
//StartReplay("/home/poul/.gamesaves/blockattack/quicksave"); |
| b283e0f7 |
sago007 |
2012-07-29 14:01 |
2652 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2653 |
if ( event.key.keysym.sym == SDLK_F9 ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2654 |
writeScreenShot(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2655 |
} |
| ca486238 |
sago007 |
2015-08-23 15:12 |
2656 |
if ( event.key.keysym.sym == SDLK_F5 ) { |
| b283e0f7 |
sago007 |
2012-07-29 14:01 |
2657 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2658 |
if ( event.key.keysym.sym == SDLK_F11 ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2659 |
} //F11 |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2660 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2661 |
if ( event.key.keysym.sym == SDLK_F12 ) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2662 |
done=1; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2663 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2664 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2665 |
} //while event PollEvent - read keys |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2666 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2667 |
/********************************************************************** |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2668 |
**************************** Repeating start ************************** |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2669 |
**********************************************************************/ |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2670 |
|
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
2671 |
keys = SDL_GetKeyboardState(nullptr); |
| b7590374 |
sago007 |
2011-05-19 16:15 |
2672 |
//Also the joysticks: |
| b7590374 |
sago007 |
2011-05-19 16:15 |
2673 |
//Repeating not implemented |
| b7590374 |
sago007 |
2011-05-19 16:15 |
2674 |
|
| b7590374 |
sago007 |
2011-05-19 16:15 |
2675 |
//Player 1 start |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2676 |
if (!(keys[keySettings[player1keys].up])) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2677 |
repeatingN[0]=false; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2678 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2679 |
while ((repeatingN[0])&&(keys[keySettings[player1keys].up])&&(SDL_GetTicks()>timeHeldP1N+timesRepeatedP1N*repeatDelay+startRepeat)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2680 |
theGame.MoveCursor('N'); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2681 |
timesRepeatedP1N++; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2682 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2683 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2684 |
if (!(keys[keySettings[player1keys].down])) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2685 |
repeatingS[0]=false; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2686 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2687 |
while ((repeatingS[0])&&(keys[keySettings[player1keys].down])&&(SDL_GetTicks()>timeHeldP1S+timesRepeatedP1S*repeatDelay+startRepeat)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2688 |
theGame.MoveCursor('S'); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2689 |
timesRepeatedP1S++; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2690 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2691 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2692 |
if (!(keys[keySettings[player1keys].left])) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2693 |
repeatingW[0]=false; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2694 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2695 |
while ((repeatingW[0])&&(keys[keySettings[player1keys].left])&&(SDL_GetTicks()>timeHeldP1W+timesRepeatedP1W*repeatDelay+startRepeat)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2696 |
timesRepeatedP1W++; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2697 |
theGame.MoveCursor('W'); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2698 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2699 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2700 |
if (!(keys[keySettings[player1keys].right])) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2701 |
repeatingE[0]=false; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2702 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2703 |
while ((repeatingE[0])&&(keys[keySettings[player1keys].right])&&(SDL_GetTicks()>timeHeldP1E+timesRepeatedP1E*repeatDelay+startRepeat)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2704 |
timesRepeatedP1E++; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2705 |
theGame.MoveCursor('E'); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2706 |
} |
| b7590374 |
sago007 |
2011-05-19 16:15 |
2707 |
|
| b7590374 |
sago007 |
2011-05-19 16:15 |
2708 |
//Player 1 end |
| b7590374 |
sago007 |
2011-05-19 16:15 |
2709 |
|
| b7590374 |
sago007 |
2011-05-19 16:15 |
2710 |
//Player 2 start |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2711 |
if (!(keys[keySettings[player2keys].up])) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2712 |
repeatingN[1]=false; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2713 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2714 |
while ((repeatingN[1])&&(keys[keySettings[player2keys].up])&&(SDL_GetTicks()>timeHeldP2N+timesRepeatedP2N*repeatDelay+startRepeat)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2715 |
theGame2.MoveCursor('N'); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2716 |
timesRepeatedP2N++; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2717 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2718 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2719 |
if (!(keys[keySettings[player2keys].down])) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2720 |
repeatingS[1]=false; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2721 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2722 |
while ((repeatingS[1])&&(keys[keySettings[player2keys].down])&&(SDL_GetTicks()>timeHeldP2S+timesRepeatedP2S*repeatDelay+startRepeat)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2723 |
theGame2.MoveCursor('S'); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2724 |
timesRepeatedP2S++; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2725 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2726 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2727 |
if (!(keys[keySettings[player2keys].left])) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2728 |
repeatingW[1]=false; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2729 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2730 |
while ((repeatingW[1])&&(keys[keySettings[player2keys].left])&&(SDL_GetTicks()>timeHeldP2W+timesRepeatedP2W*repeatDelay+startRepeat)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2731 |
theGame2.MoveCursor('W'); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2732 |
timesRepeatedP2W++; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2733 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2734 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2735 |
if (!(keys[keySettings[player2keys].right])) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2736 |
repeatingE[1]=false; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2737 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2738 |
while ((repeatingE[1])&&(keys[keySettings[player2keys].right])&&(SDL_GetTicks()>timeHeldP2E+timesRepeatedP2E*repeatDelay+startRepeat)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2739 |
theGame2.MoveCursor('E'); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2740 |
timesRepeatedP2E++; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2741 |
} |
| b7590374 |
sago007 |
2011-05-19 16:15 |
2742 |
|
| b7590374 |
sago007 |
2011-05-19 16:15 |
2743 |
//Player 2 end |
| b7590374 |
sago007 |
2011-05-19 16:15 |
2744 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2745 |
/********************************************************************** |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2746 |
**************************** Repeating end **************************** |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2747 |
**********************************************************************/ |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2748 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2749 |
/********************************************************************** |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2750 |
***************************** Joypad start **************************** |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2751 |
**********************************************************************/ |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2752 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2753 |
//Gameplay |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2754 |
if (joyplay1||joyplay2) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2755 |
if (joypad1.working && !theGame.GetAIenabled()) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2756 |
if (joyplay1) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2757 |
joypad1.update(); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2758 |
if (joypad1.up) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2759 |
theGame.MoveCursor('N'); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2760 |
repeatingN[0]=true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2761 |
timeHeldP1N=SDL_GetTicks(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2762 |
timesRepeatedP1N=0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2763 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2764 |
if (joypad1.down) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2765 |
theGame.MoveCursor('S'); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2766 |
repeatingS[0]=true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2767 |
timeHeldP1S=SDL_GetTicks(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2768 |
timesRepeatedP1S=0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2769 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2770 |
if (joypad1.left) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2771 |
theGame.MoveCursor('W'); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2772 |
repeatingW[0]=true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2773 |
timeHeldP1W=SDL_GetTicks(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2774 |
timesRepeatedP1W=0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2775 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2776 |
if (joypad1.right) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2777 |
theGame.MoveCursor('E'); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2778 |
repeatingE[0]=true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2779 |
timeHeldP1E=SDL_GetTicks(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2780 |
timesRepeatedP1E=0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2781 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2782 |
if (joypad1.but1) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2783 |
theGame.SwitchAtCursor(); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2784 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2785 |
if (joypad1.but2) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2786 |
theGame.PushLine(); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2787 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2788 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2789 |
else { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2790 |
joypad1.update(); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2791 |
if (joypad1.up) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2792 |
theGame2.MoveCursor('N'); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2793 |
repeatingN[1]=true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2794 |
timeHeldP2N=SDL_GetTicks(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2795 |
timesRepeatedP2N=0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2796 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2797 |
if (joypad1.down) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2798 |
theGame2.MoveCursor('S'); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2799 |
repeatingS[1]=true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2800 |
timeHeldP2S=SDL_GetTicks(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2801 |
timesRepeatedP2S=0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2802 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2803 |
if (joypad1.left) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2804 |
theGame2.MoveCursor('W'); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2805 |
repeatingW[1]=true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2806 |
timeHeldP2W=SDL_GetTicks(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2807 |
timesRepeatedP2W=0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2808 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2809 |
if (joypad1.right) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2810 |
theGame2.MoveCursor('E'); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2811 |
repeatingE[1]=true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2812 |
timeHeldP2E=SDL_GetTicks(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2813 |
timesRepeatedP2E=0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2814 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2815 |
if (joypad1.but1) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2816 |
theGame2.SwitchAtCursor(); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2817 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2818 |
if (joypad1.but2) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2819 |
theGame2.PushLine(); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2820 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2821 |
} |
| 80b830cd |
sago007 |
2012-08-19 17:51 |
2822 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2823 |
if (joypad2.working && !theGame2.GetAIenabled()) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2824 |
if (!joyplay2) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2825 |
joypad2.update(); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2826 |
if (joypad2.up) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2827 |
theGame.MoveCursor('N'); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2828 |
repeatingN[0]=true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2829 |
timeHeldP1N=SDL_GetTicks(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2830 |
timesRepeatedP1N=0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2831 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2832 |
if (joypad2.down) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2833 |
theGame.MoveCursor('S'); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2834 |
repeatingS[0]=true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2835 |
timeHeldP1S=SDL_GetTicks(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2836 |
timesRepeatedP1S=0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2837 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2838 |
if (joypad2.left) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2839 |
theGame.MoveCursor('W'); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2840 |
repeatingW[0]=true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2841 |
timeHeldP1W=SDL_GetTicks(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2842 |
timesRepeatedP1W=0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2843 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2844 |
if (joypad2.right) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2845 |
theGame.MoveCursor('E'); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2846 |
repeatingE[0]=true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2847 |
timeHeldP1E=SDL_GetTicks(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2848 |
timesRepeatedP1E=0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2849 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2850 |
if (joypad2.but1) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2851 |
theGame.SwitchAtCursor(); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2852 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2853 |
if (joypad2.but2) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2854 |
theGame.PushLine(); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2855 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2856 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2857 |
else { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2858 |
joypad2.update(); |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2859 |
if (joypad2.up) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2860 |
theGame2.MoveCursor('N'); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2861 |
repeatingN[1]=true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2862 |
timeHeldP2N=SDL_GetTicks(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2863 |
timesRepeatedP2N=0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2864 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2865 |
if (joypad2.down) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2866 |
theGame2.MoveCursor('S'); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2867 |
repeatingS[1]=true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2868 |
timeHeldP2S=SDL_GetTicks(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2869 |
timesRepeatedP2S=0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2870 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2871 |
if (joypad2.left) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2872 |
theGame2.MoveCursor('W'); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2873 |
repeatingW[1]=true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2874 |
timeHeldP2W=SDL_GetTicks(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2875 |
timesRepeatedP2W=0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2876 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2877 |
if (joypad2.right) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2878 |
theGame2.MoveCursor('E'); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2879 |
repeatingE[1]=true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2880 |
timeHeldP2E=SDL_GetTicks(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2881 |
timesRepeatedP2E=0; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2882 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2883 |
if (joypad2.but1) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2884 |
theGame2.SwitchAtCursor(); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2885 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2886 |
if (joypad2.but2) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2887 |
theGame2.PushLine(); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2888 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2889 |
} |
| 80b830cd |
sago007 |
2012-08-19 17:51 |
2890 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2891 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2892 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2893 |
/********************************************************************** |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2894 |
***************************** Joypad end ****************************** |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2895 |
**********************************************************************/ |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2896 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2897 |
|
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
2898 |
SDL_GetKeyboardState(nullptr); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2899 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2900 |
SDL_GetMouseState(&mousex,&mousey); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2901 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2902 |
/******************************************************************** |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2903 |
**************** Here comes mouse play ****************************** |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2904 |
********************************************************************/ |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2905 |
|
| 80b830cd |
sago007 |
2012-08-19 17:51 |
2906 |
if ((mouseplay1)&&( ( (!editorMode)&&(!theGame.GetAIenabled()) ) ||(editorModeTest))) //player 1 |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2907 |
if ((mousex > 50)&&(mousey>100)&&(mousex<50+300)&&(mousey<100+600)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2908 |
int yLine, xLine; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2909 |
yLine = ((100+600)-(mousey-100+theGame.GetPixels()))/50; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2910 |
xLine = (mousex-50+25)/50; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2911 |
yLine-=2; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2912 |
xLine-=1; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2913 |
if ((yLine>10)&&(theGame.GetTowerHeight()<12)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2914 |
yLine=10; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2915 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2916 |
if (((theGame.GetPixels()==50)||(theGame.GetPixels()==0)) && (yLine>11)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2917 |
yLine=11; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2918 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2919 |
if (yLine<0) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2920 |
yLine=0; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2921 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2922 |
if (xLine<0) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2923 |
xLine=0; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2924 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2925 |
if (xLine>4) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2926 |
xLine=4; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2927 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2928 |
theGame.MoveCursorTo(xLine,yLine); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2929 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2930 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2931 |
if ((mouseplay2)&&(!editorMode)&&(!theGame2.GetAIenabled())) //player 2 |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2932 |
if ((mousex > xsize-500)&&(mousey>100)&&(mousex<xsize-500+300)&&(mousey<100+600)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2933 |
int yLine, xLine; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2934 |
yLine = ((100+600)-(mousey-100+theGame2.GetPixels()))/50; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2935 |
xLine = (mousex-(xsize-500)+25)/50; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2936 |
yLine-=2; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2937 |
xLine-=1; |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2938 |
if ((yLine>10)&&(theGame2.GetTowerHeight()<12)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2939 |
yLine=10; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2940 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2941 |
if (((theGame2.GetPixels()==50)||(theGame2.GetPixels()==0)) && (yLine>11)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2942 |
yLine=11; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2943 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2944 |
if (yLine<0) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2945 |
yLine=0; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2946 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2947 |
if (xLine<0) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2948 |
xLine=0; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2949 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2950 |
if (xLine>4) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2951 |
xLine=4; |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2952 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2953 |
theGame2.MoveCursorTo(xLine,yLine); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2954 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2955 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2956 |
/******************************************************************** |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2957 |
**************** Here ends mouse play ******************************* |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2958 |
********************************************************************/ |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2959 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2960 |
// If the mouse button is released, make bMouseUp equal true |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2961 |
if (!SDL_GetMouseState(nullptr, nullptr)&SDL_BUTTON(1)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2962 |
bMouseUp=true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2963 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2964 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2965 |
// If the mouse button 2 is released, make bMouseUp2 equal true |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2966 |
if ((SDL_GetMouseState(nullptr, nullptr)&SDL_BUTTON(3))!=SDL_BUTTON(3)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2967 |
bMouseUp2=true; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2968 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2969 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2970 |
if ((!singlePuzzle)&&(!editorMode)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2971 |
//read mouse events |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2972 |
if (SDL_GetMouseState(nullptr,nullptr)&SDL_BUTTON(1) && bMouseUp) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2973 |
bMouseUp = false; |
| c699a9f9 |
sago007 |
2015-12-05 17:22 |
2974 |
DrawIMG(backgroundImage, screen, 0, 0); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2975 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2976 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2977 |
/******************************************************************** |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2978 |
**************** Here comes mouse play ****************************** |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2979 |
********************************************************************/ |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2980 |
{ |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2981 |
if (mouseplay1 && !theGame.GetAIenabled()) //player 1 |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2982 |
if ((mousex > 50)&&(mousey>100)&&(mousex<50+300)&&(mousey<100+600)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2983 |
theGame.SwitchAtCursor(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2984 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2985 |
if (mouseplay2 && !theGame2.GetAIenabled()) //player 2 |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2986 |
if ((mousex > xsize-500)&&(mousey>100)&&(mousex<xsize-500+300)&&(mousey<100+600)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2987 |
theGame2.SwitchAtCursor(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2988 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2989 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2990 |
/******************************************************************** |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2991 |
**************** Here ends mouse play ******************************* |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2992 |
********************************************************************/ |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2993 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2994 |
if (stageButtonStatus != SBdontShow && (mousex > theGame.GetTopX()+cordNextButton.x) |
| acd79baf |
sago007 |
2015-11-22 19:37 |
2995 |
&&(mousex < theGame.GetTopX()+cordNextButton.x+cordNextButton.xsize) |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
2996 |
&&(mousey > theGame.GetTopY()+cordNextButton.y)&&(mousey < theGame.GetTopY()+cordNextButton.y+cordNextButton.ysize)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2997 |
//Clicked the next button after a stage clear or puzzle |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2998 |
theGame.nextLevel(SDL_GetTicks()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
2999 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
3000 |
if (stageButtonStatus != SBdontShow && (mousex > theGame.GetTopX()+cordRetryButton .x) |
| acd79baf |
sago007 |
2015-11-22 19:37 |
3001 |
&&(mousex < theGame.GetTopX()+cordRetryButton.x+cordRetryButton.xsize) |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
3002 |
&&(mousey > theGame.GetTopY()+cordRetryButton.y)&&(mousey < theGame.GetTopY()+cordRetryButton.y+cordRetryButton.ysize)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3003 |
//Clicked the retry button |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3004 |
theGame.retryLevel(SDL_GetTicks()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3005 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3006 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3007 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3008 |
//cout << "Mouse x: " << mousex << ", mouse y: " << mousey << endl; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3009 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3010 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3011 |
//Mouse button 2: |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
3012 |
if ((SDL_GetMouseState(nullptr,nullptr)&SDL_BUTTON(3))==SDL_BUTTON(3) && bMouseUp2) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3013 |
bMouseUp2=false; //The button is pressed |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3014 |
/******************************************************************** |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3015 |
**************** Here comes mouse play ****************************** |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3016 |
********************************************************************/ |
| acd79baf |
sago007 |
2015-11-22 19:37 |
3017 |
|
| acd79baf |
sago007 |
2015-11-22 19:37 |
3018 |
if (mouseplay1 && !theGame.GetAIenabled()) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
3019 |
//player 1 |
| acd79baf |
sago007 |
2015-11-22 19:37 |
3020 |
if ((mousex > 50)&&(mousey>100)&&(mousex<50+300)&&(mousey<100+600)) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
3021 |
theGame.PushLine(); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
3022 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
3023 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
3024 |
if (mouseplay2 && !theGame2.GetAIenabled()) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
3025 |
//player 2 |
| acd79baf |
sago007 |
2015-11-22 19:37 |
3026 |
if ((mousex > xsize-500)&&(mousey>100)&&(mousex<xsize-500+300)&&(mousey<100+600)) { |
| acd79baf |
sago007 |
2015-11-22 19:37 |
3027 |
theGame2.PushLine(); |
| 1a156b60 |
sago007 |
2015-08-22 17:29 |
3028 |
} |
| acd79baf |
sago007 |
2015-11-22 19:37 |
3029 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3030 |
/******************************************************************** |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3031 |
**************** Here ends mouse play ******************************* |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3032 |
********************************************************************/ |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3033 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3034 |
} //if !singlePuzzle |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
3035 |
else { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3036 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3037 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3038 |
} //if !bScreenBocked; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3039 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3040 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3041 |
//Sees if music is stopped and if music is enabled |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
3042 |
if ((!NoSound)&&(!Mix_PlayingMusic())&&(MusicEnabled)&&(!bNearDeath)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3043 |
// then starts playing it. |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3044 |
Mix_VolumeMusic(MIX_MAX_VOLUME); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3045 |
Mix_PlayMusic(bgMusic, -1); //music loop |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3046 |
} |
| b7590374 |
sago007 |
2011-05-19 16:15 |
3047 |
|
| ecef5838 |
sago007 |
2015-11-24 20:01 |
3048 |
if (bNearDeath!=bNearDeathPrev) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
3049 |
if (bNearDeath) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
3050 |
if (!NoSound &&(MusicEnabled)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3051 |
Mix_VolumeMusic(MIX_MAX_VOLUME); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3052 |
Mix_PlayMusic(highbeatMusic, 1); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3053 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3054 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
3055 |
else { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
3056 |
if (!NoSound &&(MusicEnabled)) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3057 |
Mix_VolumeMusic(MIX_MAX_VOLUME); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3058 |
Mix_PlayMusic(bgMusic, -1); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3059 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3060 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3061 |
} |
| b7590374 |
sago007 |
2011-05-19 16:15 |
3062 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3063 |
bNearDeathPrev = bNearDeath; |
| b7590374 |
sago007 |
2011-05-19 16:15 |
3064 |
|
| b7590374 |
sago007 |
2011-05-19 16:15 |
3065 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3066 |
//set bNearDeath to false theGame*.Update() will change to true as needed |
| 18055aa0 |
sago007 |
2012-06-05 19:43 |
3067 |
bNearDeath = theGame.IsNearDeath() || theGame2.IsNearDeath(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3068 |
//Updates the objects |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3069 |
theGame.Update(SDL_GetTicks()); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3070 |
theGame2.Update(SDL_GetTicks()); |
| b7590374 |
sago007 |
2011-05-19 16:15 |
3071 |
|
| b7590374 |
sago007 |
2011-05-19 16:15 |
3072 |
//see if anyone has won (two players only) |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3073 |
#if NETWORK |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3074 |
if (!networkPlay) |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3075 |
#endif |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
3076 |
if (twoPlayers) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
3077 |
if ((theGame.isGameOver()) && (theGame2.isGameOver())) { |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
3078 |
if (theGame.GetScore()+theGame.GetHandicap()>theGame2.GetScore()+theGame2.GetHandicap()) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3079 |
theGame.setPlayerWon(); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
3080 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
3081 |
else if (theGame.GetScore()+theGame.GetHandicap()<theGame2.GetScore()+theGame2.GetHandicap()) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3082 |
theGame2.setPlayerWon(); |
| acd79baf |
sago007 |
2015-11-22 19:37 |
3083 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
3084 |
else { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3085 |
theGame.setDraw(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3086 |
theGame2.setDraw(); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3087 |
} |
| b283e0f7 |
sago007 |
2012-07-29 14:01 |
3088 |
//twoPlayers = false; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3089 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
3090 |
if ((theGame.isGameOver()) && (!theGame2.isGameOver())) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3091 |
theGame2.setPlayerWon(); |
| b283e0f7 |
sago007 |
2012-07-29 14:01 |
3092 |
//twoPlayers = false; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3093 |
} |
| ecef5838 |
sago007 |
2015-11-24 20:01 |
3094 |
if ((!theGame.isGameOver()) && (theGame2.isGameOver())) { |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3095 |
theGame.setPlayerWon(); |
| b283e0f7 |
sago007 |
2012-07-29 14:01 |
3096 |
//twoPlayers = false; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3097 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3098 |
} |
| dfdb7d66 |
sago007 |
2015-11-29 19:21 |
3099 |
|
| dfdb7d66 |
sago007 |
2015-11-29 19:21 |
3100 |
if (theGame.isGameOver() && registerTTHighscorePlayer1) { |
| dfdb7d66 |
sago007 |
2015-11-29 19:21 |
3101 |
registerTTHighscorePlayer1 = false; |
| dfdb7d66 |
sago007 |
2015-11-29 19:21 |
3102 |
theTopScoresTimeTrial.addScore(theGame.name, theGame.GetScore()); |
| dfdb7d66 |
sago007 |
2015-11-29 19:21 |
3103 |
} |
| dfdb7d66 |
sago007 |
2015-11-29 19:21 |
3104 |
if (theGame2.isGameOver() && registerTTHighscorePlayer2) { |
| dfdb7d66 |
sago007 |
2015-11-29 19:21 |
3105 |
registerTTHighscorePlayer2 = false; |
| dfdb7d66 |
sago007 |
2015-11-29 19:21 |
3106 |
theTopScoresTimeTrial.addScore(theGame2.name, theGame2.GetScore()); |
| dfdb7d66 |
sago007 |
2015-11-29 19:21 |
3107 |
} |
| dfdb7d66 |
sago007 |
2015-11-29 19:21 |
3108 |
if (theGame.isGameOver() && registerEndlessHighscore) { |
| dfdb7d66 |
sago007 |
2015-11-29 19:21 |
3109 |
registerEndlessHighscore = false; |
| dfdb7d66 |
sago007 |
2015-11-29 19:21 |
3110 |
theTopScoresEndless.addScore(theGame.name, theGame.GetScore()); |
| dfdb7d66 |
sago007 |
2015-11-29 19:21 |
3111 |
theGame.EndlessHighscoreEvent(); |
| dfdb7d66 |
sago007 |
2015-11-29 19:21 |
3112 |
} |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3113 |
|
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3114 |
//Once evrything has been checked, update graphics |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3115 |
DrawEverything(xsize,ysize,&theGame,&theGame2); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3116 |
SDL_GetMouseState(&mousex,&mousey); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3117 |
//Remember mouse placement |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3118 |
oldMousex = mousex; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3119 |
oldMousey = mousey; |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3120 |
//Draw the mouse: |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
3121 |
mouse.Draw(screen, SDL_GetTicks(), mousex, mousey); |
| 1d2e2129 |
sago007 |
2015-12-23 15:41 |
3122 |
SDL_RenderPresent(screen); |
| c53e6443 |
sago007 |
2012-04-17 11:04 |
3123 |
} //game loop |
| 80b830cd |
sago007 |
2012-08-19 17:51 |
3124 |
return 0; |
| 605138b3 |
sago007 |
2012-04-14 15:12 |
3125 |
} |
|
|
1970-01-01 00:00 |
3126 |
|