Created
February 27, 2015 02:27
-
-
Save lunacodes/9d70fe8ce66a81103d66 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame, sys | |
from pygame.locals import * | |
from pygame.draw import rect as square | |
winWidth = 600 | |
winHeight = 600 | |
black = ( 0, 0, 0) | |
green = ( 0, 255, 0) | |
red = (255, 0, 0) | |
blue = ( 0, 0, 255) | |
brown = (139, 69, 19) | |
grey = (119, 136, 153) | |
purple = (160, 32, 240) | |
gameDisplay = pygame.display.set_mode((winWidth, winHeight)) | |
pygame.display.set_caption('RPG Skeleton') | |
pygame.init() | |
def intro(): | |
intro = True | |
while intro: | |
for event in pygame.event.get(): | |
if event.type == KEYDOWN: | |
if event.key == K_k: | |
pygame.quit() | |
sys.exit() | |
if event.key == K_p: | |
main() | |
#intro = False | |
basicfont = pygame.font.Font('freesansbold.ttf', 50) | |
text = basicfont.render('This is a Test', 50, green) | |
textRect = text.get_rect() | |
gameDisplay.blit(text, textRect) | |
pygame.display.update() | |
def scene2(): | |
run = True | |
playerx = winWidth * .5 | |
playery = winHeight * .5 | |
xchange = 0 | |
ychange = 0 | |
while run: | |
gameDisplay.fill(black) | |
playerx += xchange | |
playery += ychange | |
for event in pygame.event.get(): | |
if event.type == KEYDOWN: | |
if event.key == K_k: | |
pygame.quit() | |
sys.exit() | |
if event.key == K_UP or event.key == K_w: | |
ychange = -5 | |
if event.key == K_DOWN or event.key == K_s: | |
ychange = 5 | |
if event.key == K_LEFT or event.key == K_a: | |
xchange = -5 | |
if event.key == K_RIGHT or event.key == K_d: | |
xchange = 5 | |
if event.type == KEYUP: | |
if event.key == K_UP or event.key == K_w: | |
ychange = 0 | |
if event.key == K_DOWN or event.key == K_s: | |
ychange = 0 | |
if event.key == K_LEFT or event.key == K_a: | |
xchange = 0 | |
if event.key == K_RIGHT or event.key == K_d: | |
xchange = 0 | |
#pygame.display.update() | |
wallWidth = winWidth * .4 | |
wallHeight = winHeight * .4 | |
wallx = winWidth - wallWidth | |
wally = winHeight -(wallHeight) | |
player = square(gameDisplay, green, (playerx, playery, 50, 50)) | |
wall1 = square(gameDisplay, red, (0, 0, wallWidth, wallHeight)) | |
wall2 = square(gameDisplay, red, (wallx, 0, wallWidth, wallHeight)) | |
wall3 = square(gameDisplay, red, (0, wally, wallWidth, wallHeight)) | |
wall4 = square(gameDisplay, red, (wallx, wally, wallWidth, wallHeight)) | |
walls = [wall1, wall2, wall3, wall4] | |
twofortyacross = pygame.draw.line(gameDisplay, green, (0, 240), (winWidth, 240)) | |
threesixtydown = pygame.draw.line(gameDisplay, red, (240, 0), (240, winHeight)) | |
threesixtyacross = pygame.draw.line(gameDisplay, blue, (0, 360), (winWidth, 360)) | |
if (player.left <= wallWidth) and player.bottom <= 241: #top left - side collision | |
playerx = 241 | |
elif player.right >= winWidth - wallWidth and player.bottom <= 241: #top right - side collision | |
playerx = 310 | |
elif player.top <= 241 and player.left <= wallWidth: # top left - bottom collision | |
playery = 241 | |
elif player.top <= 241 and player.left >= winWidth - wallWidth: # top right - bottom collision | |
playery = 241 | |
elif player.bottom >= 360 and player.right <= wallWidth + 40: # bottom left - top collision | |
playery = 310 | |
elif player.bottom >= 360 and player.left >= winWidth - wallWidth + 40: #bottom right top collision | |
playery = 310 | |
elif player.left <= wallWidth and player.bottom >= 360: #bottomr left - side collision | |
playerx = wallWidth | |
elif player.right >= winWidth - wallWidth and player.top >= 360: | |
playerx = winWidth - wallWidth - 50 | |
if player.top >= winHeight - 50: | |
main() | |
pygame.display.update() | |
def main(): | |
run = True | |
playerx = winWidth * .5 | |
playery = winHeight * .5 | |
xchange = 0 | |
ychange = 0 | |
while run: | |
gameDisplay.fill(black) | |
playerx += xchange | |
playery += ychange | |
for event in pygame.event.get(): | |
if event.type == KEYDOWN: | |
if event.key == K_k: | |
pygame.quit() | |
sys.exit() | |
if event.key == K_UP or event.key == K_w: | |
ychange = -5 | |
if event.key == K_DOWN or event.key == K_s: | |
ychange = 5 | |
if event.key == K_LEFT or event.key == K_a: | |
xchange = -5 | |
if event.key == K_RIGHT or event.key == K_d: | |
xchange = 5 | |
if event.type == KEYUP: | |
if event.key == K_UP or event.key == K_w: | |
ychange = 0 | |
if event.key == K_DOWN or event.key == K_s: | |
ychange = 0 | |
if event.key == K_LEFT or event.key == K_a: | |
xchange = 0 | |
if event.key == K_RIGHT or event.key == K_d: | |
xchange = 0 | |
#pygame.display.update() | |
wallWidth = winWidth * .4 | |
wallHeight = winHeight * .4 | |
wallx = winWidth - wallWidth | |
wally = winHeight -(wallHeight) | |
player = square(gameDisplay, green, (playerx, playery, 50, 50)) | |
wall1 = square(gameDisplay, grey, (0, 0, wallWidth, wallHeight)) | |
wall2 = square(gameDisplay, grey, (wallx, 0, wallWidth, wallHeight)) | |
wall3 = square(gameDisplay, grey, (0, wally, wallWidth, wallHeight)) | |
wall4 = square(gameDisplay, grey, (wallx, wally, wallWidth, wallHeight)) | |
walls = [wall1, wall2, wall3, wall4] | |
twofortyacross = pygame.draw.line(gameDisplay, green, (0, 240), (winWidth, 240)) | |
threesixtydown = pygame.draw.line(gameDisplay, red, (240, 0), (240, winHeight)) | |
threesixtyacross = pygame.draw.line(gameDisplay, blue, (0, 360), (winWidth, 360)) | |
pygame.draw.polygon(gameDisplay, red, ((400, 200), (550, 200), (475, 0)), 10) | |
if (player.left <= wallWidth) and player.bottom <= 241: #top left - side collision | |
playerx = 241 | |
elif player.right >= winWidth - wallWidth and player.bottom <= 241: #top right - side collision | |
playerx = 310 | |
elif player.top <= 241 and player.left <= wallWidth: # top left - bottom collision | |
playery = 241 | |
elif player.top <= 241 and player.left >= winWidth - wallWidth: # top right - bottom collision | |
playery = 241 | |
elif player.bottom >= 360 and player.right <= wallWidth + 40: # bottom left - top collision | |
playery = 310 | |
elif player.bottom >= 360 and player.left >= winWidth - wallWidth + 40: #bottom right top collision | |
playery = 310 | |
elif player.left <= wallWidth and player.bottom >= 360: #bottomr left - side collision | |
playerx = wallWidth | |
elif player.right >= winWidth - wallWidth and player.top >= 360: | |
playerx = winWidth - wallWidth - 50 | |
if player.top <= 50: | |
scene2() | |
run = False | |
pygame.display.update() | |
intro() | |
#main() | |
#scene2() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment