Created
February 27, 2015 02:55
-
-
Save lunacodes/1565bb42721ffaae933f 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 = 800 | |
winHeight = 800 | |
black = (0, 0, 0) | |
everything = pygame.sprite.Group() | |
gameDisplay = pygame.display.set_mode((winWidth,winHeight)) | |
pygame.display.set_caption('RPG Skeleton with Classes') | |
class Player(pygame.sprite.Sprite): | |
def __init__(self, x, y, w, h): | |
pygame.sprite.Sprite.__init__(self) #super(Player, self).__init__() | |
self.display = gameDisplay | |
green = (0,255,0) | |
self.xchange = 0 | |
self.ychange = 0 | |
self.x = x | |
self.y = y | |
self.w = w | |
self.h = h | |
self.x += self.xchange | |
self.y += self.ychange | |
self.color = green | |
self.player = square(self.display, self.color, (self.x, self.y, self.w, self.h)) | |
self.add(Players) | |
self.image = pygame.Surface([self.x, self.y]) | |
self.rect = self.image.get_rect() | |
def draw(self): | |
self.x += self.xchange | |
self.y += self.ychange | |
self.player = square(self.display, self.color, (self.x, self.y, self.w, self.h)) | |
#self.image = pygame.Surface([self.x, self.y]) | |
#self.rect = self.image.get_rect() | |
#self.rect = self.get_rect() | |
#self.rect = (self.x, self.y, self.w, self.h) | |
#if self.rect.colliderect(walls.rect): | |
# print "Collision" | |
class Wall(pygame.sprite.Sprite): | |
def __init__(self, x, y, w, h): | |
pygame.sprite.Sprite.__init__(self) #super(Wall, self).__init__() | |
self.display = gameDisplay | |
grey = (119, 136, 153) | |
self.x = x | |
self.y = y | |
self.w = w | |
self.h = h | |
self.add(Walls) | |
self.color = grey | |
self.player = square(self.display, self.color, (self.x, self.y, self.w, self.h)) | |
#self.rect = (self.x, self.y, self.w, self.h) | |
self.image = pygame.Surface([self.x, self.y]) | |
self.rect = self.image.get_rect() | |
def draw(self): | |
self.wall = square(self.display, self.color, (self.x, self.y, self.w, self.h)) | |
#self.image = pygame.Surface([self.x, self.y]) | |
#self.rect = self.image.get_rect() | |
#self.rect = (self.x, self.y, self.w, self.h) | |
wallWidth = winWidth * .4 | |
wallHeight = winHeight * .4 | |
Players = pygame.sprite.Group() | |
Walls = pygame.sprite.Group() | |
link = Player(winWidth / 2 - 50, winHeight / 2 - 50, 50, 50) | |
wall1 = Wall(0, 0, wallWidth, wallHeight) | |
wall2 = Wall(winWidth - wallWidth, 0, wallWidth, wallHeight) | |
wall3 = Wall(0, winHeight - wallHeight, wallWidth, wallHeight) | |
wall4 = Wall(winWidth - wallWidth, winHeight - wallHeight, wallWidth, wallHeight) | |
pygame.init() | |
def main(): | |
pygame.display.update() | |
run = True | |
while run: | |
gameDisplay.fill(black) | |
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: | |
link.ychange = -5 | |
if event.key == K_DOWN or event.key == K_s: | |
link.ychange = 5 | |
if event.key == K_LEFT or event.key == K_a: | |
link.xchange = -5 | |
if event.key == K_RIGHT or event.key == K_d: | |
link.xchange = 5 | |
if event.type == KEYUP: | |
if event.key == K_UP or event.key == K_w: | |
link.ychange = 0 | |
if event.key == K_DOWN or event.key == K_s: | |
link.ychange = 0 | |
if event.key == K_LEFT or event.key == K_a: | |
link.xchange = 0 | |
if event.key == K_RIGHT or event.key == K_d: | |
link.xchange = 0 | |
link.draw() | |
wall1.draw() | |
wall2.draw() | |
wall3.draw() | |
wall4.draw() | |
hitWalls = pygame.sprite.groupcollide(Players, Walls, False, False) | |
for wall in Walls.sprites(): | |
print wall.rect | |
# for collision in hitWalls: | |
# print "collision" | |
pygame.display.update() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment