Esempio n. 1
0
 def update(self):
     self.animations[self.current_animation].update()
     SpriteControlled.update(self)
     if self.is_moving:
         self.current_animation = "walking"
     else:
         self.current_animation = "idle"
Esempio n. 2
0
class Level01(Scene):
    def __init__(self, background_file, ground_file):
        Scene.__init__(self, background_file, ground_file)
        _, screen_h = pygame.display.get_surface().get_size()
        ground_height = screen_h - self.ground.surface.get_height()
        self.ground.y = ground_height
        self.player = SpriteControlled(10, ground_height, 'sprite.png', True,
                                       2)
        self.cursor = Sprite(0, 0, 'cursor.png', False)
        self.warp = Warp(680, 0, 'warp.png', False, "level00")
        self.warp.y = ground_height - self.warp.surface.get_height() / 2

    def load(self):
        pass

    def inputs(self, events):
        for event in events:
            if event.type == pygame.MOUSEBUTTONDOWN:
                mouse_click = pygame.mouse.get_pos()
                self.player.move_to(mouse_click[0])

    def update(self, change_scene):
        self.cursor.set_position(pygame.mouse.get_pos())
        self.player.update()
        if self.player.intersects(self.warp):
            change_scene(self.warp.to_scene)

    def draw(self, screen):
        self.background.draw(screen)
        self.ground.draw(screen)
        self.warp.draw(screen)
        self.player.draw(screen)
        self.cursor.draw(screen)
Esempio n. 3
0
class Scene:
    def __init__(self, name, background_file, ground_file):
        self.name = name
        self.background = Sprite(0, 0, background_file, False)
        self.ground = Sprite(0, 0, ground_file, False)
        screen_w, screen_h = pygame.display.get_surface().get_size()
        ground_height = screen_h - self.ground.surface.get_height()
        self.ground.y = ground_height

        self.player = SpriteControlled(10, ground_height, 'sprite.png', True,
                                       2)
        self.cursor = Sprite(0, 0, 'cursor.png', False)

    def load(self):
        pass

    def inputs(self, events):
        for event in events:
            if event.type == pygame.MOUSEBUTTONDOWN:
                mouse_click = pygame.mouse.get_pos()
                self.player.move_to(mouse_click[0])

    def update(self):
        self.cursor.set_position(pygame.mouse.get_pos())
        self.player.update()

    def draw(self, screen):
        self.background.draw(screen)
        self.ground.draw(screen)
        self.player.draw(screen)
        self.cursor.draw(screen)
Esempio n. 4
0
def main():

    #Load
    pygame.init()
    screen = pygame.display.set_mode((800,600))
    font = pygame.font.Font(None,24)   

    background = pygame.image.load('background.png').convert()
    ground = pygame.image.load('ground.png').convert()
    ground_height = 600 - ground.get_height()
    
    player = SpriteControlled(100, ground_height, 'sprite.png', True, 2)
    copain = Sprite(500, ground_height, 'copain.png', True)

    mouse_click = (0, 0)

    collision_text = font.render("Oops, sorry!", False, (0,0,0))
    
    cursor = Sprite(0,0, 'cursor.png', False)
    pygame.mouse.set_visible(False)

    quit_game = False

    while not quit_game:
        #Inputs/
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    quit_game = True
            if event.type == pygame.MOUSEBUTTONDOWN:
                mouse_click = pygame.mouse.get_pos()
                player.move_to(mouse_click[0])

        
        #Update
        cursor.set_position(pygame.mouse.get_pos())
        player.update()

        #Draw
        screen.fill((0,0,0))
        screen.blit(background,(0,0))
        screen.blit(ground,(0, 500))   

        copain.draw(screen)
        player.draw(screen)
        if(player.intersects(copain)):
            screen.blit(collision_text, (player.x, player.y - 100))
        cursor.draw(screen)
        
        pygame.display.update()
