class Goomba(EntityBase): def __init__(self, screen, spriteColl, x, y, level): super(Goomba, self).__init__(y, x - 1, 1.25) self.spriteCollection = spriteColl self.animation = Animation([self.spriteCollection.get("goomba-1").image, self.spriteCollection.get("goomba-2").image]) self.screen = screen self.leftrightTrait = LeftRightWalkTrait(self, level) self.type = "Mob" self.dashboard = level.dashboard def update(self, camera): if(self.alive): self.applyGravity() self.screen.blit( self.animation.image, (self.rect.x + camera.x, self.rect.y)) self.animation.update() self.leftrightTrait.update() else: if(self.timer == 0): self.textPos = vec2D(self.rect.x + 3, self.rect.y) if(self.timer < self.timeAfterDeath): self.textPos.y += -0.5 self.dashboard.drawText( "100", self.textPos.x + camera.x, self.textPos.y, 8) self.screen.blit(self.spriteCollection.get( "goomba-flat").image, (self.rect.x + camera.x, self.rect.y)) else: self.alive = None self.timer += 0.1
class Goomba(EntityBase): def __init__(self, screen, spriteColl, x, y, level): super(Goomba, self).__init__(y, x - 1, 1.25) self.spriteCollection = spriteColl self.animation = Animation([ self.spriteCollection.get("goomba-1").image, self.spriteCollection.get("goomba-2").image ]) self.screen = screen self.leftrightTrait = LeftRightWalkTrait(self, level) self.type = "Mob" def update(self, camera): if (self.alive): self.applyGravity() self.screen.blit(self.animation.image, (self.rect.x + camera.pos.x * 32, self.rect.y)) self.animation.update() self.leftrightTrait.update() else: if (self.timer < self.timeAfterDeath): self.screen.blit( self.spriteCollection.get("goomba-flat").image, (self.rect.x + camera.pos.x * 32, self.rect.y)) else: self.alive = None self.timer += 0.1
class Lacy(EntityBase): def __init__(self, screen, spriteColl, x, y, level): super(Lacy, self).__init__(y, x - 1, 1.25) self.spriteCollection = spriteColl self.animation = Animation( [ self.spriteCollection.get("lacy-1").image, self.spriteCollection.get("lacy-2").image, ] ) self.screen = screen self.leftrightTrait = LacyFight(self, level) self.type = "Mob" self.inAir = False self.inJump = False self.dashboard = level.dashboard self.lives = 3 self.level = level self.immuneTimer = 0 def update(self, camera): self.immuneTimer += 1 if self.lives < 1: self.drawFlatGoomba(camera) if self.alive: self.applyGravity() self.drawLacy(camera) self.leftrightTrait.update() else: self.onDead(camera) def drawLacy(self, camera): self.screen.blit(self.animation.image, (self.rect.x + camera.x - 16, self.rect.y - 32)) self.animation.update() def onDead(self, camera): if self.timer == 0: self.setPointsTextStartPosition(self.rect.x + 3, self.rect.y) if self.timer < self.timeAfterDeath and self.immuneTimer > 50: self.lives = self.lives - 1 self.immuneTimer = 0 self.level.mario.setPos(self.level.mario.rect.x, 3*32) else: self.alive = None self.timer += 0.1 def drawFlatGoomba(self, camera): self.level.mario.sound.music_channel.stop() self.level.mario.sound.play_sfx(self.level.mario.sound.clear) sleep(6.5) self.level.mario.restart = True def setPointsTextStartPosition(self, x, y): self.textPos = vec2D(x, y) def movePointsTextUpAndDraw(self, camera): self.textPos.y += -0.5 self.dashboard.drawText("100", self.textPos.x + camera.x, self.textPos.y, 8)
class RedMushroom(EntityBase): def __init__(self, screen, spriteColl, x, y, level, sound): super(RedMushroom, self).__init__(y, x - 1, 1.25) self.spriteCollection = spriteColl self.animation = Animation([ self.spriteCollection.get("mushroom").image, ]) self.screen = screen self.leftrightTrait = LeftRightWalkTrait(self, level) self.type = "Mob" self.dashboard = level.dashboard self.collision = Collider(self, level) self.EntityCollider = EntityCollider(self) self.levelObj = level self.sound = sound def update(self, camera): if self.alive: self.applyGravity() self.drawRedMushroom(camera) self.leftrightTrait.update() self.checkEntityCollision() else: self.onDead(camera) def drawRedMushroom(self, camera): self.screen.blit(self.animation.image, (self.rect.x + camera.x, self.rect.y)) self.animation.update() def onDead(self, camera): if self.timer == 0: self.setPointsTextStartPosition(self.rect.x + 3, self.rect.y) if self.timer < self.timeAfterDeath: self.movePointsTextUpAndDraw(camera) else: self.alive = None self.timer += 0.1 def setPointsTextStartPosition(self, x, y): self.textPos = Vec2D(x, y) def movePointsTextUpAndDraw(self, camera): self.textPos.y += -0.5 self.dashboard.drawText("100", self.textPos.x + camera.x, self.textPos.y, 8) def checkEntityCollision(self): pass
class Goomba(EntityBase): def __init__(self, screen, spriteColl, x, y, level): super(Goomba, self).__init__(y, x - 1, 1.25) self.spriteCollection = spriteColl self.animation = Animation([ self.spriteCollection.get("goomba-1").image, self.spriteCollection.get("goomba-2").image, ]) self.screen = screen self.leftrightTrait = LeftRightWalkTrait(self, level) self.type = "Mob" self.dashboard = level.dashboard def update(self, camera): if self.alive: self.applyGravity() self.drawGoomba(camera) self.leftrightTrait.update() else: self.onDead(camera) def drawGoomba(self, camera): self.screen.blit(self.animation.image, (self.rect.x + camera.x, self.rect.y)) self.animation.update() def onDead(self, camera): if self.timer == 0: self.setPointsTextStartPosition(self.rect.x + 3, self.rect.y) if self.timer < self.timeAfterDeath: self.movePointsTextUpAndDraw(camera) self.drawFlatGoomba(camera) else: self.alive = None self.timer += 0.1 def drawFlatGoomba(self, camera): self.screen.blit( self.spriteCollection.get("goomba-flat").image, (self.rect.x + camera.x, self.rect.y), ) def setPointsTextStartPosition(self, x, y): self.textPos = vec2D(x, y) def movePointsTextUpAndDraw(self, camera): self.textPos.y += -0.5 self.dashboard.drawText("100", self.textPos.x + camera.x, self.textPos.y, 8)
class Koopa(EntityBase): def __init__(self, screen, spriteColl, x, y, level): super(Koopa, self).__init__(y - 1, x, 1.25) self.spriteCollection = spriteColl self.animation = Animation([ self.spriteCollection.get("koopa-1").image, self.spriteCollection.get("koopa-2").image, ]) self.screen = screen self.leftrightTrait = LeftRightWalkTrait(self, level) self.timer = 0 self.timeAfterDeath = 35 self.type = "Mob" self.dashboard = level.dashboard self.collision = Collider(self, level) self.EntityCollider = EntityCollider(self) self.levelObj = level def update(self, camera): if self.alive == True: self.updateAlive(camera) self.checkEntityCollision() elif self.alive == "sleeping": self.sleepingInShell(camera) self.checkEntityCollision() elif self.alive == "shellBouncing": self.shellBouncing(camera) elif self.alive == False: self.die(camera) def drawKoopa(self, camera): if self.leftrightTrait.direction == -1: self.screen.blit(self.animation.image, (self.rect.x + camera.x, self.rect.y - 32)) else: self.screen.blit( pygame.transform.flip(self.animation.image, True, False), (self.rect.x + camera.x, self.rect.y - 32), ) def shellBouncing(self, camera): self.leftrightTrait.speed = 4 self.applyGravity() self.animation.image = self.spriteCollection.get("koopa-hiding").image self.drawKoopa(camera) self.leftrightTrait.update() def die(self, camera): if self.timer == 0: self.textPos = vec2D(self.rect.x + 3, self.rect.y - 32) if self.timer < self.timeAfterDeath: self.textPos.y += -0.5 self.dashboard.drawText("100", self.textPos.x + camera.x, self.textPos.y, 8) self.vel.y -= 0.5 self.rect.y += self.vel.y self.screen.blit( self.spriteCollection.get("koopa-hiding").image, (self.rect.x + camera.x, self.rect.y - 32), ) else: self.vel.y += 0.3 self.rect.y += self.vel.y self.textPos.y += -0.5 self.dashboard.drawText("100", self.textPos.x + camera.x, self.textPos.y, 8) self.screen.blit( self.spriteCollection.get("koopa-hiding").image, (self.rect.x + camera.x, self.rect.y - 32), ) if self.timer > 500: # delete entity self.alive = None self.timer += 6 def sleepingInShell(self, camera): if self.timer < self.timeAfterDeath: self.screen.blit( self.spriteCollection.get("koopa-hiding").image, (self.rect.x + camera.x, self.rect.y - 32), ) else: self.alive = True self.timer = 0 self.timer += 0.1 def updateAlive(self, camera): self.applyGravity() self.drawKoopa(camera) self.animation.update() self.leftrightTrait.update() def checkEntityCollision(self): for ent in self.levelObj.entityList: collisionState = self.EntityCollider.check(ent) if collisionState.isColliding: if ent.type == "Mob": self._onCollisionWithMob(ent, collisionState) def _onCollisionWithMob(self, mob, collisionState): if collisionState.isColliding and mob.alive == "shellBouncing": self.alive = False
class Goomba(EntityBase): def __init__(self, screen, spriteColl, x, y, level, sound): super(Goomba, self).__init__(y, x - 1, 1.25) self.spriteCollection = spriteColl self.animation = Animation( [ self.spriteCollection.get("goomba-1").image, self.spriteCollection.get("goomba-2").image, ] ) self.screen = screen self.leftrightTrait = LeftRightWalkTrait(self, level) self.type = "Mob" self.dashboard = level.dashboard self.collision = Collider(self, level) self.EntityCollider = EntityCollider(self) self.levelObj = level self.sound = sound self.textPos = Vec2D(0, 0) def update(self, camera): if self.alive: self.applyGravity() self.drawGoomba(camera) self.leftrightTrait.update() self.checkEntityCollision() else: self.onDead(camera) def drawGoomba(self, camera): self.screen.blit(self.animation.image, (self.rect.x + camera.x, self.rect.y)) self.animation.update() def onDead(self, camera): if self.timer == 0: self.setPointsTextStartPosition(self.rect.x + 3, self.rect.y) if self.timer < self.timeAfterDeath: self.movePointsTextUpAndDraw(camera) self.drawFlatGoomba(camera) else: self.alive = None self.timer += 0.1 def drawFlatGoomba(self, camera): self.screen.blit( self.spriteCollection.get("goomba-flat").image, (self.rect.x + camera.x, self.rect.y), ) def setPointsTextStartPosition(self, x, y): self.textPos = Vec2D(x, y) def movePointsTextUpAndDraw(self, camera): self.textPos.y += -0.5 self.dashboard.drawText("100", self.textPos.x + camera.x, self.textPos.y, 8) def checkEntityCollision(self): for ent in self.levelObj.entityList: collisionState = self.EntityCollider.check(ent) if collisionState.isColliding: if ent.type == "Mob": self._onCollisionWithMob(ent, collisionState) def _onCollisionWithMob(self, mob, collisionState): if collisionState.isColliding and mob.alive == "shellBouncing": self.alive = False self.sound.play_sfx(self.sound.brick_bump)
class Koopa(EntityBase): def __init__(self, screen, spriteColl, x, y, level): super(Koopa, self).__init__(y - 1, x, 1.25) self.spriteCollection = spriteColl self.animation = Animation([ self.spriteCollection.get("koopa-1").image, self.spriteCollection.get("koopa-2").image ]) self.screen = screen self.leftrightTrait = LeftRightWalkTrait(self, level) self.timer = 0 self.timeAfterDeath = 35 self.type = "Mob" def update(self, camera): if (self.alive == True): self.updateAlive(camera) elif self.alive == "sleeping": self.sleepingInShell(camera) elif self.alive == "shellBouncing": self.shellBouncing(camera) elif self.alive == False: self.die(camera) def drawKoopa(self, camera): if self.leftrightTrait.direction == -1: self.screen.blit( self.animation.image, (self.rect.x + camera.pos.x * 32, self.rect.y - 32)) else: self.screen.blit( pygame.transform.flip(self.animation.image, True, False), (self.rect.x + camera.pos.x * 32, self.rect.y - 32)) def shellBouncing(self, camera): self.leftrightTrait.speed = 4 self.applyGravity() self.animation.image = self.spriteCollection.get("koopa-hiding").image self.drawKoopa(camera) self.leftrightTrait.update() def die(self, camera): if (self.timer < self.timeAfterDeath): self.vel.y -= 0.5 self.rect.y += self.vel.y self.screen.blit( self.spriteCollection.get("koopa-hiding").image, (self.rect.x + camera.pos.x * 32, self.rect.y - 32)) else: self.vel.y += 0.3 self.rect.y += self.vel.y self.screen.blit( self.spriteCollection.get("koopa-hiding").image, (self.rect.x + camera.pos.x * 32, self.rect.y - 32)) if (self.timer > 500): #delete entity self.alive = None self.timer += 6 def sleepingInShell(self, camera): if (self.timer < self.timeAfterDeath): self.screen.blit( self.spriteCollection.get("koopa-hiding").image, (self.rect.x + camera.pos.x * 32, self.rect.y - 32)) else: self.alive = True self.timer = 0 self.timer += 0.1 def updateAlive(self, camera): self.applyGravity() self.drawKoopa(camera) self.animation.update() self.leftrightTrait.update()
class Koopa(EntityBase): def __init__(self, screen, spriteColl, x, y, level, sound): super(Koopa, self).__init__(y - 1, x, 1.25) self.spriteCollection = spriteColl self.animation = Animation( [ self.spriteCollection.get("koopa-1").image, self.spriteCollection.get("koopa-2").image, ] ) self.screen = screen self.leftrightTrait = LeftRightWalkTrait(self, level) self.timer = 0 self.timeAfterDeath = 35 self.type = "Mob" self.dashboard = level.dashboard self.collision = Collider(self, level) self.EntityCollider = EntityCollider(self) self.levelObj = level self.sound = sound def update(self, camera): if self.alive and self.active: self.updateAlive(camera) self.checkEntityCollision() elif self.alive and not self.active and not self.bouncing: self.sleepingInShell(camera) self.checkEntityCollision() elif self.bouncing: self.shellBouncing(camera) def drawKoopa(self, camera): if self.leftrightTrait.direction == -1: self.screen.blit( self.animation.image, (self.rect.x + camera.x, self.rect.y - 32) ) else: self.screen.blit( pygame.transform.flip(self.animation.image, True, False), (self.rect.x + camera.x, self.rect.y - 32), ) def shellBouncing(self, camera): self.leftrightTrait.speed = 4 self.applyGravity() self.animation.image = self.spriteCollection.get("koopa-hiding").image self.drawKoopa(camera) self.leftrightTrait.update() def sleepingInShell(self, camera): if self.timer < self.timeAfterDeath: self.screen.blit( self.spriteCollection.get("koopa-hiding").image, (self.rect.x + camera.x, self.rect.y - 32), ) else: self.alive = True self.active = True self.bouncing = False self.timer = 0 self.timer += 0.1 def updateAlive(self, camera): self.applyGravity() self.drawKoopa(camera) self.animation.update() self.leftrightTrait.update() def checkEntityCollision(self): for ent in self.levelObj.entityList: if ent is not self: collisionState = self.EntityCollider.check(ent) if collisionState.isColliding: if ent.type == "Mob": self._onCollisionWithMob(ent, collisionState) def _onCollisionWithMob(self, mob, collisionState): if collisionState.isColliding and mob.bouncing: self.alive = False self.sound.play_sfx(self.sound.brick_bump)