Back to index

gcompris  8.2.2
Public Member Functions | Public Attributes
gnumch.Muncher Class Reference
Inheritance diagram for gnumch.Muncher:
Inheritance graph
[legend]
Collaboration diagram for gnumch.Muncher:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def spawn
def die
def getEaten
def push_key
def handle_key
def munch
def stop
def isAt
def isNear
def move_step
def move
def startMunching
def stopMunching

Public Attributes

 lives
 anim
 spare
 key_queue
 exists
 move_stepnum
 x
 y
 x_old
 y_old
 moving
 action_start
 velocity
 movestep_timer
 munch_timer
 foodchain

Detailed Description

Definition at line 403 of file gnumch.py.


Constructor & Destructor Documentation

def gnumch.Muncher.__init__ (   self)

Reimplemented from gnumch.Player.

Definition at line 404 of file gnumch.py.

00404 
00405     def __init__(self):
00406         super(Muncher, self).__init__()
00407         self.lives = 1
00408         self.anim = gcompris.anim.CanvasItem(game.munchanimation, game.rootitem)
00409         self.spare = gcompris.anim.CanvasItem(game.munchanimation, game.rootitem)
00410         self.anim.gnomecanvas.hide()
00411         self.key_queue = []
00412         self.spare.gnomecanvas.set(x=0, y=0)


Member Function Documentation

def gnumch.Muncher.die (   self)

Reimplemented from gnumch.Player.

Definition at line 426 of file gnumch.py.

00426 
00427     def die(self):
00428         super(Muncher, self).die()
00429         self.lives -= 1
00430         self.exists = False
00431         self.anim.gnomecanvas.hide()
00432         self.key_queue = []

def gnumch.Muncher.getEaten (   self)

Reimplemented from gnumch.Player.

Definition at line 433 of file gnumch.py.

00433 
00434     def getEaten(self):
00435         game.show_message( _("You were eaten by a Troggle.\nPress <Return> to continue.") )
00436         self.die()

Here is the call graph for this function:

def gnumch.Muncher.handle_key (   self,
  key 
)

Definition at line 450 of file gnumch.py.

00450 
00451     def handle_key(self, key):
00452         if key == gtk.keysyms.Left:
00453             if self.x > 0:
00454                 self.move(self.x, self.y, (self.x-1), self.y)
00455             else:
00456                 self.stop()
00457         elif key == gtk.keysyms.Right:
00458             if self.x < game.width - 1:
00459                 self.move(self.x, self.y, (self.x+1), self.y)
00460             else:
00461                 self.stop()
00462         elif key == gtk.keysyms.Up:
00463             if self.y > 0:
00464                 self.move(self.x, self.y, self.x, (self.y-1))
00465             else:
00466                 self.stop()
00467         elif key == gtk.keysyms.Down:
00468             if self.y < game.height - 1:
00469                 self.move(self.x, self.y, self.x, (self.y+1))
00470             else:
00471                 self.stop()
00472         elif key == gtk.keysyms.space:
00473             self.munch()
00474             if len( self.key_queue ) > 0: # we don't need to wait for munching to finish to start the next action
00475                 self.handle_key( self.key_queue.pop(0) )

Here is the call graph for this function:

Here is the caller graph for this function:

def gnumch.Player.isAt (   self,
  x,
  y 
) [inherited]

Definition at line 333 of file gnumch.py.

00333 
00334     def isAt(self, x, y):
00335         return self.exists and not self.moving and (self.x == x and self.y == y)

def gnumch.Player.isNear (   self,
  x,
  y 
) [inherited]

Definition at line 336 of file gnumch.py.

00336 
00337     def isNear(self, x, y):
00338         return self.exists and (    (self.x == x and self.y == y)
00339                                 or  (self.moving and self.x_old == x
00340                                                  and self.y_old == y)
00341                                )

def gnumch.Player.move (   self,
  x_old,
  y_old,
  x,
  y 
) [inherited]

Reimplemented in gnumch.Troggle.

Definition at line 361 of file gnumch.py.

00361 
00362     def move(self, x_old, y_old, x, y):
00363         self.x_old = x_old
00364         self.y_old = y_old
00365         self.x = x
00366         self.y = y
00367         self.velocity = [x-x_old, y-y_old]
00368         self.anim.gnomecanvas.set(x=(self.x_old * game.sw + game.left),
00369                                    y=(self.y_old * game.sh + game.top))
00370         self.moving = True
00371 
00372         # it takes game.num_moveticks iterations of duration game.move_tick to move squares
00373         if x != x_old or y != y_old:
00374             self.anim.setState(1)
00375             self.movestep_timer = game.timeout_add(game.move_tick, self.move_step)
00376         else:
00377             self.stop()

Here is the call graph for this function:

Here is the caller graph for this function:

def gnumch.Player.move_step (   self) [inherited]

Definition at line 342 of file gnumch.py.

00342 
00343     def move_step(self):
00344         if self.move_stepnum < game.num_moveticks-1:
00345             self.move_stepnum += 1
00346             x_old = self.anim.gnomecanvas.get_property("x")
00347             y_old = self.anim.gnomecanvas.get_property("y")
00348             x = self.anim.gnomecanvas.get_property("x") + self.velocity[0]*game.sw/game.num_moveticks
00349             y = self.anim.gnomecanvas.get_property("y") + self.velocity[1]*game.sh/game.num_moveticks
00350             ret = True
00351         else:
00352             self.move_stepnum = 0
00353             x = game.sw * self.x + game.left
00354             y = game.sh * self.y + game.top
00355             self.stop()
00356             self.movestep_timer = 0
00357             ret = False
00358 
00359         self.anim.gnomecanvas.set(x=x, y=y)
00360         return ret

Here is the call graph for this function:

Here is the caller graph for this function:

def gnumch.Muncher.munch (   self)

Definition at line 476 of file gnumch.py.

00476 
00477     def munch(self):
00478         num = game.squares[self.x][self.y].num
00479         if num == None:
00480             return
00481         if num.good:
00482             self.startMunching()
00483         else:
00484             game.show_message( _("You ate a wrong number.\n") +game.levelset.getError(num) +
00485                                _("\nPress <Return> to continue.") )
00486             self.die()
00487         game.setNum(self.x, self.y, None)

Here is the call graph for this function:

Here is the caller graph for this function:

def gnumch.Muncher.push_key (   self,
  key 
)

Definition at line 437 of file gnumch.py.

00437 
00438     def push_key(self, key):
00439         if self.exists:
00440             if self.moving:
00441                 self.key_queue.append(key)
00442             elif len(self.key_queue) == 0:
00443                 self.handle_key(key)
00444             else:
00445                 self.key_queue.append(key)
00446                 self.handle_key(self.key_queue.pop(0))
00447         else:
00448             if key == gtk.keysyms.Return:
00449                 self.spawn()

Here is the call graph for this function:

def gnumch.Muncher.spawn (   self)

Reimplemented from gnumch.Player.

Definition at line 413 of file gnumch.py.

00413 
00414     def spawn(self):
00415         if self.lives >= 1:
00416             self.spare.gnomecanvas.show()
00417         elif self.lives == 0:
00418             self.spare.gnomecanvas.hide()
00419         else:
00420             game.loseGame()
00421         self.key_queue = []
00422         game.hide_message()
00423         self.exists = True
00424         self.move(0,0,0,0)
00425         self.anim.gnomecanvas.show()

def gnumch.Player.startMunching (   self) [inherited]

Definition at line 378 of file gnumch.py.

00378 
00379     def startMunching(self):
00380         self.anim.setState(2)
00381         self.munch_timer = game.timeout_add(game.munch_time, self.stopMunching)
00382         return False

Here is the call graph for this function:

Here is the caller graph for this function:

def gnumch.Muncher.stop (   self)

Reimplemented from gnumch.Player.

Definition at line 488 of file gnumch.py.

00488 
00489     def stop(self):
00490         super(Muncher, self).stop()
00491         if len(self.key_queue) > 0:
00492             key = self.key_queue.pop(0)
00493             self.handle_key(key)
00494 

Here is the call graph for this function:

def gnumch.Player.stopMunching (   self) [inherited]

Definition at line 383 of file gnumch.py.

00383 
00384     def stopMunching(self):
00385         self.munch_timer = 0
00386         self.anim.setState(0)
00387         return False

Here is the caller graph for this function:


Member Data Documentation

Definition at line 308 of file gnumch.py.

Reimplemented from gnumch.Player.

Definition at line 407 of file gnumch.py.

Reimplemented from gnumch.Player.

Definition at line 422 of file gnumch.py.

Reimplemented in gnumch.Troggle.

Definition at line 316 of file gnumch.py.

Definition at line 410 of file gnumch.py.

Definition at line 406 of file gnumch.py.

Definition at line 305 of file gnumch.py.

Definition at line 312 of file gnumch.py.

gnumch.Player.moving [inherited]

Reimplemented in gnumch.Troggle.

Definition at line 307 of file gnumch.py.

Definition at line 313 of file gnumch.py.

Definition at line 408 of file gnumch.py.

Definition at line 310 of file gnumch.py.

gnumch.Player.x [inherited]

Reimplemented in gnumch.Troggle.

Definition at line 306 of file gnumch.py.

gnumch.Player.x_old [inherited]

Reimplemented in gnumch.Troggle.

Definition at line 306 of file gnumch.py.

gnumch.Player.y [inherited]

Reimplemented in gnumch.Troggle.

Definition at line 306 of file gnumch.py.

gnumch.Player.y_old [inherited]

Reimplemented in gnumch.Troggle.

Definition at line 306 of file gnumch.py.


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