1 /*
2  * This file is part of TONG.              http://www.nongnu.org/tong
3  * Copyright 2004, 2007 Owen Swerkstrom
4  *
5  * TONG is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * Tong is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef __PONG_H__
20 #define __PONG_H__
21 
22 class Ball;
23 class Paddle;
24 
25 #include <stdlib.h>
26 #include <math.h>
27 
28 #include "SDL.h"
29 #include "SDL_image.h"
30 
31 #include "tetris.h"
32 #include "option.h"
33 #include "media.h"
34 
35 #define PI 3.14159265
36 
37 #define BOUND_TOP    ( 5 * TILESIZE)
38 #define BOUND_LEFT   (15 * TILESIZE)
39 #define BOUND_RIGHT  (25 * TILESIZE)
40 #define BOUND_BOTTOM (25 * TILESIZE)
41 
42 #define NEWBALL_NOTICE 500  //half a second for a new ball to "appear"
43 
44 #define OUT_OF_BOUNDS 0
45 #define MOVED         1
46 #define BOUNCED       2
47 
48 
49 class Ball {
50  private:
51 	int ballstatus;
52 	int trappedbounces;
53 	float x, y;
54 	float angle; //0~360, but sin() takes radians so sin(angle*PI/180)
55 	float speed;    //pixels per second
56 	float startspeed;
57 	Uint32 lastmove, startmoving;
58 	bool visible;
59 	bool tetrisreacted;
60 	SDL_Surface *pongbits;
61 	SDL_Rect ballrect, destrect;
62 	void ReactWithStack(int, int, int, Bucket*, Option*);
63 	void ReactWithTetrad(int, int, int, Tetrad*, Tetrad*, Bucket*, bool*,
64 						 Option*);
65 	void LoadGraphics();
66  public:
67 	Ball();
68 	~Ball();
69 	void Init(float);
70 	void Theme(const char*);
71 	void UpdateTime();
72 	int Move(Paddle*, Bucket*, Tetrad*, Tetrad*, bool*, Option*);
73 	void Bounce(int direction);
74 	void Draw(SDL_Surface*);
75 };
76 
77 class Paddle {
78  private:
79 	int x, y;
80 	int xsize, ysize;
81 	float xspeed, yspeed;
82 	SDL_Surface *pongbits;
83 	SDL_Rect paddlerect, destrect;
84 	Uint32 lastdraw;
85 	void LoadGraphics();
86  public:
87 	Paddle();
88 	~Paddle();
89 	void Init(int, int);
90 	void Theme(const char*);
91 	bool MouseMoved(int, int);
92 	bool MoveX(int);
93 	bool MoveY(int);
94 	float GetXSpeed();
95 	float GetYSpeed();
96 	bool IsAtX(int);
97 	bool IsAtY(int);
98 	void Draw(SDL_Surface*);
99 };
100 
101 int pong2tetris(int, int);
102 int tetris2pongx(int);
103 int tetris2pongy(int);
104 
105 #endif
106