Example #1
0
    def __init__(self, image, image_alternate, columns, rows):
        super().__init__(image, image_alternate, columns, rows)
        pygame.mixer.pre_init(
            44100, -16, 1, 512
        )  # Prevents Pygame sound delay: https://www.reddit.com/r/pygame/comments/8gsoue/delayed_audio_in_pygame/
        self.lives = 2
        self.moving = False
        self.dead = False
        self.shooting = False
        self.jumping = False
        #self.rolling = False
        self.invincible = False
        self.bullets = []
        self.velocity = Vector(0, 0)
        self.pos = Vector(SCREENWIDTH / 2, SCREENHEIGHT - 20)
        self.gravity = Vector(0, 0)
        self.frameCounter = 0
        self.deadCounter = 0
        self.inAir = False

        # Sound effects for the player
        __location__ = os.path.realpath(
            os.path.join(os.getcwd(), os.path.dirname(__file__)))
        soundeffect = os.path.join(__location__, 'Sounds/classic_hurt.ogg')
        self.oof = simplegui._load_local_sound(soundeffect)

        __location__ = os.path.realpath(
            os.path.join(os.getcwd(), os.path.dirname(__file__)))
        soundeffect = os.path.join(__location__, 'Sounds/gunSound.ogg')
        self.pew = simplegui._load_local_sound(soundeffect)
        self.pew.set_volume(.25)
Example #2
0
    def __init__(self):

        #Boiler Plate Loading and setting of Variables
        self.__location__ = os.path.realpath(
            os.path.join(os.getcwd(), os.path.dirname(__file__)))
        self.fcat = os.path.join(self.__location__,
                                 'images/sprites/catmandoRight.png')
        self.fcatleft = os.path.join(self.__location__,
                                     'images/sprites/catmandoLeft.png')
        self.fman = os.path.join(self.__location__,
                                 'images/sprites/kramer_sprites.png')
        self.fmanleft = os.path.join(self.__location__,
                                     'images/sprites/kramer_sprites_left.png')
        self.fwiz = os.path.join(self.__location__,
                                 'images/sprites/wizzardRight.png')
        self.fwizleft = os.path.join(self.__location__,
                                     'images/sprites/wizzardLeft.png')
        self.lives = os.path.join(self.__location__, 'images/lives.png')
        self.error = os.path.join(self.__location__,
                                  'images/sprites/error.png')
        self.load = os.path.join(self.__location__, 'images/loading.png')
        self.loading = simplegui._load_local_image(self.load)
        self.back = os.path.join(self.__location__,
                                 'images/1280x720GameBackground.png')
        self.background = simplegui._load_local_image(self.back)
        self.level = 0
        self.player = Player(self.fcat, self.fcatleft, 16, 16)
        self.keyboard = KeyBoard()
        self.enemies = []
        self.gui = Gui(self.lives, self.lives, 1, 1, self.player)
        self.counter = 0
        self.gameOver = False

        # Load from correct directories to work on all systems.
        __location__ = os.path.realpath(
            os.path.join(os.getcwd(), os.path.dirname(__file__)))
        soundeffect = os.path.join(__location__,
                                   'Sounds/bensound-jazzyfrenchy.ogg')
        self.music1 = simplegui._load_local_sound(soundeffect)

        soundeffect = os.path.join(__location__,
                                   'Sounds/bensound-theelevatorbossanova.ogg')
        self.music2 = simplegui._load_local_sound(soundeffect)

        soundeffect = os.path.join(
            __location__, 'Sounds/Captive_Portal_-_03_-_An_Example_For.ogg')
        self.music3 = simplegui._load_local_sound(soundeffect)

        self.interaction = Interaction(self.player, self.keyboard,
                                       self.enemies, self.gui)
        self.frame = simplegui.create_frame("Catmando", WIDTH, HEIGHT)
        self.frame.set_draw_handler(self.draw)
        self.frame.set_keydown_handler(self.keyboard.keyDown)
        self.frame.set_keyup_handler(self.keyboard.keyUp)
Example #3
0
harpoon_image = Image(PREFIX + "VCC6wZL.png", [2, 200], [5, 400], 5, 120, True,
                      2)
hero_image = Image(PREFIX + "9v5ehnO.png", [32, 32], [64, 64], 25, 0, True, 9)

# Sphere Images in a list.
sphere_image.append(Image(PREFIX + "FDqGDmc.png", [37, 37], [75, 75], 37))
sphere_image.append(Image(PREFIX + "NljADnB.png", [37, 37], [75, 75], 37))
sphere_image.append(Image(PREFIX + "Nl5u05O.png", [37, 37], [75, 75], 37))
sphere_image.append(Image(PREFIX + "IHXoEES.png", [37, 37], [75, 75], 37))
sphere_image.append(Image(PREFIX + "pX44tkA.png", [37, 37], [75, 75], 37))
sphere_image.append(Image(PREFIX + "LdTCEUo.png", [37, 37], [75, 75], 37))
sphere_image.append(Image(PREFIX + "Vlt8FBC.png", [37, 37], [75, 75], 37))

