Back to index

gcompris  8.2.2
Public Member Functions | Public Attributes
ballcatch.Gcompris_ballcatch Class Reference

List of all members.

Public Member Functions

def __init__
def start
def end
def ok
def repeat
def config
def key_press
def pause
def set_level
def next_level
def timer_inc_display
def ball_move
def get_bounds
def init_balloon
def increment_level

Public Attributes

 gcomprisBoard
 board_paused
 gamewon
 ballinc
 timer_diff
 rootitem
 lefthand
 balloon_item
 leftkey
 rightkey
 timerinc
 left_continue
 right_continue
 counter_left
 counter_right
 timer_inc
 balloon_size
 balloon_width_units
 balloon_x
 balloon_y

Detailed Description

catch the ball

Definition at line 15 of file ballcatch.py.


Constructor & Destructor Documentation

def ballcatch.Gcompris_ballcatch.__init__ (   self,
  gcomprisBoard 
)

Definition at line 19 of file ballcatch.py.

00019 
00020   def __init__(self, gcomprisBoard):
00021     self.gcomprisBoard = gcomprisBoard
00022 
00023     self.gcomprisBoard.disable_im_context = True
00024 
00025     # These are used to let us restart only after the bonus is displayed.
00026     # When the bonus is displayed, it call us first with pause(1) and then with pause(0)
00027     self.board_paused  = 0;
00028     self.gamewon       = 0;
00029 
00030     print("Gcompris_ballcatch __init__.")
00031 


Member Function Documentation

Definition at line 241 of file ballcatch.py.

00241 
00242   def ball_move(self):
00243 
00244     # The move simulation
00245     self.balloon_size -= 3
00246     self.balloon_x    += self.timer_diff
00247     self.balloon_y    -= 5
00248 
00249     if(self.balloon_width_units>1.0):
00250       self.balloon_width_units -= 0.5
00251 
00252     self.balloon_item.set(
00253       x1=self.balloon_x - self.balloon_size/2,
00254       y1=self.balloon_y - self.balloon_size/2,
00255       x2=self.balloon_x + self.balloon_size/2,
00256       y2=self.balloon_y + self.balloon_size/2,
00257       width_units=self.balloon_width_units
00258       )
00259 
00260     if(self.balloon_size>48):
00261       self.timer_inc  = gtk.timeout_add(self.ballinc, self.ball_move)
00262     else:
00263       # We are done with the ballon move
00264       if(self.counter_left == self.counter_right):
00265         # This is a win
00266         if (self.increment_level() == 1):
00267           self.gamewon = 1
00268           gcompris.bonus.display(gcompris.bonus.WIN, gcompris.bonus.TUX)
00269       else:
00270         # This is a loose
00271         self.gamewon = 0
00272         gcompris.bonus.display(gcompris.bonus.LOOSE, gcompris.bonus.TUX)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 139 of file ballcatch.py.

00139 
00140   def config(self):
00141     print("Gcompris_ballcatch config.")
00142 

Definition at line 122 of file ballcatch.py.

00122 
00123   def end(self):
00124 
00125     # Remove the root item removes all the others inside it
00126     self.rootitem.destroy()
00127 
00128     if self.timer_inc :
00129       gtk.timeout_remove(self.timer_inc)
00130 

def ballcatch.Gcompris_ballcatch.get_bounds (   self,
  item 
)

Definition at line 273 of file ballcatch.py.

00273 
00274   def get_bounds(self, item):
00275     if gobject.type_name(item)=="GnomeCanvasPixbuf":
00276       x1=item.get_property("x")
00277       y1=item.get_property("y")
00278       x2=item.get_property("x")+item.get_property("width")
00279       y2=item.get_property("y")+item.get_property("height")
00280     return (min(x1,x2),min(y1,y2),max(x1,x2),max(y1,y2))

Definition at line 300 of file ballcatch.py.

00300 
00301   def increment_level(self):
00302     self.gcomprisBoard.sublevel += 1
00303 
00304     if(self.gcomprisBoard.sublevel>self.gcomprisBoard.number_of_sublevel):
00305       # Try the next level
00306       self.gcomprisBoard.sublevel=1
00307       self.gcomprisBoard.level += 1
00308       if(self.gcomprisBoard.level>self.gcomprisBoard.maxlevel):
00309         # the current board is finished : bail out
00310         gcompris.bonus.board_finished(gcompris.bonus.FINISHED_RANDOM)
00311         return 0
00312 
00313     return 1
00314 

Here is the caller graph for this function:

Definition at line 281 of file ballcatch.py.

00281 
00282   def init_balloon(self):
00283     self.balloon_size = 160
00284     self.balloon_width_units = 5.0
00285     self.balloon_x    = gcompris.BOARD_WIDTH/2-20
00286     self.balloon_y    = gcompris.BOARD_HEIGHT - 130
00287 
00288     self.balloon_item.set(
00289       x1=self.balloon_x - self.balloon_size/2,
00290       y1=self.balloon_y - self.balloon_size/2,
00291       x2=self.balloon_x + self.balloon_size/2,
00292       y2=self.balloon_y + self.balloon_size/2,
00293       fill_color_rgba=0xFF1212FFL,
00294       outline_color_rgba=0x000000FFL,
00295       width_units=self.balloon_width_units
00296       )

Here is the caller graph for this function:

def ballcatch.Gcompris_ballcatch.key_press (   self,
  keyval,
  commit_str,
  preedit_str 
)

Definition at line 143 of file ballcatch.py.

00143 
00144   def key_press(self, keyval, commit_str, preedit_str):
00145     print("Gcompris_ballcatch key press. %i" % keyval)
00146 
00147     if (keyval == gtk.keysyms.Shift_L):
00148       self.left_continue  = False
00149 
00150     if (keyval == gtk.keysyms.Shift_R):
00151       self.right_continue = False
00152 
00153     return False

Definition at line 177 of file ballcatch.py.

00177 
00178   def next_level(self):
00179 
00180     # Set the level in the control bar
00181     gcompris.bar_set_level(self.gcomprisBoard);
00182 
00183     self.init_balloon()
00184     self.left_continue  = True
00185     self.right_continue = True
00186     self.counter_left  = 0
00187     self.counter_right = 0
00188 
00189     if(self.gcomprisBoard.level == 1):
00190       self.timerinc = 900
00191     elif(self.gcomprisBoard.level == 2):
00192       self.timerinc = 350
00193     elif(self.gcomprisBoard.level == 3):
00194       self.timerinc = 300
00195     elif(self.gcomprisBoard.level == 4):
00196       self.timerinc = 200
00197     elif(self.gcomprisBoard.level == 5):
00198       self.timerinc = 150
00199     elif(self.gcomprisBoard.level == 6):
00200       self.timerinc = 100
00201     elif(self.gcomprisBoard.level == 7):
00202       self.timerinc = 60
00203     elif(self.gcomprisBoard.level == 8):
00204       self.timerinc = 30
00205     elif(self.gcomprisBoard.level == 9):
00206       self.timerinc = 15
00207 
00208     if(self.timerinc<1):
00209       self.timerinc = 1
00210 
00211     # Restart the timer
00212     self.timer_inc  = gtk.timeout_add(self.timerinc, self.timer_inc_display)
00213 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 131 of file ballcatch.py.

00131 
00132   def ok(self):
00133     print("Gcompris_ballcatch ok.")
00134 

def ballcatch.Gcompris_ballcatch.pause (   self,
  pause 
)

Definition at line 155 of file ballcatch.py.

00155 
00156   def pause(self, pause):
00157 
00158     self.board_paused = pause
00159 
00160     # When the bonus is displayed, it call us first with pause(1) and then with pause(0)
00161     # the game is won
00162     if(pause == 0):
00163       self.next_level()
00164       self.gamewon = 0
00165 
00166     return
00167 

Here is the call graph for this function:

Definition at line 135 of file ballcatch.py.

00135 
00136   def repeat(self):
00137     print("Gcompris_ballcatch repeat.")
00138 

Here is the caller graph for this function:

def ballcatch.Gcompris_ballcatch.set_level (   self,
  level 
)

Definition at line 169 of file ballcatch.py.

00169 
00170   def set_level(self, level):
00171     self.gcomprisBoard.level=level
00172     self.gcomprisBoard.sublevel=1
00173     self.next_level()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 32 of file ballcatch.py.

