Skip to content

Commit

Permalink
Merge branch 'master' into Add-red-mushroom
Browse files Browse the repository at this point in the history
  • Loading branch information
PeanutbutterWarrior authored and PeanutbutterWarrior committed Oct 29, 2020
2 parents fb794d2 + 4fbf81f commit bdad528
Show file tree
Hide file tree
Showing 19 changed files with 96 additions and 99 deletions.
4 changes: 2 additions & 2 deletions classes/Camera.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from classes.Maths import vec2D
from classes.Maths import Vec2D


class Camera:
def __init__(self, pos, entity):
self.pos = vec2D(pos.x, pos.y)
self.pos = Vec2D(pos.x, pos.y)
self.entity = entity
self.x = self.pos.x * 32
self.y = self.pos.y * 32
Expand Down
4 changes: 2 additions & 2 deletions classes/Collider.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ def checkY(self):
self.entity.vel.y = 0
# reset jump on bottom
if self.entity.traits is not None:
if "jumpTrait" in self.entity.traits:
self.entity.traits["jumpTrait"].reset()
if "JumpTrait" in self.entity.traits:
self.entity.traits["JumpTrait"].reset()
if "bounceTrait" in self.entity.traits:
self.entity.traits["bounceTrait"].reset()
if self.entity.vel.y < 0:
Expand Down
4 changes: 2 additions & 2 deletions classes/Font.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def loadFont(self):
row,
2,
colorkey=pygame.color.Color(0, 0, 0),
xTileSize = 8,
yTileSize = 8
xTileSize=8,
yTileSize=8
)
}
)
Expand Down
7 changes: 4 additions & 3 deletions classes/GaussianBlur.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import pygame
from scipy.ndimage.filters import *


class GaussianBlur:
def __init__(self,kernelsize=7):
def __init__(self, kernelsize=7):
self.kernel_size = kernelsize

def filter(self, srfc, xpos, ypos, width, height):
nSrfc = pygame.Surface((width,height))
nSrfc = pygame.Surface((width, height))
pxa = pygame.surfarray.array3d(srfc)
blurred = gaussian_filter(pxa,sigma=(self.kernel_size, self.kernel_size, 0))
blurred = gaussian_filter(pxa, sigma=(self.kernel_size, self.kernel_size, 0))
pygame.surfarray.blit_array(nSrfc, blurred)
del pxa
return nSrfc
31 changes: 12 additions & 19 deletions classes/Input.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ 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):
def checkForMouseInput(self, events):
mouseX, mouseY = pygame.mouse.get_pos()
if self.isRightMouseButtonPressed(events):
self.entity.levelObj.addKoopa(
Expand All @@ -47,7 +47,7 @@ def checkForMouseInput(self,events):
mouseX / 32 - self.entity.camera.pos.x, mouseY / 32
)

def checkForQuitAndRestartInputEvents(self,events):
def checkForQuitAndRestartInputEvents(self, events):
for event in events:
if event.type == pygame.QUIT:
pygame.quit()
Expand All @@ -58,20 +58,13 @@ def checkForQuitAndRestartInputEvents(self,events):
self.entity.pauseObj.createBackgroundBlur()

def isLeftMouseButtonPressed(self, events):
return self.checkMouse(events,1)


return self.checkMouse(events, 1)

def isRightMouseButtonPressed(self, events):
return self.checkMouse(events,3)

return self.checkMouse(events, 3)

def checkMouse(self, events, button):
for e in events:
if e.type == pygame.MOUSEBUTTONUP:
if e.button == button:
return True
else:
return False


if e.type == pygame.MOUSEBUTTONUP and e.button == button:
return True
return False
9 changes: 5 additions & 4 deletions classes/Level.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
from classes.Sprites import Sprites
from classes.Tile import Tile
from entities.Coin import Coin
from entities.CoinBrick import CoinBrick
from entities.Goomba import Goomba
from entities.Mushroom import RedMushroom
from entities.Koopa import Koopa
from entities.RandomBox import RandomBox
from entities.CoinBrick import CoinBrick


class Level:
def __init__(self, screen, sound, dashboard):
Expand Down Expand Up @@ -36,7 +37,7 @@ def loadEntities(self, data):
[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
# if no entities in Level
pass

def loadLayers(self, data):
Expand Down Expand Up @@ -112,7 +113,7 @@ def addCloudSprite(self, x, y):

def addPipeSprite(self, x, y, length=2):
try:
# add Pipe Head
# add pipe head
self.level[y][x] = Tile(
self.sprites.spriteCollection.get("pipeL"),
pygame.Rect(x * 32, y * 32, 32, 32),
Expand All @@ -121,7 +122,7 @@ def addPipeSprite(self, x, y, length=2):
self.sprites.spriteCollection.get("pipeR"),
pygame.Rect((x + 1) * 32, y * 32, 32, 32),
)
# add pipe Body
# add pipe body
for i in range(1, length + 20):
self.level[y + i][x] = Tile(
self.sprites.spriteCollection.get("pipe2L"),
Expand Down
2 changes: 1 addition & 1 deletion classes/Maths.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class vec2D:
class Vec2D:
def __init__(self, x=0, y=0):
self.x = x
self.y = y
32 changes: 16 additions & 16 deletions classes/Menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, screen, dashboard, level, sound):
0, 150, 2, colorkey=[255, 0, 220], ignoreTileSize=True
)
self.menu_dot2 = self.spritesheet.image_at(
20, 150, 2, colorkey=[255, 0, 220], ignoreTileSize=True
20, 150, 2, colorkey=[255, 0, 220], ignoreTileSize=True
)
self.loadSettings("./settings.json")

Expand Down Expand Up @@ -98,7 +98,7 @@ def drawMenu(self):
self.dashboard.drawText("SETTINGS", 180, 320, 24)
self.dashboard.drawText("EXIT", 180, 360, 24)

def drawMenuBackground(self,withBanner=True):
def drawMenuBackground(self, withBanner=True):
for y in range(0, 13):
for x in range(0, 20):
self.screen.blit(
Expand All @@ -111,7 +111,7 @@ def drawMenuBackground(self,withBanner=True):
self.level.sprites.spriteCollection.get("ground").image,
(x * 32, y * 32),
)
if(withBanner):
if withBanner:
self.screen.blit(self.menu_banner, (150, 80))
self.screen.blit(
self.level.sprites.spriteCollection.get("mario_idle").image,
Expand All @@ -132,7 +132,7 @@ def drawMenuBackground(self,withBanner=True):
self.screen.blit(
self.level.sprites.spriteCollection.get("bush_3").image, (18 * 32, 12 * 32)
)
self.screen.blit(self.level.sprites.spriteCollection.get("goomba-1").image,(18.5*32,12*32))
self.screen.blit(self.level.sprites.spriteCollection.get("goomba-1").image, (18.5*32, 12*32))

def drawSettings(self):
self.drawDot()
Expand All @@ -154,28 +154,28 @@ def chooseLevel(self):
self.levelNames = self.loadLevelNames()
self.drawLevelChooser()

def drawBorder(self,x,y,width,height,color,thickness):
pygame.draw.rect(self.screen,color,(x,y,width,thickness))
pygame.draw.rect(self.screen,color,(x,y+width,width,thickness))
pygame.draw.rect(self.screen,color,(x,y,thickness,width))
pygame.draw.rect(self.screen,color,(x+width,y,thickness,width+thickness))
def drawBorder(self, x, y, width, height, color, thickness):
pygame.draw.rect(self.screen, color, (x, y, width, thickness))
pygame.draw.rect(self.screen, color, (x, y+width, width, thickness))
pygame.draw.rect(self.screen, color, (x, y, thickness, width))
pygame.draw.rect(self.screen, color, (x+width, y, thickness, width+thickness))

def drawLevelChooser(self):
j = 0
offset = 75
textOffset = 90
for i, levelName in enumerate(self.loadLevelNames()):
if self.currSelectedLevel == i+1:
color = (255,255,255)
color = (255, 255, 255)
else:
color = (150,150,150)
color = (150, 150, 150)
if i < 3:
self.dashboard.drawText(levelName,175*i+textOffset,100,12)
self.drawBorder(175*i+offset,55,125,75,color,5)
self.dashboard.drawText(levelName, 175*i+textOffset, 100, 12)
self.drawBorder(175*i+offset, 55, 125, 75, color, 5)
else:
self.dashboard.drawText(levelName,175*j+textOffset,250,12)
self.drawBorder(175*j+offset,210,125,75,color,5)
j+=1
self.dashboard.drawText(levelName, 175*j+textOffset, 250, 12)
self.drawBorder(175*j+offset, 210, 125, 75, color, 5)
j += 1

def loadLevelNames(self):
files = []
Expand Down
4 changes: 2 additions & 2 deletions classes/Pause.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ def __init__(self, screen, entity, dashboard):
0, 150, 2, colorkey=[255, 0, 220], ignoreTileSize=True
)
self.gray_dot = self.spritesheet.image_at(
20, 150, 2, colorkey=[255, 0, 220], ignoreTileSize=True
20, 150, 2, colorkey=[255, 0, 220], ignoreTileSize=True
)

