Back to index

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

List of all members.

Public Member Functions

def __init__
def spawn
def die
def getEaten
def move
def stop
def getTrogMove
def trogMove_straight
def trogMove_random
def trogMove_chase
def trogMove_run
def onMove_create
def onStop_munch
def isAt
def isNear
def move_step
def startMunching
def stopMunching

Public Attributes

 anim
 nextspawn_timer
 nextmove_timer
 warn_timer
 foodchain
 exists
 getMove
 onMove
 onStop
 x_old
 x
 y
 y_old
 moving
 move_stepnum
 action_start
 velocity
 movestep_timer
 munch_timer

Detailed Description

Definition at line 495 of file gnumch.py.


Constructor & Destructor Documentation

def gnumch.Troggle.__init__ (   self)

Reimplemented from gnumch.Player.

Definition at line 496 of file gnumch.py.

00496 
00497     def __init__(self):
00498         super(Troggle, self).__init__()
00499         self.anim = gcompris.anim.CanvasItem(game.munchanimation, game.rootitem)
00500 
00501         self.nextspawn_timer = 0
00502         self.nextmove_timer = 0
00503         self.warn_timer = 0
00504 
00505         self.foodchain = 1


Member Function Documentation

def gnumch.Troggle.die (   self)

Reimplemented from gnumch.Player.

Definition at line 535 of file gnumch.py.

00535 
00536     def die(self):
00537         super(Troggle, self).die()
00538         self.exists = 0
00539         self.anim.gnomecanvas.hide()
00540 
00541         time = game.trog_spawn_time()
00542         self.nextspawn_timer = game.timeout_add( time + game.trogwarn_time, self.spawn )
00543         self.warn_timer = game.timeout_add( time, game.show_trogwarning )
00544         if self.nextmove_timer != 0:
00545             gtk.timeout_remove(self.nextmove_timer)
00546             self.nextmove_timer = 0

Here is the call graph for this function:

def gnumch.Troggle.getEaten (   self)

Reimplemented from gnumch.Player.

Definition at line 547 of file gnumch.py.

00547 
00548     def getEaten(self):
00549         self.die()

Here is the call graph for this function:

Definition at line 567 of file gnumch.py.

00567 
00568     def getTrogMove(self):
00569         self.nextmove_timer = 0
00570         x_old = self.x
00571         y_old = self.y
00572         x, y = self.getMove(self)
00573         self.move(x_old, y_old, x, y)

Here is the call 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.Troggle.move (   self,
  a,
  b,
  c,
  d 
)

Reimplemented from gnumch.Player.

Definition at line 550 of file gnumch.py.

00550 
00551     def move(self, a, b, c, d):
00552         if self.onMove != None and (a != c or b != d) and game.onBoard(a, b):
00553             self.x = a
00554             self.y = b
00555             self.onMove(self)
00556         super(Troggle, self).move(a, b, c, d)

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:

Definition at line 623 of file gnumch.py.

00623 
00624     def onMove_create(self):
00625         game.setNum( self.x, self.y, game.levelset.getNumber() )

Definition at line 626 of file gnumch.py.

00626 
00627     def onStop_munch(self):
00628         if game.squares[self.x][self.y].num != None:
00629             self.startMunching()
00630             game.setNum( self.x, self.y, None )

Here is the call graph for this function:

def gnumch.Troggle.spawn (   self)

Reimplemented from gnumch.Player.

Definition at line 506 of file gnumch.py.

00506 
00507     def spawn(self):
00508         self.nextspawn_timer = 0
00509         self.warn_timer = 0
00510         self.exists = True
00511         index = random.randint(0, (len( game.troganimation )-1) * game.board.sublevel / game.board.number_of_sublevel)
00512         self.anim.swapAnimation(game.troganimation[index])
00513         self.getMove = game.trogmoves[index]
00514         self.onMove = game.onmove[index]
00515         self.onStop = game.onstop[index]
00516         if random.randint(0,1) == 0:
00517             if random.randint(0,1) == 0:
00518                 self.x_old = -1
00519                 self.x = 0
00520             else:
00521                 self.x_old = game.width
00522                 self.x = game.width - 1
00523             self.y = self.y_old = random.randint(0, game.height-1)
00524         else:
00525             if random.randint(0,1) == 0:
00526                 self.y_old = -1
00527                 self.y = 0
00528             else:
00529                 self.y_old = game.height
00530                 self.y = game.height - 1
00531             self.x = self.x_old = random.randint(0, game.width-1)
00532         self.move(self.x_old, self.y_old, self.x, self.y)
00533         self.anim.gnomecanvas.show()
00534         game.hide_trogwarning()

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.Troggle.stop (   self)

