This server is intended for use for Academic Classwork related Git repositories only. Projects/repositories will generally be removed after 6 months following close of the semester. Inactive repositories from previous semester are now being archived when no activity for 365 days. They are renamed and marked as 'archived'. After 90 days in that state they will be removed from the system completely.

Commit b92f45b8 authored by jng2ng's avatar jng2ng

Mario only jumps once if button is held

parent 1584fcab
from block import Block
from ..block import Block
class Brick(Block):
\ No newline at end of file
......@@ -3,7 +3,7 @@
#This is the class definition file for the subclass powerBlock
import pygame
import block
from .block import Block
from enum import Enum
#block state to check if block is a dead block or not.
......@@ -20,7 +20,7 @@ class BlockState(Enum):
dead box
class powerBlock(block.Block,pygame.sprite.Sprite):
class powerBlock(Block,pygame.sprite.Sprite):
def __init__(self, xCord, yCord, blockTexture, GameDisplay, power, hiddenBlock, hiddenTexture, BrokenTexture):
......@@ -4,7 +4,7 @@ import time
from enum import Enum
import math
import imwatchingyou
import powerBlock
from Blocks import powerBlock
......@@ -97,6 +97,7 @@ class Player(pygame.sprite.Sprite):
#Frame of animation
self.animation = AnimFrame.IDLE
self.crouched = False
self.jumped = False
#Collision rect and sprite image
self.imageRect = pygame.Rect(0,0,16*scale,16*scale)
......@@ -150,7 +151,8 @@ class Player(pygame.sprite.Sprite):
self.yVelocity = 0
def jump(self):
if not self.midair():
if not self.midair() and not self.jumped:
self.jumped = True
if not self.crouched:
self.animation = AnimFrame.JUMP
self.fallingGravity = int("00700", 16)
......@@ -385,6 +387,7 @@ class Player(pygame.sprite.Sprite):
for block in pygame.sprite.spritecollide(self,self.collisionGroup,False):
if(block.rect.bottom - <= 8 and self.rect.bottom > block.rect.bottom and self.yVelocity < 0):
self.yVelocity = 0
block.dead = powerBlock.BlockState.DEAD
return True
return False
......@@ -395,8 +398,8 @@ def main():
display = pygame.display.set_mode((width,height))
block = powerBlock.powerBlock(200,380, "MarioPowerBlock.jpeg", display, 0, False, "MarioPowerBlock.jpeg", "MarioPowerBlock.jpeg")
block2 = powerBlock.powerBlock(400,420, "MarioPowerBlock.jpeg", display, 0, False, "MarioPowerBlock.jpeg", "MarioPowerBlock.jpeg")
block = powerBlock.powerBlock(200,380, "Blocks/MarioPowerBlock.jpeg", display, 0, False, "Blocks/MarioPowerBlock.jpeg", "Blocks/MarioPowerBlock.jpeg")
block2 = powerBlock.powerBlock(400,420, "Blocks/MarioPowerBlock.jpeg", display, 0, False, "Blocks/MarioPowerBlock.jpeg", "Blocks/MarioPowerBlock.jpeg")
group = pygame.sprite.Group()
......@@ -418,6 +421,7 @@ def main():
if event.type == pygame.QUIT:
done = True
keys = pygame.key.get_pressed()
if keys[pygame.K_RIGHT] and keys[pygame.K_z] and (mario.midair() or not keys[pygame.K_DOWN]):
......@@ -430,6 +434,8 @@ def main():
if keys[pygame.K_SPACE]:
elif not keys[pygame.K_SPACE]:
if not mario.midair():
mario.jumped = False
if (not keys[pygame.K_LEFT] and not keys[pygame.K_RIGHT]) or (not mario.midair() and keys[pygame.K_DOWN]):
......@@ -445,10 +451,8 @@ def main():
collide = pygame.sprite.spritecollide(mario, group, False)
display.blit(mario.image, (mario.imageRect.x,mario.imageRect.y))
This diff is collapsed.
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment