Skip to content

Commit

Permalink
Add CoinBrick entity and add to Level 1-1.
Browse files Browse the repository at this point in the history
  • Loading branch information
mitruly committed Oct 24, 2020
1 parent 2f6bce8 commit 262a30b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
15 changes: 15 additions & 0 deletions classes/Level.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from entities.Goomba import Goomba
from entities.Koopa import Koopa
from entities.RandomBox import RandomBox
from entities.CoinBrick import CoinBrick

class Level:
def __init__(self, screen, sound, dashboard):
Expand All @@ -32,6 +33,7 @@ def loadEntities(self, data):
[self.addGoomba(x, y) for x, y in data["level"]["entities"]["Goomba"]]
[self.addKoopa(x, y) for x, y in data["level"]["entities"]["Koopa"]]
[self.addCoin(x, y) for x, y in data["level"]["entities"]["coin"]]
[self.addCoinBrick(x, y) for x, y in data["level"]["entities"]["coinBrick"]]
except:
#if no entities in Level
pass
Expand Down Expand Up @@ -159,6 +161,19 @@ def addRandomBox(self, x, y):
def addCoin(self, x, y):
self.entityList.append(Coin(self.screen, self.sprites.spriteCollection, x, y))

def addCoinBrick(self, x, y):
self.level[y][x] = Tile(None, pygame.Rect(x * 32, y * 32 - 1, 32, 32))
self.entityList.append(
CoinBrick(
self.screen,
self.sprites.spriteCollection,
x,
y,
self.sound,
self.dashboard
)
)

def addGoomba(self, x, y):
self.entityList.append(
Goomba(self.screen, self.sprites.spriteCollection, x, y, self, self.sound)
Expand Down
27 changes: 27 additions & 0 deletions entities/CoinBrick.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from copy import copy

from entities.EntityBase import EntityBase
from entities.Item import Item


class CoinBrick(EntityBase):
def __init__(self, screen, spriteCollection, x, y, sound, dashboard, gravity=0):
super(CoinBrick, self).__init__(x, y, gravity)
self.screen = screen
self.spriteCollection = spriteCollection
self.image = self.spriteCollection.get("bricks").image
self.type = "Block"
self.triggered = False
self.sound = sound
self.dashboard = dashboard
self.item = Item(spriteCollection, screen, self.rect.x, self.rect.y)

def update(self, cam):
if not self.alive or self.triggered:
self.image = self.spriteCollection.get("empty").image
self.item.spawnCoin(cam, self.sound, self.dashboard)
self.screen.blit(
self.spriteCollection.get("sky").image,
(self.rect.x + cam.x, self.rect.y + 2),
)
self.screen.blit(self.image, (self.rect.x + cam.x, self.rect.y - 1))
3 changes: 3 additions & 0 deletions levels/Level1-1.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
[42,5],
[56,2]
],
"coinBrick":[
[37,9]
],
"coin":[
[21,8],
[22,8],
Expand Down

0 comments on commit 262a30b

Please sign in to comment.