Back to index

gcompris  8.2.2
Public Member Functions | Public Attributes
followline.Gcompris_followline 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 cleanup
def next_level
def init_board
def increment_level
def highlight_next_line
def highlight_previous_line
def is_done
def loosing_item_event
def line_item_event

Public Attributes

 gcomprisBoard
 board_paused
 gamewon
 loosing_count
 color_empty
 color_full
 color_target
 color_border
 background_item
 background_item_connect_id
 state
 rootitem
 lines_group
 water_spot_group
 water_spot

Detailed Description

follow the line

Definition at line 17 of file followline.py.


Constructor & Destructor Documentation

def followline.Gcompris_followline.__init__ (   self,
  gcomprisBoard 
)

Definition at line 21 of file followline.py.

00021 
00022   def __init__(self, gcomprisBoard):
00023     self.gcomprisBoard = gcomprisBoard
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     self.loosing_count = 0
00031 
00032     self.color_empty   = 0xcee871FFL
00033     self.color_full    = 0x1a24cbffL
00034     self.color_target  = 0xFF0000FFL
00035     self.color_border  = 0x101010FFL
00036 
00037     print("Gcompris_followline __init__.")
00038 


Member Function Documentation

Definition at line 103 of file followline.py.

00103 
00104   def cleanup(self):
00105     # Remove the root item removes all the others inside it
00106     self.state = "Done"
00107 
00108     self.rootitem.destroy()
00109     self.lines_group.destroy()
00110     self.water_spot_group.destroy()

Here is the caller graph for this function:

Definition at line 72 of file followline.py.

00072 
00073   def config(self):
00074     print("Gcompris_followline config.")
00075 

Definition at line 56 of file followline.py.

00056 
00057   def end(self):
00058 
00059     # Remove the root item removes all the others inside it
00060     self.cleanup()
00061 
00062     # Disconnect from the background item
00063     self.background_item.disconnect(self.background_item_connect_id)

Here is the call graph for this function:

Definition at line 230 of file followline.py.

00230 
00231   def highlight_next_line(self):
00232     for item in self.lines_group.item_list:
00233       if(item.get_data("gotit") != True):
00234         item.set(
00235           fill_color_rgba = self.color_target,
00236           )
00237         item.set_data("iamnext", True);
00238         return

Here is the caller graph for this function:

Definition at line 243 of file followline.py.

00243 
00244   def highlight_previous_line(self):
00245     previous_item = []
00246 
00247     for item in self.lines_group.item_list:
00248 
00249       if(item.get_data("iamnext") == True):
00250 
00251         if(previous_item):
00252           # Remove the target info for this item
00253           item.set_data("iamnext", False)
00254           item.set(
00255             fill_color_rgba = self.color_empty,
00256             )
00257 
00258           # Set the target info on the previous item
00259           previous_item.set(
00260             fill_color_rgba = self.color_target,
00261             )
00262           item.set_data("gotit", False)
00263           previous_item.set_data("iamnext", True);
00264 
00265         return
00266 
00267       previous_item = item
00268 

Here is the caller graph for this function:

Definition at line 213 of file followline.py.

00213 
00214   def increment_level(self):
00215     self.gcomprisBoard.sublevel += 1
00216 
00217     if(self.gcomprisBoard.sublevel>self.gcomprisBoard.number_of_sublevel):
00218       # Try the next level
00219       self.gcomprisBoard.sublevel=1
00220       self.gcomprisBoard.level += 1
00221       if(self.gcomprisBoard.level>self.gcomprisBoard.maxlevel):
00222         # the current board is finished : bail out
00223         gcompris.bonus.board_finished(gcompris.bonus.FINISHED_RANDOM)
00224         return 0
00225 
00226     return 1

Here is the caller graph for this function:

Definition at line 122 of file followline.py.

