Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Bernabé <laurent.bernabe@gmail.com>2013-09-25 11:03:57 (GMT)
committer Laurent Bernabé <laurent.bernabe@gmail.com>2013-09-25 11:03:57 (GMT)
commit6b2667cd1bf4fef8db3a8b4fa7cf6fec558fe336 (patch)
tree48cde86a910b3bcbfd0a4f84145e78b3dd379c82
parent9f4d914d2b44e9777ac96a4c0bf5fb9f2e8e0a37 (diff)
Applied two patches of Alan Jhonn Aguiar Schwyn in order to add .gitignore and improve game integration with Sugar.
-rw-r--r--.gitignore5
-rw-r--r--activity.py31
-rw-r--r--activity/activity.info2
-rw-r--r--elements_painter.py12
-rw-r--r--main.py22
-rw-r--r--main_game.py27
6 files changed, 67 insertions, 32 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..37e9f4b
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+*.pyc
+*.py~
+*.xo
+*.pyo
+*.*~
diff --git a/activity.py b/activity.py
index ca14109..63faeff 100644
--- a/activity.py
+++ b/activity.py
@@ -1,10 +1,27 @@
-from olpcgames import activity
-from gettext import gettext as _
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+import sugargame
+import sugargame.canvas
+from sugar.activity import activity
-class Activity(activity.PyGameActivity):
+import main
- """Your Sugar activity"""
- game_name = 'main:main'
- game_title = _('Hit the balls')
- game_size = None
+
+class Activity(activity.Activity):
+
+ def __init__(self, handle):
+ activity.Activity.__init__(self, handle)
+
+ self.max_participants = 1
+ self._act = main.Game()
+ self._pygamecanvas = sugargame.canvas.PygameCanvas(self)
+ self.set_canvas(self._pygamecanvas)
+ self._pygamecanvas.grab_focus()
+ self._pygamecanvas.run_pygame(self._act.run)
+
+ def read_file(self, file_path):
+ pass
+
+ def write_file(self, file_path):
+ pass
diff --git a/activity/activity.info b/activity/activity.info
index 5b336ee..bf0aa0f 100644
--- a/activity/activity.info
+++ b/activity/activity.info
@@ -2,7 +2,5 @@
name = HitTheBalls
bundle_id = com.loloof64.HitTheBalls
activity_version = 1
-host_version = 1
-service_name = com.loloof64.HitTheBalls
icon = activity
exec = sugar-activity activity.Activity
diff --git a/elements_painter.py b/elements_painter.py
index 07bc8e5..df1ef06 100644
--- a/elements_painter.py
+++ b/elements_painter.py
@@ -8,7 +8,6 @@ Created on Sun Sep 15 01:28:19 2013
"""
import pygame
-from olpcgames.pangofont import PangoFont
def paint_ball(ball, surface):
@@ -26,7 +25,7 @@ def paint_ball(ball, surface):
txt_position = (int(ball_center[0] - txt_width / 2),
int(ball_center[1] - txt_height / 2))
txt_surface = ball.get_txt_font().render(
- ball.get_operation().get_text(), color=ball.get_txt_color())
+ ball.get_operation().get_text(), 1, ball.get_txt_color())
surface.blit(txt_surface, txt_position)
@@ -65,8 +64,8 @@ def paint_result_bar(result_bar, surface):
text = result_bar.get_header() + str(result_bar.get_result())
except NameError:
text = result_bar.get_header()
- text_surface = result_bar.get_text_font(). \
- render(text, color=result_bar.get_foreground())
+ text_surface = result_bar.get_text_font().render(
+ text, 1, result_bar.get_foreground())
surface.blit(text_surface,
(edge[0] + result_bar.get_insets(),
edge[1] + result_bar.get_insets()))
@@ -79,7 +78,8 @@ def paint_results(game_area, balls_list, surface):
balls_list : list of balls => list of Ball
surface : the destination surface => PyGame.Surface
"""
- font = PangoFont(family='Helvetica', size=16)
+ font = pygame.font.Font(None, 16)
+ #font = PangoFont(family='Helvetica', size=16)
LINE_HEIGHT = font.size("0123456789")[1]
CIRCLES_RADIUS = LINE_HEIGHT / 2
ball_index = 0
@@ -92,7 +92,7 @@ def paint_results(game_area, balls_list, surface):
CIRCLES_RADIUS)
txt = ball.get_operation().get_text() + " = " + str(ball.get_operation().
get_result())
- txt_surface = font.render(txt, color=BLACK)
+ txt_surface = font.render(txt, 1, BLACK)
surface.blit(txt_surface,
(game_area[0] + 40, game_area[1] + ball_index * LINE_HEIGHT))
ball_index += 1
diff --git a/main.py b/main.py
index 24d82c1..9c55ed1 100644
--- a/main.py
+++ b/main.py
@@ -10,10 +10,20 @@ from operation import OPER_ADD, OPER_SUB, OPER_MUL, OPER_DIV
from balls_generator import OperationConfig
from main_game import play_game
-if __name__ == "__main__":
- operations_config = [OperationConfig(OPER_ADD, 2, 2),
- OperationConfig(OPER_MUL, 2, 1),
- OperationConfig(OPER_SUB, 2, 2),
- OperationConfig(OPER_DIV, 2, 2)]
- play_game(30, operations_config)
+class Game():
+
+ def __init__(self):
+ pass
+
+ def run(self):
+ operations_config = [OperationConfig(OPER_ADD, 2, 2),
+ OperationConfig(OPER_MUL, 2, 1),
+ OperationConfig(OPER_SUB, 2, 2),
+ OperationConfig(OPER_DIV, 2, 2)]
+
+ play_game(30, operations_config)
+
+if __name__ == "__main__":
+ g = Game()
+ g.run()
diff --git a/main_game.py b/main_game.py
index 254eeec..740c0cb 100644
--- a/main_game.py
+++ b/main_game.py
@@ -5,12 +5,10 @@ Created on Tue Sep 24 13:54:20 2013
@author: laurent-bernabe
"""
-
-import olpcgames
+from gi.repository import Gtk
import pygame
from random import randint
from sys import exit
-from olpcgames.pangofont import PangoFont
from pygame.locals import QUIT, USEREVENT, MOUSEBUTTONUP
from elements_painter import paint_ball, paint_time_bar, paint_result_bar,\
paint_results
@@ -72,16 +70,19 @@ def play_game(time_seconds, operations_config):
DARK_GREEN = (0, 100, 0)
GRAY = (200, 200, 200)
- if olpcgames.ACTIVITY:
- size = olpcgames.ACTIVITY.game_size
- screen = pygame.display.set_mode(size)
- else:
+ screen = pygame.display.get_surface()
+ if not(screen):
size = (600, 400)
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Hit the balls")
+ else:
+ size = screen.get_size()
+
clock = pygame.time.Clock()
- font = PangoFont(family='Helvetica', size=16, bold=True)
- end_font = PangoFont(family='Helvetica', size=30, bold=True)
+ font = pygame.font.Font(None, 16)
+ #font = PangoFont(family='Helvetica', size=16, bold=True)
+ #end_font = PangoFont(family='Helvetica', size=30, bold=True)
+ end_font = font = pygame.font.Font(None, 30)
END_TXT_POS = (int(size[0] / 4)), int(size[1] / 2.6)
game_state = GameState.NORMAL
@@ -117,6 +118,10 @@ def play_game(time_seconds, operations_config):
if game_state == GameState.NORMAL:
for ball in the_balls:
paint_ball(ball, screen)
+
+ while Gtk.events_pending():
+ Gtk.main_iteration()
+
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
@@ -149,8 +154,8 @@ def play_game(time_seconds, operations_config):
end_txt = "Success !"
else:
end_txt = "Failure !"
- end_txt_surface = end_font.render(end_txt,
- color=BLUE, background=RED)
+ end_txt_surface = end_font.render(end_txt, 1,
+ BLUE, RED)
screen.blit(end_txt_surface, END_TXT_POS)
for event in pygame.event.get():
if event.type == QUIT: