Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/boards
diff options
context:
space:
mode:
authorBruno Coudoin <bcoudoin@src.gnome.org>2008-04-27 22:43:21 (GMT)
committer Bruno Coudoin <bcoudoin@src.gnome.org>2008-04-27 22:43:21 (GMT)
commit857da06defd75612139c9b671d123ccdcd9692be (patch)
tree15d89fd140fdc8fc9b566fa067260aff012071ce /src/boards
parent90031f4342b3888c181f0b04bc8e85e89c5d2eba (diff)
New activity to learn the doubleclick in an intuite fashion.
svn path=/trunk/; revision=3388
Diffstat (limited to 'src/boards')
-rw-r--r--src/boards/python/doubleclick.py238
1 files changed, 175 insertions, 63 deletions
diff --git a/src/boards/python/doubleclick.py b/src/boards/python/doubleclick.py
index f26aa36..cdd66a6 100644
--- a/src/boards/python/doubleclick.py
+++ b/src/boards/python/doubleclick.py
@@ -52,15 +52,12 @@ class Gcompris_doubleclick:
self.gcomprisBoard.sublevel=1
self.gcomprisBoard.number_of_sublevel=1
gcompris.bar_set(gcompris.BAR_LEVEL)
- self.background_item = \
- gcompris.set_background(self.gcomprisBoard.canvas.root(),
- "opt/beach1.png")
- self.background_item_connect_id = \
- self.background_item.connect("event", self.shoot_item_event)
+ gcompris.set_background(self.gcomprisBoard.canvas.root(),
+ "images/penalty_bg.svg")
gcompris.bar_set_level(self.gcomprisBoard)
- self.ballinc = 20 # Event loop timer for the ball move
+ self.ballinc = 20 # Event loop timer for the ball move
# Create our rootitem. We put each canvas item in it so at the end we
# only have to kill it. The canvas deletes all the items it contains automaticaly.
@@ -70,38 +67,40 @@ class Gcompris_doubleclick:
y=0.0
)
+ # Help
+ self.help_item = self.rootitem.add(
+ gnomecanvas.CanvasText,
+ font = gcompris.skin.get_font("gcompris/board/medium"),
+ x = gcompris.BOARD_WIDTH / 2,
+ y = gcompris.BOARD_HEIGHT - 170,
+ anchor=gtk.ANCHOR_CENTER,
+ fill_color = "white"
+ )
+ self.help_item.hide()
+
# Tux
+ pixbuf = gcompris.utils.load_pixmap("gcompris/misc/tux.png")
item = self.rootitem.add(
gnomecanvas.CanvasPixbuf,
- pixbuf = gcompris.utils.load_pixmap("gcompris/misc/tux.png"),
- x=gcompris.BOARD_WIDTH/2 - 60,
- y=135.0
- )
- item.connect("event", self.shoot_item_event)
-
- # Balloon
- self.balloon_item = self.rootitem.add(
- gnomecanvas.CanvasEllipse,
- x1=0.0,
- y1=0.0,
- x2=0.0,
- y2=0.0
+ pixbuf = pixbuf,
+ x=gcompris.BOARD_WIDTH/2 - pixbuf.get_width()/2,
+ y=195.0
)
- self.balloon_item.connect("event", self.shoot_item_event)
+ item.connect("event", self.help)
# The activity help
item = self.rootitem.add(
gnomecanvas.CanvasPixbuf,
- pixbuf = gcompris.utils.load_pixmap("images/shift_key.png"),
- x=gcompris.BOARD_WIDTH/2+100.0,
- y=gcompris.BOARD_HEIGHT - 80
+ pixbuf = gcompris.utils.load_pixmap("images/doubleclick.svg"),
+ x = gcompris.BOARD_WIDTH - 150,
+ y = gcompris.BOARD_HEIGHT - 100
)
- item.connect("event", self.shoot_item_event)
+ item.connect("event", self.help)
# The click indicator
indicator_h = 30
- indicator_w = 4
- y_ref = 150
+ indicator_w = 10
+ y_ref = 107
self.indicator = []
self.indicator.append(
@@ -132,19 +131,19 @@ class Gcompris_doubleclick:
200)
)
- for i in self.indicator:
- i.item.connect("event", self.shoot_item_event)
+ self.balloon = Balloon(self, 10, 10)
+ self.balloon.item.connect("event", self.shoot_item_event)
self.next_level()
def end(self):
- # Disconnect from the background item
- self.background_item.disconnect(self.background_item_connect_id)
+ self.balloon.reset()
if self.timer_indic:
gobject.source_remove(self.timer_indic)
+ self.timer_indic = 0
# Remove the root item removes all the others inside it
self.rootitem.destroy()
@@ -191,9 +190,7 @@ class Gcompris_doubleclick:
# Set the level in the control bar
gcompris.bar_set_level(self.gcomprisBoard);
- self.init_balloon()
-
- self.counter = [0, 0, 0]
+ self.balloon.reset()
if self.timer_indic:
gobject.source_remove(self.timer_indic)
@@ -201,51 +198,29 @@ class Gcompris_doubleclick:
if(self.gcomprisBoard.level == 1):
winlimit = 1000
- gcompris.set_background(self.gcomprisBoard.canvas.root(),"opt/beach1.png")
elif(self.gcomprisBoard.level == 2):
winlimit = 800
elif(self.gcomprisBoard.level == 3):
winlimit = 600
- gcompris.set_background(self.gcomprisBoard.canvas.root(),"opt/beach2.png")
elif(self.gcomprisBoard.level == 4):
winlimit = 400
elif(self.gcomprisBoard.level == 5):
winlimit = 250
- gcompris.set_background(self.gcomprisBoard.canvas.root(),"opt/beach3.png")
elif(self.gcomprisBoard.level == 6):
winlimit = 200
elif(self.gcomprisBoard.level == 7):
winlimit = 180
- gcompris.set_background(self.gcomprisBoard.canvas.root(),"opt/beach4.png")
elif(self.gcomprisBoard.level == 8):
winlimit = 170
elif(self.gcomprisBoard.level == 9):
winlimit = 160
+ self.counter = [0, 0, 0]
for i in self.indicator:
i.reset()
i.winlimit = winlimit
- def ball_move(self):
- pass
-
- def init_balloon(self):
- self.balloon_size = 160
- self.balloon_width_units = 5.0
- self.balloon_x = gcompris.BOARD_WIDTH/2-20
- self.balloon_y = gcompris.BOARD_HEIGHT - 130
-
- self.balloon_item.set(
- x1=self.balloon_x - self.balloon_size/2,
- y1=self.balloon_y - self.balloon_size/2,
- x2=self.balloon_x + self.balloon_size/2,
- y2=self.balloon_y + self.balloon_size/2,
- fill_color_rgba=0xFF1212FFL,
- outline_color_rgba=0x000000FFL,
- width_units=self.balloon_width_units
- )
-
# Code that increments the sublevel and level
# And bail out if no more levels are available
# return 1 if continue, 0 if bail out
@@ -266,6 +241,7 @@ class Gcompris_doubleclick:
def update_counter(self, button, time):
if self.counter[button] == 0:
+ # FIRST CLICK
# Check we are not already running
for i in range(3):
if self.counter[i] != 0:
@@ -276,18 +252,41 @@ class Gcompris_doubleclick:
self.timer_indic = gobject.timeout_add(self.timerinc,
self.indicator[button].refresh,
self.timerinc)
+ gcompris.sound.play_ogg("sounds/flip.wav")
return False
elif self.counter[button] != 0:
+ # SECOND CLICK
self.counter[button] = abs(self.counter[button] - time)
self.counter[button] = 0
- self.indicator[button].stop()
+ self.balloon.move_to(self.indicator[button].stop())
return True
def shoot_item_event(self, widget, event=None):
if event.type == gtk.gdk.BUTTON_PRESS:
if event.button <= 3:
- self.update_counter(event.button - 1,
- event.time)
+ if self.balloon.need_reset:
+ self.balloon.reset()
+ for i in range(3):
+ self.counter[i] = 0
+ self.indicator[i].reset()
+ else:
+ self.update_counter(event.button - 1,
+ event.time)
+
+ return False
+
+ #
+ # Display an info string when the user clicks
+ # on the wrong item
+ def help(self, widget, event=None):
+ if event.type == gtk.gdk.BUTTON_PRESS:
+ if self.balloon.need_reset:
+ text=_("Click on the balloon to place it again.")
+ else:
+ text=_("Click twice on the balloon to shoot it.")
+
+ self.help_item.set(text = text)
+ self.help_item.show()
return False
@@ -326,9 +325,18 @@ class Indicator:
fill_color_rgba = self.color_init)
self.stopped = True
+ #
+ # Return the calculated coordinate of the ballon
+ # return: (win, X, Y) with win = True or False
+ #
def stop(self):
self.stopped = True
+ return (self.counter <= self.winlimit,
+ self.target_x,
+ self.target_y)
+
+
def start(self):
self.stopped = False
self.counter = 0
@@ -340,9 +348,7 @@ class Indicator:
if self.stopped:
return False
return True
- #
- # Return true if its a win
- #
+
def update(self, counter):
length = min( (counter * self.max) / self.winlimit,
self.max)
@@ -350,12 +356,18 @@ class Indicator:
if self.orientation == 0:
x2 = self.x + length
self.item.set(x2 = x2)
+ self.target_x = x2
+ self.target_y = self.y
elif self.orientation == 1:
y2 = self.y + length
self.item.set(y2 = y2)
+ self.target_x = self.x
+ self.target_y = y2
elif self.orientation == 2:
x1 = (self.x + self.w) - length
self.item.set(x1 = x1)
+ self.target_x = x1
+ self.target_y = self.y
# Calc a proportional red and green color
color = 0L
@@ -375,4 +387,104 @@ class Indicator:
self.item.set(fill_color_rgba = color)
- return counter <= self.winlimit
+#
+# The balloon display and it's motion
+#
+class Balloon:
+ x = 0
+ y = 0
+ size = 0
+ stopped = True
+ item = 0
+ timerinc = 20
+ timer = 0
+ need_reset = False
+
+ def __init__(self, doubleclick, x, y):
+
+ self.doubleclick = doubleclick
+ self.rootitem = doubleclick.rootitem
+ self.x = x
+ self.y = y
+
+ # Balloon shadow
+ self.shadow = self.rootitem.add(
+ gnomecanvas.CanvasPixbuf,
+ pixbuf = gcompris.utils.load_pixmap("images/foot_shadow.svg"),
+ )
+
+ # Balloon
+ self.item = self.rootitem.add(
+ gnomecanvas.CanvasPixbuf,
+ pixbuf = gcompris.utils.load_pixmap("images/foot.svg"),
+ )
+ # This item is clickeable and it must be seen
+ self.item.connect("event", gcompris.utils.item_event_focus)
+
+ bounds = self.item.get_bounds()
+ self.size = bounds[2] - bounds[1]
+
+ def reset(self):
+ self.need_reset = False
+ self.x = gcompris.BOARD_WIDTH/2
+ self.y = gcompris.BOARD_HEIGHT - 115
+
+ self.item.set(
+ x = self.x - self.size/2,
+ y = self.y - self.size/2,
+ )
+
+ self.shadow.set(
+ x = self.x - self.size/2,
+ y = self.y + self.size/2 - 5,
+ )
+
+ if self.timer:
+ gobject.source_remove(self.timer)
+ self.timer = 0
+
+
+ def move_step(self):
+ self.x -= self.dx
+ self.y -= self.dy
+ self.item.set(
+ x = self.x - self.size/2,
+ y = self.y - self.size/2,
+ )
+ self.step -= 1
+
+ if self.step == 0:
+ if self.win:
+ gcompris.sound.play_ogg("sounds/bonus.wav")
+ self.doubleclick.increment_level()
+ self.doubleclick.next_level()
+ else:
+ gcompris.sound.play_ogg("sounds/tuxok.wav")
+
+ return False
+
+ return True
+
+
+ # target: (win, X, Y) with win = True or False
+ def move_to(self, target):
+ if self.timer != 0:
+ return
+
+ self.need_reset = True
+ gcompris.sound.play_ogg("sounds/brick.wav")
+
+ self.win = target[0]
+ target_x = target[1]
+ target_y = target[2]
+ if target[0] == False:
+ target_x = gcompris.BOARD_WIDTH / 2
+ target_y = 260
+
+ self.step = 100.0
+ self.dx = (self.x - target_x) / self.step
+ self.dy = (self.y - target_y) / self.step
+
+ self.timer = gobject.timeout_add(self.timerinc,
+ self.move_step)
+