Exemple #1
0
 def __init__(self, position):
     ball_asset = ImageAsset("images/orb-150545_640.png") #pull from repository
     ball = Sprite(ball_asset, (0, 400))
     ball.scale = 0.07
     # custom attributes
     ball.direction = 1
     ball.go = True
     # Sounds
     pew1_asset = SoundAsset("sounds/pew1.mp3")
     pew1 = Sound(pew1_asset)
     pop_asset = SoundAsset("sounds/reappear.mp3")
     pop = Sound(pop_asset)
     super().__init__(ball_asset, position)
Exemple #2
0
    def __init__(self):
        super().__init__()

        self.gameover = False

        rectangle = RectangleAsset(1000, 1000, thinline, blue)
        rectangle1 = RectangleAsset(1000, 1000, thinline, white)

        Sprite(rectangle, (0, 0))
        Sprite(rectangle1, (0, 350))

        #initial positions
        Background((0, 0))
        Background((512, 0))
        Background((1024, 0))
        House1((300, 350))
        House2((900, 350))
        Grinch((1000, 335))
        Grinch((100, 335))
        Grinch((1500, 335))
        self.p1 = Present1((350, 50))
        self.Hlist = Heartlist()

        #sleigh
        sleigh_asset = ImageAsset("images/santa_sleigh_PNG72.png")
        sleigh = Sprite(sleigh_asset, (350, 50))
        sleigh.scale = 0.3

        #music
        jingle_asset = SoundAsset("sounds/Santa Claus Is Coming To Town.mp3")
        jingle = Sound(jingle_asset)
        jingle.volume = 8
        jingle.play()
Exemple #3
0
class Tree(Icon):
    asset = ImageAsset("images/tree.png")
    noise = SoundAsset("sounds/Tree.mp3")

    def __init__(self, position, prop):
        super().__init__(Tree.asset, position, prop)
        self.scale = 0.5
Exemple #4
0
class Bird(Icon):
    asset = ImageAsset("images/blue_bird.png")
    noise = SoundAsset("sounds/Birdie.mp3")

    def __init__(self, position, prop):
        super().__init__(Bird.asset, position, prop)
        self.scale = 0.18
Exemple #5
0
class kid(Icon):
    asset = ImageAsset("images/cartoon_boy.png")
    noise = SoundAsset("sounds/boi.mp3")

    def __init__(self, position, prop):
        super().__init__(kid.asset, position, prop)
        self.scale = 0.06
Exemple #6
0
class Flowr(Icon):
    asset = ImageAsset("images/pinkflowr.png")
    noise = SoundAsset("sounds/Flr.mp3")

    def __init__(self, position, prop):
        super().__init__(Flowr.asset, position, prop)
        self.scale = 0.2
Exemple #7
0
class Bunny(Icon):
    asset = ImageAsset("images/bunny.png")
    noise = SoundAsset("sounds/Bunny.mp3")

    def __init__(self, position, prop):
        super().__init__(Bunny.asset, position, prop)
        self.scale = 0.8
Exemple #8
0
class Cat(Icon):
    asset = ImageAsset(
        "images/cute-cartoon-cat-cute-light-brown-cartoon-cat-with-a-black-nose-and-7VM6VK-clipart.png"
    )
    noise = SoundAsset("sounds/Cat.mp3")

    def __init__(self, position, prop):
        super().__init__(Cat.asset, position, prop)
        self.scale = 0.2
