annotate lamertetris/sources/game.h @ 6:542e305f23f4

arkanoid-trix-debian-dir
author prymula <prymula76@outlook.com>
date Wed, 31 Jan 2024 20:40:57 +0100
parents 2787f5e749ae
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
prymula <prymula76@outlook.com>
parents:
diff changeset
1 /*
prymula <prymula76@outlook.com>
parents:
diff changeset
2 * LamerTetris 2
prymula <prymula76@outlook.com>
parents:
diff changeset
3 * author: prymula
prymula <prymula76@outlook.com>
parents:
diff changeset
4 * date: 10-VI-2023
prymula <prymula76@outlook.com>
parents:
diff changeset
5 * licence: Public Domain
prymula <prymula76@outlook.com>
parents:
diff changeset
6 * tool: Geany
prymula <prymula76@outlook.com>
parents:
diff changeset
7 * Program based on:
prymula <prymula76@outlook.com>
parents:
diff changeset
8 * -This source code copyrighted by Lazy Foo' Productions (2004-2020)
prymula <prymula76@outlook.com>
parents:
diff changeset
9 * and may not be redistributed without written permission.
prymula <prymula76@outlook.com>
parents:
diff changeset
10 * -Andrew Lim Chong Liang https://github.com/andrew-lim/sdl2-boilerplate
prymula <prymula76@outlook.com>
parents:
diff changeset
11 */
prymula <prymula76@outlook.com>
parents:
diff changeset
12
prymula <prymula76@outlook.com>
parents:
diff changeset
13 #ifndef GAME_H
prymula <prymula76@outlook.com>
parents:
diff changeset
14 #define GAME_H
prymula <prymula76@outlook.com>
parents:
diff changeset
15
prymula <prymula76@outlook.com>
parents:
diff changeset
16 #include <SDL2/SDL.h>
prymula <prymula76@outlook.com>
parents:
diff changeset
17 #include <SDL_ttf.h>
prymula <prymula76@outlook.com>
parents:
diff changeset
18 #include <cstdio>
prymula <prymula76@outlook.com>
parents:
diff changeset
19 #include <iostream>
prymula <prymula76@outlook.com>
parents:
diff changeset
20 #include <unistd.h> // sleep access
prymula <prymula76@outlook.com>
parents:
diff changeset
21 #include <time.h>
prymula <prymula76@outlook.com>
parents:
diff changeset
22 #include <map>
prymula <prymula76@outlook.com>
parents:
diff changeset
23
prymula <prymula76@outlook.com>
parents:
diff changeset
24 #if WINDOWS
prymula <prymula76@outlook.com>
parents:
diff changeset
25 #include <windows.h>
prymula <prymula76@outlook.com>
parents:
diff changeset
26 #include "hiscore_win.h"
prymula <prymula76@outlook.com>
parents:
diff changeset
27 #elif LINUX
prymula <prymula76@outlook.com>
parents:
diff changeset
28 #include "hiscore_linux.h"
prymula <prymula76@outlook.com>
parents:
diff changeset
29 #endif
prymula <prymula76@outlook.com>
parents:
diff changeset
30
prymula <prymula76@outlook.com>
parents:
diff changeset
31 #include "field.h"
prymula <prymula76@outlook.com>
parents:
diff changeset
32 #include "szlam.h"
prymula <prymula76@outlook.com>
parents:
diff changeset
33 #include "text.h"
prymula <prymula76@outlook.com>
parents:
diff changeset
34
prymula <prymula76@outlook.com>
parents:
diff changeset
35
prymula <prymula76@outlook.com>
parents:
diff changeset
36 #define SIZEFONT 35
prymula <prymula76@outlook.com>
parents:
diff changeset
37 #define SCOREFONT 20
prymula <prymula76@outlook.com>
parents:
diff changeset
38
prymula <prymula76@outlook.com>
parents:
diff changeset
39 enum {
prymula <prymula76@outlook.com>
parents:
diff changeset
40 DISPLAY_WIDTH = 400
prymula <prymula76@outlook.com>
parents:
diff changeset
41 , DISPLAY_HEIGHT = 600
prymula <prymula76@outlook.com>
parents:
diff changeset
42 , UPDATE_INTERVAL = 1000/60
prymula <prymula76@outlook.com>
parents:
diff changeset
43 , HERO_SPEED = 2
prymula <prymula76@outlook.com>
parents:
diff changeset
44 , SHAPE_SIZE = 200
prymula <prymula76@outlook.com>
parents:
diff changeset
45 , BALL_SIZE = 75
prymula <prymula76@outlook.com>
parents:
diff changeset
46 , RED_BALL = 0
prymula <prymula76@outlook.com>
parents:
diff changeset
47 , YELLOW_BALL = 75
prymula <prymula76@outlook.com>
parents:
diff changeset
48 , GREEN_BALL = 150
prymula <prymula76@outlook.com>
parents:
diff changeset
49 , BLUE_BALL = 225
prymula <prymula76@outlook.com>
parents:
diff changeset
50
prymula <prymula76@outlook.com>
parents:
diff changeset
51 };
prymula <prymula76@outlook.com>
parents:
diff changeset
52
prymula <prymula76@outlook.com>
parents:
diff changeset
53 class Game {
prymula <prymula76@outlook.com>
parents:
diff changeset
54 public:
prymula <prymula76@outlook.com>
parents:
diff changeset
55 Game();
prymula <prymula76@outlook.com>
parents:
diff changeset
56 ~Game();
prymula <prymula76@outlook.com>
parents:
diff changeset
57 void start();
prymula <prymula76@outlook.com>
parents:
diff changeset
58 void stop() ;
prymula <prymula76@outlook.com>
parents:
diff changeset
59 void draw(SDL_Rect *srcField, SDL_Rect *positionField, bool end);
prymula <prymula76@outlook.com>
parents:
diff changeset
60
prymula <prymula76@outlook.com>
parents:
diff changeset
61
prymula <prymula76@outlook.com>
parents:
diff changeset
62 void fillRect(SDL_Rect* rc, int r, int g, int b );
prymula <prymula76@outlook.com>
parents:
diff changeset
63 void fpsChanged( int fps );
prymula <prymula76@outlook.com>
parents:
diff changeset
64 void run();
prymula <prymula76@outlook.com>
parents:
diff changeset
65
prymula <prymula76@outlook.com>
parents:
diff changeset
66 private:
prymula <prymula76@outlook.com>
parents:
diff changeset
67 void up_direction();
prymula <prymula76@outlook.com>
parents:
diff changeset
68 void left_direction();
prymula <prymula76@outlook.com>
parents:
diff changeset
69 void right_direction();
prymula <prymula76@outlook.com>
parents:
diff changeset
70
prymula <prymula76@outlook.com>
parents:
diff changeset
71 std::map<int,int> keys; // No SDLK_LAST. SDL2 migration guide suggests std::map
prymula <prymula76@outlook.com>
parents:
diff changeset
72 int frameSkip ;
prymula <prymula76@outlook.com>
parents:
diff changeset
73 int running ;
prymula <prymula76@outlook.com>
parents:
diff changeset
74 SDL_Window* window;
prymula <prymula76@outlook.com>
parents:
diff changeset
75 SDL_Rect dst;
prymula <prymula76@outlook.com>
parents:
diff changeset
76 TTF_Font* gFont = NULL;
prymula <prymula76@outlook.com>
parents:
diff changeset
77 TTF_Font* fontScore = NULL;
prymula <prymula76@outlook.com>
parents:
diff changeset
78 SDL_Surface *background = NULL;
prymula <prymula76@outlook.com>
parents:
diff changeset
79 SDL_Surface *screenSurface;
prymula <prymula76@outlook.com>
parents:
diff changeset
80 SDL_Texture *texture;
prymula <prymula76@outlook.com>
parents:
diff changeset
81 HiScore hiscore;
prymula <prymula76@outlook.com>
parents:
diff changeset
82 int score, hi_score;
prymula <prymula76@outlook.com>
parents:
diff changeset
83 Text scoreTxt;
prymula <prymula76@outlook.com>
parents:
diff changeset
84 Field field;
prymula <prymula76@outlook.com>
parents:
diff changeset
85 Szlam szlam;
prymula <prymula76@outlook.com>
parents:
diff changeset
86 int color,n_element=0, figure=1, rate=1, tmp_element=0;
prymula <prymula76@outlook.com>
parents:
diff changeset
87 SDL_Rect positionField, srcField;
prymula <prymula76@outlook.com>
parents:
diff changeset
88 int left=0;
prymula <prymula76@outlook.com>
parents:
diff changeset
89 SDL_Renderer* renderer;
prymula <prymula76@outlook.com>
parents:
diff changeset
90 bool loadWallpaper();
prymula <prymula76@outlook.com>
parents:
diff changeset
91 bool loadFromFile( std::string path, SDL_Renderer * renderer);
prymula <prymula76@outlook.com>
parents:
diff changeset
92
prymula <prymula76@outlook.com>
parents:
diff changeset
93 };
prymula <prymula76@outlook.com>
parents:
diff changeset
94 #endif //GAME_H