Created
December 23, 2013 08:56
-
-
Save abcsds/8093698 to your computer and use it in GitHub Desktop.
Pygame basic class structure
This file contains 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 | |
from pygame.locals import * | |
class Game(object): | |
"""docstring for Game""" | |
def __init__(self,arg): | |
self.arg = arg | |
self.fullscreen = False | |
img = pygame.image.load('image.png') | |
self.crosshair_image = pygame.transform.scale(img,(50,50)) | |
self.clk = pygame.time.Clock() | |
self.x = width/2 | |
self.y = heigth/2 | |
self.fullscreen = False | |
pygame.mouse.set_visible(False) | |
def main(self, screen): | |
"""Main Game Loop""" | |
while True: | |
self.clk.tick(24) | |
x,y = pygame.mouse.get_pos() | |
screen.fill((0,0,0)) | |
screen.blit(self.crosshair_image,(x-25,y-25)) | |
pygame.display.flip() | |
for event in pygame.event.get(): | |
if event.type == QUIT: | |
return | |
elif event.type == KEYDOWN: | |
if event.key == K_ESCAPE: | |
return | |
elif event.key == K_RETURN: | |
self.fullscreen = pygame.display.toggle_fullscreen() | |
print self.fullscreen | |
elif event.type == VIDEORESIZE: | |
width,heigth = event.dict['size'] | |
screen = pygame.display.set_mode((width,heigth),HWSURFACE|DOUBLEBUF|RESIZABLE) | |
if __name__ == '__main__': | |
pygame.init() | |
width = 800 | |
heigth = 600 | |
screen = pygame.display.set_mode((width, heigth),HWSURFACE|DOUBLEBUF|RESIZABLE) | |
pygame.display.set_caption('Python Game') | |
Game(0).main(screen) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment