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):
pass
\ 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):
pygame.sprite.Sprite.__init__(self)
......
......@@ -4,7 +4,7 @@ import time
from enum import Enum
import math
import imwatchingyou
import powerBlock
from Blocks import powerBlock
#imwatchingyou.show_debugger_window()
......@@ -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 - self.rect.top <= 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]):
mario.walkRight(True)
......@@ -430,6 +434,8 @@ def main():
if keys[pygame.K_SPACE]:
mario.jump()
elif not keys[pygame.K_SPACE]:
if not mario.midair():
mario.jumped = False
mario.noJumpInput()
if (not keys[pygame.K_LEFT] and not keys[pygame.K_RIGHT]) or (not mario.midair() and keys[pygame.K_DOWN]):
mario.noInput()
......@@ -445,10 +451,8 @@ def main():
collide = pygame.sprite.spritecollide(mario, group, False)
display.fill([255,255,255])
#group.draw(display)
group.draw(display)
display.blit(mario.image, (mario.imageRect.x,mario.imageRect.y))
pygame.draw.rect(display,(255,0,0),block2.rect,2)
pygame.draw.rect(display,(255,0,0),block.rect,2)
pygame.draw.rect(display,(255,0,0),mario.rect,2)
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment