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
30 changes: 27 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@

"""Model classes"""
class Player(object):
def __init__(self,x=0,y=0,width=50,height=50,dx=1,shiftdx=0):
def __init__(self,x=0,y=0,width=50,height=50,dx=1,dy=0,shiftdx=0):
# places player centered above the coordinate given
self.x = x
self.y = y-height
self.width = width
self.height = height
self.dx = dx
self.dy = dy
self.shiftdx = shiftdx

def train_wreck(self, train):
Expand All @@ -44,6 +45,9 @@ def shift_world(self):
def go_back(self):
return self.x < 130

def hit_ground(self,ground):
return (self.y + self.height) > ground.y

class PainTrain(object):
def __init__(self,x=0,y=0,width=200,height=200,constdx=.05,dx=0,shiftdx=-1):
# places train centered above coordinate given
Expand Down Expand Up @@ -124,8 +128,8 @@ def handle_event(self):
# time passed isn't actually time based... based on while loop efficiency
player = self.player
models = self.models
keys = pygame.key.get_pressed() # checking pressed keys
for model in models:
keys = pygame.key.get_pressed() # checking pressed keys
if keys[pygame.K_LEFT]:
if player.go_back():
model.x -= model.shiftdx
Expand All @@ -137,6 +141,13 @@ def handle_event(self):
else:
model.x += model.dx

if keys[pygame.K_UP] and player.dy == 0:
player.dy = -2





def main():
pygame.init()
screen = pygame.display.set_mode((640,480))
Expand Down Expand Up @@ -172,10 +183,14 @@ def main():
running = True
counter = 0



# variable to make speed lower
delta_speed = .00005 # good one is .00005

while running == True:
print player.y, player.dy

# Pretty awful way to slow player down.
counter += 1 # adjust this if it's running to slow. Sorry.
if counter%5 == 0:
Expand All @@ -190,8 +205,17 @@ def main():
player.dx = 0
running = False

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


# keep train moving
train.step()
player.y += player.dy
if player.dy != 0:
player.dy += 0.01


# decrease speed of player (and all things relative to it)
for model in controlled_models:
Expand Down Expand Up @@ -222,4 +246,4 @@ def main():
pygame.quit()

if __name__ == '__main__':
main()
main()