Exemplo n.º 1
0
 def __init__(self, game, prio, scoop_mode):
     '''
     Constructor
     '''
     StoryMode.__init__(self, game, prio, scoop_mode)
     
     self.blink_delay_ms = 200
     self.lights = ['pop1', 'pop2', 'pop3']
     self.switches = ['pop1', 'pop2', 'pop3']
     self.level_colors = [self.game.color(255,0,0), #red
                          self.game.color(0,255,0), #green
                          self.game.color(0,0,255), #blue
                          ]
     self.level_hits_required = [10, 20, 50]
     self.max_level_score = 10000
     self.at_max_level = False
     self.level = 0
     self.hits_till_next_level = self.level_hits_required[self.level]
     
     self.hits_remaining_layer = TextLayer(ui.fonts.BIG_FONT,
                                   '%s hits to next level' % self.level_hits_required[0],
                                   self.game.color(255,255,255),
                                   align='center')
     self.hits_remaining_layer.move(1024/2, 80)
     self.level_layer = TextLayer(ui.fonts.BIG_FONT,
                                  'Pops level 1', 
                                  self.game.color(255,255,255),
                                  align='center')
     self.level_layer.move(1024/2, 50)
Exemplo n.º 2
0
 def introduce(self):
     # introduce the mode with sound and an intro animation
     map_layer = ImageLayer(self.game.datapath('map_background.png'))
     title_layer = AnimatedTextLayer(ui.fonts.TITLE_FONT,
                             self.MODE_NAME, 
                             self.game.color(255,255,255), align='center')
     title_layer.move(1024/2, 50)
     description_layer = TextLayer(ui.fonts.BIG_FONT,
                             self.MODE_DESC, 
                             self.game.color(255,255,255), align='center')
     description_layer.move(1024/2, 175)
     self.layer = GroupedLayer([map_layer, title_layer, description_layer])
     self.layer.opaque = True
     self.delay('end_intro', 3, self.endIntroduce)
Exemplo n.º 3
0
 def start(self):
     self.level = 0
     for switch in self.switches:
         self.addHandler(switch, 'closed', 0, self.switchHit)
     
     self.layer = TextLayer(ui.fonts.TITLE_FONT,
                            '???', 
                            self.game.color(255,255,255), align='center')
     self.layer.move(1024/2, 50)
     self.layer.opaque = True
     
     self.startLevel()
Exemplo n.º 4
0
 def __init__(self, game, prio, ball):
     '''
     Constructor
     '''
     Mode.__init__(self, game, prio)
     self.layer = TextLayer(ui.fonts.BIG_FONT,
                            'Ball %s locked' % ball,
                            self.game.color(255,255,255),
                            'center')
     self.layer.move(1024/2, 175)
     self.layer.opaque = True
     self.delay('wait', 2, self.done)
Exemplo n.º 5
0
class BallLockedMode(Mode):
    '''
    classdocs
    '''


    def __init__(self, game, prio, ball):
        '''
        Constructor
        '''
        Mode.__init__(self, game, prio)
        self.layer = TextLayer(ui.fonts.BIG_FONT,
                               'Ball %s locked' % ball,
                               self.game.color(255,255,255),
                               'center')
        self.layer.move(1024/2, 175)
        self.layer.opaque = True
        self.delay('wait', 2, self.done)
    
    def done(self):
        self.game.trough.launchBall()
        self.game.modes.remove(self)
