summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReimar <Reimar@Leike.name>2014-12-03 00:13:36 +0100
committerReimar <Reimar@Leike.name>2014-12-03 00:13:36 +0100
commit33e9f1db579685dd1ffab767ba7733a8e9503c78 (patch)
treefecfb030dd3560357bda44e68648444be8086dc6
parentcd89b5b3fc2d25b401fb8d6dc6ea4e0337e28fa2 (diff)
downloadSpaceCannon-33e9f1db579685dd1ffab767ba7733a8e9503c78.tar
SpaceCannon-33e9f1db579685dd1ffab767ba7733a8e9503c78.tar.gz
SpaceCannon-33e9f1db579685dd1ffab767ba7733a8e9503c78.tar.bz2
SpaceCannon-33e9f1db579685dd1ffab767ba7733a8e9503c78.tar.xz
SpaceCannon-33e9f1db579685dd1ffab767ba7733a8e9503c78.zip
Added score and easy colorsetting
-rw-r--r--JnR.cpp75
-rw-r--r--Makefile5
-rw-r--r--fonts/Apache License Version 2.txt53
-rw-r--r--fonts/OpenSans-Semibold.ttfbin0 -> 221328 bytes
-rw-r--r--settings.dat6
5 files changed, 123 insertions, 16 deletions
diff --git a/JnR.cpp b/JnR.cpp
index 9cc3e61..8b9bd43 100644
--- a/JnR.cpp
+++ b/JnR.cpp
@@ -3,11 +3,12 @@
3#include <stdio.h> 3#include <stdio.h>
4#include <stdlib.h> 4#include <stdlib.h>
5#include <SDL/SDL.h> 5#include <SDL/SDL.h>
6#include <SDL/SDL_ttf.h>
7#include <SDL/SDL_rotozoom.h>
6#include <algorithm> 8#include <algorithm>
7#include <fstream> 9#include <fstream>
8#include <sstream> 10#include <sstream>
9#include <ctime> 11#include <ctime>
10//#include "/usr/include/SDL/SDL_image.h"
11#include <cstdio> 12#include <cstdio>
12#include <vector> 13#include <vector>
13#include <list> 14#include <list>
@@ -15,7 +16,14 @@
15 16
16using namespace std; 17using namespace std;
17 18
18/* 19
20string lltostr(const long long& l)
21{
22 stringstream str;
23 str << l;
24 return str.str();
25}
26
19class Label 27class Label
20{ 28{
21protected: 29protected:
@@ -82,7 +90,7 @@ int Label::setCaption(string ncaption)
82 90
83int Label::render() 91int Label::render()
84{ 92{
85 TTF_Font *font = TTF_OpenFont("data/fonts/OpenSans-Semibold.ttf",pos.h); 93 TTF_Font *font = TTF_OpenFont("fonts/OpenSans-Semibold.ttf",pos.h);
86 image = NULL; 94 image = NULL;
87 image = TTF_RenderText_Solid(font, caption.c_str(),textColor); 95 image = TTF_RenderText_Solid(font, caption.c_str(),textColor);
88 if(caption.size() == 0) 96 if(caption.size() == 0)
@@ -108,7 +116,7 @@ Label::~Label()
108{ 116{
109 SDL_FreeSurface(image); 117 SDL_FreeSurface(image);
110} 118}
111*/ 119
112 120
113int xres = 600; 121int xres = 600;
114int yres = 450; 122int yres = 450;
@@ -148,6 +156,13 @@ void blacken(SDL_Surface* screen)
148 SDL_FillRect(screen,NULL,0); 156 SDL_FillRect(screen,NULL,0);
149} 157}
150 158
159Uint8 playerR = 100;
160Uint8 playerG = 100;
161Uint8 playerB = 100;
162
163Uint8 obstacleR = 255;
164Uint8 obstacleG = 100;
165Uint8 obstacleB = 100;
151 166
152class Obstacle 167class Obstacle
153{ 168{
@@ -174,7 +189,7 @@ public:
174 temp.x -= levelx; 189 temp.x -= levelx;
175 temp.y -= levely; 190 temp.y -= levely;
176 temp.y = yres - temp.y- temp.h; 191 temp.y = yres - temp.y- temp.h;
177 SDL_FillRect(screen, &temp, SDL_MapRGB(screen->format, 255, 255, 255)); 192 SDL_FillRect(screen, &temp, SDL_MapRGB(screen->format, obstacleR, obstacleG, obstacleB));
178 } 193 }
179 void step(double time) 194 void step(double time)
180 { 195 {
@@ -240,6 +255,7 @@ public:
240 } 255 }
241}; 256};
242 257
258
243vector<Particle> makeDeathAnimation(double x, double y, double r, double vxb, double vyb, int mode) 259vector<Particle> makeDeathAnimation(double x, double y, double r, double vxb, double vyb, int mode)
244{ 260{
245 vector<Particle> result; 261 vector<Particle> result;
@@ -251,7 +267,7 @@ vector<Particle> makeDeathAnimation(double x, double y, double r, double vxb, do
251 continue; 267 continue;
252 tx += x; 268 tx += x;
253 ty += y; 269 ty += y;
254 Particle temp = Particle(tx, ty, 1, 100, 100, 100); 270 Particle temp = Particle(tx, ty, 1, playerR, playerG, playerB);
255 double vb = (rand()%5000)/30.0; 271 double vb = (rand()%5000)/30.0;
256 double vp = ((rand()%10000)/10000.0)*2*M_PI; 272 double vp = ((rand()%10000)/10000.0)*2*M_PI;
257 if(!mode) 273 if(!mode)
@@ -283,16 +299,37 @@ double position_multiplier = 3;
283double win_bonus = 5000; 299double win_bonus = 5000;
284bool hardcore = false; 300bool hardcore = false;
285 301
302void loadConstants()
303{
304 ifstream ins;
305 ins.open("settings.dat");
306 int i = 0;
307 ins >> i;
308 playerR = i;
309 ins >> i;
310 playerG = i;
311 ins >> i;
312 playerB = i;
313 ins >> i;
314 obstacleR = i;
315 ins >> i;
316 obstacleG = i;
317 ins >> i;
318 obstacleB = i;
319 ins.close();
320}
321
286int main() 322int main()
287{ 323{
324 loadConstants();
288 string name; 325 string name;
289 cout << "This is a simple jump and run" << endl; 326 cout << "This is a simple jump and run" << endl;
290 cout << "Please enter your name:"; 327 cout << "Please enter your name:";
291 cin >> name; 328 cin >> name;
292 cout << "Please enter difficulty (0-100):" << endl; 329 cout << "Please enter difficulty (0-100):";
293 int difficulty; 330 int difficulty;
294 cin >> difficulty; 331 cin >> difficulty;
295 cout << "Do you want to play in hardcore mode?" << endl; 332 cout << "Do you want to play in hardcore mode(0/1)?";
296 cin >> hardcore; 333 cin >> hardcore;
297 if(hardcore) 334 if(hardcore)
298 { 335 {
@@ -315,21 +352,21 @@ int main()
315 if(SDL_Init(SDL_INIT_VIDEO) == -1) 352 if(SDL_Init(SDL_INIT_VIDEO) == -1)
316 { 353 {
317 cout << "Error: Could not initialize SDL" << endl; 354 cout << "Error: Could not initialize SDL" << endl;
318 return 0; 355 return 1;
319 } 356 }
320 screen = SDL_SetVideoMode(xres,yres,32,SDL_SWSURFACE); 357 screen = SDL_SetVideoMode(xres,yres,32,SDL_SWSURFACE);
321 if(!screen) 358 if(!screen)
322 { 359 {
323 cout << "could not initialize screen" << endl; 360 cout << "could not initialize screen" << endl;
324 return 0; 361 return 1;
325 } 362 }
326 /* 363
327 if(TTF_Init() == -1) 364 if(TTF_Init() == -1)
328 { 365 {
329 cout << "could not initialize True Fonts" << endl; 366 cout << "could not initialize True Fonts" << endl;
330 return 0; 367 return 1;
331 }*/ 368 }
332 SDL_WM_SetCaption("Ballroller - v0.1", NULL); 369 SDL_WM_SetCaption("Ballroller - v0.2", NULL);
333 370
334 371
335 bool Game_Quit = false; 372 bool Game_Quit = false;
@@ -368,6 +405,8 @@ int main()
368 lpos.y = 10; 405 lpos.y = 10;
369 lpos.w = 300; 406 lpos.w = 300;
370 lpos.h = 20; 407 lpos.h = 20;
408 Label scoreLabel = Label("Score: " + lltostr((long long)((1+0.5*hardcore)*(highscore + x_pos*position_multiplier))), lpos);
409
371 while(!Game_Quit) 410 while(!Game_Quit)
372 { 411 {
373 steps++; 412 steps++;
@@ -414,6 +453,7 @@ int main()
414 cout << "Collision: You lost the game" << endl; 453 cout << "Collision: You lost the game" << endl;
415 cout << "Better luck next time!" << endl; 454 cout << "Better luck next time!" << endl;
416 highscore = (int)((1+0.5*hardcore)*(highscore + x_pos*position_multiplier)); 455 highscore = (int)((1+0.5*hardcore)*(highscore + x_pos*position_multiplier));
456 scoreLabel.setCaption("Score: " + lltostr(highscore));
417 cout << "Your highscore: " << highscore << endl; 457 cout << "Your highscore: " << highscore << endl;
418 lost = true; 458 lost = true;
419 deathanimation = makeDeathAnimation(x_pos,y_pos,ball_rad,x_vel, y_vel,1); 459 deathanimation = makeDeathAnimation(x_pos,y_pos,ball_rad,x_vel, y_vel,1);
@@ -430,7 +470,8 @@ int main()
430 { 470 {
431 x_pos = x_pos + x_vel/60.0; 471 x_pos = x_pos + x_vel/60.0;
432 y_pos = y_pos + y_vel/60.0; 472 y_pos = y_pos + y_vel/60.0;
433 drawCircle(screen, xres/4, fabs(yres-y_pos), ball_rad, 100, 100, 100); 473 drawCircle(screen, xres/4, fabs(yres-y_pos), ball_rad, playerR, playerG, playerB);
474 scoreLabel.setCaption("Score: " + lltostr((long long)((1+0.5*hardcore)*(highscore + x_pos*position_multiplier))));
434 } 475 }
435 476
436 right = -keyState[SDLK_LEFT]+keyState[SDLK_RIGHT]; 477 right = -keyState[SDLK_LEFT]+keyState[SDLK_RIGHT];
@@ -472,6 +513,7 @@ int main()
472 cout << "You win the game!" << endl; 513 cout << "You win the game!" << endl;
473 highscore = (int)((1+0.5*hardcore)*(highscore + x_pos*position_multiplier + win_bonus)); 514 highscore = (int)((1+0.5*hardcore)*(highscore + x_pos*position_multiplier + win_bonus));
474 cout << "Your highscore: " << highscore << endl; 515 cout << "Your highscore: " << highscore << endl;
516 scoreLabel.setCaption("Score: " + lltostr(highscore));
475 Game_Quit = true; 517 Game_Quit = true;
476 } 518 }
477 for(int i = 0; i < xres; ++i) 519 for(int i = 0; i < xres; ++i)
@@ -487,11 +529,14 @@ int main()
487 } 529 }
488 if(animation_term && lost) 530 if(animation_term && lost)
489 Game_Quit = true; 531 Game_Quit = true;
532 scoreLabel.draw(screen);
490 SDL_Flip(screen); 533 SDL_Flip(screen);
491 Uint32 time = SDL_GetTicks()-start; 534 Uint32 time = SDL_GetTicks()-start;
492 if(1000/60.0 - time > 0) 535 if(1000/60.0 - time > 0)
493 SDL_Delay(1000/60.0 - time); 536 SDL_Delay(1000/60.0 - time);
494 } 537 }
538
539 /*The Game has ended*/
495 if(!quickquit) 540 if(!quickquit)
496 { 541 {
497 ifstream ins; 542 ifstream ins;
diff --git a/Makefile b/Makefile
index 11e46ce..47e7d82 100644
--- a/Makefile
+++ b/Makefile
@@ -3,4 +3,7 @@
3all: JnR 3all: JnR
4 4
5JnR: JnR.cpp 5JnR: JnR.cpp
6 g++ JnR.cpp -O2 -Wall -lSDL -o JnR 6 g++ JnR.cpp -O2 -Wall -lSDL -std=c++11 -lSDL_ttf -o JnR
7
8clean:
9 rm -f JnR
diff --git a/fonts/Apache License Version 2.txt b/fonts/Apache License Version 2.txt
new file mode 100644
index 0000000..4df74b8
--- /dev/null
+++ b/fonts/Apache License Version 2.txt
@@ -0,0 +1,53 @@
1Apache License
2
3Version 2.0, January 2004
4
5http://www.apache.org/licenses/
6
7TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
91. Definitions.
10
11"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
12
13"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
14
15"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
16
17"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
18
19"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
20
21"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
22
23"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
24
25"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
26
27"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
28
29"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
30
312. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
32
333. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
34
354. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
36
37You must give any other recipients of the Work or Derivative Works a copy of this License; and
38
39You must cause any modified files to carry prominent notices stating that You changed the files; and
40
41You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
42
43If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
44
455. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
46
476. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
48
497. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
50
518. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
52
539. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. \ No newline at end of file
diff --git a/fonts/OpenSans-Semibold.ttf b/fonts/OpenSans-Semibold.ttf
new file mode 100644
index 0000000..1a7679e
--- /dev/null
+++ b/fonts/OpenSans-Semibold.ttf
Binary files differ
diff --git a/settings.dat b/settings.dat
new file mode 100644
index 0000000..92ca51e
--- /dev/null
+++ b/settings.dat
@@ -0,0 +1,6 @@
1170
2150
390
4220
5220
6220