Mercurial > traipse_dev
comparison orpg/mapper/isometric.py @ 0:4385a7d0efd1 grumpy-goblin
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
author | sirebral |
---|---|
date | Tue, 14 Jul 2009 16:41:58 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4385a7d0efd1 |
---|---|
1 # Copyright (C) 2000-2001 The OpenRPG Project | |
2 # | |
3 # openrpg-dev@lists.sourceforge.net | |
4 # | |
5 # This program 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 2 of the License, or | |
8 # (at your option) any later version. | |
9 # | |
10 # This program 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, write to the Free Software | |
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
18 # -- | |
19 # | |
20 # File: mapper/isometric.py | |
21 # Author: Todd Faris (Snowdog) | |
22 # Maintainer: | |
23 # Version: | |
24 # | |
25 # Description: | |
26 # helper class definition for drawing and line collision within an isometric grid | |
27 # based on a interger based coordinate system where X increase to the right | |
28 # and Y increases in the downward direction | |
29 | |
30 | |
31 class IsoGrid: | |
32 def __init__(self,width): | |
33 self.ratio = 2.0 | |
34 self.width = width | |
35 self.height = 0 | |
36 self.CalcRatio() | |
37 self.center_x = 0 | |
38 self.center_y = 0 | |
39 | |
40 def Ratio(self, r ): | |
41 "changes the height/width ratio of the isometric rectangle with respect to the horizontal (x) axis" | |
42 self.ratio = float(r) | |
43 self.CalcRatio() | |
44 | |
45 def CalcRatio(self): | |
46 if (self.ratio <= 0): self.ratio = 1 | |
47 self.height = int( float(self.width)/float(self.ratio) ) | |
48 | |
49 def BoundPlace(self, left,top): | |
50 "Places the isometric rectangle using its upper left bounding corner for positioning" | |
51 dx,dy = self.CornerOffset() | |
52 self.Recenter( left+dx, top+dy) | |
53 | |
54 def Recenter(self,x,y): | |
55 "Places the isomentric rectangle using the centerpoint" | |
56 self.center_x = x | |
57 self.center_y = y | |
58 | |
59 def Top(self): | |
60 "Returns the topmost point of the isometric rectangle as a tuple (x,y)" | |
61 x = int(self.center_x) | |
62 y = int(self.center_y) - int(self.height/2) | |
63 return(x,y) | |
64 | |
65 def Left(self): | |
66 "Returns the leftmost point of the isometric rectangle as a tuple (x,y)" | |
67 x = int(self.center_x) - int(self.width/2) | |
68 y = int(self.center_y) | |
69 return(x,y) | |
70 | |
71 def Right(self): | |
72 "Returns the rightmost point of the isometric rectangle as a tuple (x,y)" | |
73 x,y = self.Left() | |
74 x = x + self.width | |
75 return(x,y) | |
76 | |
77 def Bottom(self): | |
78 "Returns the bottommost point of the isometric rectangle as a tuple (x,y)" | |
79 x,y = self.Top() | |
80 y = y + self.height | |
81 return(x,y) | |
82 | |
83 def Center(self): | |
84 "Returns the center point of the isometric rectangle as a tuple (x,y)" | |
85 x = int(self.center_x) | |
86 y = int(self.center_y) | |
87 return(x,y) | |
88 | |
89 def CornerOffset(self): | |
90 """Returns a tuple (delta_x,delta_y) representing the offset from the centerpoint | |
91 of the isometric rectangle to the upper left corner of its rectangular bounding box""" | |
92 dx = float(self.width/2) | |
93 dy = float(self.height/2) | |
94 return (dx,dy) | |
95 | |
96 def Height(self): | |
97 "Returns the height of the isometric rectangle based on current ratio" | |
98 return int(self.height) | |
99 | |
100 def Width(self): | |
101 "returns the width of the isomentric rectangle" | |
102 return int(self.width) |