def update(self):
self.screen.blit(self.pause_srfc,(0,0))
self.screen.blit(self.pause_srfc, (0, 0))
self.dashboard.drawText("PAUSED", 120, 160, 68)
self.dashboard.drawText("CONTINUE", 150, 280, 32)
self.dashboard.drawText("BACK TO MENU", 150, 320, 32)
Expand Down
2 changes: 1 addition & 1 deletion classes/Spritesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def image_at(self, x, y, scalingfactor, colorkey=None, ignoreTileSize=False,
image = pygame.Surface(rect.size)
image.blit(self.sheet, (0, 0), rect)
if colorkey is not None:
if colorkey is -1:
if colorkey == -1:
colorkey = image.get_at((0, 0))
image.set_colorkey(colorkey, pygame.RLEACCEL)
return pygame.transform.scale(
Expand Down
3 changes: 2 additions & 1 deletion compile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from distutils.core import setup

import py2exe, glob
import py2exe
import glob

setup(
# this is the file that is run when you start the game from the command line.
Expand Down
12 changes: 6 additions & 6 deletions entities/EntityBase.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import pygame

from classes.Maths import vec2D
from classes.Maths import Vec2D


class EntityBase(object):
def __init__(self, x, y, gravity):
self.vel = vec2D()
self.vel = Vec2D()
self.rect = pygame.Rect(x * 32, y * 32, 32, 32)
self.gravity = gravity
self.traits = None
Expand All @@ -14,10 +14,10 @@ def __init__(self, x, y, gravity):
self.timer = 0
self.type = ""
self.onGround = False
self.obeygravity = True
self.obeyGravity = True

def applyGravity(self):
if self.obeygravity:
if self.obeyGravity:
self.vel.y += self.gravity

def updateTraits(self):
Expand All @@ -28,7 +28,7 @@ def updateTraits(self):
pass

def getPosIndex(self):
return vec2D(int(self.rect.x / 32), int(self.rect.y / 32))
return Vec2D(int(self.rect.x / 32), int(self.rect.y / 32))

def getPosIndexAsFloat(self):
return vec2D(self.rect.x / 32.0, self.rect.y / 32.0)
return Vec2D(self.rect.x / 32.0, self.rect.y / 32.0)
10 changes: 6 additions & 4 deletions entities/Goomba.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
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
from classes.Maths import Vec2D
from entities.EntityBase import EntityBase
from traits.leftrightwalk import LeftRightWalkTrait


class Goomba(EntityBase):
def __init__(self, screen, spriteColl, x, y, level, sound):
Expand All @@ -23,6 +24,7 @@ def __init__(self, screen, spriteColl, x, y, level, sound):
self.EntityCollider = EntityCollider(self)
self.levelObj = level
self.sound = sound
self.textPos = Vec2D(0, 0)

def update(self, camera):
if self.alive:
Expand Down Expand Up @@ -54,7 +56,7 @@ def drawFlatGoomba(self, camera):
)

def setPointsTextStartPosition(self, x, y):
self.textPos = vec2D(x, y)
self.textPos = Vec2D(x, y)

def movePointsTextUpAndDraw(self, camera):
self.textPos.y += -0.5
Expand Down
6 changes: 3 additions & 3 deletions entities/Item.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from copy import copy

from classes.Dashboard import Dashboard
from classes.Maths import vec2D
from classes.Maths import Vec2D


class Item(Dashboard):
def __init__(self, collection, screen, x, y):
super(Item, self).__init__("./img/font.png", 8, screen)
self.ItemPos = vec2D(x, y)
self.itemVel = vec2D(0, 0)
self.ItemPos = Vec2D(x, y)
self.itemVel = Vec2D(0, 0)
self.screen = screen
self.coin_animation = copy(collection.get("coin-item").animation)
self.sound_played = False
Expand Down
Loading

0 comments on commit bdad528

Please sign in to comment.