00032 
00033   def start(self):
00034     self.gcomprisBoard.level=1
00035     self.gcomprisBoard.maxlevel=9
00036     self.gcomprisBoard.sublevel=1
00037     self.gcomprisBoard.number_of_sublevel=1
00038     gcompris.bar_set(gcompris.BAR_LEVEL)
00039     gcompris.set_background(self.gcomprisBoard.canvas.root(),
00040                             "images/beach.png")
00041     gcompris.bar_set_level(self.gcomprisBoard)
00042 
00043 
00044     self.ballinc    = 20        # Event loop timer for the ball move
00045     self.timer_diff = 0         # Store the time diff between left and right key
00046 
00047     # Create our rootitem. We put each canvas item in it so at the end we
00048     # only have to kill it. The canvas deletes all the items it contains automaticaly.
00049     self.rootitem = self.gcomprisBoard.canvas.root().add(
00050       gnomecanvas.CanvasGroup,
00051       x=0.0,
00052       y=0.0
00053       )
00054 
00055     # Tux
00056     self.lefthand = self.rootitem.add(
00057       gnomecanvas.CanvasPixbuf,
00058       pixbuf = gcompris.utils.load_pixmap("gcompris/misc/tux.png"),
00059       x=gcompris.BOARD_WIDTH/2 - 60,
00060       y=135.0
00061       )
00062 
00063     # Balloon
00064     self.balloon_item = self.rootitem.add(
00065       gnomecanvas.CanvasEllipse,
00066       x1=0.0,
00067       y1=0.0,
00068       x2=0.0,
00069       y2=0.0
00070       )
00071     self.init_balloon()
00072 
00073     # The Left Hand
00074     self.lefthand = self.rootitem.add(
00075       gnomecanvas.CanvasPixbuf,
00076       pixbuf = gcompris.utils.load_pixmap("gcompris/misc/hand.png"),
00077       x=gcompris.BOARD_WIDTH/2-150.0,
00078       y=gcompris.BOARD_HEIGHT - 150
00079       )
00080 
00081     # The Right Hand
00082     item = self.lefthand = self.rootitem.add(
00083       gnomecanvas.CanvasPixbuf,
00084       pixbuf = gcompris.utils.load_pixmap("gcompris/misc/hand.png"),
00085       x=gcompris.BOARD_WIDTH/2+100.0,
00086       y=gcompris.BOARD_HEIGHT - 150.0
00087       )
00088     bounds = self.get_bounds(item)
00089     (cx, cy) = ( (bounds[2]+bounds[0])/2 , (bounds[3]+bounds[1])/2)
00090     mat = ( -1, 0, 0, 1, 2*cx, 0)
00091     item.affine_relative(mat)
00092 
00093     # The Left Shift KEY
00094     self.leftkey = self.rootitem.add(
00095       gnomecanvas.CanvasPixbuf,
00096       pixbuf = gcompris.utils.load_pixmap("images/shift_key.png"),
00097       x=gcompris.BOARD_WIDTH/2-240.0,
00098       y=gcompris.BOARD_HEIGHT - 80
00099       )
00100 
00101     # The Right Shift KEY
00102     self.rightkey = self.rootitem.add(
00103       gnomecanvas.CanvasPixbuf,
00104       pixbuf = gcompris.utils.load_pixmap("images/shift_key.png"),
00105       x=gcompris.BOARD_WIDTH/2+100.0,
00106       y=gcompris.BOARD_HEIGHT - 80
00107       )
00108 
00109     # The basic tick for object moves
00110     self.timerinc = 1000
00111 
00112     self.left_continue  = True
00113     self.right_continue = True
00114 
00115     self.counter_left  = 0
00116     self.counter_right = 0
00117 
00118     self.timer_inc  = gtk.timeout_add(self.timerinc, self.timer_inc_display)
00119 
00120     print("Gcompris_ballcatch start.")
00121 

Definition at line 214 of file ballcatch.py.

00214 
00215   def timer_inc_display(self):
00216 
00217     if(self.left_continue):
00218       self.counter_left += self.timer_inc
00219 
00220     if(self.right_continue):
00221       self.counter_right += self.timer_inc
00222 
00223     if(self.left_continue or self.right_continue):
00224       self.timer_inc  = gtk.timeout_add(self.timerinc, self.timer_inc_display)
00225     else:
00226       # Send the ball now
00227       self.timer_diff = self.counter_right/1000 - self.counter_left/1000
00228       # Make some adjustment so that it cannot be too or too far close from the target
00229       # In between, the calculated value stay proportional to the error.
00230       print self.timer_diff
00231       if(self.timer_diff < -6):
00232         self.timer_diff = -6
00233       elif(self.timer_diff > 6):
00234         self.timer_diff = 6
00235       elif(self.timer_diff > -1.5 and self.timer_diff < 0 ):
00236         self.timer_diff = -1.5
00237       elif(self.timer_diff < 1.5 and self.timer_diff > 0 ):
00238         self.timer_diff = 1.5
00239 
00240       self.timer_inc  = gtk.timeout_add(self.ballinc, self.ball_move)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 43 of file ballcatch.py.

Definition at line 63 of file ballcatch.py.

Definition at line 282 of file ballcatch.py.

Definition at line 283 of file ballcatch.py.

Definition at line 284 of file ballcatch.py.

Definition at line 285 of file ballcatch.py.

Definition at line 26 of file ballcatch.py.

Definition at line 114 of file ballcatch.py.

Definition at line 115 of file ballcatch.py.

Definition at line 27 of file ballcatch.py.

Definition at line 20 of file ballcatch.py.

Definition at line 111 of file ballcatch.py.

Definition at line 55 of file ballcatch.py.

Definition at line 93 of file ballcatch.py.

Definition at line 112 of file ballcatch.py.

Definition at line 101 of file ballcatch.py.

Definition at line 48 of file ballcatch.py.

Definition at line 44 of file ballcatch.py.

Definition at line 117 of file ballcatch.py.

Definition at line 109 of file ballcatch.py.


The documentation for this class was generated from the following file: