Skip to content

Commit

Permalink
Initial commit with two falling puyos
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrius Chamentauskas committed Apr 10, 2010
0 parents commit d2899e9
Show file tree
Hide file tree
Showing 16 changed files with 235 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pyc
Binary file added data/puyo_blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/puyo_green.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/puyo_neutral.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/puyo_purple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/puyo_red.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/puyo_yellow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions planas
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Puyo Pop klonas
* Išsinagrinėti PyGame veikimą (Bal 8)
* Padaryti pradinį langą su krentančiais įvairių spalvų blokais. (Bal 15)
* Padaryti blokų judinimą ir vartaliojimą (Bal 22)
* Keturių ar daugiau šalia esančių blokų sunaikinimas, taškų skaičiavimas (Bal 29)
* Gyvo priešininko implementacija (Geg 5)
* Dirbtinis intelektas (Geg 19)
* Nustatymai (sudėtingumas, valdymas ir pan.) (Geg 26)
7 changes: 7 additions & 0 deletions puyo.kpf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Komodo Project File - DO NOT EDIT -->
<project id="459e1c0d-6632-46d5-8843-31843b3d6c4d" kpf_version="4" name="puyo.kpf">
<preference-set idref="459e1c0d-6632-46d5-8843-31843b3d6c4d">
<boolean id="import_live">1</boolean>
</preference-set>
</project>
22 changes: 22 additions & 0 deletions puyo/board.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pygame, random
from puyo import *
COLORS = ['blue', 'green', 'purple', 'red', 'yellow']

class Board(pygame.sprite.Group, Movable):
def __init__(self, puyo_size):
pygame.sprite.Group.__init__(self)
self.rows_count = 14
self.cols_count = 6
Movable.__init__(self, pygame.Rect(10, 10, puyo_size[0] * 6, puyo_size[1] * 14))

background = pygame.sprite.Sprite()
background.image = pygame.Surface(self.rect.size)
background.image.fill((240, 240, 240))
background.rect = self.rect
self.add(background)

self.puyo_size = puyo_size

def spawn_puyo(self):
self.add(Puyo(self, random.choice(COLORS)))
self.add(Puyo(self, random.choice(COLORS), -1))
39 changes: 39 additions & 0 deletions puyo/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python

import sys
import pygame
from pygame.locals import *

from board import *

if not pygame.font: print 'Warning, fonts disabled'
if not pygame.mixer: print 'Warning, sound disabled'

pygame.init()
screen = pygame.display.set_mode((800, 600))
pygame.display.set_caption('Puyo Pop')
pygame.mouse.set_visible(0)

background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill((0, 0, 0))
screen.blit(background, (0, 0))
pygame.display.flip()

board = Board((32, 32))
board.spawn_puyo()
allsprites = pygame.sprite.RenderPlain((board))
clock = pygame.time.Clock()

while 1:
clock.tick(60)

for event in pygame.event.get():
if event.type == QUIT:
sys.exit(0)

allsprites.update()

screen.blit(background, (0, 0))
allsprites.draw(screen)
pygame.display.flip()
31 changes: 31 additions & 0 deletions puyo/puyo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pygame
from sprite import *

PUYO_SIZE = 64
BOARD_BOTTOM_ROW = 9

class Puyo(Sprite, Movable):
def __init__(self, parent, color, row = 0):
Sprite.__init__(self) #call Sprite initializer
self.image = pygame.transform.smoothscale(Sprite.load_image(self, 'puyo_%s.png' % color), parent.puyo_size)
width, height = parent.puyo_size
Movable.__init__(self, pygame.Rect(2 * width, row * height, width, height), parent)

def update(self):
if self.y < (self.parent.rows_count - 1) * self.height:
self.y += 1

def draw(self):
print self.image, self.rect

def get_row(self):
return self.y / self.height
row = property(get_row)

def get_col(self):
return self.x / self.width
col = property(get_col)

def get_rect(self):
return self.create_rect(self.col * self.width, self.row * self.height, self.width, self.height)
rect = property(get_rect)
31 changes: 31 additions & 0 deletions puyo/sprite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pygame, os

class Movable():
def __init__(self, rect, parent = None):
self.x = rect.left
self.y = rect.top
self.width = rect.width
self.height = rect.height
self.parent = parent