Exemple #9
0
class Bullet(GravitySprite):

    asset = ImageAsset("images/blast.png", Frame(0, 0, 8, 8), 8)
    pewasset = SoundAsset("sounds/pew1.mp3")

    def __init__(self, app, sun, sun2):
        super().__init__(Bullet.asset, (0, 0), (0, 0), sun, sun2)
        self.visible = False
        self.firing = False
        self.time = 0
        self.circularCollisionModel()
        self.pew = Sound(Bullet.pewasset)
        self.pew.volume = 10

    def shoot(self, position, velocity, time):
        self.position = position
        self.vx = velocity[0]
        self.vy = velocity[1]
        self.time = time
        self.visible = True
        self.firing = True
        self.pew.play()

    def step(self, T, dT):
        if self.time > 0:
            self.time = self.time - dT
            if self.visible:
                self.nextImage(True)
                super().step(T, dT)
                if self.collidingWith(self.sun):
                    self.visible = False
                if self.collidingWith(self.sun2):
                    self.visible = False
                    ExplosionSmall(self.position)
                ships = []
                ships = self.collidingWithSprites(Ship1)
                ships.extend(self.collidingWithSprites(Ship2))
                if len(ships):
                    if not self.firing and ships[0].visible:
                        ships[0].hitCount = ships[0].hitCount + 1
                        self.visible = False
                        ExplosionSmall(self.position)
                    if ships[0].hitCount >= 3:
                        ships[0].explode()
                        ships[0].hitCount = 0
                        self.visible = False

                    if ships[0].hitCount >= 2:
                        ships[0].shipThrust = int(ships[0].shipThrust) / 3

                elif self.firing:
                    self.firing = False

        else:
            if self.visible:
                self.visible = False
            self.time = 0
Exemple #10
0
class ExplosionSmall(Sprite):

    asset = ImageAsset("images/explosion1.png", Frame(0, 0, 128, 128), 10)
    boomasset = SoundAsset("sounds/explosion1.mp3")

    def __init__(self, position):
        super().__init__(ExplosionSmall.asset, position)
        self.image = 0
        self.center = (0.5, 0.5)
        self.boom = Sound(ExplosionSmall.boomasset)
        self.boom.play()

    def step(self):
        self.setImage(self.image // 2)  # slow it down
        self.image += 1
        if self.image == 20:
            self.destroy()
class ExplosionBig(Sprite):
    
    asset = ImageAsset("images/explosion2.png", Frame(0,0,4800/25,195), 25)
    boomasset = SoundAsset("sounds/explosion2.mp3")
    
    def __init__(self, position):
        super().__init__(ExplosionBig.asset, position)
        self.image = 0
        self.center = (0.5, 0.5)
        self.boom = Sound(ExplosionBig.boomasset)
        self.boom.play()
        
    def step(self):
        self.setImage(self.image//2)  # slow it down
        self.image = self.image + 1
        if self.image == 50:
            self.destroy()
class Explosion(Sprite):
    
    image = ImageAsset("images/explosion2.png", Frame(0,0,4800/25,195), 25)
    sound = SoundAsset("sounds/explosion2.mp3")
    
    def __init__(self, position):
        super().__init__(Explosion.image, position)
        self.image = 0
        self.center = (0.5, 0.5)
        self.boom = Sound(Explosion.sound)
        self.boom.play()
        
    def step(self):
        self.setImage(self.image//2) 
        self.image = self.image + 1
        if self.image == 50:
            self.destroy()
Exemple #13
0
class Bullet(GravitySprite):

    asset = ImageAsset("images/blast.png", Frame(0, 0, 8, 8), 8)
    collisionasset = CircleAsset(4)
    pewasset = SoundAsset("sounds/pew1.mp3")

    def __init__(self, app, sun):
        super().__init__(Bullet.asset, Bullet.collisionasset, (0, 0), (0, 0),
                         sun)
        self.visible = False
        self.firing = False
        self.time = 0
        self.pew = Sound(Bullet.pewasset)
        self.pew.volume = 10

    def shoot(self, position, velocity, time):
        self.position = position
        self.vx = velocity[0]
        self.vy = velocity[1]
        self.time = time
        self.visible = True
        self.firing = True
        self.pew.play()

    def step(self, T, dT):
        self.time = self.time - dT
        if self.visible:
            if self.time <= 0:
                self.visible = False
            else:
                self.nextImage(True)
                super().step(T, dT)
                if self.collidingWith(self.sun):
                    self.visible = False
                    ExplosionSmall(self.position)
                else:
                    ships = self.collidingWithSprites(Ship1)
                    ships.extend(self.collidingWithSprites(Ship2))
                    for ship in ships:
                        if not self.firing and ship.visible:
                            ship.explode()
                            self.visible = False
                    if not ships:
                        self.firing = False
class SpaceShip(Sprite):
    
    spaceship_asset = ImageAsset("images/four_spaceship_by_albertov_with_thrust.png",
    Frame(227,0,65,125), 4, 'vertical')
   
    shotasset = SoundAsset("sounds/pew1.mp3")
    
    def __init__(self, position):
        super().__init__(SpaceShip.spaceship_asset, position)
        self.x=1
        self.y=1
        self.v=0.01
        self.scale=.5
        SpaceGame.listenKeyEvent("keydown", "right arrow", self.rightarrowKey)
        SpaceGame.listenKeyEvent('keydown', "left arrow", self.leftarrowKey)
        SpaceGame.listenKeyEvent('keydown', "up arrow", self.uparrowKey)
        SpaceGame.listenKeyEvent('keydown', "down arrow", self.downarrowKey)
        self.thrust = 0
        self.thrustframe = 1
        SpaceGame.listenKeyEvent("keydown", "space", self.thrustOn)
        SpaceGame.listenKeyEvent("keyup", "space", self.thrustOff)
        self.fxcenter = self.fycenter = 0.5
        self.pew=Sound(SpaceShip.shotasset)
        self.pew.volume=5
        
        
    def rightarrowKey(self, event):
        self.x+=.5
        self.pew.play()
        
        
    def leftarrowKey(self, event):
        self.x+=-.5
        self.pew.play()
        
    def uparrowKey(self, event):
        self.y+=-.5
        self.pew.play()
        
    def downarrowKey(self, event):
        self.y+=.5
        self.pew.play()
       
        
    def step(self):
        if self.x>(myapp.width-100) or self.x<0 or self.y>(myapp.height+100) or self.y<0:
            myapp.text.visible = True
        else: 
            self.x+=self.x
            self.y += self.y
            self.rotation += self.v
    
        if self.thrust == 1:
            self.setImage(self.thrustframe)
            self.thrustframe += 1
            if self.thrustframe == 4:
                self.thrustframe = 1
        else:
            self.setImage(0)
          
        if self.visible and self.collidingWithSprites(Asteroid):
            self.visible=False
            Explosion(self.position)
            myapp.text.visible=True
            
        
    def thrustOn(self, event):
        self.thrust = 1
        
    def thrustOff(self, event):
        self.thrust = 0
Exemple #15
0
class Ship(GravitySprite):

    R = 2.0
    bullets = 6
    healthcount = 6
    reappearasset = SoundAsset("sounds/reappear.mp3")

    def __init__(self, asset, app, position, velocity, sun):
        self.bullets = []
        for i in range(Ship.bullets):
            self.bullets.append(Bullet(app, sun))
        super().__init__(asset, position, velocity, sun)
        self.initposition = position
        self.initvelocity = self.vx, self.vy
        self.initrotation = self.rotation
        self.app = app
        self.mass = 1.0
        self.circularCollisionModel()
        self.imagex = 0
        self.reappear = Sound(Ship.reappearasset)
        self.reappear.volume = 40
        self.waitspawn = 0
        self.respawnplayed = False
        healthpos = 'left' if position[0] < app.width / 2 else 'right'
        self.health = HealthBar(asset, Ship.healthcount, healthpos, app)
        self.dead = False

    def registerKeys(self, keys):
        commands = ["left", "right", "forward", "fire"]
        self.keymap = dict(zip(keys, commands))
        [self.app.listenKeyEvent("keydown", k, self.controldown) for k in keys]
        [self.app.listenKeyEvent("keyup", k, self.controlup) for k in keys]

    def shootvector(self):
        vel = 150
        xv = vel * (-math.sin(self.rotation))
        yv = vel * (-math.cos(self.rotation))
        return xv + self.vx, yv + self.vy

    def controldown(self, event):
        if self.visible:
            command = self.keymap[event.key]
            if command == "left":
                self.rrate = Ship.R
            elif command == "right":
                self.rrate = -Ship.R
            elif command == "forward":
                self.thrust = 40.0
                self.imagex = 1  # start the animated rockets
                self.setImage(self.imagex)
            elif command == "fire":
                for bullet in self.bullets:
                    if bullet.time == 0:
                        bullet.shoot(self.position, self.shootvector(), 10)
                        break

    def controlup(self, event):
        command = self.keymap[event.key]
        if command in ["left", "right"]:
            self.rrate = 0.0
        elif command == "forward":
            self.thrust = 0.0
            self.imagex = 0  # stop the animated rockets
            self.setImage(self.imagex)

    def step(self, T, dT):
        if self.waitspawn > 0:
            self.waitspawn -= dT
            if self.waitspawn < 1 and not self.respawnplayed:
                self.reappear.play()
                self.respawnplayed = True
            if self.waitspawn <= 0:
                self.reset()
        for bullet in self.bullets:
            bullet.step(T, dT)
        if self.visible:
            super().step(T, dT)
            self.rotation += self.rrate * dT
            if self.collidingWith(self.sun):
                self.explode()
            if self.thrust != 0.0:
                self.imagex += 1  # animate the rockets
                if self.imagex == 4:
                    self.imagex = 1
                self.setImage(self.imagex)
            if (self.x < -100 or self.x > self.app.width + 100 or self.y < -100
                    or self.y > self.app.height + 100):
                self.explode()

    def explode(self):
        self.visible = False
        ExplosionBig(self.position)
        self.waitspawn = 5

    def reset(self):
        if not self.health.dead():
            self.position = self.initposition
            self.vx, self.vy = self.initvelocity
            self.rotation = self.initrotation
            self.visible = True
            self.respawnplayed = False
            self.health.killone()
        else:
            self.dead = True

    def newgame(self):
        self.health.restart()
        self.dead = False
        self.reset()
Exemple #16
0
by E. Dennison
"""
from ggame import App, RectangleAsset, ImageAsset, SoundAsset, Sprite, Sound
from ggame import LineStyle, Color

SCREEN_WIDTH = 640
SCREEN_HEIGHT = 480

green = Color(0x00ff00, 1)
black = Color(0, 1)
noline = LineStyle(0, black)
bg_asset = RectangleAsset(SCREEN_WIDTH, SCREEN_HEIGHT, noline, green)
bg = Sprite(bg_asset, (0,0))

# Sounds
pew1_asset = SoundAsset("sounds/pew1.mp3")
pew1 = Sound(pew1_asset)
pop_asset = SoundAsset("sounds/reappear.mp3")
pop = Sound(pop_asset)
# A ball! This is already in the ggame-tutorials repository
ball_asset = ImageAsset("images/orb-150545_640.png")
ball = Sprite(ball_asset, (0, 0))
# Original image is too big. Scale it to 1/10 its original size
ball.scale = 0.1
ball.y = 200
# custom attributes
ball.dir = 1
ball.go = True
# Sounds
pew1_asset = SoundAsset("sounds/pew1.mp3")
pew1 = Sound(pew1_asset)
Exemple #17
0
from ggame import Sound, SoundAsset

e5 = Sound(SoundAsset("sounds/00_part1_entry-5.wav"))
e6 = Sound(SoundAsset("sounds/00_part1_entry-6.wav"))
e7 = Sound(SoundAsset("sounds/00_part1_entry-7.wav"))
e7.play()
Exemple #18
0
class Ship(GravitySprite):

    R = int(input("What speed do you want the ship to turn? (2.0 is standard)")
            )  #This is the speed at which the ship spins
    bullets = int(
        input("How many bullets can you shoot before relodaing?"
              ))  #this is how many bullets the ship can shoot before reloading
    healthcount = int(input("How many lives should each player have?"))
    reappearasset = SoundAsset("sounds/reappear.mp3")

    def __init__(self, asset, app, position, velocity, sun, sun2, thrust):
        self.bullets = []
        for i in range(Ship.bullets):
            self.bullets.append(Bullet(app, sun, sun2))
        super().__init__(asset, position, velocity, sun, sun2)
        self.initposition = position
        self.initvelocity = self.vx, self.vy
        self.initrotation = self.rotation
        self.app = app
        self.mass = 1.0
        self.circularCollisionModel()
        self.imagex = 0
        self.reappear = Sound(Ship.reappearasset)
        self.reappear.volume = 40
        self.waitspawn = 0
        self.respawnplayed = False
        healthpos = 'left' if position[0] < app.width / 2 else 'right'
        self.health = HealthBar(asset, Ship.healthcount, healthpos, app)
        self.dead = False
        self.hitCount = 0
        self.shipThrust = thrust

    def registerKeys(self, keys):
        commands = ["left", "right", "forward", "fire"]
        self.keymap = dict(zip(keys, commands))
        [self.app.listenKeyEvent("keydown", k, self.controldown) for k in keys]
        [self.app.listenKeyEvent("keyup", k, self.controlup) for k in keys]

    def shootvector(self):
        vel = 200  # this is the velocity of the bullets normally 150
        xv = vel * (-math.sin(self.rotation))
        yv = vel * (-math.cos(self.rotation))
        return xv + self.vx, yv + self.vy

    def controldown(self, event):
        if self.visible:
            command = self.keymap[event.key]
            if command == "left":
                self.rrate = Ship.R
            elif command == "right":
                self.rrate = -Ship.R
            elif command == "forward":
                self.thrust = self.shipThrust  #this is the ship thrust
                self.imagex = 1  # start the animated rockets
                self.setImage(self.imagex)
            elif command == "fire":
                for bullet in self.bullets:
                    if bullet.time == 0:
                        bullet.shoot(
                            self.position, self.shootvector(), 10
                        )  #ten is the number of seconds that a bullet lasts before self destructing and reappearing able to shoot
                        break

    def controlup(self, event):
        command = self.keymap[event.key]
        if command in ["left", "right"]:
            self.rrate = 0.0
        elif command == "forward":
            self.thrust = 0.0
            self.imagex = 0  # stop the animated rockets
            self.setImage(self.imagex)

    def step(self, T, dT):
        if self.waitspawn > 0:
            self.waitspawn = self.waitspawn - dT
            if self.waitspawn < 1 and not self.respawnplayed:
                self.reappear.play()
                self.respawnplayed = True
            if self.waitspawn <= 0:
                self.reset()
        for bullet in self.bullets:
            bullet.step(T, dT)
        if self.visible:
            super().step(T, dT)
            self.rotation = self.rotation + self.rrate * dT
            if self.collidingWith(self.sun):
                self.explode()
            if self.collidingWith(self.sun2):
                self.explode()
            if self.thrust != 0.0:
                self.imagex = self.imagex + 1  # animate the rockets
                if self.imagex == 4:
                    self.imagex = 1
                self.setImage(self.imagex)
            if (self.x < -100 or self.x > self.app.width + 100 or self.y < -100
                    or self.y > self.app.height + 100):
                self.explode()

    def explode(self):
        self.visible = False
        ExplosionBig(self.position)
        self.waitspawn = 5
        self.hitCount = 0

    def reset(self):
        if not self.health.dead():
            self.position = self.initposition
            self.vx, self.vy = self.initvelocity
            self.rotation = self.initrotation
            self.visible = True
            self.respawnplayed = False
            self.health.killone()
        else:
            self.dead = True

    def newgame(self):
        self.health.restart()
        self.dead = False
        self.reset()

SCREEN_WIDTH = 640
SCREEN_HEIGHT = 480

green = Color(0x00ff00, 1)
black = Color(0, 1)
noline = LineStyle(0, black)
bg_asset = RectangleAsset(SCREEN_WIDTH, SCREEN_HEIGHT, noline, green)
bg = Sprite(bg_asset, (0,0))

# A ball! This is already in the ggame-tutorials repository
ball_asset = ImageAsset("images/dog-png-29.png")
ball = Sprite(ball_asset, (0, 0))
# Sounds
pew1_asset = SoundAsset("sounds/pew1.mp3")
pew1 = Sound(pew1_asset)
pop_asset = SoundAsset("sounds/reappear.mp3")
pop = Sound(pop_asset)
dog1_asset = SoundAsset("sounds/dog-panting-breathing-fast-daniel_simon.mp3")
dog = Sound(dog1_asset)
bark_asset = SoundAsset("sounds/Dog_woof.mp3")
bark = Sound(bark_asset)
# Original image is too big. Scale it to 1/10 its original size
ball.scale = 0.3
# custom attributes
ball.dir = 1
ball.go = True
def reverse(b):
    b.dir *= -1
def step():