# Sounds
# sounds needs to be .wav format
pop_sound = simplegui._load_local_sound(SOUND_DIR + "pop.wav")
arrow_sound = simplegui._load_local_sound(SOUND_DIR + "arrow.wav")
soundtrack = simplegui._load_local_sound(SOUND_DIR + "paza-moduless.wav")
soundtrack.set_volume(0.3)


# Classes
# Sprite class with rectangular collision, scaling, gravity
# and friction properities.
class Sprite:
    def __init__(self, image, pos, vel, scale=1):
        self.image = image.get_image()
        self.pos = pos
        self.vel = vel
        self.size = image.get_size()
        self.center = image.get_center()
Example #4
0
        self.image = simplegui._load_local_image(self.url)

    def draw(self, canvas, pos, size, angle=0):
        center = [size[0] / 2.0, size[1] / 2.0]
        canvas.draw_image(self.image, center, size, pos, size, angle)


bird0 = Image('./flappy_bird_image/bird0.png', [30, 22])
bird1 = Image('./flappy_bird_image/bird1.png', [30, 22])
bird2 = Image('./flappy_bird_image/bird2.png', [30, 22])
pipe = Image('./flappy_bird_image/pipe.png', [40, 300])
ground = Image('./flappy_bird_image/ground.png', [400, 8])
background = Image('./flappy_bird_image/background.png', [400, 400])
spacebar = Image('./flappy_bird_image/spacebar.png', [100, 20])
board = Image('./flappy_bird_image/board.png', [78, 158])
coin = simplegui._load_local_sound('./flappy_bird_sound/coin.wav')
bump = simplegui._load_local_sound('./flappy_bird_sound/bump.wav')
end = simplegui._load_local_sound('./flappy_bird_sound/end.wav')
jump = simplegui._load_local_sound('./flappy_bird_sound/jump.wav')
bg_music = simplegui._load_local_sound('./flappy_bird_sound/funky_bg.wav')


class Bird:
    def __init__(self, pos):
        self.pos = pos
        self.radius = 10
        self.vel = 0
        self.time = 0
        self.image = None
        self.flap_up_velocity = flap_up_velocity
bg_image = Image(PREFIX + "HfReHl5.jpg", [300, 200], [600, 400])
harpoon_image = Image(PREFIX + "VCC6wZL.png", [2, 200], [5, 400], 5, 120, True, 2)
hero_image = Image(PREFIX + "9v5ehnO.png", [32, 32], [64, 64], 25, 0, True, 9)

# Sphere Images in a list.
sphere_image.append(Image(PREFIX + "FDqGDmc.png", [37, 37], [75, 75], 37))
sphere_image.append(Image(PREFIX + "NljADnB.png", [37, 37], [75, 75], 37))
sphere_image.append(Image(PREFIX + "Nl5u05O.png", [37, 37], [75, 75], 37))
sphere_image.append(Image(PREFIX + "IHXoEES.png", [37, 37], [75, 75], 37))
sphere_image.append(Image(PREFIX + "pX44tkA.png", [37, 37], [75, 75], 37))
sphere_image.append(Image(PREFIX + "LdTCEUo.png", [37, 37], [75, 75], 37))
sphere_image.append(Image(PREFIX + "Vlt8FBC.png", [37, 37], [75, 75], 37))

# Sounds
# sounds needs to be .wav format
pop_sound = simplegui._load_local_sound(SOUND_DIR + "pop.wav")
arrow_sound = simplegui._load_local_sound(SOUND_DIR + "arrow.wav")
soundtrack = simplegui._load_local_sound(SOUND_DIR + "paza-moduless.wav")
soundtrack.set_volume(0.3)


# Classes
# Sprite class with rectangular collision, scaling, gravity
# and friction properities.
class Sprite:
    def __init__(self, image, pos, vel, scale=1):
        self.image = image.get_image()
        self.pos = pos
        self.vel = vel
        self.size = image.get_size()
        self.center = image.get_center()
 def __init__(self, url):
     self.url = url
     self.count = 0
     self.sound = {}
     for i in range(3):
         self.sound[i] = simplegui._load_local_sound (self.url)
        for i in range(3):
            self.sound[i] = simplegui._load_local_sound (self.url)
        
    def play(self):
        self.sound[self.count].play()
        self.count = (self.count + 1) % 3

bird0 = Image('./flappy_bird_image/bird0.png', [30, 22])
bird1 = Image('./flappy_bird_image/bird1.png', [30, 22])
bird2 = Image('./flappy_bird_image/bird2.png', [30, 22])
pipe = Image('./flappy_bird_image/pipe.png', [40, 300])
ground = Image('./flappy_bird_image/ground.png', [400, 8])
background = Image('./flappy_bird_image/background.png', [400, 400])
spacebar = Image('./flappy_bird_image/spacebar.png', [100, 20])
board = Image('./flappy_bird_image/board.png', [78, 158])
coin = simplegui._load_local_sound('./flappy_bird_sound/coin.wav')
bump = simplegui._load_local_sound('./flappy_bird_sound/bump.wav')
end = simplegui._load_local_sound('./flappy_bird_sound/end.wav')
jump = Sound('./flappy_bird_sound/jump.wav')



