[gcompris: 78/111] added asteroids to intro_gravity



commit 20d4bddbfc13849537fbe423a81c745eae423df7
Author: serah <serah4291 gmail com>
Date:   Sun Aug 19 15:19:03 2012 +0530

    added asteroids to intro_gravity

 src/intro_gravity-activity/init_path.sh            |    5 +-
 src/intro_gravity-activity/intro_gravity.py        |  105 +++++++++++++++++++-
 src/intro_gravity-activity/intro_gravity.xml.in    |   15 ++-
 .../resources/intro_gravity/Makefile.am            |    8 ++-
 .../resources/intro_gravity/README                 |    1 +
 .../resources/intro_gravity/asteroid0.jpg          |  Bin 0 -> 1677 bytes
 .../resources/intro_gravity/asteroid1.jpg          |  Bin 0 -> 2260 bytes
 .../resources/intro_gravity/asteroid2.jpg          |  Bin 0 -> 9184 bytes
 .../resources/intro_gravity/asteroid3.jpg          |  Bin 0 -> 3084 bytes
 .../resources/intro_gravity/asteroid4.jpg          |  Bin 0 -> 1027 bytes
 .../resources/intro_gravity/crash.png              |  Bin 0 -> 9981 bytes
 src/land_safe-activity/resources/land_safe/README  |    2 +-
 12 files changed, 125 insertions(+), 11 deletions(-)
---
diff --git a/src/intro_gravity-activity/init_path.sh b/src/intro_gravity-activity/init_path.sh
index 29bd7ce..fa118f7 100755
--- a/src/intro_gravity-activity/init_path.sh
+++ b/src/intro_gravity-activity/init_path.sh
@@ -3,6 +3,7 @@
 path=$1
 activity=intro_gravity
 plugindir=$path/../boards/.libs
-pythonplugindir=$path 
+pythonplugindir=$path
 resourcedir=$path/resources
-section="/experimental"
+section="/experince"
+
diff --git a/src/intro_gravity-activity/intro_gravity.py b/src/intro_gravity-activity/intro_gravity.py
index 9ea0114..50a0f1c 100644
--- a/src/intro_gravity-activity/intro_gravity.py
+++ b/src/intro_gravity-activity/intro_gravity.py
@@ -18,6 +18,7 @@
 # intro_gravity activity.
 import gtk
 import gtk.gdk
+import random
 import gcompris
 import gcompris.utils
 import gcompris.skin
@@ -83,11 +84,13 @@ class Gcompris_intro_gravity:
     Slider(self.rootitem, 780, 200, planet_right)
 
     # Load the tux_ship
