diff --git a/classes/Collider.py b/classes/Collider.py index 732db300..53f6d146 100644 --- a/classes/Collider.py +++ b/classes/Collider.py @@ -12,6 +12,7 @@ def checkX(self): rows = [ self.level[self.entity.getPosIndex().y], self.level[self.entity.getPosIndex().y + 1], + self.level[self.entity.getPosIndex().y + 2], ] except Exception: return diff --git a/classes/Input.py b/classes/Input.py index 55d7527d..72f4c564 100644 --- a/classes/Input.py +++ b/classes/Input.py @@ -19,16 +19,16 @@ def checkForKeyboardInput(self): pressedKeys = pygame.key.get_pressed() if pressedKeys[K_LEFT] or pressedKeys[K_h] and not pressedKeys[K_RIGHT]: - self.entity.traits["GoTrait"].direction = -1 + self.entity.traits["goTrait"].direction = -1 elif pressedKeys[K_RIGHT] or pressedKeys[K_l] and not pressedKeys[K_LEFT]: - self.entity.traits["GoTrait"].direction = 1 + self.entity.traits["goTrait"].direction = 1 else: - self.entity.traits['GoTrait'].direction = 0 + self.entity.traits['goTrait'].direction = 0 isJumping = pressedKeys[K_SPACE] or pressedKeys[K_UP] or pressedKeys[K_k] - self.entity.traits['JumpTrait'].jump(isJumping) + self.entity.traits['jumpTrait'].jump(isJumping) - self.entity.traits['GoTrait'].boost = pressedKeys[K_LSHIFT] + self.entity.traits['goTrait'].boost = pressedKeys[K_LSHIFT] def checkForMouseInput(self, events): mouseX, mouseY = pygame.mouse.get_pos() diff --git a/classes/Level.py b/classes/Level.py index 3edadd87..a7bb635d 100644 --- a/classes/Level.py +++ b/classes/Level.py @@ -8,6 +8,7 @@ from entities.Goomba import Goomba from entities.Mushroom import RedMushroom from entities.Koopa import Koopa +from entities.CoinBox import CoinBox from entities.RandomBox import RandomBox @@ -31,11 +32,12 @@ def loadLevel(self, levelname): def loadEntities(self, data): try: - [self.addRandomBox(x, y) for x, y in data["level"]["entities"]["randomBox"]] + [self.addCoinBox(x, y) for x, y in data["level"]["entities"]["CoinBox"]] [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"]] + [self.addRandomBox(x, y, item) for x, y, item in data["level"]["entities"]["RandomBox"]] except: # if no entities in Level pass @@ -147,7 +149,20 @@ def addBushSprite(self, x, y): except IndexError: return - def addRandomBox(self, x, y): + def addCoinBox(self, x, y): + self.level[y][x] = Tile(None, pygame.Rect(x * 32, y * 32 - 1, 32, 32)) + self.entityList.append( + CoinBox( + self.screen, + self.sprites.spriteCollection, + x, + y, + self.sound, + self.dashboard, + ) + ) + + def addRandomBox(self, x, y, item): self.level[y][x] = Tile(None, pygame.Rect(x * 32, y * 32 - 1, 32, 32)) self.entityList.append( RandomBox( @@ -155,8 +170,10 @@ def addRandomBox(self, x, y): self.sprites.spriteCollection, x, y, + item, self.sound, self.dashboard, + self ) ) diff --git a/entities/CoinBox.py b/entities/CoinBox.py new file mode 100644 index 00000000..e35d2b82 --- /dev/null +++ b/entities/CoinBox.py @@ -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)) diff --git a/entities/Mushroom.py b/entities/Mushroom.py index 11fc19ec..2088d836 100644 --- a/entities/Mushroom.py +++ b/entities/Mushroom.py @@ -1,5 +1,5 @@ from classes.Animation import Animation -from classes.Maths import vec2D +from classes.Maths import Vec2D from entities.EntityBase import EntityBase from traits.leftrightwalk import LeftRightWalkTrait from classes.Collider import Collider @@ -47,7 +47,7 @@ def onDead(self, camera): self.timer += 0.1 def setPointsTextStartPosition(self, x, y): - self.textPos = vec2D(x, y) + self.textPos = Vec2D(x, y) def movePointsTextUpAndDraw(self, camera): self.textPos.y += -0.5 diff --git a/entities/RandomBox.py b/entities/RandomBox.py index 2978508b..4c19d7b2 100644 --- a/entities/RandomBox.py +++ b/entities/RandomBox.py @@ -1,15 +1,14 @@ from copy import copy from entities.EntityBase import EntityBase -from entities.Item import Item class RandomBox(EntityBase): - def __init__(self, screen, spriteCollection, x, y, sound, dashboard, gravity=0): + def __init__(self, screen, spriteCollection, x, y, item, sound, dashboard, level, gravity=0): super(RandomBox, self).__init__(x, y, gravity) self.screen = screen self.spriteCollection = spriteCollection - self.animation = copy(self.spriteCollection.get("randomBox").animation) + self.animation = copy(self.spriteCollection.get("CoinBox").animation) self.type = "Block" self.triggered = False self.time = 0 @@ -17,14 +16,17 @@ def __init__(self, screen, spriteCollection, x, y, sound, dashboard, gravity=0): self.sound = sound self.dashboard = dashboard self.vel = 1 - self.item = Item(spriteCollection, screen, self.rect.x, self.rect.y) + self.item = item + self.level = level 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.item == 'RedMushroom': + self.level.addRedMushroom(self.rect.y // 32 - 1, self.rect.x // 32) + self.item = None if self.time < self.maxTime: self.time += 1 self.rect.y -= self.vel diff --git a/levels/Level1-1.json b/levels/Level1-1.json index 27f56c37..edbdaaff 100644 --- a/levels/Level1-1.json +++ b/levels/Level1-1.json @@ -66,9 +66,8 @@ } }, "entities": { - "randomBox":[ + "CoinBox":[ [4,8], - [4,3], [42,5], [56,2] ], @@ -111,6 +110,10 @@ [12,22], [12,33], [12,40] + ], + "RandomBox":[ + [4, 3, "RedMushroom"], + [52, 2, "RedMushroom"] ] } diff --git a/sprites/Animations.json b/sprites/Animations.json index 34702ae0..bbe769fa 100644 --- a/sprites/Animations.json +++ b/sprites/Animations.json @@ -3,7 +3,7 @@ "type":"animation", "sprites":[ { - "name":"randomBox", + "name":"CoinBox", "images":[ { "x":24,