changeset 66:05346a412b55

A sprite cursor attempt
author Stefano Rivera <stefano@rivera.za.net>
date Mon, 23 Aug 2010 19:50:45 +0200
parents cab924519037
children 6b0f7364f3bf
files gamelib/cursor.py gamelib/gamescreen.py gamelib/menu.py
diffstat 3 files changed, 52 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gamelib/cursor.py	Mon Aug 23 19:50:45 2010 +0200
@@ -0,0 +1,36 @@
+# cursor.py
+# Copyright Boomslang team, 2010 (see COPYING File)
+# Sprite Cursor
+
+from albow.screen import Screen
+from albow.resource import get_image
+import pygame.mouse as mouse
+from pygame.sprite import Sprite, RenderUpdates
+
+class CursorSprite(Sprite):
+    "A Sprite that follows the Cursor"
+
+    def __init__(self, filename):
+        Sprite.__init__(self)
+        self.image = get_image('items', filename + '.png')
+        self.rect = self.image.get_rect()
+
+    def update(self):
+        self.rect.midtop = mouse.get_pos()
+
+
+class CursorSpriteScreen(Screen):
+    "A Screen with a CursorSprite"
+
+    def __init__(self, shell):
+        Screen.__init__(self, shell)
+
+        sprite = CursorSprite('hand')
+        self.cursor_group = RenderUpdates(sprite)
+
+    def draw(self, surface):
+        self.cursor_group.update()
+        self.cursor_group.draw(surface)
+
+    def mouse_move(self, event):
+        self.invalidate()
--- a/gamelib/gamescreen.py	Mon Aug 23 19:45:07 2010 +0200
+++ b/gamelib/gamescreen.py	Mon Aug 23 19:50:45 2010 +0200
@@ -2,20 +2,19 @@
 # Copyright Boomslang team, 2010 (see COPYING File)
 # Main menu for the game
 
-from state import initial_state, Item
-from hand import HandButton
-from popupmenu import PopupMenu
-from constants import BUTTON_SIZE
-
-from pygame.color import Color
-from pygame import Rect
-from pygame.locals import BLEND_ADD
-from albow.screen import Screen
-from albow.resource import get_font
 from albow.controls import Button, Label, Widget
 from albow.layout import Column
 from albow.palette_view import PaletteView
+from albow.resource import get_font
+from pygame import Rect
+from pygame.color import Color
+from pygame.locals import BLEND_ADD
 
+from constants import BUTTON_SIZE
+from cursor import CursorSpriteScreen
+from hand import HandButton
+from popupmenu import PopupMenu
+from state import initial_state, Item
 
 class InventoryView(PaletteView):
 
@@ -72,9 +71,10 @@
             # queue a redraw
             self.invalidate()
 
-class GameScreen(Screen):
+
+class GameScreen(CursorSpriteScreen):
     def __init__(self, shell):
-        Screen.__init__(self, shell)
+        CursorSpriteScreen.__init__(self, shell)
 
         # TODO: Randomly plonk the state here for now
         self.state = initial_state()
--- a/gamelib/menu.py	Mon Aug 23 19:45:07 2010 +0200
+++ b/gamelib/menu.py	Mon Aug 23 19:50:45 2010 +0200
@@ -6,9 +6,11 @@
 from albow.controls import Button, Label
 from albow.layout import Column
 
-class MenuScreen(Screen):
+from cursor import CursorSpriteScreen
+
+class MenuScreen(CursorSpriteScreen):
     def __init__(self, shell):
-        Screen.__init__(self, shell)
+        CursorSpriteScreen.__init__(self, shell)
         StartButton = Button('Start New Game', action = self.start)
         QuitButton = Button('Quit', action = shell.quit)
         Title = Label('Suspended Sentence')