-    ship_instance = Spaceship(self, self.rootitem,
+    self.ship_instance = Spaceship(self, self.rootitem,
                               gcompris.BOARD_WIDTH/2.0, 200,
                               self.gcomprisBoard.level,
                               planet_left,
                               planet_right)
+    # Load random asteroids
+    asteroid_instance = Asteroids(self.ship_instance, self.rootitem)
 
   def end(self):
     # Remove the root item removes all the others inside it
@@ -108,7 +111,7 @@ class Gcompris_intro_gravity:
     print("intro_gravity config_start.")
 
   def key_press(self, keyval, commit_str, preedit_str):
-    pass
+    self.ship_instance.handle_key(keyval)
 
   def pause(self, pause):
     # When the bonus is displayed, it call us first with pause(1) and then with pause(0)
@@ -134,6 +137,7 @@ class Gcompris_intro_gravity:
 class Spaceship(Gcompris_intro_gravity):
   """Class representing the spaceship"""
 
+
   def __init__(self, game, rootitem, x, y, level,
                planet_left, planet_right):
     self.game = game
@@ -143,12 +147,14 @@ class Spaceship(Gcompris_intro_gravity):
     # Let us determine a success case
     self.trip_distance = 0
 
+
     # load spaceship
     self.tux_spaceship = goocanvas.Image(
       parent = self.rootitem,
       pixbuf = gcompris.utils.load_pixmap("intro_gravity/tux_spaceship.png"),
       x = x,
       y = y)
+
     # Center it
     bounds = self.tux_spaceship.get_bounds()
     self.tux_spaceship.translate( (bounds.x2 - bounds.x1) / 2.0 * -1,
@@ -157,6 +163,7 @@ class Spaceship(Gcompris_intro_gravity):
     self.planet_right = planet_right
     self.planet_left = planet_left
 
+
     # load arrows for force applied on spacehip
     point = goocanvas.Points([(x - 50, y),(x - 90, y)])
     self.force_line = goocanvas.Polyline(
@@ -225,9 +232,102 @@ class Spaceship(Gcompris_intro_gravity):
     self.done = True
     self.game.crash()
 
+  def handle_key(self, key):
+    bounds = self.tux_spaceship.get_bounds()
+    if key == gtk.keysyms.Up:
+      if bounds.y1 > 145:
+        self.tux_spaceship.translate(0, -1)
+        self.force_line.translate(0, -1)
+
+    elif key == gtk.keysyms.Down:
+      if bounds.y2 < 255:
+        self.tux_spaceship.translate(0, 1)
+        self.force_line.translate(0, 1)
+
+class Asteroids:
+  """Class for the asteroids"""
+
+
+  def __init__(self, ship_instance, rootitem):
+    self.ship_instance = ship_instance
+    self.rootitem = rootitem
+    self.load_asteroid()
+
+  def load_asteroid(self):
+    self.count = 1
+    self.asteroid_rootitem = goocanvas.Group(parent = self.rootitem)
+
+    # Make sure the ateroids are loaded between the planet and spaceship
+    bounds = self.ship_instance.tux_spaceship.get_bounds()
+    left_asteroid_x = random.uniform(150, bounds.x1 - 50)
+    right_asteroid_x = random.uniform(450, bounds.x2 + 20)
+    y_asteroid = [200, 160]
+    left_asteroid_y = random.choice(y_asteroid)
+    right_asteroid_y = random.choice(y_asteroid)
+
+    # Pick a random asteroid and load image
+    asteroid_number = [0, 1, 2, 3, 4]
+    asteroid = random.choice(asteroid_number)
+    image = "intro_gravity/asteroid" + str(asteroid) + ".jpg"
+    self.asteroid1 = goocanvas.Image(
+      parent = self.asteroid_rootitem,
+      pixbuf = gcompris.utils.load_pixmap(image),
+      x = left_asteroid_x,
+      y = left_asteroid_y)
+
+    # Make sure same asteroid is not picked
+    asteroid_number.remove(asteroid)
+    asteroid = random.choice(asteroid_number)
+    image = "intro_gravity/asteroid" + str(asteroid) + ".jpg"
+    self.asteroid2 = goocanvas.Image(
+      parent = self.asteroid_rootitem,
+      pixbuf = gcompris.utils.load_pixmap(image),
+      x = right_asteroid_x,
+      y = right_asteroid_y)
+
+    self.asteroid_rootitem.lower(self.ship_instance.tux_spaceship)
+    gobject.timeout_add(30, self.check_asteroid)
+
+  def check_asteroid(self):
+    self.count += 1
+    if self.count > 500:
+      self.asteroid_rootitem.remove()
+      self.load_asteroid()
+      return False
+
+    # Check whether ship and asteroid have collided
+    bound1 = self.asteroid1.get_bounds()
+    bound2 = self.asteroid2.get_bounds()
+    bound_ship = self.ship_instance.tux_spaceship.get_bounds()
+
+    bound1_x = (bound1.x1 + bound1.x2) / 2
+    bound2_x = (bound2.x1 + bound2.x2) / 2
+    bound1_y = (bound1.y1 + bound1.y2) / 2
+    bound2_y = (bound2.y1 + bound2.y2) / 2
+    bound_ship_x = (bound_ship.x1 + bound_ship.x2) / 2
+    bound_ship_y = (bound_ship.y1 + bound_ship.y2) / 2
+    if abs(bound1_x - bound_ship_x) < 40 and abs(bound1_y - bound_ship_y) < 40:
+      self.crash_image(bound_ship_x, bound_ship_y)
+    elif abs(bound2_x - bound_ship_x) < 40 and abs(bound2_y - bound_ship_y) < 40:
+      self.crash_image(bound_ship_x, bound_ship_y)
+    else:
+      return True
+
+  def crash_image(self, x, y):
+    image = goocanvas.Image(
+      parent = self.rootitem,
+      pixbuf = gcompris.utils.load_pixmap('/intro_gravity/crash.png'),
+      x = x - 50,
+      y = y - 50)
+
+    self.ship_instance.crash()
+
+
+
 class Fixed_planet:
   """ Fixed planets """
 
+
   def __init__(self, rootitem, x, y, planet_image):
     self.rootitem = rootitem
     self.scale = 0
@@ -256,6 +356,7 @@ class Fixed_planet:
 class Slider:
   """ class for scale slider"""
 
+
   def __init__(self, rootitem, x, y, planet_instance):
     self.planet_instance = planet_instance
     self.height = 60
diff --git a/src/intro_gravity-activity/intro_gravity.xml.in b/src/intro_gravity-activity/intro_gravity.xml.in
index 22915c3..658fe22 100644
--- a/src/intro_gravity-activity/intro_gravity.xml.in
+++ b/src/intro_gravity-activity/intro_gravity.xml.in
@@ -3,24 +3,29 @@
   <Board
         name="intro_gravity"
         type="python:intro_gravity"
-        section="/experimental"
+        section="/experience"
         icon="intro_gravity.svg"
-        difficulty="1"
-        author="your name here"
+        difficulty="4"
+        author="Matilda Bernard (seah4291 gmail com)"
         boarddir=""
         >
         <_title>Intro gravity</_title>
         <_description>Introduction to the concept of gravity</_description>
-        <_goal>Maintain the spaceship in the middle without crashing into the planets</_goal>
+        <_goal>Maintain the spaceship in the middle without crashing into the planets or the asteroids</_goal>
         <_manual xml:space="preserve">
 Gravity is universal and Newton's law of universal gravitation extends gravity beyond earth.This force of gravitational attraction is directly dependent upon the masses of both objects and inversely proportional to the square of the distance that separates their centers.
 
 Since the gravitational force is directly proportional to the mass of both interacting objects, more massive objects will attract each other with a greater gravitational force. So as the mass of either object increases, the force of gravitational attraction between them also increases but this force is inversely proportional to the square of the separation distance between the two interacting objects, more separation distance will result in weaker gravitational forces.
 
-Increase and decrease the size of the planets at the two ends to see how the force on the spaceship changes with changes in the size and distance. This force results in acceleration of the spaceship. The arrow indicates the direction of force.
+Increase and decrease the size of the planets at the two ends to see how the force on the spaceship changes with changes in the size and distance. This force results in acceleration of the spaceship.
+The arrow indicates the direction of force.
+
+Use the up/down keys to move the spaceship up/down in order to save it from crashing into the asteroids on the way.
 
 With every level the speed of the spaceship will increase.
         </_manual>
+        <_credit>www.openclipart.org</_credit>
   </Board>
   <Data directory=""/>
 </GCompris>
+
diff --git a/src/intro_gravity-activity/resources/intro_gravity/Makefile.am b/src/intro_gravity-activity/resources/intro_gravity/Makefile.am
index b327bf2..1969dd9 100644
--- a/src/intro_gravity-activity/resources/intro_gravity/Makefile.am
+++ b/src/intro_gravity-activity/resources/intro_gravity/Makefile.am
@@ -1,7 +1,13 @@
 imgdir = $(pkgdatadir)/@PACKAGE_DATA_DIR@/intro_gravity
 img_DATA = \
-	neptune.png \
+	asteroid0.jpg \
+	asteroid1.jpg \
+	asteroid2.jpg \
+	asteroid3.jpg \
+	asteroid4.jpg \
 	background.svg \
+    crash.png \
+	neptune.png \
 	saturn.png \
 	tux_spaceship.png
 
diff --git a/src/intro_gravity-activity/resources/intro_gravity/README b/src/intro_gravity-activity/resources/intro_gravity/README
index ab6cdcf..6476e5c 100644
--- a/src/intro_gravity-activity/resources/intro_gravity/README
+++ b/src/intro_gravity-activity/resources/intro_gravity/README
@@ -1,2 +1,3 @@
 arrows, neptune.png, saturn.png taken from openclipart.org
 tux_spaceship.png taken from clker.com and modified according to requirement.
+asteroids have been taken from nasaimages.org
diff --git a/src/intro_gravity-activity/resources/intro_gravity/asteroid0.jpg b/src/intro_gravity-activity/resources/intro_gravity/asteroid0.jpg
new file mode 100644
index 0000000..e90a353
Binary files /dev/null and b/src/intro_gravity-activity/resources/intro_gravity/asteroid0.jpg differ
diff --git a/src/intro_gravity-activity/resources/intro_gravity/asteroid1.jpg b/src/intro_gravity-activity/resources/intro_gravity/asteroid1.jpg
new file mode 100644
index 0000000..7959f51
Binary files /dev/null and b/src/intro_gravity-activity/resources/intro_gravity/asteroid1.jpg differ
diff --git a/src/intro_gravity-activity/resources/intro_gravity/asteroid2.jpg b/src/intro_gravity-activity/resources/intro_gravity/asteroid2.jpg
new file mode 100644
index 0000000..84d6b4c
Binary files /dev/null and b/src/intro_gravity-activity/resources/intro_gravity/asteroid2.jpg differ
diff --git a/src/intro_gravity-activity/resources/intro_gravity/asteroid3.jpg b/src/intro_gravity-activity/resources/intro_gravity/asteroid3.jpg
new file mode 100644
index 0000000..355fb0e
Binary files /dev/null and b/src/intro_gravity-activity/resources/intro_gravity/asteroid3.jpg differ
diff --git a/src/intro_gravity-activity/resources/intro_gravity/asteroid4.jpg b/src/intro_gravity-activity/resources/intro_gravity/asteroid4.jpg
new file mode 100644
index 0000000..a70e0bf
Binary files /dev/null and b/src/intro_gravity-activity/resources/intro_gravity/asteroid4.jpg differ
diff --git a/src/intro_gravity-activity/resources/intro_gravity/crash.png b/src/intro_gravity-activity/resources/intro_gravity/crash.png
new file mode 100644
index 0000000..e43553c
Binary files /dev/null and b/src/intro_gravity-activity/resources/intro_gravity/crash.png differ
diff --git a/src/land_safe-activity/resources/land_safe/README b/src/land_safe-activity/resources/land_safe/README
index cccabe9..5d1e9e2 100644
--- a/src/land_safe-activity/resources/land_safe/README
+++ b/src/land_safe-activity/resources/land_safe/README
@@ -1,3 +1,3 @@
 flames and crash.png taken from OpenClipart.org
 rocket.png also taken from openclipart.org and modified according to requirement.
-
+Last background image is from nasaimages.org



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]