1 | /* |
2 | * Copyright (C) 2000-2005 Stefan Schimanski <1Stein@gmx.de> |
3 | * Copyright (C) 2007 Tomasz Boczkowski <tboczkowski@onet.pl> |
4 | * |
5 | * This file is part of the KDE project "KBounce" |
6 | * |
7 | * KBounce is free software; you can redistribute it and/or |
8 | * modify it under the terms of the GNU Library General Public |
9 | * License as published by the Free Software Foundation; either |
10 | * version 2 of the License, or (at your option) any later version. |
11 | * |
12 | * KBounce is distributed in the hope that it will be useful, |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | * Library General Public License for more details. |
16 | * |
17 | * You should have received a copy of the GNU Library General Public |
18 | * License along with KBounce; if not, write to the Free |
19 | * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
20 | * Boston, MA 02110-1301, USA. |
21 | */ |
22 | |
23 | #ifndef GAMEOBJECT_H |
24 | #define GAMEOBJECT_H |
25 | |
26 | #include <QList> |
27 | #include <QRectF> |
28 | |
29 | enum KBounceObjectType |
30 | { |
31 | TILE = 1, |
32 | BALL = 2, |
33 | WALL = 4, |
34 | ALL = 0xFF |
35 | }; |
36 | |
37 | /* |
38 | * Simple 2D vector ( as in math not container ) |
39 | */ |
40 | struct KBounceVector |
41 | { |
42 | qreal x, y; |
43 | |
44 | KBounceVector( qreal newx = 0, qreal newy = 0 ) : x( newx ), y( newy ) {}; |
45 | |
46 | KBounceVector& operator+=( const KBounceVector& rv ) |
47 | { |
48 | x += rv.x; y += rv.y; |
49 | return *this; |
50 | } |
51 | |
52 | /* |
53 | * Simple function to calculate a vector perpendicular to |
54 | * sufrace of rect2 in the spot where rect1 intersects it. |
55 | * Note it is a very simple function as the vectors it generates |
56 | * can have different lengths. |
57 | */ |
58 | static KBounceVector normal( const QRectF& rect1, const QRectF& rect2 ); |
59 | }; |
60 | |
61 | /* |
62 | * This struct contains information about collision of one pair of objects |
63 | * Collision testing functions in this game choose one objects referred as |
64 | * "being hitted" and check if it intersects with another referred as |
65 | * "hitters" |
66 | */ |
67 | struct KBounceHit |
68 | { |
69 | /* |
70 | * Type of hitter |
71 | */ |
72 | KBounceObjectType type; |
73 | /* |
74 | * Bounding rect of hitter |
75 | */ |
76 | QRectF boundingRect; |
77 | /* |
78 | * Velocity of hiter |
79 | */ |
80 | KBounceVector velocity; |
81 | /* |
82 | * Vector perpendicular to object's being hitted surface in |
83 | * the area of intersection with hitter |
84 | */ |
85 | KBounceVector normal; |
86 | }; |
87 | |
88 | typedef QList<KBounceHit> KBounceCollision; |
89 | |
90 | #define GAME_DELAY 16 |
91 | #define MS2TICKS( ms ) ((ms)/GAME_DELAY) |
92 | #define SOUND_DELAY MS2TICKS( 60 ) |
93 | |
94 | #endif //GAMEOBJECT_H |
95 | |
96 | |