Exemple #1
0
        def dragon_hit():
            #I extracted the GIF Frames from my gif img of 8bit explosion and placed in nan/images/gifframes
            #Total of 23 frames, I will do for i in range(23) and update the image for each frame. Delay 0.05s
            #Create Entities
            frame = 1
            
            explosion1 = create_entity(self.world,"gifframes/frame_0_delay-0.05s.png",pygame.Rect(853,121,80,80))
            
            time.sleep(0.5)
            self.world.component_for_entity(explosion1,components.Image).image = pygame.image.load("images/gifframes/frame_" + str(frame) + "_delay-0.05s.png")
            frame=frame+1
                
                
                
            
            self.world.component_for_entity(dragon, components.Animation).frame = 1
            damage = notify(self.world, self.font, "999,999,999,999,999,999", self, text.TextScene("And thusly the skilled adventurer NaN took out yet another dragon. Dragon killing was no longer a dangerous quest but rather routine cleaning. With the dragon population dwindling NaN had time to help more people with their non life threatening problems.", SceneTwo()))
            image = self.font.render("999,999,999,999,999,999", False, (255, 128, 0))

            self.world.component_for_entity(damage, components.Image).image = image
            self.world.component_for_entity(damage, components.Position).x = 960
            self.world.component_for_entity(damage, components.Position).y = 320
            self.world.component_for_entity(damage, components.Size).width = image.get_width()
            self.world.component_for_entity(damage, components.Size).height = image.get_height()
        
            pygame.mixer.Sound(os.path.join(components.get_base_path(), 'audio', 'dragon.ogg')).play()
Exemple #2
0
 def dragon_hit():
     self.world.component_for_entity(dragon, components.Animation).frame = 1
     damage = notify(self.world, self.font, "Dragon Tamed", self, text.TextScene("Sadly, the dragon refused to be tamed. Instead, though, it granted NaN the power of fireballs! Let's see how this turns out...",SceneEight()))
     image = self.font.render("Dragon Tamed", False, (255, 128, 0))
     self.world.component_for_entity(damage, components.Image).image = image
     self.world.component_for_entity(damage, components.Position).x = 960
     self.world.component_for_entity(damage, components.Position).y = 320
     self.world.component_for_entity(damage, components.Size).width = image.get_width()
     self.world.component_for_entity(damage, components.Size).height = image.get_height()
     pygame.mixer.Sound(os.path.join(components.get_base_path(), 'audio', 'dragon.ogg')).play()
Exemple #3
0
def FireballMessage(world):
    #since this isnt a class, we have to manually get font.
    
    font_path_for_fireball = os.path.join(components.get_base_path(), "kenpixel.ttf")
    small_font_fire = pygame.font.Font(font_path_for_fireball, 16)
    bubble = create_entity(world, "speech.png", pygame.Rect(200, 100, 307, 173))
    world.add_component(bubble, components.Hang())
    image = world.component_for_entity(bubble, components.Image).image
    #I used random strs
    firetexts = ["AHHHHH HOW ARE YOU SHOOTING FIREBALLS AHHHHH!!!!!!!!!!","OH MY GOD HE IS A DEMON!!! RUN!!!","CALL THE FIRE DEPARTMENT NAN JUST SPIT UP A FIREBALL!!!!"]
    util.drawText(image,str(random.choice(firetexts)),(255, 255, 255), pygame.Rect(30, 20, 246, 134),small_font_fire)
Exemple #4
0
    def switch_to_scene(self, next_scene):
        if next_scene is not None:
            next_scene.init()

            if pygame.mixer.music.get_busy():
                pygame.mixer.music.fadeout(1000)
            if next_scene.bgm is not None:
                pygame.mixer.music.load(
                    os.path.join(components.get_base_path(), next_scene.bgm))
                pygame.mixer.music.play(-1)

        self.next = next_scene