Exemplo n.º 6
0
class TakedownMode(StoryMode):
    '''
    classdocs
    '''
    MODE_NAME = 'Takedown'
    MODE_DESC = 'Shoot pop bumpers'

    def __init__(self, game, prio, scoop_mode):
        '''
        Constructor
        '''
        StoryMode.__init__(self, game, prio, scoop_mode)
        
        self.blink_delay_ms = 200
        self.lights = ['pop1', 'pop2', 'pop3']
        self.switches = ['pop1', 'pop2', 'pop3']
        self.level_colors = [self.game.color(255,0,0), #red
                             self.game.color(0,255,0), #green
                             self.game.color(0,0,255), #blue
                             ]
        self.level_hits_required = [10, 20, 50]
        self.max_level_score = 10000
        self.at_max_level = False
        self.level = 0
        self.hits_till_next_level = self.level_hits_required[self.level]
        
        self.hits_remaining_layer = TextLayer(ui.fonts.BIG_FONT,
                                      '%s hits to next level' % self.level_hits_required[0],
                                      self.game.color(255,255,255),
                                      align='center')
        self.hits_remaining_layer.move(1024/2, 80)
        self.level_layer = TextLayer(ui.fonts.BIG_FONT,
                                     'Pops level 1', 
                                     self.game.color(255,255,255),
                                     align='center')
        self.level_layer.move(1024/2, 50)
        
    def start(self):
        for light in self.lights:
            self.game.lights[light].blink(self.blink_delay_ms, self.level_colors[self.level])
        
        for switch in self.switches:
            self.addHandler(switch, 'closed', 0, self.popHit)
        
        self.layer = GroupedLayer([self.hits_remaining_layer, self.level_layer])
    
    def popHit(self, switch):
        if self.level >= len(self.level_hits_required):
            self.game.player().score += self.max_level_score
            return True
        
        self.game.player().score += (1000 * (self.level+1))
        self.hits_till_next_level -= 1
        
        if self.hits_till_next_level == 0:
            self.level += 1
            if self.level >= len(self.level_hits_required):
                self.level_layer.setText('Pops at maximum!')
                self.layer = GroupedLayer([self.level_layer])
                for light in self.lights:
                    self.game.lights[light].on(self.game.color(255,255,255))
                return True
                
            self.hits_till_next_level = self.level_hits_required[self.level]
            self.level_layer.setText('Pops level %s' % str(self.level+1))
            for light in self.lights:
                self.game.lights[light].blink(self.blink_delay_ms, self.level_colors[self.level])
        self.hits_remaining_layer.setText('%s hits to next level' % self.hits_till_next_level)
        return True
Exemplo n.º 7
0
class CodebreakerMode(StoryMode):
    '''
    Hit every shot to unlock all the letters
    '''
    MODE_NAME = 'Codebreaker'
    MODE_DESC = 'Crack the password'

    def __init__(self, game, prio, scoop_mode):
        '''
        Constructor
        '''
        StoryMode.__init__(self, game, prio, scoop_mode)
        
        # TODO: proper lights and switches when added
        self.lights = ['leftorbit', 'pop1', 'pop2', 'pop3', 'rightorbit']
        self.switches = ['orbitL', 'standup1', 'standup2', 'standup3', 'orbitR']
        
        self.level = 0
        self.letter_scramble_delay = 50
        
        # password is a random one of these each time the mode starts
        self.words = ['hunts', 'brain', 'safer']
    
    def start(self):
        self.level = 0
        for switch in self.switches:
            self.addHandler(switch, 'closed', 0, self.switchHit)
        
        self.layer = TextLayer(ui.fonts.TITLE_FONT,
                               '???', 
                               self.game.color(255,255,255), align='center')
        self.layer.move(1024/2, 50)
        self.layer.opaque = True
        
        self.startLevel()
        
    def startLevel(self):
        self.letters_found = [False] * len(self.switches)
        self.password = random.choice(self.words)
        
        for light in self.lights:
            self.game.lights[light].blink(500, self.game.color(255,0,0))
        
        self.delay('scramble', 0.1, self.scramble)
        self.delay('defeat', 60, self.defeat)
    
    def switchHit(self, switch):
        self.game.player().score += 1000
        
        index = self.switches.index(switch.name)
        self.letters_found[index] = True
        self.game.lights[self.lights[index]].off()
        
    def scramble(self):
        letters = []
        for i, found in enumerate(self.letters_found):
            if found:
                letters.append(self.password[i])
            else:
                letters.append(random.choice(string.ascii_letters+string.digits))
        self.layer.setText(''.join(letters))
        
        if all(self.letters_found):
            self.delay('victory', 0.6, self.victory)
        else:
            self.delay('scramble', 0.1, self.scramble)
    
    def victory(self):
        self.layer.setText('Success!')
        self.game.player().score += 10000
        self.delay('victory', 1, self.victory2)
    
    def victory2(self):
        self.game.modes.remove(self)
    
    def defeat(self):
        if all(self.letters_found):
            return # we didn't lose, it just timed out before the victory sequence fired
        self.game.modes.remove(self)