Esempio n. 5
0
def main():

    # Load
    pygame.init()
    screen = pygame.display.set_mode((800, 600))
    font = pygame.font.Font(None, 24)

    path = 'D:\\Code\\ArtFx\\Python\\python-training\\01.adventure\\07.copain\\'
    background = pygame.image.load(path+'background.png').convert()
    ground = pygame.image.load(path+'ground.png').convert()

    mouse_click = (0, 0)

    player = SpriteControlled(100, 400, 'sprite.png', 2)
    copain = Sprite(500, 400, 'copain.png')
    cursor = Sprite(0, 0, 'cursor.png')
    pygame.mouse.set_visible(False)
    collision_text = font.render("Oops, sorry.", False, (0, 0, 0))

    quit_game = False

    while not quit_game:
        # Inputs
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                quit_game = True
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    quit_game = True
            if event.type == pygame.MOUSEBUTTONDOWN:
                mouse_click = pygame.mouse.get_pos()
                player.move_to(mouse_click[0])

        # Update
        cursor.set_position(pygame.mouse.get_pos())
        player.update()
        
        # Draw
        screen.fill((0, 0, 0))
        screen.blit(background, (0, 0))
        screen.blit(ground, (0, 500))

        copain.draw(screen)
        player.draw(screen)
        if(player.intersects(copain)):
            screen.blit(collision_text, (player.x, player.y - 100))
        cursor.draw(screen)
        
        pygame.display.update()
Esempio n. 6
0
def main():

    #Load
    pygame.init()
    screen = pygame.display.set_mode((800, 600))
    font = pygame.font.Font(None, 24)
    pygame.mouse.set_visible(False)
    player = SpriteControlled(100, 400, 'player.png', 2)
    quit = False

    #Text
    col_text = font.render("Im walking over here!", False, (0, 0, 0))

    #Paths
    path = 'D:\\AdventureGame\\'
    background = pygame.image.load(path + 'background.png').convert()
    ground = pygame.image.load(path + 'ground.png').convert()
    #player = Sprite(100,400,"player.png")
    friend = Sprite(500, 400, "friend.png", 2)
    cursor = pygame.image.load(path + 'mouse.png').convert_alpha()

    while not (quit):
        #Inputs
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    quit = True
            if event.type == pygame.MOUSEBUTTONDOWN:
                cursor_pos = pygame.mouse.get_pos()
                player.move_to(cursor_pos[0])

        #Update

        player.update()

        cursor_pos = pygame.mouse.get_pos()

        #Draw
        screen.fill((0, 0, 0))  #screen color, 0,0,0 is black
        screen.blit(background, (0, 0))
        screen.blit(ground, (0, 424))
        player.draw(screen)
        friend.draw(screen)
        if (player.intersects(friend)):
            screen.blit(col_text, (player.x, player.y - 100))
        screen.blit(cursor, cursor_pos)
        pygame.display.update()  #changes screen to new updated one
Esempio n. 7
0
class Scene:
    
    def __init__(self, background_file, ground_file):
        self.background = Sprite(0, 0, background_file, False)
        self.ground = Sprite(0, 0, ground_file, False)
        screen_w, screen_h = pygame.display.get_surface().get_size()
        ground_height = screen_h - self.ground.surface.get_height()
        self.ground.y = ground_height
        self.player = SpriteControlled(150, ground_height, 'Sprite.png', True, 2)
        self.copain = SpriteControlled(500, ground_height, 'copain.png', True, 0)
        self.cursor = Sprite(0, 0, 'cursor.jpg', False)
        #self.collision_text = font.render("Oops sorry Mamen", False,(0, 0,0))
        self.warp = Warp(700, 0, 'warp.png', False, "level01")
        self.warp.y = ground_height - self.warp.surface.get_height() / 2

    def load(self):
        pass

    def inputs(self, events):
        for event in events:
            if event.type == pygame.MOUSEBUTTONDOWN:
                mouse_click = pygame.mouse.get_pos()
                self.player.move_to(mouse_click[0])

    def update(self, change_scene):
        self.cursor.set_position(pygame.mouse.get_pos())
        self.player.update()
        if(self.player.intersects(self.warp)):
            
            change_scene(self.warp.to_scene)

        #if(self.player.intersects(self.copain)):
            #screen.blit(self.collision_text,(self.copain_x, self.copain_y - 100))

            

    def draw(self, screen):
        self.background.draw(screen)
        self.ground.draw(screen)
        self.warp.draw(screen)
        self.player.draw(screen)
        self.cursor.draw(screen)
        self.copain.draw(screen)
