Skip to content
Browse files

Initial commit

  • Loading branch information...
0 parents commit d828c945b5dcfc06fcd854dadc7f5a9738438c34 Mark Ransom committed Sep 18, 2011
Showing with 137 additions and 0 deletions.
  1. +7 −0 .gitignore
  2. +1 −0 README
  3. +129 −0 loadRunner.py
7 .gitignore
@@ -0,0 +1,7 @@
+# git-ls-files --others --exclude-from=.git/info/exclude
+# Lines that start with '#' are comments.
+# For a project mostly in C, the following would be a good set of
+# exclude patterns (uncomment them if you want to use them):
+# *.[oa]
+*~
+*.pyc
1 README
@@ -0,0 +1 @@
+A python implementation of the old game Lode Runner.
129 loadRunner.py
@@ -0,0 +1,129 @@
+import pygame, sys, random
+from pygame.locals import *
+
+# set up pygame
+pygame.init()
+mainClock = pygame.time.Clock()
+
+# set up the window
+WINDOWWIDTH = 400
+WINDOWHEIGHT = 400
+windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT), 0, 32)
+pygame.display.set_caption('Input')
+
+# set up the colors
+BLACK = (0, 0, 0)
+GREEN = (0, 255, 0)
+WHITE = (255, 255, 255)
+
+# set up the player and food data structure
+GOLD_HEIGHT = 10
+GOLD_WIDTH = 20
+FLOOR_HEIGHT = 5
+player = pygame.Rect(300, 100, 10, 30)
+
+def load_floors(floor_data):
+ floors = []
+ for floor in floor_data:
+ floors.append(pygame.Rect(floor['left'], floor['top'], floor['width'], FLOOR_HEIGHT))
+ return floors
+
+floor_data = [
+ { 'width' : 200, 'left' : 20, 'top' : 40 },
+ { 'width' : 70, 'left' : 200, 'top' : 80 },
+ { 'width' : 300, 'left' : 80, 'top' : 300 },
+ { 'width' : 100, 'left' : 250, 'top' : 150 },
+]
+
+floors = load_floors(floor_data)
+
+gold = []
+for i in range(random.randint(5, 10)):
+ floor = random.choice(floors)
+ left = random.randint(floor.left, floor.left + floor.width)
+ gold.append(pygame.Rect(left, floor.top - GOLD_HEIGHT, GOLD_WIDTH, GOLD_HEIGHT))
+
+# set up movement variables
+moveLeft = False
+moveRight = False
+moveUp = False
+moveDown = False
+
+MOVESPEED = 6
+
+
+# run the game loop
+while True:
+ # check for events
+ for event in pygame.event.get():
+ if event.type == QUIT:
+ pygame.quit()
+ sys.exit()
+ if event.type == KEYDOWN:
+ # change the keyboard variables
+ if event.key == K_LEFT or event.key == ord('a'):
+ moveRight = False
+ moveLeft = True
+ if event.key == K_RIGHT or event.key == ord('d'):
+ moveLeft = False
+ moveRight = True
+ if event.key == K_UP or event.key == ord('w'):
+ moveDown = False
+ moveUp = True
+ if event.key == K_DOWN or event.key == ord('s'):
+ moveUp = False
+ moveDown = True
+ if event.type == KEYUP:
+ if event.key == K_ESCAPE:
+ pygame.quit()
+ sys.exit()
+ if event.key == K_LEFT or event.key == ord('a'):
+ moveLeft = False
+ if event.key == K_RIGHT or event.key == ord('d'):
+ moveRight = False
+ if event.key == K_UP or event.key == ord('w'):
+ moveUp = False
+ if event.key == K_DOWN or event.key == ord('s'):
+ moveDown = False
+ if event.key == ord('x'):
+ player.top = random.randint(0, WINDOWHEIGHT - player.height)
+ player.left = random.randint(0, WINDOWWIDTH - player.width)
+
+ if event.type == MOUSEBUTTONUP:
+ gold.append(pygame.Rect(event.pos[0], event.pos[1], GOLD_WIDTH, GOLD_HEIGHT))
+
+ #if gold >= NEWFOOD:
+ # add new food
+ #gold.append(pygame.Rect(random.randint(0, WINDOWWIDTH - GOLD_WIDTH), random.randint(0, WINDOWHEIGHT - GOLD_HEIGHT), GOLD_WIDTH, GOLD_HEIGHT))
+
+ # draw the black background onto the surface
+ windowSurface.fill(BLACK)
+
+ # move the player
+ if moveDown and player.bottom < WINDOWHEIGHT:
+ player.top += MOVESPEED
+ if moveUp and player.top > 0:
+ player.top -= MOVESPEED
+ if moveLeft and player.left > 0:
+ player.left -= MOVESPEED
+ if moveRight and player.right < WINDOWWIDTH:
+ player.right += MOVESPEED
+
+ # draw the player onto the surface
+ pygame.draw.rect(windowSurface, WHITE, player)
+
+ # check if the player has intersected with any food squares.
+ for brick in gold[:]:
+ if player.colliderect(brick):
+ gold.remove(brick)
+
+ # draw the food
+ for i in range(len(gold)):
+ pygame.draw.rect(windowSurface, GREEN, gold[i])
+
+ for floor in floors:
+ pygame.draw.rect(windowSurface, WHITE, floor)
+
+ # draw the window onto the screen
+ pygame.display.update()
+ mainClock.tick(40)

0 comments on commit d828c94

Please sign in to comment.
Something went wrong with that request. Please try again.