Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Aguiar <alanjas@hotmail.com>2013-05-13 12:12:46 (GMT)
committer Alan Aguiar <alanjas@hotmail.com>2013-05-13 12:12:46 (GMT)
commit7edab44538b1b16a82f478cddadbd5cb1dfc3b93 (patch)
tree762159f0dcdfb37d915caa4a49c844f6ffa07675
parent86a411686ba4026e810e544e07c4823da742c11d (diff)
add basic resize
-rwxr-xr-xactivity.py28
-rwxr-xr-xmain.py86
2 files changed, 73 insertions, 41 deletions
diff --git a/activity.py b/activity.py
index 2ba2600..d6549e4 100755
--- a/activity.py
+++ b/activity.py
@@ -40,7 +40,8 @@ class Activity(activity.Activity):
def __init__(self, handle):
activity.Activity.__init__(self, handle)
- self.game = main.Game()
+ self.game_size = (8, 6)
+ self.game = main.Game(self)
self.build_toolbar()
self._pygamecanvas = sugargame.canvas.PygameCanvas(self)
self.set_canvas(self._pygamecanvas)
@@ -59,25 +60,36 @@ class Activity(activity.Activity):
toolbar_box.toolbar.insert(activity_button, -1)
activity_button.show()
+ item1 = gtk.ToolItem()
+ label1 = gtk.Label()
+ label1.set_text(_('Horizontal'))
+ item1.add(label1)
+ toolbar_box.toolbar.insert(item1, -1)
+
+ item2 = gtk.ToolItem()
+ h_spin = gtk.SpinButton()
+ h_spin.set_range(2, 30)
+ h_spin.set_increments(1, 2)
+ h_spin.props.value = 5
+ h_spin.connect('notify::value', self.h_spin_change)
+ item2.add(h_spin)
+ toolbar_box.toolbar.insert(item2, -1)
+
separator = gtk.SeparatorToolItem()
separator.props.draw = False
separator.set_expand(True)
toolbar_box.toolbar.insert(separator, -1)
separator.show()
- #self.create_help(toolbar_box.toolbar)
-
stop_button = StopButton(self)
toolbar_box.toolbar.insert(stop_button, -1)
stop_button.show()
self.show_all()
- def create_help(self, toolbar):
- helpitem = HelpButton()
- toolbar.insert(helpitem, -1)
- helpitem.show()
- helpitem.add_paragraph(_('or press A for an apple'), 'apple')
+ def h_spin_change(self, spin, value):
+ self.game_size = (int(spin.props.value), self.game_size[1])
+ self.game.set_board_size(self.game_size)
def read_file(self, file_path):
pass
diff --git a/main.py b/main.py
index 50919f3..3213bcb 100755
--- a/main.py
+++ b/main.py
@@ -5,11 +5,7 @@
import pygame
import gtk
-GRID_SIZE = (8, 6)
-BOX_SIZE = (60, 60)
LINE_SIZE = 10
-X_OFFSET = 200
-Y_OFFSET = 200
T = 15
COLOR1 = (0, 0, 0)
COLOR_OWNER = (255, 0, 0)
@@ -19,8 +15,17 @@ class box:
def __init__(self, parent, x, y):
self.screen = parent.screen
self.fuente = parent.fuente
+ self.box_size = parent.box_size
+ self.x_offset = parent.x_offset
+ self.y_offset = parent.y_offset
self.x = x
self.y = y
+ x1 = self.x * self.box_size[0] + self.x_offset
+ y1 = self.y * self.box_size[1] + self.y_offset
+ dx = int(self.box_size[0] / 2.0)
+ dy = int(self.box_size[1] / 2.0)
+ self.pos_x = x1 + dx
+ self.pos_y = y1 + dy
self.up = 0
self.left = 0
self.right = 0
@@ -33,38 +38,50 @@ class box:
def showText(self, texto):
text = self.fuente.render(texto, 1, COLOR_OWNER)
textrect = text.get_rect()
- x = self.x * BOX_SIZE[0] + X_OFFSET
- y = self.y * BOX_SIZE[1] + Y_OFFSET
- dx = int(BOX_SIZE[0] / 2.0)
- dy = int(BOX_SIZE[1] / 2.0)
- textrect.center = (x + dx, y + dy)
+ textrect.center = (self.x, self.y)
self.screen.blit(text, textrect)
class Game:
def __init__(self, parent=None):
self.parent = parent
- self.horizontal = []
- self.vertical = []
- self.boxes = []
- self.x_end = 0
- self.y_end = 0
self.current = 'A'
+ self.grid_size = (8, 6)
+ self.box_size = (50, 50)
+ self.x_offset = 100
+ self.y_offset = 100
def draw_line(self, r1, r2):
pygame.draw.line(self.screen, COLOR1, r1, r2, LINE_SIZE)
- def draw_grid(self):
+ def set_board_size(self, size):
+ self.grid_size = size
+ self.draw_grid()
- w = GRID_SIZE[0]
- h = GRID_SIZE[1]
+ def draw_grid(self):
+ self.screen.fill((84, 185, 72))
+ self.horizontal = []
+ self.vertical = []
+ self.boxes = []
+ self.x_end = 0
+ self.y_end = 0
+ w = self.grid_size[0]
+ h = self.grid_size[1]
+ print self.box_size
+ s_w = self.screen.get_width()
+ if s_w < w * self.box_size[0]:
+ print 'pasa x'
+ else:
+ xx = s_w - w * (self.box_size[0] - 1)
+ self.x_offset = int(xx / 2.0)
+ print self.box_size
for i in range(w):
- x = i * BOX_SIZE[0] + X_OFFSET
+ x = i * self.box_size[0] + self.x_offset
self.horizontal.append(x)
v_boxes = []
for j in range(h):
- y = j * BOX_SIZE[1] + Y_OFFSET
+ y = j * self.box_size[1] + self.y_offset
if i == 0:
self.vertical.append(y)
if j > 0:
@@ -72,8 +89,8 @@ class Game:
pygame.draw.circle(self.screen, (0, 0, 0), (x, y), LINE_SIZE, LINE_SIZE)
if i > 0:
self.boxes.append(v_boxes)
- self.x_end = (len(self.horizontal) - 1) * BOX_SIZE[0] + X_OFFSET
- self.y_end = (len(self.vertical) - 1) * BOX_SIZE[1] + Y_OFFSET
+ self.x_end = (len(self.horizontal) - 1) * self.box_size[0] + self.x_offset
+ self.y_end = (len(self.vertical) - 1) * self.box_size[1] + self.y_offset
def where_x(self, x):
for i in range(len(self.horizontal)):
@@ -97,7 +114,7 @@ class Game:
x, y = pos
r1 = self.where_x(x)
r2 = self.where_y(y)
-
+ print r1, r2
if not(r1[0] == False):
if not(r2[0] == False):
if x < (r1[0] + T):
@@ -130,7 +147,8 @@ class Game:
if b.check():
b.showText(self.current)
con = True
- if x_b < GRID_SIZE[1]:
+ #print 'aca', x_b, self.grid_size[0]
+ if x_b < self.grid_size[0]:
b2 = self.boxes[x_b + 1][y_b]
b2.left = 1
if b2.check():
@@ -139,7 +157,7 @@ class Game:
self.draw_line((r1[1],r2[0]), (r1[1],r2[1]))
return con
else:
- if (x > (X_OFFSET - T)) and (x < X_OFFSET):
+ if (x > (self.x_offset - T)) and (x < self.x_offset):
if not(r2[0] == False):
x_b = 0
y_b = r2[2] - 1
@@ -151,11 +169,11 @@ class Game:
if b.check():
b.showText(self.current)
con = True
- self.draw_line((X_OFFSET,r2[0]), (X_OFFSET,r2[1]))
+ self.draw_line((self.x_offset,r2[0]), (self.x_offset,r2[1]))
return con
elif (x < (self.x_end + T)) and (x > self.x_end):
if not(r2[0] == False):
- x_b = GRID_SIZE[0] - 2
+ x_b = self.grid_size[0] - 2
y_b = r2[2] - 1
b = self.boxes[x_b][y_b]
if b.right:
@@ -200,7 +218,7 @@ class Game:
if b.check():
b.showText(self.current)
con = True
- if y_b < GRID_SIZE[1] - 2:
+ if y_b < self.grid_size[1] - 2:
b2 = self.boxes[x_b][y_b+1]
b2.up = 1
if b2.check():
@@ -209,7 +227,7 @@ class Game:
self.draw_line((r1[0],r2[1]), (r1[1],r2[1]))
return con
else:
- if (y > Y_OFFSET - T) and (y < Y_OFFSET):
+ if (y > self.y_offset - T) and (y < self.y_offset):
if not(r1[0] == False):
x_b = r1[2] - 1
y_b = 0
@@ -221,12 +239,12 @@ class Game:
if b.check():
b.showText(self.current)
con = True
- pygame.draw.line(self.screen, COLOR1, (r1[0],Y_OFFSET), (r1[1],Y_OFFSET), LINE_SIZE)
+ pygame.draw.line(self.screen, COLOR1, (r1[0],self.y_offset), (r1[1],self.y_offset), LINE_SIZE)
return con
elif (y < (self.y_end + T)) and (y > self.y_end):
if not(r1[0] == False):
x_b = r1[2] - 1
- y_b = GRID_SIZE[1] - 2
+ y_b = self.grid_size[1] - 2
b = self.boxes[x_b][y_b]
if b.down:
return True
@@ -240,11 +258,13 @@ class Game:
def run(self):
pygame.init()
- self.screen = pygame.display.set_mode((900, 700))
+ self.screen = pygame.display.get_surface()
+ if not self.screen:
+ self.screen = pygame.display.set_mode((900, 700))
self.screen.fill((84, 185, 72))
- self.fuente = pygame.font.Font(None, BOX_SIZE[0])
+ self.fuente = pygame.font.Font(None, self.box_size[0])
self.draw_grid()
-
+ print dir(self.screen)
run = True
while run:
while gtk.events_pending():