Mercurial > fife-parpg
annotate engine/python/fife/extensions/fife_math.py @ 494:e241d7553496
Fixing the epydoc markup. Did some more commenting.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Mon, 10 May 2010 15:54:21 +0000 |
parents | 16ceb3228324 |
children | ae9f5383f5b1 |
rev | line source |
---|---|
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
2 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
3 # #################################################################### |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
4 # Copyright (C) 2005-2010 by the FIFE team |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
5 # http://www.fifengine.net |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
6 # This file is part of FIFE. |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
7 # |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
8 # FIFE is free software; you can redistribute it and/or |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
9 # modify it under the terms of the GNU Lesser General Public |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
10 # License as published by the Free Software Foundation; either |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
11 # version 2.1 of the License, or (at your option) any later version. |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
12 # |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
13 # This library is distributed in the hope that it will be useful, |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
16 # Lesser General Public License for more details. |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
17 # |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
18 # You should have received a copy of the GNU Lesser General Public |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
19 # License along with this library; if not, write to the |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
20 # Free Software Foundation, Inc., |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
21 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
22 # #################################################################### |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
23 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
24 from fife import fife |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
25 import math |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
26 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
27 """ |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
28 Math Library |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
29 ================================== |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
30 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
31 This is a collection of useful 2D math functions/classes. |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
32 """ |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
33 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
34 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
35 def normalize(vector): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
36 """ |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
37 Helper function to normalize a 2D vector |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
38 |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
39 @param vector: a L{fife.DoublePoint} to be normalized |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
40 @type vector: L{fife.DoublePoint} |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
41 |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
42 @return: A normalized L{fife.DoublePoint} |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
43 """ |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
44 norm = fife.DoublePoint(0,0) |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
45 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
46 invLength = 1.0/vector.length() |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
47 if invLength > 1e-06: |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
48 norm.x = vector.x * invLength; |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
49 norm.y = vector.y * invLength; |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
50 else: |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
51 norm.x = 0 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
52 norm.y = 0 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
53 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
54 return norm |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
55 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
56 class Rect(object): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
57 """ |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
58 A simple rectangle class that allows floating point values. |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
59 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
60 A class used to specify the bounding box of objects. For use |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
61 with collision detection. This was written in python because |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
62 FIFE does not provide a Rect class that can use floating point |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
63 values. |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
64 """ |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
65 def __init__(self, x = 0, y = 0, w = 0, h = 0): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
66 """ |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
67 @param x: The x coordinate |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
68 @type x: C{int} or C{float} |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
69 @param y: The y coordinate |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
70 @type y: C{int} or C{float} |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
71 @param w: The width |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
72 @type w: C{int} or C{float} |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
73 @param h: The height |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
74 @type h: C{int} or C{float} |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
75 """ |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
76 self._x = x |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
77 self._y = y |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
78 self._w = w |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
79 self._h = h |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
80 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
81 def intersects(self, rect): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
82 """ |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
83 Tests for intersection of rect. |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
84 |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
85 @param rect: the L{Rect} to perform the test against. |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
86 @type rect: L{Rect} |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
87 |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
88 @return: True if the rectancles intersect, False if not. |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
89 @rtype: C{boolean} |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
90 """ |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
91 _x = self._x - rect.x; |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
92 _y = self._y - rect.y; |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
93 _w = self._w; |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
94 _h = self._h; |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
95 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
96 if _x < 0: |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
97 _w += _x |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
98 _x = 0 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
99 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
100 if _y < 0: |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
101 _h += _y |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
102 _y = 0 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
103 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
104 if _x + _w > rect.w: |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
105 _w = rect.w - _x |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
106 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
107 if _y + _h > rect.h: |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
108 _h = rect.h - _y |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
109 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
110 if _w <= 0 or _h <= 0: |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
111 return False |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
112 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
113 return True |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
114 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
115 def _setX(self, x): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
116 self._x = x |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
117 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
118 def _getX(self): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
119 return self._x |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
120 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
121 def _setY(self, y): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
122 self._y = y |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
123 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
124 def _getY(self): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
125 return self._y |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
126 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
127 def _setW(self, w): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
128 self._w = w |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
129 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
130 def _getW(self): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
131 return self._w |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
132 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
133 def _setH(self, h): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
134 self._h = h |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
135 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
136 def _getH(self): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
137 return self._h |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
138 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
139 x = property(_getX, _setX) |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
140 y = property(_getY, _setY) |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
141 w = property(_getW, _setW) |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
142 h = property(_getH, _setH) |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
143 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
144 def rotatePoint(origin, point, angle): |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
145 """ |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
146 Rotates a point around the specified origin. |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
147 |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
148 @param origin: A L{fife.DoublePoint} specifying the origin. |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
149 @type origin: L{fife.DoublePoint} |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
150 @param point: A L{fife.DoublePoint} to be rotated. |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
151 @type point: L{fife.DoublePoint} |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
152 @param angle: The angle in which to rotate the point. |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
153 @type angle: C{int} or C{float} |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
154 |
494
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
155 @return: A L{fife.DoublePoint} representing the rotated point. |
e241d7553496
Fixing the epydoc markup. Did some more commenting.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
492
diff
changeset
|
156 @rtype: L{fife.DoublePoint} |
492
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
157 """ |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
158 newp = fife.DoublePoint(0,0) |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
159 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
160 theta = (angle * math.pi)/180 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
161 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
162 costheta = math.cos(theta) |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
163 sintheta = math.sin(theta) |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
164 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
165 x = point.x - origin.x |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
166 y = point.y - origin.y |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
167 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
168 newp.x = costheta * x - sintheta * y |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
169 newp.y = sintheta * x + costheta * y |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
170 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
171 return newp |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
172 |
16ceb3228324
Moved the SoundManager and the 2D math function (helpers) from the shooter demo to the fife extensions.
prock@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
173 __all__ = ['normalize','Rect','rotatePoint'] |