-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from PeanutbutterWarrior/Add-red-mushroom
Add red mushroom
- Loading branch information
Showing
15 changed files
with
296 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from copy import copy | ||
|
||
from entities.EntityBase import EntityBase | ||
from entities.Item import Item | ||
|
||
|
||
class CoinBox(EntityBase): | ||
def __init__(self, screen, spriteCollection, x, y, sound, dashboard, gravity=0): | ||
super(CoinBox, self).__init__(x, y, gravity) | ||
self.screen = screen | ||
self.spriteCollection = spriteCollection | ||
self.animation = copy(self.spriteCollection.get("CoinBox").animation) | ||
self.type = "Block" | ||
self.triggered = False | ||
self.time = 0 | ||
self.maxTime = 10 | ||
self.sound = sound | ||
self.dashboard = dashboard | ||
self.vel = 1 | ||
self.item = Item(spriteCollection, screen, self.rect.x, self.rect.y) | ||
|
||
def update(self, cam): | ||
if self.alive and not self.triggered: | ||
self.animation.update() | ||
else: | ||
self.animation.image = self.spriteCollection.get("empty").image | ||
self.item.spawnCoin(cam, self.sound, self.dashboard) | ||
if self.time < self.maxTime: | ||
self.time += 1 | ||
self.rect.y -= self.vel | ||
else: | ||
if self.time < self.maxTime * 2: | ||
self.time += 1 | ||
self.rect.y += self.vel | ||
self.screen.blit( | ||
self.spriteCollection.get("sky").image, | ||
(self.rect.x + cam.x, self.rect.y + 2), | ||
) | ||
self.screen.blit(self.animation.image, (self.rect.x + cam.x, self.rect.y - 1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from classes.Animation import Animation | ||
from classes.Maths import Vec2D | ||
from entities.EntityBase import EntityBase | ||
from traits.leftrightwalk import LeftRightWalkTrait | ||
from classes.Collider import Collider | ||
from classes.EntityCollider import EntityCollider | ||
|
||
|
||
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): | ||
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) |
Oops, something went wrong.