Skip to content

Commit

Permalink
Fix Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
PeanutbutterWarrior authored and PeanutbutterWarrior committed Oct 28, 2020
1 parent d09842f commit dd5e118
Show file tree
Hide file tree
Showing 19 changed files with 90 additions and 93 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 @@ -52,8 +52,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 @@ -44,7 +44,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 @@ -55,20 +55,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
7 changes: 4 additions & 3 deletions classes/Level.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
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.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 @@ -111,7 +112,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 @@ -120,7 +121,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
1 change: 1 addition & 0 deletions classes/Spritesheet.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pygame


class Spritesheet(object):
def __init__(self, filename):
try:
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
16 changes: 8 additions & 8 deletions entities/Koopa.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import pygame

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 Koopa(EntityBase):
Expand All @@ -30,15 +30,15 @@ def __init__(self, screen, spriteColl, x, y, level, sound):
self.sound = sound

def update(self, camera):
if self.alive == True:
if self.alive:
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:
elif not self.alive:
self.die(camera)

def drawKoopa(self, camera):
Expand All @@ -61,10 +61,10 @@ def shellBouncing(self, camera):

def die(self, camera):
if self.timer == 0:
self.textPos = vec2D(self.rect.x + 3, self.rect.y - 32)
self.textPos = Vec2D(self.rect.x + 3, self.rect.y - 32)
if self.timer < self.timeAfterDeath:
self.textPos.y += -0.5
self.textPos = vec2D(self.rect.x + 3, self.rect.y - 32)
self.textPos = Vec2D(self.rect.x + 3, self.rect.y - 32)
self.dashboard.drawText("100", self.textPos.x + camera.x, self.textPos.y, 8)
self.vel.y -= 0.5
self.rect.y += self.vel.y
Expand Down Expand Up @@ -113,4 +113,4 @@ def checkEntityCollision(self):
def _onCollisionWithMob(self, mob, collisionState):
if collisionState.isColliding and mob.alive == "shellBouncing":
self.alive = False
self.sound.play_sfx(self.sound.brick_bump)
self.sound.play_sfx(self.sound.brick_bump)
Loading

0 comments on commit dd5e118

Please sign in to comment.