Ejemplo n.º 1
0
 def jump(self, mute):
     if not self.off_ground:
         self.off_ground = True
         self.vy = 280 #jump speed
         self.jumpsound = load_sfx("jump")
         if mute == False:
             self.jumpsound.play()
Ejemplo n.º 2
0
    def __init__(self, loc, level, bounds):
        Sprite.__init__(self)
        self.vx = 0
        self.vy = 0

        self.collect = False

        self.facing = "right"  #facing right

        self.level = level
        self.spawnpoint = loc
        self.bounds = bounds
        self.dying = False

        self.anim = PlayerAnimation(self, "chetanim.png", 120)
        self.image = self.anim.get_current_frame()

        self.rect = self.image.get_rect()
        self.rect.center = loc
        
        rect = self.image.get_rect().inflate(-4,-4) #what does this do?        

        self.off_ground = True
        self.waves = Group() #soundwaves
        self.treats = Group() #dog treats
        self.whistlecount = 0
        self.treatcount = 0
        self.dyingcounter = 0
        self.diefalling = False
        self.scorenum = 0
        self.has_played = False
        self.has_fallen = False
        self.has_splat = False

        self.falls = ["fall1","fall2","fall3","fall4","fall5","fall6"]
        self.fallsound = str(self.falls[(randint(0, 5))])
        self.fallingsound = load_sfx(self.fallsound)

        self.splats = ["splat1","splat2","splat3","splat4"]
        self.splatsound = str(self.splats[(randint(0, 3))])
        self.hitsound = load_sfx(self.splatsound)
Ejemplo n.º 3
0
 def throw(self, mute):
     if self.treatcount < self.level.tlimit and self.level.tlimit > 0:
         treat = Treat(self.bounds, self.level, self.facing)
         self.throwsound = load_sfx("throw")
         if mute == False:
             self.throwsound.play()
         if self.facing == "right":
             treat.rect.left = self.rect.right
             treat.rect.midleft = self.rect.midright
         elif self.facing == "left":
             treat.rect.right = self.rect.left
             treat.rect.midright = self.rect.midleft
         self.treats.add(treat)
         self.treatcount += 1
Ejemplo n.º 4
0
 def whistle(self, mute):
     if self.whistlecount < self.level.wlimit and self.level.wlimit > 0:
         soundwave = Wave(self.bounds, self.level, self.facing)
         self.whistlesound = load_sfx("whistle")
         if mute == False:
             self.whistlesound.play()
         if self.facing == "right":
             soundwave.rect.left = self.rect.right
             soundwave.rect.midleft = self.rect.midright
         elif self.facing == "left":
             soundwave.rect.right = self.rect.left
             soundwave.rect.midright = self.rect.midleft
         self.waves.add(soundwave)
         self.whistlecount += 1
Ejemplo n.º 5
0
    def update(self, dt, mute):
        self.mute = mute
        #animation
        self.anim.update(dt)
        self.image = self.anim.get_current_frame()

        keystate = pygame.key.get_pressed()
        self.vx = 0
        if self.dying == False:
            if keystate[K_LEFT]:
                self.vx -= self.playerspeed
                self.facing = "left"
            if keystate[K_RIGHT]:
                self.vx += self.playerspeed
                self.facing = "right"

        dt = dt / 1000.0
        self.vy -= dt * self.gravity
        dx = self.vx * dt
        dy = -self.vy * dt

        self.collect = False

        if self.off_ground == True:  #slow jumping
            dx *= 0.7
        #update position
        prev_rect = self.rect
        self.rect = self.rect.move(dx, dy)
        self.off_ground = True
        
        for sprite in self.touches(self.level.tiles):
            rect = sprite.rect

            #collide walls
            if self.rect.left <= rect.right and prev_rect.left >= rect.right:
                self.rect.left = rect.right
            if self.rect.right >= rect.left and prev_rect.right <= rect.left:
                self.rect.right = rect.left
            #collide ceilings
            if self.rect.top <= rect.bottom and prev_rect.top >= rect.bottom:
                self.vy /= 2.0 #half speed
                self.rect.top = rect.bottom
                
            #land
            if self.rect.bottom >= rect.top and prev_rect.bottom <= rect.top:
                if sprite.state == 0 or sprite.state == 3:
                    if not self.has_played:
                        self.bark = load_sfx("bark")
                        if self.mute == False:
                            self.bark.play()
                        self.has_played = True
                
                self.vy = 0
                self.rect.bottom = rect.top
                self.off_ground = False
            
        if self.has_played and self.off_ground:
            self.has_played = False

        if self.dying == True:  #death pause
            if self.diefalling == True:
                self.dyingcounter += dt*3
                if not self.has_fallen:
                    self.fallingsound.play()
                    self.has_fallen = True
                    self.diefalling = False
            else:
                self.dyingcounter += dt*10
            if self.dyingcounter > 2:
                self.dying = False
        if self.dyingcounter > 2:
            self.die(dt)

        #collide doors
        for sprite in self.touches(self.level.door):
            self.endsound = load_sfx("endlevel")
            if self.mute == False:
                self.endsound.play()
            self.endlevel()

        #fall off bottom
        if self.rect.bottom > self.bounds.bottom:
            self.diefalling = True
            self.dying = True

        if self.rect.left < self.bounds.left: #left side of screen
            self.vx = 0
            self.rect.left = self.bounds.left

        elif self.rect.right > self.bounds.right:
            self.vx = 0
            self.rect.right = self.bounds.right

        for sprite in self.touches(self.level.pups):
            rect = sprite.rect
            for RegPuppy in self.touches(self.level.pups):
                #killed by puppy
                if RegPuppy.state == 1 or RegPuppy.state == 2 or RegPuppy.state == 4:
                    if not self.has_splat:
                        if self.mute == False:
                            self.hitsound.play()
                            self.fallingsound.play()
                        self.has_splat = True
                    self.vx = 0
                    self.vy = 0
                    self.dying = True
      
                #collect gold puppy
                elif RegPuppy.state == 5:
                    self.goldsound = load_sfx("collect")
                    if self.mute == False:
                        self.goldsound.play()
                    RegPuppy.kill()
                    self.scorenum += 1
                    self.level.score = self.scorenum
        
            for Gold in self.touches(self.level.pups):
                if Gold.state == 5:
                    Gold.collected()