def backup_attack_loop(self): g = self.g self.image = self.orginalImage.subsurface((160, 0, 32, 32)) speed = self.walktimer self.walktimer += 1 if self.walktimer > 6: self.walktimer = 6 self.timer += 1 timergate = self.timer % 100 if timergate >= 80: if timergate == 80: self.face_the_player() if timergate == 85: Shot(g, self.direction, (self.rect.x + 16, self.rect.y + 8), 'shot8', 'enemy') self.walking = 0 else: self.walking = 1 if timergate % 100 == 0: self.face_the_player() dx = self.rect.x - g.player.rect.x if dx <40 and dx > -40: if self.dy == 10.0: self.dy = -10.0 if self.walking: self.rect.x += (1 - (self.direction * 2)) * speed framen = self.timer / 2 % 3 self.image = self.orginalImage.subsurface((32 + framen * 32, 0, 32, 32)) else: self.walktimer = 0 self.dy += .5 if self.dy > 10.0: self.dy = 10.0 self.rect.y += self.dy if self.rect.x < 416: self.direction = 0 self.image = pygame.transform.flip(self.image, self.direction, 0) # hitting the bullets and player s = Rect(self.rect) if s.colliderect (g.player.rect): g.player.touch(self) for b in g.bullets: if b.owner == 'player': drect = (b.rect.x + 30, b.rect.y ) if s.collidepoint(drect): b.destroy() self.health -= b.get_damage() e = Effect(self.g, 'health', (self.rect.x, self.rect.y)) e.healthchange = -b.get_damage() self.image = g.make_image_white(self.image)
def addHealth(self, n): self.health += n ef = Effect(self.g, "health", (self.rect.x, self.rect.y - 10)) ef.healthchange = n if self.health > self.healthmax: self.health = self.healthmax self.g.saveData["health"] = self.health
def touch(self, e): if self.imortal == 0: self.g.hurt.play() self.imortal = 10 self.health -= e.get_damage() ef = Effect(self.g, "health", (self.rect.x, self.rect.y)) ef.healthchange = -e.get_damage() # drop some skyberries if "weapon" in self.g.saveData: if self.g.saveData["weapon"] >= 1: wpnstr = "shot" + str(self.g.saveData["weapon"]) + "_lvl" if self.g.saveData[wpnstr] > 1: self.g.saveData[wpnstr] -= 1 if self.g.saveData[wpnstr] == 9: Effect(self.g, "msg", (self.rect.x, self.rect.y), "Level Down") if self.g.saveData[wpnstr] == 19: Effect(self.g, "msg", (self.rect.x, self.rect.y), "Level Down") sb = Inventory(self.g, "skyberry", (self.rect.x, self.rect.y)) sb.canget = 0 sb = Inventory(self.g, "skyberry", (self.rect.x, self.rect.y)) sb.canget = 0 sb = Inventory(self.g, "skyberry", (self.rect.x, self.rect.y)) sb.canget = 0 self.g.player.gravity = 15 self.g.player.jumping = 1 if self.g.saveData["weapon"] != 0: shotType = "shot" + str(self.g.saveData["weapon"]) self.g.saveData[shotType] -= 1 self.g.saveData["health"] = self.health
def mushroom_attack_loop(self): g = self.g if self.health <= 0: if self.feeling != 'dead': self.feeling = 'dead' self.timer = 0 if self.feeling == 'dead': if self.timer > 70: self.image = pygame.Surface((1, 1), SRCALPHA) self.dead = 1 return if self.timer % 10 == 0: self.exp2.play() if self.timer % 3 == 0: # flash on and off self.image = pygame.Surface((1, 1), SRCALPHA) else: x = random.randint(0, 256) y = random.randint(0, 256) e = Effect(self.g, 'explosion', (self.rect.x + x, self.rect.y + y)) return if self.timer % 20 == 1: if self.timer % 200 < 100: c = random.randint(0, 20) s = Shot(self.g, self.direction, (self.rect.x + 128, self.rect.y + 128 + c), 'shot5', 'enemy') s.callback = self.create_slime_monster self.squirt2.play() s = Rect(self.rect) s.x += 80 s.width -= 100 s.y += 100 s.height -= 180 if s.colliderect (g.player.rect): g.player.touch(self) for b in g.bullets: if b.owner == 'player': drect = (b.rect.x + 30, b.rect.y ) if s.collidepoint(drect): b.destroy() self.health -= b.get_damage() e = Effect(self.g, 'health', (self.rect.x, self.rect.y)) e.healthchange = -b.get_damage() tmp = pygame.Surface((256, 256), SRCALPHA) tmp.blit(self.image, (0,0)) tmp.blit(self.secondImage, (0,0)) self.image = tmp self.hitme.play() speed = 2 self.rect.x += (1 - (self.direction * 2)) * speed self.draw_health_meter()
def robot_attack_loop(self): g = self.g self.timer += 1 speed = 9 attackphase = self.timer % 70 self.image = self.orginalImage.subsurface((0, 32, 32, 32)) if attackphase == 1: # lunge at the player self.face_the_player() self.attacking = 2 # 2 = lunging elif attackphase == 50: # fire a ball of death at the player Shot(self.g, self.direction, (self.rect.x + 16, self.rect.y + 20), 'shot8', 'enemy') if attackphase >= 50 and attackphase <= 65: # fire a ball of death at the player self.image = self.orginalImage.subsurface((64, 32, 32, 32)) # lunging if self.attacking == 2: self.image = self.orginalImage.subsurface((32, 32, 32, 32)) if self.rect.colliderect (self.g.player.rect): self.g.player.touch(self) self.rect.x += speed if self.direction: self.rect.x -= speed*2 # loop through bullets and see if I die for b in g.bullets: if b.owner == 'player': drect = (b.rect.x + 30, b.rect.y ) if self.rect.collidepoint(drect): b.destroy() self.health -= b.get_damage() e = Effect(self.g, 'health', (self.rect.x, self.rect.y)) e.healthchange = -b.get_damage() self.image = g.make_image_white(self.image, (32, 32)) self.image = pygame.transform.flip(self.image, not self.direction, 0) if self.health <= 0: self.feeling = 'dead' self.attacking = 0 self.dontwalk = 1
def loop_hit_death(self, g, r, canbehit, canhitplayer): self.timer += 1 self.image = pygame.transform.flip(self.image, self.direction, 0) s = Rect(self.rect) if self.mode != 'death': if s.colliderect (g.player.rect): if canhitplayer: g.player.touch(self) if canbehit: for b in g.bullets: if b.owner == 'player': drect = (b.rect.x, b.rect.y) if s.collidepoint(drect): b.destroy() self.health -= b.get_damage() e = Effect(self.g, 'health', (self.rect.x, self.rect.y)) e.healthchange = -b.get_damage() if self.mode != 'ouch': self.birdhit.play() self.mode = 'ouch' self.btimer = 0 #k = Rect(b.rect) #k.x -= g.view.x #k.y -= g.view.y #pygame.draw.rect(g.screen, (0,255,255), k) #s.x -= g.view.x #s.y -= g.view.y #pygame.draw.rect(g.screen, (255,0,255), s) # dead if self.health <= 0: if self.mode != 'death': self.mode = 'death' self.btimer = 0
def fox_attack_loop(self): g = self.g if self.health <= 0: self.feeling = 'sad' self.health = 0 if self.attacking == 3: self.feeling = 'dead' self.rect.y += 3 else: self.attacking = 0 self.walking = 0 self.jumping = 0 self.walktopos = (self.rect.x, self.rect.y) return self.timer += 1 if self.jumping == 1: self.rect.y += self.jumpvec self.jumpvec += 1 # if timer is in the minus, you're firing for a while if self.timer < 0: self.walking = 0 if self.timer < -10: self.feeling = 'shooting' if self.attacking == 1:# first battle if self.timer % 2 == 0: s = Shot(g, self.direction, (self.rect.x + 44, self.rect.y + 35), 'shot3', 'enemy') elif self.attacking == 2: # second battle if self.timer % 4 == 0: s = Shot(g, self.direction, (self.rect.x + 44, self.rect.y + 35), 'shot3', 'enemy') s.keep_alive = 6 elif self.attacking == 3: # last if self.timer % 10 == 0: s = Shot(g, self.direction, (self.rect.x + 44, self.rect.y + 35), 'shot8', 'enemy') else: self.feeling = 'normal' speed = 4 if self.attacking == 2: speed = 5 self.rect.x += (1 - (self.direction * 2)) * speed self.rect.y += 2 # gravity if self.walktopos == (self.rect.x, self.rect.y) : # walking into something self.jumping = 1 self.jumpvec = -10 if self.attacking == 1: # first battle with fox if self.timer == 2: self.jumping = 1 self.jumpvec = -10 # shooting every random interval if random.randint(0, 70) == 0 and self.framecount > 10: self.timer = -30 if self.attacking == 2 or self.attacking == 3: # second battle with Fox dv = self.rect.x - self.g.player.rect.x if dv > 200: self.direction = 1 if dv < -200: self.direction = 0 if self.jumping == 0: # jumping every 30 frames if self.framecount % 40 == 0 and self.jumping == 0: self.jumping = 1 self.jumpvec = -10 if self.attacking == 3: self.jumpvec = -15 # shooting every random interval elif random.randint(0, 15) == 0 and self.framecount > 10: self.timer = -30 self.framecount += 1 self.walking = 1 self.walktopos = (self.rect.x, self.rect.y) # hitting the bullets and player s = Rect(self.rect) if s.colliderect (g.player.rect): g.player.touch(self) for b in g.bullets: if b.owner == 'player': drect = (b.rect.x + 30, b.rect.y ) if s.collidepoint(drect): b.destroy() self.health -= b.get_damage() e = Effect(self.g, 'health', (self.rect.x, self.rect.y)) e.healthchange = -b.get_damage() if self.feeling != 'sad': self.hitme.play() self.feeling = 'sad' self.image = g.make_image_white(self.image, (96, 64))
def loop(self, g, r): enableflip = 1 # reseting the frame count if not walking if self.walking == 0: self.framecount = 0 # animation if self.type == None: # assistant ima self.image = self.orginalImage.subsurface((32 * ((self.framecount/2) % 4), 0, 32, 32)) # hack! to get ima the only holding hand character if g.connected == 1 and self.direction == 0 and self.orginalImage.get_size() == (256, 128): self.image = self.orginalImage.subsurface((32 * ((self.framecount/2) % 4), 64, 32, 32)) if self.faceup == 1: self.image = self.orginalImage.subsurface((32 * 4, 0, 32, 32)) elif self.feeling == 'worried': self.image = self.orginalImage.subsurface((32 * 5, 0, 32, 32)) elif self.feeling == 'pulled': self.image = self.orginalImage.subsurface((32 * 6, 0, 32, 32)) elif self.feeling == 'coma': self.image = self.orginalImage.subsurface((32 * 7, 0, 32, 32)) elif self.feeling == 'coma2': self.image = self.orginalImage.subsurface((32 * 7, 32, 32, 32)) elif self.type == 'director':# director victora self.image = self.orginalImage.subsurface((32 * ((self.framecount/2) % 5), 0, 32, 32)) if self.feeling == 'sit': self.image = self.orginalImage.subsurface((32 * 5, 0, 32, 32)) elif self.feeling == 'sitangry': self.image = self.orginalImage.subsurface((32 * 6, 0, 32, 32)) elif self.feeling == 'sitawake': self.image = self.orginalImage.subsurface((32 * 7, 0, 32, 32)) elif self.type == 'robot':# robot 0 self.image = self.orginalImage.subsurface((0, 0, 32, 32)) if self.feeling == 'blink': self.image = self.orginalImage.subsurface((32, 0, 32, 32)) elif self.feeling == 'happy': self.image = self.orginalImage.subsurface((64, 0, 32, 32)) elif self.feeling == 'arms': self.image = self.orginalImage.subsurface((96, 0, 32, 32)) elif self.feeling == 'attack': self.image = self.orginalImage.subsurface((96, 0, 32, 32)) elif self.feeling == 'dead': self.image = self.orginalImage.subsurface((96, 32, 32, 32)) elif self.type == 'mushroom':# mushroom king if self.dead: self.image = pygame.Surface((1, 1), SRCALPHA) return enableflip = 0 self.timer += 1 self.image = self.orginalImage.subsurface((256, 256, 256, 256)) if self.feeling == 'walking': m = (self.timer / 3) % 3 if m == 0: self.image = self.orginalImage.subsurface((0, 0, 256, 256)) elif m == 1: self.image = self.orginalImage.subsurface((256, 0, 256, 256)) elif m == 2: self.image = self.orginalImage.subsurface((0, 256, 256, 256)) elif self.type == 'doctor':# doctor robot if self.dead == 1: #self.image = pygame.Surface((1, 1), SRCALPHA) return self.image = pygame.Surface((256, 256), SRCALPHA) enableflip = 0 self.timer += 1 leftarmlength = self.attackleft rightarmlength = self.attackright rightarmspnning = 0 if rightarmlength == 10: rightarmspnning = ((self.timer % 1000) - 600) / 40 + 1 dead = 0 if self.health <= 0: leftarmlength = 0 rightarmlength = 0 self.feeling = 'dead' self.image.blit(self.imagel, (0,0)) dead = 1 else: self.image.blit(self.imageh, (0,0)) if self.feeling == 'walking': m = (self.timer / 2) % 2 == 0 if m == 1: self.image.blit(self.imagee, (0,0)) # wonky tracks 2 else: self.image.blit(self.imagef, (0,0)) # wonky tracks 1 else: self.image.blit(self.imageg, (0,0)) # normal tracks # getting hit by a bullet s = Rect(self.rect) s.x += 50 s.y += 40 s.width -= 120 s.height -= 140 for b in g.bullets: if b.owner == 'player': drect = (b.rect.x , b.rect.y ) if s.collidepoint(drect) and not dead and rightarmspnning == 0: dmg = b.get_damage() self.health -= dmg e = Effect(self.g, 'health', (self.rect.x + 128, self.rect.y + 60)) e.healthchange = -dmg self.hitme.play() self.image.blit(self.imagek, (0,0)) # white flash hit b.destroy() if self.health <= 0: self.timer = 0 # blit the right arm if rightarmspnning == 0: if rightarmlength == 4 or leftarmlength == 4: self.attack.play() if rightarmlength == 0 or rightarmlength == 2: self.image.blit(self.imagec, (0,0)) elif rightarmlength == 1 or rightarmlength == 3: self.image.blit(self.imagei, (0,0)) else: self.image.blit(self.imagec, (0,(rightarmlength - 4) * 20)) if rightarmlength >= 0 and rightarmlength <= 3: rpos = (0,0) armr = self.imagea elif rightarmlength == 4: rpos = (-50,-65) armr = pygame.transform.rotate(self.imagea, -27) elif rightarmlength == 5: # there's no way to rotate around a point in pygame. rpos = (-55,-90) armr = pygame.transform.rotate(self.imagea, -45) else: # there's no way to rotate around a point in pygame. rpos = (-55,-90) armr = pygame.transform.rotate(self.imagea, -50) self.image.blit(armr, rpos) else: # covering the cross from player fire if rightarmspnning == 1 or rightarmspnning >= 9: armrd = pygame.transform.rotate(self.imagea, -10) armrc = pygame.transform.rotate(self.imagec, -25) self.image.blit(armrd, (-30, -25)) self.image.blit(armrc, (-60,-75)) else: armrd = pygame.transform.rotate(self.imagea, -20) armrc = pygame.transform.rotate(self.imagec, -50) self.image.blit(armrd, (-40, -50)) self.image.blit(armrc, (-80,-130)) # blit the left arm if leftarmlength == 0 or leftarmlength == 2: self.image.blit(self.imaged, (0,0)) elif leftarmlength == 1 or leftarmlength == 3: self.image.blit(self.imagej, (0,0)) else: self.image.blit(self.imaged, (0,(leftarmlength - 4) * 18)) if leftarmlength >= 0 and leftarmlength <= 3: rpos = (0,0) arml = self.imageb elif leftarmlength == 4: rpos = (-35,-60) arml = pygame.transform.rotate(self.imageb, 27) elif leftarmlength == 5: rpos = (-40,-80) arml = pygame.transform.rotate(self.imageb, 45) else: rpos = (-40,-80) arml = pygame.transform.rotate(self.imageb, 50) self.image.blit(arml, rpos) if self.attackright > 0: self.attackright += 1 if self.attackright > 7: self.attackright = 0 if self.attackleft > 0: self.attackleft += 1 if self.attackleft > 7: self.attackleft = 0 elif self.type == 'nurse': # the devil child of the doctor. special nurse if self.feeling == 'dead': self.image = self.orginalImage.subsurface((5 * 32, 0, 32, 32)) elif self.feeling == 'look0': self.image = self.orginalImage.subsurface((6 * 32, 0, 32, 32)) elif self.feeling == 'look1': self.image = self.orginalImage.subsurface((7 * 32, 0, 32, 32)) else: self.image = self.orginalImage.subsurface((0, 0, 32, 32)) if self.walking: self.image = self.orginalImage.subsurface((32 * (1 + (self.framecount/3) % 3), 0, 32, 32)) elif self.type == 'fox': if self.lastframehidden != self.hidden and self.lastframehidden != -1: print 'out of frame animation effect' Effect(g, 'foxentrance', (self.rect.x + 32, self.rect.y + 8)) self.teleport.play() self.lastframehidden = self.hidden if self.jumping: self.image = self.orginalImage.subsurface((96, 0, 96, 64)) elif self.walking: self.image = self.orginalImage.subsurface((96 * ((self.framecount/3) % 2), 64, 96, 64)) else: self.image = self.orginalImage.subsurface((0, 0, 96, 64)) if self.feeling == 'sad': self.image = self.orginalImage.subsurface((0, 128, 96, 64)) elif self.feeling == 'shooting': self.image = self.orginalImage.subsurface((96, 128, 96, 64)) elif self.feeling == 'dead': self.image = self.orginalImage.subsurface((96, 192, 96, 64)) if self.faceup == 1: self.image = self.orginalImage.subsurface((0, 192, 96, 64)) elif self.type == 'backup': self.image = self.orginalImage.subsurface((0, 0, 32, 32)) if self.dead: self.image = self.orginalImage.subsurface((196, 0, 32, 32)) elif self.type == 'boat': return # if you look the way you are facing if enableflip: self.image = pygame.transform.flip(self.image, self.direction, 0) # AI Mode has been activated if self.attacking != 0: if self.type == 'mushroom':# robot 0 self.mushroom_attack_loop() elif self.type == 'doctor': self.doctor_attack_loop() elif self.type == 'robot': self.robot_attack_loop() elif self.type == 'backup': self.backup_attack_loop() else: self.fox_attack_loop() return if self.dontwalk: return # if you're walking to a position p = (self.rect.x, self.rect.y) self.walking = 0 if p != self.walktopos and self.walktopos != None: self.walking = 1 self.framecount += 1 if p[0] > self.walktopos[0] + self.walkspeed: self.rect.x -= self.walkspeed elif p[0] < self.walktopos[0] - self.walkspeed: self.rect.x += self.walkspeed else: self.rect.x = self.walktopos[0] if p[1] > self.walktopos[1] + self.walkspeed: self.rect.y -= self.walkspeed elif p[1] < self.walktopos[1] - self.walkspeed: self.rect.y += self.walkspeed else: self.rect.y = self.walktopos[1] if self.hidden == 1: self.image = self.orginalImage.subsurface((0, 0, 0, 0))