Esempio n. 8
0
class Scene:

    path = 'D:\\Code\\ArtFx\\Python\\python-training\\01.adventure\\26.etat_sprite\\data\\'

    def __init__(self, filename, inventory):
        self.inventory = inventory
        self.filename = filename
        self.load(filename)

    def load(self, filename):
        file = open(Scene.path + filename)
        data = file.read().splitlines()

        ground_height = 0
        self.cursor = Sprite(0, 0, 'cursor.png', False)
        self.sprites = []
        self.state_sprites = []
        self.warps = []
        self.pickables = []

        self.ui_top = UiGroup()
        panel = UiPanel(0, 0, 800, 110)
        self.ui_top.add_element(panel)

        for line in data:
            cell = line.split(";")
            # Ground
            if (cell[0] == "ground"):
                self.ground = Sprite(0, 0, cell[1] + ".png", False)
                _, screen_h = pygame.display.get_surface().get_size()
                ground_height = screen_h - self.ground.surface.get_height()
                self.ground.y = ground_height
            # Background
            elif (cell[0] == "background"):
                self.background = Sprite(0, 0, cell[1] + ".png", False)
            # Player
            elif (cell[0] == "player"):
                height = 0
                if cell[3] == "ground":
                    height = -1
                self.player = SpriteControlled(int(cell[2]), height,
                                               cell[1] + ".png", True,
                                               int(cell[4]))
            # Sprites
            elif (cell[0] == "sprite"):
                height = 0
                if cell[3] == "ground":
                    height = -1
                sprite = Sprite(int(cell[2]), height, cell[1] + ".png", True)
                self.sprites.append(sprite)
            # Stateful sprites
            elif (cell[0] == "stateful"):
                height = 0
                if cell[3] == "ground":
                    height = -1
                sprite = SpriteStateful(int(cell[2]), height, eval(cell[1]),
                                        True, eval(cell[4]), cell[5])
                self.state_sprites.append(sprite)
            # Warps
            elif (cell[0] == "warp"):
                height = 0
                if cell[3] == "ground":
                    height = -1
                warp = Warp(int(cell[2]), height, cell[1] + ".png", False,
                            eval(cell[4]))
                self.warps.append(warp)
            # Items
            elif (cell[0] == "pickable"):
                height = 0
                if cell[3] == "ground":
                    height = -1
                item = SpritePickable(int(cell[2]), height,
                                      cell[1] + "_ingame.png", False, cell[1])
                self.pickables.append(item)

        # Set heights
        if (self.player.y == -1):
            self.player.y = ground_height
        for s in self.sprites:
            if (s.y == -1):
                s.y = ground_height
        for s in self.state_sprites:
            if (s.y == -1):
                s.y = ground_height
        for w in self.warps:
            if (w.y == -1):
                w.y = ground_height - w.surface.get_height() / 2
        for p in self.pickables:
            if (p.y == -1):
                p.y = ground_height - p.surface.get_height()

    def after_change(self):
        self.update_inventory_ui()

    def inputs(self, events):
        for event in events:
            if event.type == pygame.MOUSEBUTTONDOWN:
                mouse_click = pygame.mouse.get_pos()
                if (mouse_click[1] >
                        self.ui_top.elements[0].h):  # Dirty but effective
                    self.player.move_to(mouse_click[0])
            if event.type == pygame.KEYDOWN:
                keys = pygame.key.get_pressed()
                if keys[pygame.K_F5]:
                    self.load(self.filename)
                    self.after_change()
        self.ui_top.inputs(events)

    def update(self, change_scene):
        self.cursor.set_position(pygame.mouse.get_pos())
        self.player.update()
        for w in self.warps:
            if (self.player.intersects(w)):
                change_scene(w.to_scene, w.to_scene_x)
        for p in self.pickables:
            if (self.player.intersects(p) and not (p.is_picked)):
                self.add_to_inventory(p.pick())
        self.ui_top.update()

    def add_to_inventory(self, item):
        self.inventory.append(item)
        self.update_inventory_ui()

    def update_inventory_ui(self):
        i = 0
        for item in self.inventory:
            x = i * 95 + 10
            y = 10
            w = 90
            h = 90
            self.ui_top.add_element(UiButton(x, y, w, h, item))
            i = i + 1

    def draw(self, screen):
        self.background.draw(screen)
        self.ground.draw(screen)
        for w in self.warps:
            w.draw(screen)
        for p in self.pickables:
            p.draw(screen)
        for s in self.sprites:
            s.draw(screen)
        for s in self.state_sprites:
            s.draw(screen)
        self.player.draw(screen)
        self.ui_top.draw(screen)
        self.cursor.draw(screen)