Exemplo n.º 8
0
class Trough(Mode):
    def __init__(self, game, prio):
        Mode.__init__(self, game, prio)
    
        self.balls = 3
        self.balls_in_play = 0
        self.balls_in_lock = 0
        self.balls_in_trough = self.balls
        
        self.trough_switches = ['trough1', 'trough2', 'trough3']
        self.lock_switches = ['lock1', 'lock2', 'lock3']
        self.outhole_switch = 'outhole'
        self.shooter_switch = 'shooter'
        
        self.addHandler(self.outhole_switch, 'closed', 30, self.ballDrained)
        
        for switch_name in self.trough_switches:
            self.addHandler(switch_name, 'closed', 0, self.handleTroughSwitch)
        
        for switch_name in self.lock_switches:
            self.addHandler(switch_name, 'closed', 0, self.handleLockSwitch)
        
        self.updateDebugInfo()
    
    def updateDebugInfo(self):
        text = 'T:%s L:%s P:%s' % (self.balls_in_trough, self.balls_in_lock, self.balls_in_play)
        self.layer = TextLayer(ui.fonts.SMALL_FONT, text,
                               self.game.color(255,255,255), 'center')
        self.layer.move(1024/2, 5)
    
    def ballDrained(self, switch):
        # always want to kick a ball from the outhole into the trough
        self.game.drivers['outhole'].pulse(30)
        self.balls_in_play -= 1
        self.balls_in_trough += 1
        self.game.ballDrained()
        self.updateDebugInfo()
    
    def launchBall(self):
        # if there's a ball sitting on trough1, launch ball
        if True: #self.game.switches['trough1'].active:
            self.game.drivers['trough'].pulse(30)
            self.balls_in_play += 1
            self.balls_in_trough -= 1
        
        # else ??
        self.updateDebugInfo()
    
    def unlockBall(self):
        if True: #self.game.switches['lock1'].active:
            self.game.drivers['lock'].pulse(30)
            self.balls_in_lock -= 1
            self.balls_in_play += 1
        self.updateDebugInfo()
    
    def handleTroughSwitch(self, switch):
        self.delay('check trough', 0.2, self.updateTroughStatus)
    
    def handleLockSwitch(self, switch):
        print "handle lock"
        self.delay('check lock', 0.2, self.updateLockStatus)
    
    def updateTroughStatus(self):
        self.balls_in_trough = 0
        for switch_name in self.trough_switches:
            if self.game.switches[switch_name].active:
                self.balls_in_trough += 1
        self.updateDebugInfo()
    
    def updateLockStatus(self):
        print "update lock"
        balls_in_lock = 0
        for switch_name in self.lock_switches:
            if self.game.switches[switch_name].active:
                balls_in_lock += 1
        print "%s in lock" % balls_in_lock
        if balls_in_lock > self.balls_in_lock:
            self.balls_in_lock = balls_in_lock
            self.balls_in_play = self.balls - self.balls_in_lock - self.balls_in_trough
            self.game.ballLocked()
        self.updateDebugInfo()
Exemplo n.º 9
0
 def updateDebugInfo(self):
     text = 'T:%s L:%s P:%s' % (self.balls_in_trough, self.balls_in_lock, self.balls_in_play)
     self.layer = TextLayer(ui.fonts.SMALL_FONT, text,
                            self.game.color(255,255,255), 'center')
     self.layer.move(1024/2, 5)