Exemple #5
0
        def fade_scene():
            for ent in [text, continue_text]:
                if self.world.has_component(ent, components.ChangeAlpha):
                    self.world.remove_component(ent, components.ChangeAlpha)
                self.world.add_component(ent, components.ChangeAlpha(0, .5))
                self.world.add_component(
                    ent,
                    components.ChangePosition(
                        (640,
                         self.world.component_for_entity(
                             ent, components.Position).y + 50), .5))

            self.world.add_component(text, components.Delay(1, next_scene))
            pygame.mixer.Sound(
                os.path.join(components.get_base_path(), 'audio',
                             'click')).play()
Exemple #6
0
 def dragon_hit():
     self.world.component_for_entity(dragon,
                                     components.Animation).frame = 1
     damage = notify(
         self.world, self.font, "999,999,999,999,999,999", self,
         text.TextScene(
             "And thusly the skilled adventurer NaN took out yet another dragon. Dragon killing was no longer a dangerous quest but rather routine cleaning. With the dragon population dwindling NaN had time to help more people with their non life threatening problems.",
             SceneTwo()))
     image = self.font.render("999,999,999,999,999,999", False,
                              (255, 128, 0))
     self.world.component_for_entity(damage,
                                     components.Image).image = image
     self.world.component_for_entity(damage,
                                     components.Position).x = 960
     self.world.component_for_entity(damage,
                                     components.Position).y = 320
     self.world.component_for_entity(
         damage, components.Size).width = image.get_width()
     self.world.component_for_entity(
         damage, components.Size).height = image.get_height()
     pygame.mixer.Sound(
         os.path.join(components.get_base_path(), 'audio',
                      'dragon.ogg')).play()
Exemple #7
0
def run_game(width, height, titletext, fps, starting_scene):
    pygame.init()
    screen = pygame.display.set_mode((width, height), pygame.RESIZABLE)
    small_screen = pygame.Surface((1280, 720)).convert()
    pygame.display.set_caption(titletext)
    clock = pygame.time.Clock()
    pygame.mixer.init()

    font_path = os.path.join(components.get_base_path(), "kenpixel.ttf")
    font = pygame.font.Font(font_path, 42)
    small_font = pygame.font.Font(font_path, 16)
    large_font = pygame.font.Font(font_path, 72)
    titlefont = pygame.font.Font(font_path, 144)
    scenebase.SceneBase.font = font
    scenebase.SceneBase.small_font = small_font
    scenebase.SceneBase.large_font = large_font
    scenebase.SceneBase.titlefont = titlefont

    starting_scene.init()
    active_scene = starting_scene

    bg = pygame.image.load(
        os.path.join(components.get_base_path(), 'images',
                     'menubg.png')).convert()

    while active_scene is not None:
        dt = clock.tick(fps)

        # event handling
        filtered_events = []
        pressed_keys = pygame.key.get_pressed()
        for event in pygame.event.get():
            quit_attempt = False
            if event.type == pygame.QUIT:
                quit_attempt = True
            elif event.type == pygame.KEYDOWN:
                alt_pressed = pressed_keys[pygame.K_LALT] or \
                              pressed_keys[pygame.K_RALT]
                if event.key == pygame.K_ESCAPE:
                    active_scene.switch_to_scene(title.TitleScene())
                elif event.key == pygame.K_F4 and alt_pressed:
                    quit_attempt = True
            elif event.type == pygame.VIDEORESIZE:
                screen = pygame.display.set_mode(event.size, pygame.RESIZABLE)

            if quit_attempt:
                active_scene.terminate()
            else:
                filtered_events.append(event)

        small_screen.blit(bg, (0, 0))

        active_scene.world.process(filtered_events, pressed_keys, dt / 1000,
                                   small_screen)

        screen.blit(pygame.transform.scale(small_screen, screen.get_size()),
                    (0, 0))

        text = small_font.render("FPS: " + str(int(1000 * 1 // dt)), True,
                                 (128, 255, 128))
        screen.blit(text, (10, 10))

        if active_scene is not active_scene.next:
            clock.tick(fps)

        active_scene = active_scene.next

        pygame.display.flip()