Esempio n. 9
0
class Scene:

    path = 'D:\\Code\\ArtFx\\Python\\python-training\\01.adventure\\22.rangement\\data\\'

    def __init__(self, filename):
        self.filename = filename
        self.load(filename)

    def load(self, filename):
        file = open(Scene.path + filename)
        data = file.read().splitlines()

        ground_height = 0
        self.cursor = Sprite(0, 0, 'cursor.png', False)
        self.sprites = []
        self.warps = []

        self.ui_top = UiGroup()
        panel = UiPanel(0, 0, 800, 110)
        button = UiButton(10, 10, 90, 90, "banana")
        self.ui_top.add_element(panel)
        self.ui_top.add_element(button)

        for line in data:
            cell = line.split(";")
            # Ground
            if (cell[0] == "ground"):
                self.ground = Sprite(0, 0, cell[1] + ".png", False)
                _, screen_h = pygame.display.get_surface().get_size()
                ground_height = screen_h - self.ground.surface.get_height()
                self.ground.y = ground_height
            # Background
            elif (cell[0] == "background"):
                self.background = Sprite(0, 0, cell[1] + ".png", False)
            # Player
            elif (cell[0] == "player"):
                height = 0
                if cell[3] == "ground":
                    height = -1
                self.player = SpriteControlled(int(cell[2]), height,
                                               cell[1] + ".png", True,
                                               int(cell[4]))
            # Sprites
            elif (cell[0] == "sprite"):
                height = 0
                if cell[3] == "ground":
                    height = -1
                sprite = Sprite(int(cell[2]), height, cell[1] + ".png", True)
                self.sprites.append(sprite)
            # Warps
            elif (cell[0] == "warp"):
                height = 0
                if cell[3] == "ground":
                    height = -1
                warp = Warp(int(cell[2]), height, cell[1] + ".png", False,
                            eval(cell[4]))
                self.warps.append(warp)

        # Set heights
        if (self.player.y == -1):
            self.player.y = ground_height
        for s in self.sprites:
            if (s.y == -1):
                s.y = ground_height
        for w in self.warps:
            if (w.y == -1):
                w.y = ground_height - w.surface.get_height() / 2

    def inputs(self, events):
        for event in events:
            if event.type == pygame.MOUSEBUTTONDOWN:
                mouse_click = pygame.mouse.get_pos()
                if (mouse_click[1] >
                        self.ui_top.elements[0].h):  # Dirty but effective
                    self.player.move_to(mouse_click[0])
            if event.type == pygame.KEYDOWN:
                keys = pygame.key.get_pressed()
                if keys[pygame.K_F5]:
                    self.load(self.filename)
        self.ui_top.inputs(events)

    def update(self, change_scene):
        self.cursor.set_position(pygame.mouse.get_pos())
        self.player.update()
        for w in self.warps:
            if (self.player.intersects(w)):
                change_scene(w.to_scene, w.to_scene_x)
        self.ui_top.update()

    def draw(self, screen):
        self.background.draw(screen)
        self.ground.draw(screen)
        for w in self.warps:
            w.draw(screen)
        for s in self.sprites:
            s.draw(screen)
        self.player.draw(screen)
        self.ui_top.draw(screen)
        self.cursor.draw(screen)
Esempio n. 10
0
class Scene:

    path = 'D:\\JONES_Dean\\pythonAdventure\\AdventureGame\\Images\\'
    path = 'D:\\JONES_Dean\\pythonAdventure\\AdventureGame\\Data\\'

    def __init__(self, filename):
        self.filename = filename
        self.load(filename)

    def load(self, filename):
        file = open(Scene.path + filename)
        data = file.read().splitlines()

        #self.panel = UiPanel(0, 0, 800, 100)
        #self.button = UiButton(10, 10, 80, 80)

        ground_height = 0
        self.cursor = Sprite(0, 0, 'cursor.png', False)
        self.sprites = []
        self.warps = []

        self.ui_top = UiGroup()
        panel = UiPanel(0, 0, 800, 100)
        button = UiButton(10, 10, 80, 80, filename)
        self.ui_top.add_element(panel)
        self.ui_top.add_element(button)

        collision_text = font.render("Oops, my bad!", False, (0, 0, 0))

        for line in data:
            cell = line.split(";")

            # Ground

            if (cell[0] == "ground"):
                self.ground = Sprite(0, 0, cell[1] + ".png", False)
                _, screen_h = pygame.display.get_surface().get_size()
                ground_height = screen_h - self.ground.surface.get_height()
                self.ground.y = ground_height

            # Background

            elif (cell[0] == "background"):
                self.background = Sprite(0, 0, cell[1] + ".png", False)

            # Hero

            elif (cell[0] == "hero"):
                height = 0
                if cell[3] == "ground":
                    height = -1
                self.hero = SpriteControlled(int(cell[2]), height,
                                             cell[1] + ".png", True,
                                             int(cell[4]))

            # Sprites

            elif (cell[0] == "sprite"):
                height = 0
                if cell[3] == "ground":
                    height = -1
                sprite = Sprite(int(cell[2]), height, cell[1] + ".png", True)
                self.sprites.append(sprite)

            # Warps

            elif (cell[0] == "warp"):
                height = 0
                if cell[3] == "ground":
                    height = -1
                warp = Warp(int(cell[2]), height, cell[1] + ".png", False,
                            cell[4])
                self.warps.append(warp)

        # Set heights

        if (self.hero.y == -1):
            self.hero.y = ground_height
        for s in self.sprites:
            if (s.y == -1):
                s.y = ground_height
        for w in self.warps:
            if (w.y == -1):
                w.y = ground_height - w.surface.get_height() / 2

    def inputs(self, events):
        for event in events:
            if event.type == pygame.MOUSEBUTTONDOWN:
                mouse_click = pygame.mouse.get_pos()
                if (mouse_click[1] > self.ui_top.elements[0].h
                    ):  #trick to not move player on button click
                    self.hero.move_to(mouse_click[0])
            if event.type == pygame.KEYDOWN:
                keys = pygame.key.get_pressed()
                if keys[pygame.K_F5]:
                    self.load(self.filename)
        self.ui_top.inputs(events)

    def update(self, change_scene):
        self.cursor.set_position(pygame.mouse.get_pos())
        self.hero.update()
        for w in self.warps:
            if (self.hero.intersects(w)):
                change_scene(w.to_scene)

        #self.panel.update()
        self.ui_top.update()

    def draw(self, screen):
        self.background.draw(screen)
        self.ground.draw(screen)
        for w in self.warps:
            w.draw(screen)
        for s in self.sprites:
            s.draw(screen)

            if (self.hero.intersects(s)):
                screen.blit(collision_text, (self.hero.x, self.hero.y - 100))
                #print("Collision")

        self.hero.draw(screen)

        #self.panel.draw(screen)
        self.ui_top.draw(screen)
        self.cursor.draw(screen)