Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

"""Model classes"""
class Player(object):
def __init__(self,x=0,y=0,width=50,height=50,dx=1,dy=0,shiftdx=0,jumpdy=-.75):
def __init__(self,x=0,y=0,width=50,height=50,dx=1,dy=.001,shiftdx=0,jumpdy=-.75):
# places player centered above the coordinate given
self.x = x
self.y = y-height
Expand All @@ -47,7 +47,10 @@ def go_back(self):
return self.x < 130

def hit_ground(self,ground):
return (self.y + self.height) > ground.y
return (self.y + self.height) >= ground.y and self.x < (ground.x+ground.width) and self.x > ground.x

def off_screen(self):
return self.y > 480

class PainTrain(object):
def __init__(self,x=0,y=0,width=200,height=200,constdx=.05,dx=0,shiftdx=-1):
Expand Down Expand Up @@ -151,7 +154,7 @@ def main():

# models
# level models:
ground = Ground()
ground = Ground(x=0,width=600)
platform1 = Platform(10,10)
platform2 = Platform(800,10)
platform3 = Platform(1600,10)
Expand Down Expand Up @@ -193,15 +196,16 @@ def main():
if event.type == pygame.QUIT:
running = False

if player.train_wreck(train):
if player.train_wreck(train) or player.off_screen():
train.constdx = 0
player.dx = 0
running = False

if player.hit_ground(ground):
player.dy = 0
player.y = ground.y - player.height

else:
player.dy = .3

# keep train moving
train.step()
Expand Down