def create_rect(self, x, y, width, height):
if self.parent:
x += self.parent.x
y += self.parent.y
return pygame.Rect(x, y, width, height)

def get_rect(self):
return self.create_rect(self.x, self.y, self.width, self.height)
rect = property(get_rect)

class Sprite(pygame.sprite.Sprite):
def load_image(self, path):
fullname = os.path.join('data', path)
try:
image = pygame.image.load(fullname)
except pygame.error, message:
print 'Cannot load image:', fullname
raise SystemExit, message
#self.image = self.image.convert()
#self.image.set_colorkey(self.image.get_at((0,0)), pygame.RLEACCEL)
return image
23 changes: 23 additions & 0 deletions test/test_board.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from puyo.board import *
from nose.tools import *
import pygame

class TestMovable:
def setUp(self):
self.subject = Board((64, 64))

def test_initializing(self):
assert_equal(self.subject.rows_count, 14)
assert_equal(self.subject.cols_count, 6)
assert_equal(self.subject.x, 10)
assert_equal(self.subject.y, 10)
assert_equal(self.subject.width, 64 * 6)
assert_equal(self.subject.height, 64 * 14)
assert_equal(self.subject.puyo_size, (64, 64))

def test_initialized_with_background(self):
print self.subject.sprites()
bg = self.subject.sprites()[0]
assert isinstance(bg, pygame.sprite.Sprite)
print bg, bg.rect, self.subject.rect
assert_equal(bg.rect, self.subject.rect)
51 changes: 51 additions & 0 deletions test/test_puyo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from puyo.board import *
from puyo.puyo import *
from nose.tools import *
import pygame

class TestPuyo:
def setUp(self):
self.board = Board((32, 32))
self.puyo = Puyo(self.board, 'red')

def test_initializing(self):
assert isinstance(self.puyo.image, pygame.Surface)
assert_equal(self.puyo.y, 0)
assert_equal(self.puyo.x, 64)
assert_equal(self.puyo.image.get_width(), 32)
assert_equal(self.puyo.image.get_height(), 32)

def test_return_correct_row(self):
self.puyo.y = 63
assert_equal(self.puyo.row, 1)
self.puyo.y = 64
assert_equal(self.puyo.row, 2)

def test_return_correct_col(self):
self.puyo.x = 63
assert_equal(self.puyo.col, 1)
self.puyo.x = 64
assert_equal(self.puyo.col, 2)

def test_updates_rectangle_on_move(self):
self.puyo.y, self.puyo.x = 127, 127
assert_equal(self.puyo.rect.top, 106)
assert_equal(self.puyo.rect.left, 106)

self.puyo.y, self.puyo.x = 128, 128
assert_equal(self.puyo.rect.top, 138)
assert_equal(self.puyo.rect.left, 138)

def test_allows_passing_row_on_initialize(self):
self.puyo = Puyo(self.board, 'red', -1)
assert_equal(self.puyo.row, -1)

def test_moves_down_on_update(self):
self.puyo.update()
assert_equal(self.puyo.y, 1)

def test_does_not_move_below_bottom(self):
self.puyo.y = 13 * 32
self.puyo.update()
assert_equal(self.puyo.y, 13 * 32)

22 changes: 22 additions & 0 deletions test/test_sprite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from puyo.sprite import *
from nose.tools import *
import pygame

class TestMovable:
def setUp(self):
self.subject = Movable(pygame.Rect(10, 20, 32, 64))

def test_initializing(self):
assert_equal(self.subject.x, 10)
assert_equal(self.subject.y, 20)
assert_equal(self.subject.width, 32)
assert_equal(self.subject.height, 64)

def test_rect(self):
assert_equal(self.subject.create_rect(0, 1, 2, 3), pygame.Rect(0, 1, 2, 3))
assert_equal(self.subject.rect, pygame.Rect(10, 20, 32, 64))

def test_rect_with_parent(self):
rect = Movable(pygame.Rect(5, 6, 7, 8), self.subject)
assert_equal(rect.create_rect(0, 1, 2, 3), pygame.Rect(10, 21, 2, 3))
assert_equal(rect.rect, pygame.Rect(15, 26, 7, 8))

0 comments on commit d2899e9

Please sign in to comment.