changeset 302:6d93e04036c9

CursorSprite: Default pointer-position to the centre of the cursor
author Stefano Rivera <stefano@rivera.za.net>
date Sat, 28 Aug 2010 01:32:54 +0200
parents cecdb67f4f4b
children d5cd823d04e8
files gamelib/cursor.py gamelib/scenes/bridge.py gamelib/scenes/crew_quarters.py gamelib/scenes/cryo.py gamelib/scenes/engine.py gamelib/scenes/machine.py gamelib/scenes/mess.py
diffstat 7 files changed, 19 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/cursor.py	Sat Aug 28 01:22:44 2010 +0200
+++ b/gamelib/cursor.py	Sat Aug 28 01:32:54 2010 +0200
@@ -13,7 +13,7 @@
 class CursorSprite(Sprite):
     "A Sprite that follows the Cursor"
 
-    def __init__(self, filename, x, y):
+    def __init__(self, filename, x=None, y=None):
         Sprite.__init__(self)
         self.filename = filename
         self.pointer_x = x
@@ -25,6 +25,12 @@
             self.plain_image = get_image('items', self.filename)
             self.image = self.plain_image
             self.rect = self.image.get_rect()
+
+            if self.pointer_x is None:
+                self.pointer_x = self.rect.size[0] // 2
+            if self.pointer_y is None:
+                self.pointer_y = self.rect.size[1] // 2
+
             self.highlight = pygame.Surface(self.rect.size)
             color = pygame.color.Color(255, 100, 100, 0)
             self.highlight.fill(color)
--- a/gamelib/scenes/bridge.py	Sat Aug 28 01:22:44 2010 +0200
+++ b/gamelib/scenes/bridge.py	Sat Aug 28 01:32:54 2010 +0200
@@ -142,7 +142,7 @@
     "Used for cracking safes. Found on the doctor on the chair"
 
     INVENTORY_IMAGE = 'stethoscope.png'
-    CURSOR = CursorSprite('stethoscope.png', 29, 27)
+    CURSOR = CursorSprite('stethoscope.png')
 
 
 class StethoscopeThing(Thing):
@@ -172,7 +172,7 @@
     "Used for connecting high-powered parts of the ship up"
 
     INVENTORY_IMAGE = 'superconductor_fixed.png'
-    CURSOR = CursorSprite('superconductor_fixed.png', 20, 20)
+    CURSOR = CursorSprite('superconductor_fixed.png')
 
 
 class SuperconductorThing(Thing):
--- a/gamelib/scenes/crew_quarters.py	Sat Aug 28 01:22:44 2010 +0200
+++ b/gamelib/scenes/crew_quarters.py	Sat Aug 28 01:32:54 2010 +0200
@@ -127,14 +127,14 @@
     "A bowl. Sans fish."
 
     INVENTORY_IMAGE = 'fishbowl.png'
-    CURSOR = CursorSprite('fishbowl.png', 29, 27)
+    CURSOR = CursorSprite('fishbowl.png')
 
 
 class DuctTape(Item):
     "A bowl. Sans fish."
 
     INVENTORY_IMAGE = 'duct_tape.png'
-    CURSOR = CursorSprite('duct_tape.png', 29, 27)
+    CURSOR = CursorSprite('duct_tape.png')
 
 
 class SafeDetail(Scene):
--- a/gamelib/scenes/cryo.py	Sat Aug 28 01:22:44 2010 +0200
+++ b/gamelib/scenes/cryo.py	Sat Aug 28 01:32:54 2010 +0200
@@ -190,7 +190,7 @@
     "After emptying the full can."
 
     INVENTORY_IMAGE = "cryo_pipe.png"
-    CURSOR = CursorSprite('cryo_pipe_cursor.png', 53, 44)
+    CURSOR = CursorSprite('cryo_pipe_cursor.png')
     TOOL_NAME = "pipe"
 
 
--- a/gamelib/scenes/engine.py	Sat Aug 28 01:22:44 2010 +0200
+++ b/gamelib/scenes/engine.py	Sat Aug 28 01:32:54 2010 +0200
@@ -97,7 +97,7 @@
 
 class CanOpener(Item):
     INVENTORY_IMAGE = 'triangle.png'
-    CURSOR = CursorSprite('triangle.png', 25, 23)
+    CURSOR = CursorSprite('triangle.png')
 
 
 class CanOpenerThing(Thing):
@@ -121,7 +121,7 @@
 
 class BrokenSuperconductor(Item):
     INVENTORY_IMAGE = 'superconductor_broken.png'
-    CURSOR = CursorSprite('superconductor_broken_cursor.png', 13, 19)
+    CURSOR = CursorSprite('superconductor_broken_cursor.png')
 
 
 class SuperconductorSocket(Thing):
--- a/gamelib/scenes/machine.py	Sat Aug 28 01:22:44 2010 +0200
+++ b/gamelib/scenes/machine.py	Sat Aug 28 01:32:54 2010 +0200
@@ -166,7 +166,7 @@
     "A pipe made out of welded-together tins."
 
     INVENTORY_IMAGE = "tube_fragments.png"
-    CURSOR = CursorSprite('tube_fragments_cursor.png', 36, 3)
+    CURSOR = CursorSprite('tube_fragments_cursor.png')
     TOOL_NAME = "pipe"
 
 
--- a/gamelib/scenes/mess.py	Sat Aug 28 01:22:44 2010 +0200
+++ b/gamelib/scenes/mess.py	Sat Aug 28 01:32:54 2010 +0200
@@ -62,7 +62,7 @@
     "After emptying the full can."
 
     INVENTORY_IMAGE = "empty_can.png"
-    CURSOR = CursorSprite('empty_can_cursor.png', 20, 30)
+    CURSOR = CursorSprite('empty_can_cursor.png')
 
     def interact_with_titanium_leg(self, item, state):
         return Result("Flattening the can doesn't look like a useful thing to do.")
@@ -72,7 +72,7 @@
     "Found on the shelf."
 
     INVENTORY_IMAGE = "full_can.png"
-    CURSOR = CursorSprite('full_can_cursor.png', 20, 30)
+    CURSOR = CursorSprite('full_can_cursor.png')
 
     def interact_with_titanium_leg(self, item, state):
         dented = DentedCan("dented_can")
@@ -85,7 +85,7 @@
     "A can banged on with the femur"
 
     INVENTORY_IMAGE = "dented_can.png"
-    CURSOR = CursorSprite('dented_can_cursor.png', 20, 30)
+    CURSOR = CursorSprite('dented_can_cursor.png')
 
     def interact_with_titanium_leg(self, item, state):
         return Result("You club the can with the femur. The dents shift around, but it still doesn't open.", soundfile="can_hit.ogg")
@@ -227,7 +227,7 @@
 
 class DetergentBottle(Item):
     INVENTORY_IMAGE = 'triangle.png'
-    CURSOR = CursorSprite('triangle.png', 25, 23)
+    CURSOR = CursorSprite('triangle.png')
 
 
 class ToMap(Door):