diff options
author | Paul Wise <pabs3@bonedaddy.net> | 2011-01-06 06:05:09 (GMT) |
---|---|---|
committer | Joel Stanley <joel@jms.id.au> | 2011-01-06 08:10:23 (GMT) |
commit | c53e25e4448a940268374e633a1116e8a33f0590 (patch) | |
tree | 1c515517c3766d0e62f10d06bd6c72552f478975 | |
parent | e89ecfc20d505ca6525940f5ab65a275fadeb2be (diff) |
-rw-r--r-- | ovpc.py | 38 |
1 files changed, 36 insertions, 2 deletions
@@ -19,16 +19,40 @@ import pyglet -from pyglet.window import key +from pyglet.window import key, mouse from random import randrange, random import math import time import glob from pyglet.gl import * +class MouseStateHandler(dict): + x = 0 + y = 0 + button = False + + def on_mouse_press(self, x, y, button, modifiers): + self.x = x + self.y = y + self[button] = True + + def on_mouse_release(self, x, y, button, modifiers): + self.x = x + self.y = y + self[button] = False + + def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers): + self.x = x + self.y = y + + def __getitem__(self, key): + return self.get(key, False) + window = pyglet.window.Window(800, 400, caption='One Velociraptor per Child') keys = pyglet.window.key.KeyStateHandler() window.push_handlers(keys) +ms = MouseStateHandler() +window.push_handlers(ms) batch = pyglet.graphics.Batch() @@ -89,7 +113,7 @@ def update(dt): import sys sys.exit(0) - if keys[key.ENTER] and child.image is child_death: + if child.image is child_death and (keys[key.ENTER] or ((ms[mouse.LEFT] or ms[mouse.MIDDLE] or ms[mouse.RIGHT]) and raptor_eating == -1)): score = 0 child.image = pyglet.resource.image('child.png') child.x = child.y = 0 @@ -106,6 +130,16 @@ def update(dt): if keys[key.RIGHT] and child.image is not child_death: child.x += dt * 100 + if (ms[mouse.LEFT] or ms[mouse.MIDDLE] or ms[mouse.RIGHT]) and child.image is not child_death: + if ms.x <= window.width / 3: + child.x -= dt * 100 + elif ms.x >= window.width / 3 * 2: + child.x += dt * 100 + if ms.y <= window.height / 3: + child.y -= dt * 100 + elif ms.y >= window.height / 3 * 2: + child.y += dt * 100 + if child.x > window.width: child.x = window.width if child.x < 0: |