Created
March 3, 2009 18:23
-
-
Save gcr/73440 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
#Palikka luokka | |
import pygame | |
from pygame import * | |
class Palikka: | |
def __init__(self, image, max_x, max_y): | |
self.image = pygame.image.load(image).convert_alpha() | |
self.rect = self.image.get_rect() | |
def move(self): | |
self.rect.top = self.rect.top + self.rect.height | |
def draw(self, pinta): | |
#self.move() | |
pinta.blit(self.image, self.rect) | |
def move_left(self): | |
self.rect.left = self.rect.left - self.rect.width | |
def move_right(self): | |
self.rect.left = self.rect.left + self.rect.width |
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
#Tetris | |
import pygame | |
from pygame import * | |
import time | |
from palikka import Palikka | |
pygame.init() | |
pygame.display.set_caption('Tetris') | |
max_x = 640 | |
max_y = 480 | |
screen = tausta = pygame.display.set_mode((max_x, max_y)) | |
nelio = Palikka('block.png', max_x, max_y) | |
tausta = pygame.Surface(screen.get_size()) | |
tausta = tausta.convert() | |
tausta.fill((255, 255, 255)) | |
looping = True | |
while looping: | |
for event in pygame.event.get(): | |
if event.type == QUIT: | |
looping = False | |
if event.type == KEYDOWN: | |
if event.key == K_LEFT: | |
nelio.move_left() | |
if event.key == K_RIGHT: | |
nelio.move_right() | |
screen.blit(tausta, (0, 0)) | |
nelio.draw(screen) | |
pygame.display.flip() | |
time.sleep(2) | |
pygame.quit() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment