Example #1
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()
class LifeControl(Sprite):
    
    asset = TextAsset("Lives:", fill=white)
    SAsset = SoundAsset("sounds/reappear.mp3")
    
    def __init__(self, position):
        super().__init__(LifeControl.asset, position)
        self.lives = LIVES
        self.dispLives()
        self.RespawnSound = Sound(LifeControl.SAsset)
        self.RespawnSound.volume = 10
        
    def dispLives(self):
        Lives(TextAsset(str(self.lives), fill=white), (55,20))
        
    def loseLife(self):
        for x in SpaceGame.getSpritesbyClass(Lives):
            x.destroy()
        self.lives -= 1
        self.dispLives()
        if self.lives == 0:
            LoseText((SCREEN_WIDTH/2,SCREEN_HEIGHT/2))
        else:
            RespawnText((SCREEN_WIDTH/2,SCREEN_HEIGHT/2))
            classDestroy(EnemyBullet)
                
    def respawn(self):
        if self.lives > 0:
            sleep(1)
            for x in SpaceGame.getSpritesbyClass(RespawnText):
                x.destroy()
            self.RespawnSound.play()
            Player((SCREEN_WIDTH/2,SCREEN_HEIGHT/2))
            classDestroy(Enemy)
            EnemySpawn(NUM_ENEMIES)
Example #3
0
 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
Example #4
0
 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
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
Example #6
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
Example #7
0
 def __init__(self, asset, position, prop):
     self.b = 0
     self.c = 0
     chk = 0  #preparing to check a condition
     self.ct = 1  #nothing has been clicked on
     super().__init__(asset, position)
     self.center = (0.5, 0.5)
     if prop == True:
         Draw.listenMouseEvent("mousedown", self.ym_dn)
     if prop == False:
         go = Sound(self.noise)
         go.play()
Example #8
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)
Example #9
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 = self.image + 1
        if self.image == 20:
            self.destroy()
 def __init__(self, position):
     super().__init__(Explosion.asset, position)
     self.fxcenter = self.fycenter = 0.5
     self.frame = 0
     self.ExplodeSound = Sound(Explosion.SAsset)
     self.ExplodeSound.volume = 10
     self.ExplodeSound.play()
Example #11
0
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()
Example #12
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()
Example #13
0
 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
Example #14
0
 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
Example #15
0
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()
Example #16
0
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()
Example #17
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 Explosion(Sprite):
    
    asset = ImageAsset("images/explosion1.png", Frame(0,0,128,128), 10)
    SAsset = SoundAsset("sounds/explosion1.mp3")
    
    def __init__(self, position):
        super().__init__(Explosion.asset, position)
        self.fxcenter = self.fycenter = 0.5
        self.frame = 0
        self.ExplodeSound = Sound(Explosion.SAsset)
        self.ExplodeSound.volume = 10
        self.ExplodeSound.play()
        
    def step(self):
        if self.frame == 8:
            self.destroy()
        else:
            self.frame += 1
        self.setImage(self.frame)
Example #19
0
 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
Example #20
0
 def __init__(self, position, vx, vy):
     super().__init__(Bullet.asset, position)
     self.exist = True
     self.circularCollisionModel()
     self.pew = Sound(Bullet.pewasset)
     self.pew.play()
     self.appear = 1
     self.fxcenter = 0.5
     self.fycenter = 0
     self.X = vx
     self.Y = vy
Example #21
0
class Bullet(Sprite):
    
    asset = ImageAsset("images/blast.png", Frame(0,0,8,8), 8)
    pewasset = SoundAsset("sounds/pew1.mp3")
    
    def __init__(self, position, vx, vy):
        super().__init__(Bullet.asset, position)
        self.exist = True
        self.circularCollisionModel()
        self.pew = Sound(Bullet.pewasset)
        self.pew.play()
        self.appear = 1
        self.fxcenter = 0.5
        self.fycenter = 0
        self.X = vx
        self.Y = vy
        
    
    def step(self):
        self.visible = True
        if self.exist:
            self.setImage(self.appear)
            self.appear += 1
            if self.appear == 8:
                self.appear = 1
        else:
            self.setImage(0)
        
        self.x -= 15*self.X
        self.y -= 15*self.Y
        
        collides = self.collidingWithSprites(Ship2)
        collides.extend(self.collidingWithSprites(Ship1))
        if len(collides):
            if collides[0].visible:
                self.visible = False
        else:
            self.visible = True
        
        if self.x < 0 or self.x > SCREEN_WIDTH or self.y < 0 or self.y >SCREEN_HEIGHT:
            self.destroy()
Example #22
0
 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
Example #23
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()
Example #24
0
"""
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)
pop_asset = SoundAsset("sounds/reappear.mp3")
Example #25
0
 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()
Example #26
0
 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()
Example #27
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()
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():
    if ball.go:
 def __init__(self, position):
     super().__init__(LifeControl.asset, position)
     self.lives = LIVES
     self.dispLives()
     self.RespawnSound = Sound(LifeControl.SAsset)
     self.RespawnSound.volume = 10
Example #30
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()
Example #31
0
 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()
Example #32
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()
Example #33
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()
Example #34
0
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