Beispiel #1
0
 def __title_screen(self):
     path = rospack.get_path('uchile_fun')
     path += "/src/uchile_fun/SwervinMervin/"
     title_screen = ts.TitleScreen()
     pygame.mixer.music.load(os.path.join(path + "lib", "mn84-theme.ogg"))
     pygame.mixer.music.play(-1)
     self.__progress(title_screen, s.TITLE_FPS)
Beispiel #2
0
 def handle_keyboard_event(self, event):
     if event.type == pygame.KEYDOWN:
         if event.key == pygame.K_ESCAPE:
             LevelManager().leave_level()
             LevelManager().load_level(title_screen.TitleScreen())
         if event.key == pygame.K_p:
             LevelManager().leave_level()
             player = Player()
             LevelManager().load_level(game_screen.GameScreen(player, 1))
Beispiel #3
0
 def handle_keyboard_event(self, event):
     if event.type == pygame.KEYDOWN:
         if event.key == pygame.K_ESCAPE:         
             LevelManager().leave_level()
             LevelManager().load_level(title_screen.TitleScreen())
         elif event.key == pygame.K_LEFT or event.key == pygame.K_a:
             self.player.move_left()
             self.left_keyDown = True
             # self.pixel.move_left()
         elif event.key == pygame.K_RIGHT or event.key == pygame.K_d:
             self.player.move_right()
             self.right_keyDown = True
             # self.pixel.move_right()
         elif event.key == pygame.K_UP or event.key == pygame.K_w:
             self.player.move_up()
             self.up_keyDown = True
             # self.pixel.move_up()
         elif event.key == pygame.K_DOWN or event.key == pygame.K_s:
             self.player.move_down()
             self.down_keyDown = True
             #self.pixel.move_down()
         elif event.key == pygame.K_SPACE:
             self.buy = True
         elif event.key == pygame.K_p:
             LevelManager().leave_level()
             self.player.inventory.purse.money = 0
             LevelManager().load_level(game_screen.GameScreen(self.player, self.level))
         
         
             
     elif event.type == pygame.KEYUP:
         if (event.key == pygame.K_LEFT or event.key == pygame.K_a):
             self.left_keyDown = False
             if(not self.right_keyDown):
                 self.player.stop_x()
             else:
                 self.player.move_right()
         elif (event.key == pygame.K_RIGHT or event.key == pygame.K_d):
             self.right_keyDown = False
             if (not self.left_keyDown):
                 self.player.stop_x()
             else:
                 self.player.move_left()
         elif event.key == pygame.K_UP or event.key == pygame.K_w:
             self.up_keyDown = False
             if(not self.down_keyDown):
                 self.player.stop_y()
             else:
                 self.player.move_down()
         elif event.key == pygame.K_DOWN  or event.key == pygame.K_s:
             self.down_keyDown = False
             if (not self.up_keyDown):
                 self.player.stop_y()
             else:
                 self.player.move_up()
Beispiel #4
0
    def main(self):

        self.state = tit.TitleScreen(self)

        while not self.end:

            self.update()

            self.draw()
            pygame.display.update()

            self.clock.tick(FPS)
            self.handle_input()
    def handle_keyboard_event(self, event):
        #KEYDOWN EVENTS
        if event.type == pygame.KEYDOWN:
            #ESCAPE TO TITLE SCREEN
            if event.key == pygame.K_ESCAPE:
                LevelManager().leave_level()
                self.player = Player()
                LevelManager().load_level(title_screen.TitleScreen())
                for tile in self.tile_list:
                    tile.is_plantable = True

            #F TO ATTACK
            elif event.key == pygame.K_f:
                self.player.is_swinging = True
                self.hit_time_start = pygame.time.get_ticks()
                #starts the attack animation
                self.player.attack_anim.play()
                self.player.attack_right_anim.play()

            #MOVEMENT LEFT, RIGHT, UP, DOWN
            elif event.key == pygame.K_LEFT or event.key == pygame.K_a:
                self.player.move_left()
                self.left_keyDown = True
            elif event.key == pygame.K_RIGHT or event.key == pygame.K_d:
                self.player.move_right()
                self.right_keyDown = True
            elif event.key == pygame.K_UP or event.key == pygame.K_w:
                self.player.move_up()
                self.up_keyDown = True
            elif event.key == pygame.K_DOWN or event.key == pygame.K_s:
                self.player.move_down()
                self.down_keyDown = True
            #CYCLE INVENTORY
            elif event.key == pygame.K_1:
                self.player.cycle_inventory(1)
            elif event.key == pygame.K_2:
                self.player.cycle_inventory(2)
            elif event.key == pygame.K_3:
                self.player.cycle_inventory(3)
            elif event.key == pygame.K_4:
                self.player.cycle_inventory(4)
            elif event.key == pygame.K_5:
                self.player.cycle_inventory(5)
            elif event.key == pygame.K_SPACE:
                for tile in self.tile_list:
                    if pygame.sprite.collide_rect(self.pixel, tile) and tile.is_plantable == True:
                        planted = self.player.plant(tile.rect.x, tile.rect.y)
                        if (planted):
                            tile.is_plantable = False
                            
        #KEYUP EVENTS 
        elif event.type == pygame.KEYUP:
            if (event.key == pygame.K_LEFT or event.key == pygame.K_a):
                self.left_keyDown = False
                if(not self.right_keyDown):
                    self.player.stop_x()
                else:
                    self.player.move_right()
            elif (event.key == pygame.K_RIGHT or event.key == pygame.K_d):
                self.right_keyDown = False
                if (not self.left_keyDown):
                    self.player.stop_x()
                else:
                    self.player.move_left()
            elif event.key == pygame.K_UP or event.key == pygame.K_w:
                self.up_keyDown = False
                if(not self.down_keyDown):
                    self.player.stop_y()
                else:
                    self.player.move_down()
            elif event.key == pygame.K_DOWN  or event.key == pygame.K_s:
                self.down_keyDown = False
                if (not self.up_keyDown):
                    self.player.stop_y()
                else:
                    self.player.move_up()
Beispiel #6
0
 def __title_screen(self):
     title_screen = ts.TitleScreen()
     pygame.mixer.music.load(os.path.join("lib", "mn84-theme.ogg"))
     pygame.mixer.music.play(-1)
     self.__progress(title_screen, s.TITLE_FPS)