00122 
00123   def init_board(self):
00124 
00125     self.state = "Ready"
00126 
00127     # Create our rootitem. We put each canvas item in it so at the end we
00128     # only have to kill it. The canvas deletes all the items it contains automaticaly.
00129     self.rootitem = self.gcomprisBoard.canvas.root().add(
00130       gnomecanvas.CanvasGroup,
00131       x=0.0,
00132       y=0.0
00133       )
00134 
00135     # Another group where we put each canvas line item in it
00136     self.lines_group = self.gcomprisBoard.canvas.root().add(
00137       gnomecanvas.CanvasGroup,
00138       x=0.0,
00139       y=0.0
00140       )
00141 
00142     start_x         = 40
00143     start_y         = gcompris.BOARD_HEIGHT/2
00144     stop_x          = gcompris.BOARD_WIDTH - 100
00145 
00146     # Line path (create several little line)
00147     min_boundary = 40
00148     y            = start_y
00149     line_width   = 45 - self.gcomprisBoard.level*2
00150     step         = (stop_x-start_x)/(30)
00151 
00152     frequency = 1 + int(self.gcomprisBoard.level/4)
00153 
00154     xpi = math.pi/2*frequency
00155     y   = start_y + math.cos(xpi)*(self.gcomprisBoard.level*10)
00156     for x in range(start_x, stop_x, step):
00157 
00158       xpi += (math.pi/2*frequency)/step
00159       y2 = start_y + math.cos(xpi)*(self.gcomprisBoard.level*10)
00160 
00161       # Check we stay within boundaries
00162       if(y2>=gcompris.BOARD_HEIGHT-min_boundary):
00163         y2=gcompris.BOARD_HEIGHT-min_boundary
00164       elif(y2<=min_boundary):
00165         y2=min_boundary
00166 
00167       item = self.lines_group.add(
00168         gnomecanvas.CanvasLine,
00169         points          =( x,
00170                            y,
00171                            x + step,
00172                            y2),
00173         fill_color_rgba = self.color_empty,
00174         width_units     = line_width,
00175         cap_style       = gtk.gdk.CAP_ROUND
00176         )
00177       item.connect("event", self.line_item_event)
00178 
00179       if x > start_x and x < stop_x-step:
00180         self.rootitem.add(
00181           gnomecanvas.CanvasLine,
00182           points          =( x,
00183                              y,
00184                              x + step,
00185                              y2),
00186           fill_color_rgba = self.color_border,
00187           width_units     = line_width + 20,
00188           cap_style       = gtk.gdk.CAP_ROUND
00189           )
00190 
00191       y = y2
00192 
00193     self.highlight_next_line()
00194 
00195     # Another group where we put each canvas line item in it
00196     self.water_spot_group = self.gcomprisBoard.canvas.root().add(
00197       gnomecanvas.CanvasGroup,
00198       x=0.0,
00199       y=0.0
00200       )
00201     # A water spot will be displayed when the user win
00202     self.water_spot = self.water_spot_group.add (
00203       gnomecanvas.CanvasPixbuf,
00204       pixbuf = gcompris.utils.load_pixmap("images/water_spot.png"),
00205       x=580,
00206       y=260,
00207       )
00208     self.water_spot.hide()
00209 

Here is the caller graph for this function:

Definition at line 269 of file followline.py.

00269 
00270   def is_done(self):
00271     done = True
00272     for item in self.lines_group.item_list:
00273       if(item.get_data("gotit") != True):
00274         done = False
00275 
00276     if(done):
00277       # This is a win
00278       if (self.increment_level() == 1):
00279         self.state = "Done"
00280         self.gamewon = 1
00281         self.water_spot.raise_to_top()
00282         self.water_spot.show()
00283         gcompris.bonus.display(gcompris.bonus.WIN, gcompris.bonus.FLOWER)
00284 
00285     return done

Here is the call graph for this function:

Here is the caller graph for this function:

def followline.Gcompris_followline.key_press (   self,
  keyval,
  commit_str,
  preedit_str 
)

