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-16 19:33:34 (GMT)
committer Laurent Bernabé <laurent.bernabe@gmail.com>2013-09-16 19:33:34 (GMT)
commitccbd68cca6f2954edbfd55712c183a2cd8c50c1c (patch)
tree9934b3c6907e94d6980b1f1c0771a2d73d2100eb
First commit
-rw-r--r--MANIFEST.in2
-rw-r--r--NEWS0
-rw-r--r--POTFILES.in1
-rw-r--r--activity.py10
-rw-r--r--activity/activity.info8
-rw-r--r--activity/activity.svg109
-rw-r--r--ball.py90
-rw-r--r--elements_painter.py26
-rw-r--r--main.py49
-rw-r--r--operation.py43
-rw-r--r--setup.py5
11 files changed, 343 insertions, 0 deletions
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..e83703c
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,2 @@
+include *.py *.txt *.png *.jpg NEWS README
+recursive-include activity *.svg *.info
diff --git a/NEWS b/NEWS
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/NEWS
diff --git a/POTFILES.in b/POTFILES.in
new file mode 100644
index 0000000..6c9e6b4
--- /dev/null
+++ b/POTFILES.in
@@ -0,0 +1 @@
+include *.py
diff --git a/activity.py b/activity.py
new file mode 100644
index 0000000..ca14109
--- /dev/null
+++ b/activity.py
@@ -0,0 +1,10 @@
+from olpcgames import activity
+from gettext import gettext as _
+
+
+class Activity(activity.PyGameActivity):
+
+ """Your Sugar activity"""
+ game_name = 'main:main'
+ game_title = _('Hit the balls')
+ game_size = None
diff --git a/activity/activity.info b/activity/activity.info
new file mode 100644
index 0000000..5b336ee
--- /dev/null
+++ b/activity/activity.info
@@ -0,0 +1,8 @@
+[Activity]
+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/activity/activity.svg b/activity/activity.svg
new file mode 100644
index 0000000..f606a5a
--- /dev/null
+++ b/activity/activity.svg
@@ -0,0 +1,109 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" [
+ <!ENTITY ns_svg "http://www.w3.org/2000/svg">
+ <!ENTITY ns_xlink " http://www.w3.org/1999/xlink">
+ <!ENTITY stroke_color "#000000">
+ <!ENTITY fill_color "#0000FF">
+]>
+
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="75"
+ height="75"
+ id="svg2"
+ version="1.1"
+ inkscape:version="0.48.4 r9939"
+ sodipodi:docname="activity_tmp.svg">
+ <defs
+ id="defs4" />
+ <sodipodi:namedview
+ id="base"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ inkscape:pageopacity="0.0"
+ inkscape:pageshadow="2"
+ inkscape:zoom="2.8"
+ inkscape:cx="34.14678"
+ inkscape:cy="42.857143"
+ inkscape:document-units="px"
+ inkscape:current-layer="layer3"
+ showgrid="true"
+ fit-margin-top="0"
+ fit-margin-left="0"
+ fit-margin-right="0"
+ fit-margin-bottom="0"
+ inkscape:snap-bbox="false"
+ inkscape:window-width="828"
+ inkscape:window-height="443"
+ inkscape:window-x="70"
+ inkscape:window-y="27"
+ inkscape:window-maximized="0" />
+ <metadata
+ id="metadata7">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ <dc:title></dc:title>
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <g
+ inkscape:groupmode="layer"
+ id="layer2"
+ inkscape:label="helper square"
+ style="display:none"
+ sodipodi:insensitive="true">
+ <rect
+ style="fill:none;stroke:&stroke_color;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+ id="rect2988"
+ width="45"
+ height="45"
+ x="15.5"
+ y="14.5" />
+ </g>
+ <g
+ inkscape:label="ball"
+ inkscape:groupmode="layer"
+ id="layer1"
+ transform="translate(0,-977.36218)"
+ sodipodi:insensitive="true">
+ <path
+ sodipodi:type="arc"
+ style="fill:&fill_color;stroke:&stroke_color;stroke-width:0.06873218;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
+ id="path3758"
+ sodipodi:cx="31.607143"
+ sodipodi:cy="30.892857"
+ sodipodi:rx="0.53571427"
+ sodipodi:ry="4.4642859"
+ d="m 32.142858,30.892857 a 0.53571427,4.4642859 0 1 1 -1.071429,0 0.53571427,4.4642859 0 1 1 1.071429,0 z"
+ transform="matrix(42.000001,0,0,5.0399998,-1290.0001,859.16219)" />
+ </g>
+ <g
+ inkscape:groupmode="layer"
+ id="layer3"
+ inkscape:label="text">
+ <text
+ xml:space="preserve"
+ style="font-size:14px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:&stroke_color;fill-opacity:1;stroke:none;font-family:Sans"
+ x="22.857143"
+ y="40.714287"
+ id="text3855"
+ sodipodi:linespacing="125%"><tspan
+ sodipodi:role="line"
+ id="tspan3857"
+ x="22.857143"
+ y="40.714287">1+2</tspan></text>
+ </g>
+</svg>
diff --git a/ball.py b/ball.py
new file mode 100644
index 0000000..21b5e09
--- /dev/null
+++ b/ball.py
@@ -0,0 +1,90 @@
+# -*- coding: utf-8 -*-
+"""
+Created on Sat Sep 14 10:57:17 2013
+
+@author: laurent-bernabe
+"""
+
+
+class Ball(object):
+
+ """
+ An abstractation of a ball.
+ """
+
+ def __init__(self, txt_font, txt_color, bg_color, operation):
+ """
+ Constructor
+ txt_font : text font => olpcgames.pangofont
+ txt_color : text color => Tuple of 3 integers in [0,255]
+ bg_color : background color => Tuple of 3 integers in [0,255]
+ operation : operation => An Operation value
+ """
+ self._txt_font = txt_font
+ self._txt_color = txt_color
+ self._bg_color = bg_color
+ self._operation = operation
+ self._center = (0, 0)
+ txt_size = txt_font.size(operation.get_text())
+ if txt_size[0] > txt_size[1]:
+ max_txt_size = txt_size[0]
+ else:
+ max_txt_size = txt_size[1]
+ self._diameter = int(max_txt_size * 1.25)
+
+ def get_txt_font(self):
+ """
+ Accessor to the text font
+ => olpcgames.pangofont
+ """
+ return self._txt_font
+
+ def get_diameter(self):
+ """
+ Accessor to the diameter.
+ => Int value
+ """
+ return self._diameter
+
+ def get_bg_color(self):
+ """
+ Accessor to the background color.
+ => Tuple of 3 integers
+ """
+ return self._bg_color
+
+ def get_txt_color(self):
+ """
+ Accessor to the text (foreground) color.
+ => Tuple of 3 integers
+ """
+ return self._txt_color
+
+ def get_operation(self):
+ """
+ Accessor to the operation.
+ => Operation instance.
+ """
+ return self._operation
+
+ def get_center(self):
+ """
+ Accessor to the center position.
+ => Tuple of 2 integers.
+ """
+ return self._center
+
+ def move_to(self, new_center_position):
+ """
+ Moves the ball to a particular place.
+ new_center_position : the new center position => a tuple of 2 integers
+ """
+ self._center = new_center_position
+
+ def move(self, move_value):
+ """
+ Moves the ball by the values inside move_value.
+ move_value : by how much does it move ? => a tuple of 2 integers
+ """
+ self._center = (self._center[0] + move_value[0],
+ self._center[1] + move_value[1])
diff --git a/elements_painter.py b/elements_painter.py
new file mode 100644
index 0000000..e85add9
--- /dev/null
+++ b/elements_painter.py
@@ -0,0 +1,26 @@
+# -*- coding: utf-8 -*-
+"""
+Knows how to paint the elements onto a PyGame Surface.
+
+Created on Sun Sep 15 01:28:19 2013
+
+@author: laurent-bernabe
+"""
+
+import pygame
+
+
+def paint_ball(ball, surface):
+ """
+ Draws a ball onto the given PyGame surface.
+ ball : the ball to draw => Ball instance
+ surface : the destination surface => PyGame.Surface
+ """
+ pygame.draw.circle(surface, ball.get_bg_color(), ball.get_center(),
+ ball.get_diameter() / 2)
+ ball_center = ball.get_center()
+ txt_position = (ball_center[0] - ball.get_diameter() / 2.50,
+ ball_center[1] - ball.get_diameter() / 7.75)
+ txt_surface = ball.get_txt_font().render(
+ ball.get_operation().get_text(), color=ball.get_txt_color())
+ surface.blit(txt_surface, txt_position)
diff --git a/main.py b/main.py
new file mode 100644
index 0000000..e2ae208
--- /dev/null
+++ b/main.py
@@ -0,0 +1,49 @@
+# -*- coding: utf-8 -*-
+"""
+Created on Sat Sep 14 10:57:17 2013
+
+@author: laurent-bernabe
+"""
+
+import olpcgames
+import pygame
+import sys
+from olpcgames.pangofont import PangoFont
+from pygame.locals import QUIT
+from ball import *
+from operation import *
+from elements_painter import *
+
+
+def main():
+ """ The main routine """
+ pygame.init()
+ FPS = 40
+ BACKGROUND = (255, 255, 255)
+ if olpcgames.ACTIVITY:
+ size = olpcgames.ACTIVITY.game_size
+ screen = pygame.display.set_mode(size)
+ else:
+ size = (600, 400)
+ screen = pygame.display.set_mode(size)
+ pygame.display.set_caption("Hit the balls")
+ clock = pygame.time.Clock()
+ info = pygame.display.Info()
+ screen_size = info.current_w, info.current_h
+ font = PangoFont(family='Helvetica', size=30, bold=True)
+ BLUE = (0, 0, 255)
+ WHITE = (255, 255, 255)
+ the_ball = Ball(font, WHITE, BLUE, Operation(1000, 3000, OPER_MUL))
+ the_ball.move((140, 170))
+ while True:
+ screen.fill(BACKGROUND)
+ paint_ball(the_ball, screen)
+ pygame.display.update()
+ for event in pygame.event.get():
+ if event.type == QUIT:
+ pygame.quit()
+ sys.exit()
+ clock.tick(FPS)
+
+if __name__ == "__main__":
+ main()
diff --git a/operation.py b/operation.py
new file mode 100644
index 0000000..9c43917
--- /dev/null
+++ b/operation.py
@@ -0,0 +1,43 @@
+# -*- coding: utf-8 -*-
+"""
+Created on Sat Sep 14 11:02:52 2013
+
+@author: laurent-bernabe
+"""
+
+OPER_ADD = {'txt': '+', 'operation': lambda op1, op2: op1 + op2}
+OPER_SUB = {'txt': '-', 'operation': lambda op1, op2: op1 - op2}
+OPER_MUL = {'txt': '*', 'operation': lambda op1, op2: op1 * op2}
+OPER_DIV = {'txt': '/', 'operation': lambda op1, op2: op1 / op2}
+
+
+class Operation(object):
+
+ """
+ An abstraction of an operation.
+ """
+
+ def __init__(self, op1, op2, operator):
+ """
+ Constructor
+ op1 : numeric value => operand 1
+ op2 : numeric value => operand 2
+ operator : operator => One of given OPER_* values
+ (for example OPER_ADD)
+ """
+ self._result = operator['operation'](op1, op2)
+ self._txt = str(op1) + operator['txt'] + str(op2)
+
+ def get_result(self):
+ """
+ Accessor to the result field.
+ => numeric value.
+ """
+ return self._result
+
+ def get_text(self):
+ """
+ Accessor to the text field
+ => string value
+ """
+ return self._txt
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..bb7ecb1
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,5 @@
+#!/usr/bin/env python
+from sugar3.activity import bundlebuilder
+
+if __name__ == "__main__":
+ bundlebuilder.start()