class Bird:
    def __init__(self, pos):
        self.pos = pos
        self.radius = 10
        self.vel = 0
        self.time = 0
        self.image = None

    def between(self, left, right):
Example #8
0
# asteroid images - asteroid_blue.png, asteroid_brown.png, asteroid_blend.png
asteroid_info = ImageInfo([45, 45], [90, 90], 40)
asteroid_image = simplegui.load_image(
    "http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/asteroid_blue.png"
)

# animated explosion - explosion_orange.png, explosion_blue.png, explosion_blue2.png, explosion_alpha.png
explosion_info = ImageInfo([64, 64], [128, 128], 17, 24, True)
explosion_image = simplegui.load_image(
    "http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/explosion_alpha.png"
)

# sound assets purchased from sounddogs.com, please do not redistribute
# .ogg versions of sounds are also available, just replace .mp3 by .ogg
soundtrack = simplegui._load_local_sound("soundtrack.ogg")
missile_sound = simplegui._load_local_sound("missile.ogg")
missile_sound.set_volume(.5)
ship_thrust_sound = simplegui._load_local_sound("thrust.ogg")
explosion_sound = simplegui._load_local_sound("explosion.ogg")

# alternative upbeat soundtrack by composer and former IIPP student Emiel Stopler
# please do not redistribute without permission from Emiel at http://www.filmcomposer.nl
# soundtrack = simplegui.load_sound("https://storage.googleapis.com/codeskulptor-assets/ricerocks_theme.mp3")


# helper functions to handle transformations
def angle_to_vector(ang):
    return [math.cos(ang), math.sin(ang)]

        self.image = simplegui._load_local_image(self.url)

    def draw(self, canvas, pos, size, angle=0):
        center = [size[0] / 2.0, size[1] / 2.0]
        canvas.draw_image(self.image, center, size, pos, size, angle)


bird0 = Image('./flappy_bird_image/bird0.png', [30, 22])
bird1 = Image('./flappy_bird_image/bird1.png', [30, 22])
bird2 = Image('./flappy_bird_image/bird2.png', [30, 22])
pipe = Image('./flappy_bird_image/pipe.png', [40, 300])
ground = Image('./flappy_bird_image/ground.png', [400, 8])
background = Image('./flappy_bird_image/background.png', [400, 400])
spacebar = Image('./flappy_bird_image/spacebar.png', [100, 20])
board = Image('./flappy_bird_image/board.png', [78, 158])
coin = simplegui._load_local_sound('./flappy_bird_sound/coin.wav')
bump = simplegui._load_local_sound('./flappy_bird_sound/bump.wav')
end = simplegui._load_local_sound('./flappy_bird_sound/end.wav')
jump = simplegui._load_local_sound('./flappy_bird_sound/jump.wav')
bg_music = simplegui._load_local_sound('./flappy_bird_sound/funky_bg.wav')



class Bird:
    def __init__(self, pos):
        self.pos = pos
        self.radius = 10
        self.vel = 0
        self.time = 0
        self.image = None
        self.flap_up_velocity = flap_up_velocity
Example #10
0
 def __init__(self, url):
     self.url = url
     self.count = 0
     self.sound = {}
     for i in range(3):
         self.sound[i] = simplegui._load_local_sound(self.url)
Example #11
0
            self.sound[i] = simplegui._load_local_sound(self.url)

    def play(self):
        self.sound[self.count].play()
        self.count = (self.count + 1) % 3


bird0 = Image('./flappy_bird_image/bird0.png', [30, 22])
bird1 = Image('./flappy_bird_image/bird1.png', [30, 22])
bird2 = Image('./flappy_bird_image/bird2.png', [30, 22])
pipe = Image('./flappy_bird_image/pipe.png', [40, 300])
ground = Image('./flappy_bird_image/ground.png', [400, 8])
background = Image('./flappy_bird_image/background.png', [400, 400])
spacebar = Image('./flappy_bird_image/spacebar.png', [100, 20])
board = Image('./flappy_bird_image/board.png', [78, 158])
coin = simplegui._load_local_sound('./flappy_bird_sound/coin.wav')
bump = simplegui._load_local_sound('./flappy_bird_sound/bump.wav')
end = simplegui._load_local_sound('./flappy_bird_sound/end.wav')
jump = Sound('./flappy_bird_sound/jump.wav')


class Bird:
    def __init__(self, pos):
        self.pos = pos
        self.radius = 10
        self.vel = 0
        self.time = 0
        self.image = None

    def between(self, left, right):
        return self.pos[0] + self.radius > left and self.pos[