Reimplemented from gnumch.Player.

Definition at line 557 of file gnumch.py.

00557 
00558     def stop(self):
00559         self.moving = False
00560         if self.x < 0 or self.x >= game.width or self.y < 0 or self.y >= game.height:
00561             self.die()
00562         else:
00563             super(Troggle, self).stop()
00564             self.nextmove_timer = game.timeout_add(game.trog_wait, self.getTrogMove)
00565             if self.onStop != None:
00566                 self.onStop(self)

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:

Definition at line 595 of file gnumch.py.

00595 
00596     def trogMove_chase(self):
00597         x = self.x
00598         y = self.y
00599         dx = game.muncher.x - x
00600         dy = game.muncher.y - y
00601         if dx == 0 and dy == 0:
00602             return self.trogMove_straight()
00603         if not game.muncher.exists or abs(dx) > game.width/2 or abs(dy) > game.height/2:
00604             return self.trogMove_straight()
00605         if abs(dx) > abs(dy) or (abs(dx) == abs(dy) and random.randint(0,1) == 0):
00606             x += dx / abs(dx)
00607         else:
00608             y += dy / abs(dy)
00609         return x, y

Here is the call graph for this function:

Definition at line 580 of file gnumch.py.

00580 
00581     def trogMove_random(self):
00582         x = self.x
00583         y = self.y
00584         r = random.randint(0,3)
00585         if r >= 1: # move straight
00586             x += self.x - self.x_old
00587             y += self.y - self.y_old
00588         elif r == 2: # turn left
00589             x += self.y - self.y_old
00590             y -= self.x - self.x_old
00591         else: # turn right
00592             x -= self.y - self.y_old
00593             y += self.x - self.x_old
00594         return x, y

Here is the caller graph for this function:

Definition at line 610 of file gnumch.py.

00610 
00611     def trogMove_run(self):
00612         x = self.x
00613         y = self.y
00614         dx = game.muncher.x - x
00615         dy = game.muncher.y - y
00616         if not game.muncher.exists or abs(dx) > game.width/2 or abs(dy) > game.height/2:
00617             return self.trogMove_random()
00618         if abs(dx) > abs(dy) or (abs(dx) == abs(dy) and random.randint(0,1) == 0):
00619             x -= dx / abs(dx)
00620         else:
00621             y -= dy / abs(dy)
00622         return x, y

Here is the call graph for this function:

Definition at line 575 of file gnumch.py.

00575 
00576     def trogMove_straight(self):
00577         x = self.x + (self.x - self.x_old)
00578         y = self.y + (self.y - self.y_old)
00579         return x, y

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 498 of file gnumch.py.

Reimplemented from gnumch.Player.

Definition at line 509 of file gnumch.py.

Reimplemented from gnumch.Player.

Definition at line 504 of file gnumch.py.

Definition at line 512 of file gnumch.py.

Definition at line 305 of file gnumch.py.

Definition at line 312 of file gnumch.py.

Reimplemented from gnumch.Player.

Definition at line 558 of file gnumch.py.

Definition at line 313 of file gnumch.py.

Definition at line 501 of file gnumch.py.

Definition at line 500 of file gnumch.py.

Definition at line 513 of file gnumch.py.

Definition at line 514 of file gnumch.py.

Definition at line 310 of file gnumch.py.

Definition at line 502 of file gnumch.py.

Reimplemented from gnumch.Player.

Definition at line 518 of file gnumch.py.

Reimplemented from gnumch.Player.

Definition at line 517 of file gnumch.py.

Reimplemented from gnumch.Player.

Definition at line 522 of file gnumch.py.

Reimplemented from gnumch.Player.

Definition at line 522 of file gnumch.py.


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