Definition at line 76 of file followline.py.

00076 
00077   def key_press(self, keyval, commit_str, preedit_str):
00078     return False
00079 

def followline.Gcompris_followline.line_item_event (   self,
  widget,
  event = None 
)

Definition at line 294 of file followline.py.

00294 
00295   def line_item_event(self, widget, event=None):
00296     if not self.board_paused and widget.get_data("iamnext") == True:
00297       # The first line touch means the game is started
00298       self.state = "Started"
00299       widget.set(
00300         fill_color_rgba = self.color_full,
00301         )
00302       widget.set_data("gotit", True);
00303       widget.set_data("iamnext", False);
00304       self.highlight_next_line()
00305       self.is_done()
00306 
00307     return False
00308 

Here is the call graph for this function:

def followline.Gcompris_followline.loosing_item_event (   self,
  widget,
  event = None 
)

Definition at line 286 of file followline.py.

00286 
00287   def loosing_item_event(self, widget, event=None):
00288     if(self.state == "Started"):
00289       self.loosing_count += 1
00290       if(self.loosing_count % 10):
00291         self.highlight_previous_line()
00292     return False
00293 

Here is the call graph for this function:

Definition at line 111 of file followline.py.

00111 
00112   def next_level(self):
00113 
00114     self.cleanup()
00115 
00116     # Set the level in the control bar
00117     gcompris.bar_set_level(self.gcomprisBoard);
00118 
00119     self.init_board()
00120 
00121 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 64 of file followline.py.

00064 
00065   def ok(self):
00066     print("Gcompris_followline ok.")
00067 

def followline.Gcompris_followline.pause (   self,
  pause 
)

Definition at line 81 of file followline.py.

00081 
00082   def pause(self, pause):
00083 
00084     self.board_paused = pause
00085 
00086     # When the bonus is displayed, it call us first with pause(1) and then with pause(0)
00087     # the game is won
00088     if(pause == 0):
00089       self.next_level()
00090       self.gamewon = 0
00091 
00092     return
00093 

Here is the call graph for this function:

Definition at line 68 of file followline.py.

00068 
00069   def repeat(self):
00070     print("Gcompris_followline repeat.")
00071 

Here is the caller graph for this function:

def followline.Gcompris_followline.set_level (   self,
  level 
)

Definition at line 95 of file followline.py.

00095 
00096   def set_level(self, level):
00097     self.gcomprisBoard.level=level
00098     self.gcomprisBoard.sublevel=1
00099     self.next_level()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 39 of file followline.py.

00039 
00040   def start(self):
00041     self.gcomprisBoard.level=1
00042     self.gcomprisBoard.maxlevel=9
00043     self.gcomprisBoard.sublevel=1
00044     self.gcomprisBoard.number_of_sublevel=1
00045     gcompris.bar_set(gcompris.BAR_LEVEL)
00046     self.background_item = gcompris.set_background(self.gcomprisBoard.canvas.root(),
00047                                                    "images/followline.png")
00048     self.background_item_connect_id = self.background_item.connect("event", self.loosing_item_event)
00049 
00050     gcompris.bar_set_level(self.gcomprisBoard)
00051 
00052     self.init_board()
00053 
00054     print("Gcompris_followline start.")
00055 


Member Data Documentation

Definition at line 45 of file followline.py.

Definition at line 47 of file followline.py.

Definition at line 26 of file followline.py.

Definition at line 34 of file followline.py.

Definition at line 31 of file followline.py.

Definition at line 32 of file followline.py.

Definition at line 33 of file followline.py.

Definition at line 27 of file followline.py.

Definition at line 22 of file followline.py.

Definition at line 135 of file followline.py.

Definition at line 29 of file followline.py.

Definition at line 128 of file followline.py.

Definition at line 105 of file followline.py.

Definition at line 201 of file followline.py.

Definition at line 195 of file followline.py.


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