Modified:
trunk/trunk/GUI/gblayout.py
Log:
replaced tabs with spaces and snapped objects to the position where you
clicked them in the gamescreen editor
Modified: trunk/trunk/GUI/gblayout.py
==============================================================================
--- trunk/trunk/GUI/gblayout.py (original)
+++ trunk/trunk/GUI/gblayout.py Sat Feb 21 11:30:43 2009
@@ -45,6 +45,8 @@
self.info_bar = InfoBar(self.width, self.legal_height)
#this represents the currently clicked on item
self.selected = None
+
+ self.object_offset = (0,0)
def load_objects(self, objects):
"""Wraps each gameobject in the Element class"""
@@ -93,8 +95,8 @@
if self.selected is not None:
#follow mouse
- self.selected.x = coords[0]
- self.selected.y = coords[1]
+ self.selected.x = coords[0] - self.object_offset[0]
+ self.selected.y = coords[1] - self.object_offset[1]
for event in pygame.event.get():
if event.type == QUIT:
@@ -104,18 +106,18 @@
if event.type == MOUSEBUTTONUP and event.button == 1:
if self.legal_coords(coords):
if self.selected is None:
- print coords
- self.selected = self.get_element_at_point(coords[0],
coords[1])
+ self.selected =
self.get_element_at_point(coords[0], coords[1])
+ self.object_offset =
(coords[0]-self.selected.x, coords[1] - self.selected.y)
else:
self.selected = None
def legal_coords(self, coords):
if coords[0] < self.legal_width and coords[0] > 0 and coords[1] <
self.legal_height and coords[1] > 0:
- return True
+ return True
else:
- return False
-
+ return False
+
class Element(object):
@@ -155,13 +157,13 @@
def move(self, x, y):
- self.x = x
+ self.x = x
self.y = y
def check_point_collision(self,x,y):
"""Checks if a point is within the object's collision area"""
return self.x <= x and self.y <= y and self.width + self.x >= x
and self.height + self.y >= y
-
+
def set_color(self, color):
self.image.fill(color)