Text Size
Text Size
Exit Full Screen
Python Mini
Show
Source Code
View Source Code in Full Screen
Open in New Tab
from processing import * import random width = 450 height = 480 tile_size = 30 num_columns = width / tile_size num_rows = height / tile_size print "Save Papa Franku" print "Columns:", num_columns print "Rows:", num_rows maze = [ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 3, 0, 0, 3, 0, 3, 2, 4, 0, 0, 1], [1, 3, 0, 0, 6, 0, 0, 0, 0, 0, 4, 4, 2, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 0, 1], [1, 0, 0, 0, 0, 4, 0, 0, 2, 0, 2, 2, 2, 0, 1], [1, 0, 2, 0, 0, 4, 0, 0, 1, 0, 0, 0, 0, 0, 1], [1, 0, 0, 1, 1, 4, 0, 0, 0, 0, 0, 4, 0, 0, 1], [1, 3, 0, 0, 1, 0, 0, 0, 0, 0, 5, 4, 0, 0, 1], [1, 0, 0, 1, 1, 0, 2, 2, 2, 0, 0, 4, 0, 0, 1], [1, 0, 0, 0, 4, 0, 2, 3, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 4, 2, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 3, 1, 0, 1], [1, 0, 0, 0, 3, 0, 0, 1, 0, 0, 3, 1, 1, 0, 1], [1, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1], [1, 0, 0, 0, 3, 0, 0, 0, 3, 0, 3, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] ] player = { "row": 7, "column": 10, "dead": False } teleports = [] def findTeleports(): for row in range(num_rows): for column in range(num_columns): if maze[row][column] == 3: t = { "row": row, "column": column } teleports.append(t) def setup(): global pImage, deadImage, fireImage pImage = loadImage("http://kashyyy.oyosite.com/player+alive.png") size(width, height) deadImage = loadImage("http://kashyyy.oyosite.com/player+dead.png") fireImage = loadImage ("http://kashyyy.oyosite.com/fire.png") findTeleports() def draw(): background(255, 127, 145) drawGrid() drawMaze() blackout() drawPlayer() def blackout(): for row in range(len(maze)): for column in range(len(maze[row])): if player['row'] != row and player['column'] != column: stroke(0, 0, 0) fill(0, 0, 0) rect(column * tile_size, row * tile_size, tile_size, tile_size) def drawPlayer(): row = player['row'] col = player['column'] if maze[row][col] == 2: #2=fire player['dead'] = True if not player ['dead']: image(pImage, col * tile_size, row * tile_size, tile_size, tile_size) else: image(deadImage, col * tile_size, row * tile_size, tile_size, tile_size) gameOver() if maze[row][col] == 6: win() def gameOver(): fill (240, 240, 255) textSize(40) text("You couldn't", 150, 250) text("save Frank. SMH!", 100, 300) exitp() def win(): fill(240, 240, 255) textSize(40) text("Hell yeah man", 100, 250) text("You saved Franku!", 40, 300) exitp() def drawGrid(): stroke(0, 0, 0) for x in range(0, width, tile_size): line(x, 0, x, height) for y in range(0, height, tile_size): line(0, y, width, y) def drawMaze(): for row in range(num_rows): for column in range(num_columns): if maze[row][column] in [1,4]: stroke (165, 49, 65) fill (239, 88, 108) rect(column * tile_size, row * tile_size, tile_size, tile_size) elif maze[row][column] == 2: image(fireImage, column * tile_size, row * tile_size, tile_size, tile_size) elif maze[row][column] == 3: stroke(0, 0, 0) fill(255, 127, 140) rect(column * tile_size, row * tile_size, tile_size, tile_size) def keyPressed(): if (keyboard.keyCode in [UP, DOWN, LEFT, RIGHT]): movePlayer(keyboard.keyCode) def movePlayer(direction): row = player ['row'] col = player ['column'] if direction == UP: new_row = row - 1 if (new_row >= 0 and maze[new_row][col] != 1): player['row'] = new_row elif direction == DOWN: new_row = row + 1 if (new_row < num_rows and maze [new_row][col] != 1): player ['row'] = new_row elif direction == RIGHT: new_col = col + 1 if (new_col < num_columns and maze[row][new_col] !=1): player['column'] = new_col elif direction == LEFT: new_col = col - 1 if (new_col >= 0 and maze[row][new_col] !=1): player['column'] = new_col checkTeleports(player['row'], player['column']) def checkTeleports(row, column): t_index = None for i in range(len(teleports)): tele = teleports [i] if (tele['row'] == row and tele ['column'] == column): t_index = i break if t_index is not None: new_t = random.randint(0, len(teleports)-1) while new_t == t_index: new_t = random.randint(0, len(teleports)-1) player['row'] = teleports[new_t]['row'] player['column'] = teleports[new_t]['column'] run()
torture_maze.py
( around 165 lines python code )
Published By:
Kashyyy
Published on
2017-07-14T16:29:50Z
Python Mini
- an
OYOclass
application,
own your own class today
.
Run
Result
×
Error message shows here