File indexing completed on 2024-12-01 03:46:37
0001 /* 0002 This file is part of the KDE project "KBounce" 0003 0004 SPDX-FileCopyrightText: 2000-2005 Stefan Schimanski <1Stein@gmx.de> 0005 SPDX-FileCopyrightText: 2007 Tomasz Boczkowski <tboczkowski@onet.pl> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 0010 #ifndef GAMEOBJECT_H 0011 #define GAMEOBJECT_H 0012 0013 #include <QList> 0014 #include <QRectF> 0015 0016 enum KBounceObjectType 0017 { 0018 TILE = 1, 0019 BALL = 2, 0020 WALL = 4, 0021 ALL = 0xFF 0022 }; 0023 0024 /* 0025 * Simple 2D vector ( as in math not container ) 0026 */ 0027 struct KBounceVector 0028 { 0029 qreal x, y; 0030 0031 KBounceVector( qreal newx = 0, qreal newy = 0 ) : x( newx ), y( newy ) {} 0032 0033 KBounceVector& operator+=(KBounceVector rv ) 0034 { 0035 x += rv.x; y += rv.y; 0036 return *this; 0037 } 0038 0039 /* 0040 * Simple function to calculate a vector perpendicular to 0041 * sufrace of rect2 in the spot where rect1 intersects it. 0042 * Note it is a very simple function as the vectors it generates 0043 * can have different lengths. 0044 */ 0045 static KBounceVector normal( const QRectF& rect1, const QRectF& rect2 ); 0046 }; 0047 0048 /* 0049 * This struct contains information about collision of one pair of objects 0050 * Collision testing functions in this game choose one objects referred as 0051 * "being hitted" and check if it intersects with another referred as 0052 * "hitters" 0053 */ 0054 struct KBounceHit 0055 { 0056 /* 0057 * Type of hitter 0058 */ 0059 KBounceObjectType type; 0060 /* 0061 * Bounding rect of hitter 0062 */ 0063 QRectF boundingRect; 0064 /* 0065 * Velocity of hiter 0066 */ 0067 KBounceVector velocity; 0068 /* 0069 * Vector perpendicular to object's being hitted surface in 0070 * the area of intersection with hitter 0071 */ 0072 KBounceVector normal; 0073 }; 0074 0075 typedef QList<KBounceHit> KBounceCollision; 0076 0077 #define GAME_DELAY 16 0078 0079 #endif //GAMEOBJECT_H 0080