def __init__(self):
        WorldInterface.__init__(self)
        self.world_size = (1920, 1080)

        self.bg = Sprite(
            load_image('res/space.png'),
            Vec2(self.world_size[0] // 2, self.world_size[1] // 2),
            (self.world_size[0], self.world_size[1]))
        self.enter_planet = Sprite(
            load_image("res/press_space_to_continue1.png"), Vec2(0, 0),
            (250, 50))
        self.boss_planet = (Sprite(
            load_image('res/planet_final.png'),
            Vec2((self.world_size[0] // 2) + 250,
                 (self.world_size[1] // 2) - 150), (200, 200)), 0.5)
        self.player = [
            Sprite(load_image("res/spaceship2.png"),
                   Vec2(self.world_size[0] // 2, self.world_size[1] // 2),
                   (80, 80)), 48, True, 4
        ]  # Sprite, invincibility timer, which picture

        self.planets = []
        self.meteors = []
        self.spawn_planets(5)
        self.spawn_meteors(8)

        self.player_speed = 10
        self.player_rot_speed = 5

        self.meteor_speed = self.player_speed + 0.5
        self.meteor_rot_speed = 25
        self.planet_rot_speed = 0.3

        self.current_planet = None
        self.collided_meteor = False
    def __init__(self):
        WorldInterface.__init__(self)

        self.local_sprites = []
        self.local_sprites.append(
            Sprite(load_image("res/spoon_expansion_cutscene1.png"),
                   Vec2(320, 240), (640, 480)))
        self.local_sprites.append(
            Sprite(load_image("res/spoon_expansion_cutscene2.png"),
                   Vec2(320, 240), (640, 480)))
        self.local_sprites.append(
            Sprite(load_image("res/spoon_expansion_cutscene3.png"),
                   Vec2(320, 240), (640, 480)))
        self.local_sprites.append(
            Sprite(load_image("res/spoon_expansion_cutscene4.png"),
                   Vec2(320, 240), (640, 480)))
        self.local_sprites.append(
            Sprite(load_image("res/spoon_expansion_cutscene5.png"),
                   Vec2(320, 240), (640, 480)))

        self.states = {}
        self.states[0] = self.cutscene_begin
        self.states[1] = self.cutscene_startexpansion
        self.states[2] = self.cutscene_finalexpansion
        self.states[3] = self.cutscene_standstill
        self.states[4] = self.cutscene_party

        self.current_state = 0
        self.current_frame = 0
    def update(self, game_state):
        if game_state['keyboard']['ctrl-debug']:
            self.meteorites[:] = []

        if game_state['keyboard']['ctrl-up']:
            self.player[0].pos[0] -= self.player_speed * sin(
                radians(self.player[0].angle))
            self.player[0].pos[1] -= self.player_speed * cos(
                radians(self.player[0].angle))

            hw = self.player[0].size[0] // 2
            hh = self.player[0].size[1] // 2

            if self.player[0].pos[0] - hw < 0: self.player[0].pos[0] = hw
            if self.player[0].pos[1] - hh < 0: self.player[0].pos[1] = hh
            if self.player[0].pos[0] + hw > 640:
                self.player[0].pos[0] = 640 - hw
            if self.player[0].pos[1] + hh > 480:
                self.player[0].pos[1] = 480 - hh

        if game_state['keyboard']['ctrl-left']:
            self.player[0].angle += self.player_rot_speed
        if game_state['keyboard']['ctrl-right']:
            self.player[0].angle -= self.player_rot_speed

        self.player[2] -= 1
        if self.player[2] == 0:
            if self.player[1]:
                self.player[0].image = load_image('res/spaceship1.png')
            else:
                self.player[0].image = load_image('res/spaceship2.png')
            self.player[1] = not self.player[1]
            self.player[2] = 4

        hitbox_offset = 15
        player_pos = self.player[0].pos - Vec2(
            self.player[0].size[0] // 2, self.player[0].size[1] // 2) + Vec2(
                hitbox_offset, hitbox_offset)
        player_size = (self.player[0].size[0] - hitbox_offset,
                       self.player[0].size[1] - hitbox_offset)
        for meteor in reversed(self.meteorites):
            meteor_pos = meteor[0].pos - Vec2(meteor[0].size[0] // 2,
                                              meteor[0].size[1] // 2) + Vec2(
                                                  hitbox_offset, hitbox_offset)
            meteor_size = (meteor[0].size[0] - hitbox_offset,
                           meteor[0].size[1] - hitbox_offset)
            if collides_with(player_pos, player_size, meteor_pos, meteor_size):
                game_state['went-well'] = False
                return game_state['world-gameover']

            meteor[0].pos[1] += self.meteor_speed
            meteor[0].angle += meteor[1]
            if meteor[0].pos[1] > 500:
                self.meteorites.pop(self.meteorites.index(meteor))
                self.sprites.pop(self.sprites.index(meteor[0]))

        if len(self.meteorites) == 0:
            game_state['went-well'] = True
            return game_state['world-space']
    def __init__(self):
        WorldInterface.__init__(self)
        self.bg = Sprite(load_image('res/space.png'), Vec2(320, 240),
                         (640, 480))
        self.player = [
            Sprite(load_image('res/spaceship2.png'), Vec2(320, 400), (60, 60)),
            True, 4
        ]
        self.meteorites = []

        self.generate_meteorite_waves(randint(5, 10))
        self.meteor_speed = 5
        self.player_speed = 15
        self.player_rot_speed = 10
 def spawn_planets(self, amount):
     self.planets[:] = []  # Clear planets (just in case)
     size = (50, 50)
     for i in range(amount):
         rand = randint(1, 5)
         sprite = Sprite(load_image("res/planet" + str(rand) + ".png"),
                         self.random_pos(size), size)
         self.planets.append([sprite, True,
                              rand])  # Sprite, isEnterable, type
 def spawn_meteors(self, amount):
     self.meteors[:] = []  # Clear meteors (just in case)
     size = (25, 25)
     for i in range(amount):
         sprite = Sprite(
             load_image('res/asteroid' + str(randint(1, 4)) + '.png'),
             self.random_pos(size), size)
         self.meteors.append([sprite,
                              self.random_dir(),
                              randint(5, 10)
                              ])  # Sprite, move direction, time to move
Beispiel #7
0
    def __init__(self, flying_direction):
        WorldInterface.__init__(self)

        self.background_images = {}
        self.background_images["speedlines_vertical"] = load_image("res/speedlines_vertical.png")
        
        self.player_image = load_image("res/player_falling.png")

        self.whatever_idontcare = Sprite(self.background_images["speedlines_vertical"], Vec2(320, 240), (640, 480))
        self.local_sprites = {"speedlines_vertical": [Sprite(self.background_images["speedlines_vertical"], Vec2(320, 240), (640, 480)), \
                                                      Sprite(self.background_images["speedlines_vertical"], Vec2(320, 720), (640, 480))],\
                              "flyer": Sprite(self.player_image, Vec2(320, 240), (40, 62))}

        self.current_background = self.local_sprites["speedlines_vertical"]
        self.current_flyer = self.local_sprites["flyer"]

        # speed and rotation constants
        if flying_direction == "down":
            self.background_speed = -100
            self.flyer_speed = Vec2(0, 8)
            self.flyer_rotationspeed = 11
            self.flyer_rotationdirection = -1   # 1: counter-clockwise, -1: clockwise
            self.flyer_defaultpos = Vec2(320, -31)
            self.termination_check = lambda ypos: ypos > 480 + 31
        elif flying_direction == "up":
            self.background_speed = 100
            self.flyer_speed = Vec2(0, -20)
            self.flyer_rotationspeed = 100
            self.flyer_rotationdirection = 1   # 1: counter-clockwise, -1: clockwise
            self.flyer_defaultpos = Vec2(320, 480 + 31)
            self.termination_check = lambda ypos: ypos < -31

        self.flying_direction = flying_direction

        # positions
        self.flyer_pos = Vec2(0, 0)
        self.flyer_pos.x = self.flyer_defaultpos.x
        self.flyer_pos.y = self.flyer_defaultpos.y
    def generate_meteorite_waves(self, amount):
        self.meteorites[:] = []

        for i in range(amount):
            last_x = 0
            y = (-i * 250)
            free_space = self.generate_free_space(y)
            while True:
                meteor = Sprite(load_image('res/asteroid2.png'),
                                Vec2(last_x + 50, y), (50, 50))
                if collides_with(meteor.pos, meteor.size, free_space[0],
                                 free_space[1]):
                    meteor.pos[0] += free_space[1][0]
                last_x = meteor.pos[0]
                self.meteorites.append(
                    (meteor, randint(1, 5)))  # Sprite, rot speed

                if meteor.pos[0] + meteor.size[0] > 640: break
Beispiel #9
0
    def __init__(self):
        WorldInterface.__init__(self)

        self.local_backgrounds = {}
        self.local_backgrounds["space"] = Sprite(load_image("res/space.png"),
                                                 Vec2(320, 240), (640, 480))
        self.local_backgrounds["onplanet"] = Sprite(
            load_image("res/onplanet_final.png"), Vec2(320, 240), (640, 480))

        self.local_sprites = {}
        self.local_sprites["player_falling"] = Sprite(
            load_image("res/player_falling.png"), Vec2(100, -31), (40, 62))

        self.walker_pos = Vec2(80, 380)
        self.eater_pos = Vec2(510, 380)
        self.planet_pos = Vec2(320, 240)
        self.planet_current = 0
        self.spaceship_pos = Vec2(320, 240)
        self.spaceship_speed = Vec2(12, -12)
        self.local_sprites["player_walking_body"] = []
        self.local_sprites["player_walking_body"].append(
            Sprite(load_image("res/player_large_body_walk2.png"),
                   self.walker_pos, (100, 62)))
        self.local_sprites["player_walking_body"].append(
            Sprite(load_image("res/player_large_body_walk1.png"),
                   self.walker_pos, (100, 62)))
        self.local_sprites["player_walking_body"].append(
            Sprite(load_image("res/player_large_body_eat1.png"),
                   self.walker_pos, (100, 62)))
        self.local_sprites["player_walking_body"].append(
            Sprite(load_image("res/player_large_body_eat2.png"),
                   self.walker_pos, (100, 62)))

        self.local_sprites["player_walking_legs"] = []
        self.local_sprites["player_walking_legs"].append(
            Sprite(load_image("res/player_legs1.png"), self.walker_pos,
                   (100, 62)))
        self.local_sprites["player_walking_legs"].append(
            Sprite(load_image("res/player_legs2.png"), self.walker_pos,
                   (100, 62)))

        self.local_sprites["planet"] = []
        self.local_sprites["planet"].append(
            Sprite(load_image("res/planet_final.png"), self.planet_pos,
                   (110, 110)))
        self.local_sprites["planet"].append(
            Sprite(load_image("res/planet_final_eaten1.png"), self.planet_pos,
                   (110, 110)))
        self.local_sprites["planet"].append(
            Sprite(load_image("res/planet_final_eaten2.png"), self.planet_pos,
                   (110, 110)))
        self.local_sprites["planet"].append(
            Sprite(load_image("res/planet_final_eaten3.png"), self.planet_pos,
                   (110, 110)))
        self.local_sprites["planet"].append(
            Sprite(load_image("res/planet_final_eaten4.png"), self.planet_pos,
                   (110, 110)))
        self.local_sprites["planet"].append(
            Sprite(load_image("res/planet_final_eaten5.png"), self.planet_pos,
                   (110, 110)))
        self.local_sprites["planet"].append(
            Sprite(load_image("res/planet_final_eaten6.png"), self.planet_pos,
                   (110, 110)))
        self.local_sprites["planet"].append(
            Sprite(load_image("res/planet_final_eaten7.png"), self.planet_pos,
                   (110, 110)))
        self.local_sprites["planet"].append(
            Sprite(load_image("res/planet_final_eaten8.png"), self.planet_pos,
                   (110, 110)))
        self.local_sprites["planet"].append(
            Sprite(load_image("res/planet_final_eaten9.png"), self.planet_pos,
                   (110, 110)))

        self.local_sprites["spaceship"] = []
        self.local_sprites["spaceship"].append(
            Sprite(load_image("res/spaceship1.png"), self.spaceship_pos,
                   (80, 80), -45))
        self.local_sprites["spaceship"].append(
            Sprite(load_image("res/spaceship2.png"), self.spaceship_pos,
                   (80, 80), -45))

        self.spaceship_speed_start = Vec2(12, 12)
        self.spaceship_pos_start = Vec2(-100, -160)
        self.local_sprites["spaceship_1"] = []
        self.local_sprites["spaceship_1"].append(
            Sprite(load_image("res/spaceship1.png"), self.spaceship_pos_start,
                   (80, 80), -135))
        self.local_sprites["spaceship_1"].append(
            Sprite(load_image("res/spaceship2.png"), self.spaceship_pos_start,
                   (80, 80), -135))

        self.states = {}
        self.states[0] = self.cutscene_approaching
        self.states[1] = self.cutscene_falling
        self.states[2] = self.cutscene_walking
        self.states[3] = self.cutscene_eating
        self.states[4] = self.cutscene_planeteating
        self.states[5] = self.cutscene_eating
        self.states[6] = self.cutscene_planeteating
        self.states[7] = self.cutscene_eating
        self.states[8] = self.cutscene_planeteating
        self.states[9] = self.cutscene_thefinalbite

        self.current_state = 0
        self.current_frame = 0
    def update(self, game_state):
        if len(self.sprites) == 0:
            self.set_sprites()
            self.set_camera(game_state)

        # Update player
        if game_state['keyboard']['ctrl-up']:
            self.player[0].pos[0] -= self.player_speed * sin(
                radians(self.player[0].angle))
            self.player[0].pos[1] -= self.player_speed * cos(
                radians(self.player[0].angle))

            hw = self.player[0].size[0] // 2
            hh = self.player[0].size[1] // 2

            if self.player[0].pos[0] - hw < 0: self.player[0].pos[0] = hw
            if self.player[0].pos[1] - hh < 0: self.player[0].pos[1] = hh
            if self.player[0].pos[0] + hw > self.world_size[0]:
                self.player[0].pos[0] = self.world_size[0] - hw
            if self.player[0].pos[1] + hh > self.world_size[1]:
                self.player[0].pos[1] = self.world_size[1] - hh

            self.set_camera(game_state)

        self.player[3] -= 1
        if self.player[3] == 0:
            if self.player[2]:
                self.player[0].image = load_image('res/spaceship1.png')
            else:
                self.player[0].image = load_image('res/spaceship2.png')
            self.player[2] = not self.player[2]
            self.player[3] = 4

        self.player[
            1] -= 1 if self.player[1] != 0 else 0  # invincibility timer
        if self.player[1] != 0 and self.player[1] % 3 == 0:
            self.player[0].image = None
        elif self.player[0].image == None:
            self.player[0].image = load_image('res/spaceship2.png')

        if game_state['keyboard']['ctrl-left']:
            self.player[0].angle += self.player_rot_speed
        if game_state['keyboard']['ctrl-right']:
            self.player[0].angle -= self.player_rot_speed

        # Update meteors + collision
        for meteor in self.meteors:
            if collides_with(self.player[0].pos, self.player[0].size,
                             meteor[0].pos,
                             meteor[0].size) and self.player[1] == 0:
                self.collided_meteor = True
            meteor[0].pos = meteor[0].pos - (meteor[1] * self.meteor_speed)
            meteor[0].angle += self.meteor_rot_speed
            meteor[2] -= 1
            if meteor[2] == 0:
                meteor[1] = self.random_dir()
                meteor[2] = randint(5, 10)

        if self.collided_meteor: return game_state['world-meteor']

        # Update planets, detect if close to landable planet
        can_land_on = None
        for index, planet in enumerate(self.planets):
            planet[0].angle += self.planet_rot_speed
            if collides_with(self.player[0].pos, self.player[0].size,
                             planet[0].pos, planet[0].size) and planet[1]:
                can_land_on = index

        # Boss planet
        self.boss_planet[0].angle += self.boss_planet[1]
        self.boss_planet[
            0].pos = self.boss_planet[0].pos + self.random_dir() * 2
        if game_state['spoon-pwr'] >= 5 and collides_with(
                self.player[0].pos, self.player[0].size,
                self.boss_planet[0].pos, self.boss_planet[0].size):
            can_land_on = -1

        # Detect if landing on planet
        if can_land_on is not None and game_state['keyboard']['ctrl-action']:
            self.current_planet = can_land_on
            if can_land_on != -1:
                game_state['identifier'] = self.planets[can_land_on][2]
                return game_state['world-cutscene']['falling']
            else:
                return game_state['world-cutscene']['end']

        # Set "Enter planet" prompt to render
        if can_land_on is not None:
            if self.enter_planet.image is None:
                self.enter_planet.image = load_image(
                    'res/press_space_to_continue1.png')
            self.enter_planet.pos[0] = self.player[0].pos[0]
            self.enter_planet.pos[
                1] = self.player[0].pos[1] - self.player[0].size[1]
        else:
            self.enter_planet.image = None
 def __init__(self):
     WorldInterface.__init__(self)
     
     #load all res
     self.res = {}
     self.res['bgs'] = [load_image("res/onplanet1.png"), \
                        load_image("res/onplanet2.png"), \
                        load_image("res/onplanet3.png"), \
                        load_image("res/onplanet4.png"),
                        load_image("res/onplanet5.png")]
     
     self.res['player'] = [load_image("res/player_small_body_walk1.png"), \
                           load_image("res/player_small_body_walk2.png"), \
                           load_image("res/player_small_body_eat1.png"), \
                           load_image("res/player_small_body_eat2.png"), \
                           load_image("res/player_medium_body_walk1.png"), \
                           load_image("res/player_medium_body_walk2.png"), \
                           load_image("res/player_medium_body_eat1.png"), \
                           load_image("res/player_medium_body_eat2.png"), \
                           load_image("res/player_large_body_walk1.png"), \
                           load_image("res/player_large_body_walk2.png"), \
                           load_image("res/player_large_body_eat1.png"), \
                           load_image("res/player_large_body_eat2.png"), \
                           load_image("res/player_legs1.png"), \
                           load_image("res/player_legs2.png")]
                           
     self.res['enemies'] = [load_image("res/icecreamstick1.png"), \
                            load_image("res/icecreamstick2.png"), \
                            load_image("res/icecreamcone1.png"), \
                            load_image("res/icecreamcone2.png"), \
                            load_image("res/icecreamcone1_open.png"), \
                            load_image("res/icecreamcone2_open.png"), \
                            load_image("res/icecreamboat1.png"), \
                            load_image("res/icecreamboat2.png"), \
                            load_image("res/icecreamboat3.png"), \
                            load_image("res/icecreamsmallboat1.png"), \
                            load_image("res/icecreamsmallboat2.png")]
                           
    
     #Animation configurations
     self.anims = {}
     self.anims['player'] = {}
     self.anims['player']['small_walk'] = (self.res['player'][0:2], 10, 'small_walk')
     self.anims['player']['medium_walk'] = (self.res['player'][4:6], 10, 'medium_walk')
     self.anims['player']['large_walk'] = (self.res['player'][8:10], 10, 'large_walk')        
     self.anims['player']['small_eat'] = (self.res['player'][2:4], 10, 'small_walk')
     self.anims['player']['medium_eat'] = (self.res['player'][6:8], 10, 'medium_walk')
     self.anims['player']['large_eat'] = (self.res['player'][10:12], 10, 'large_walk')        
     self.anims['player_legs'] = {}
     self.anims['player_legs']['legs_walk'] = (self.res['player'][12:14], 10, 'legs_walk')
     self.anims['enemy_stick'] = {}
     self.anims['enemy_stick']['walk'] = (self.res['enemies'][0:2], 8, 'walk')
     self.anims['enemy_cone'] = {}
     self.anims['enemy_cone']['walk'] = (self.res['enemies'][2:4], 8, 'open')
     self.anims['enemy_cone']['open'] = (self.res['enemies'][4:6], 8, 'walk')
     self.anims['enemy_boat'] = {}   
     self.anims['enemy_boat']['walk'] = (self.res['enemies'][6:9] + [self.res['enemies'][7]], 6, 'walk')
     self.anims['mini_boat'] = {} 
     self.anims['mini_boat']['walk'] = (self.res['enemies'][9:11], 4, 'walk')
            
     #Ticks
     self.ticks = {}
     self.ticks['player_attack'] = 0
     self.ticks['enemy_attack'] = 0
     self.ticks['enemy_move'] = 0       
                                         
     #BG
     self.bg = (Sprite(None, Vec2(320, 240), (640, 480)))
     
     #Player
     self.player = (Sprite(None, Vec2(150, 320), (100, 62)))
     self.player_legs = (Sprite(None, Vec2(200, 360), (100, 62)))
     self.player_speed = 7.0
     self.player_can_attack = True
     self.player_next_attack = 0
     self.player_flipped = False
     self.player_dmg = 1
     self.player_hitbox = (33,55)
     self.player_attack_hitbox_offset = Vec2(0,0)
     self.player_attack_size = (1,1)
     
     #Enemy
     self.enemies = []
Beispiel #12
0
 def __init__(self):
     WorldInterface.__init__(self)
     self.bg = Sprite(load_image('res/gameover.png'), Vec2(320, 240),
                      (640, 480))
 def __init__(self):
     WorldInterface.__init__(self)
     self.gamejam = Sprite(load_image('res/gamejam.png'), Vec2(320, 200),
                           (300, 300))
     self.load_bar = Sprite(load_image('res/load_bar.png'), Vec2(100, 400),
                            [5, 30])