Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHector Martinez <hectorsantacruz@hotmail.com>2013-01-25 22:08:13 (GMT)
committer Hector Martinez <hectorsantacruz@hotmail.com>2013-01-25 22:08:13 (GMT)
commit1ddd8bf98b0b2fb123dbf6f64c710cd4289f90c5 (patch)
tree6dcb075f8aef1fd7b8f6bec06b2d83296d5685a4
parent0474092388b1cb41789192225a458306ad075eb3 (diff)
Calculo de puntaje de acuerdo a distancia
Se implemento un calculo de puntaje de acuerdo a la distancia euclidea Seria ideal poder pasar a coordenadas polares de modo a implementar el puntaje de acuerdo a las reglas de los dardos reales
-rw-r--r--activity.py50
-rw-r--r--images/dartboard.pngbin78760 -> 67179 bytes
2 files changed, 44 insertions, 6 deletions
diff --git a/activity.py b/activity.py
index be2a77d..53d5555 100644
--- a/activity.py
+++ b/activity.py
@@ -21,6 +21,7 @@
"""Lanzar Activity: a dart game"""
import gtk
+import math
import logging
import gobject
@@ -36,8 +37,8 @@ from sugar.activity.widgets import ShareButton
DELAY = 5
DELTA = 1
-WIDTH = 512
-HEIGHT = 512
+WIDTH = 453
+HEIGHT = 453
class LanzarActivity(activity.Activity):
"""LanzarActivity class as specified in activity.info"""
@@ -110,7 +111,7 @@ class LanzarActivity(activity.Activity):
score_str = gtk.Label()
score_str.set_markup("<span foreground='white' size='xx-large'><b>%s</b></span>" % _("Score"))
self.score_text = gtk.Label()
- self.score_text_tmpl = "<span foreground='white' size='xx-large'>%d</span>"
+ self.score_text_tmpl = "<span foreground='white' size='xx-large'>%s</span>"
self.score_text.set_markup(self.score_text_tmpl % self._score)
score_box = gtk.VBox()
score_box.pack_start(score_str, expand=False, fill=False)
@@ -257,8 +258,8 @@ class LanzarActivity(activity.Activity):
self.draw_background(drawing_area)
self.draw_line(drawing_area, "HORIZONTAL", self._selected_y)
self.draw_line(drawing_area, "VERTICAL", self._selected_x)
- self.pixmap.draw_pixbuf(None, self.dart_pixbuf, 0, 0, x, y, -1, -1,
- gtk.gdk.RGB_DITHER_NONE, 0, 0)
+# self.pixmap.draw_pixbuf(None, self.dart_pixbuf, 0, 0, x, y, -1, -1,
+# gtk.gdk.RGB_DITHER_NONE, 0, 0)
def restart_game(self, drawing_area):
self._x = self._y = 0
@@ -269,4 +270,41 @@ class LanzarActivity(activity.Activity):
"""
Calcula el puntaje en base a las coordenadas X e Y dadas como parametro.
"""
- return x + y # for debugging
+ #Variables para el calculo del puntaje
+ score = 0
+ distance = 0
+ rho = 0
+
+ #Variables dependientes de la imagen de fondo (dartboard.png)
+ center_x = 226
+ center_y = 227
+ radius_bullseye = 7
+ radius_bull = 16
+ radius_dartboard = 170
+
+ #Calculo de la distancia euclidea del punto "seleccionado" respecto al centro
+ distance = math.sqrt(math.pow(abs(x - center_x),2) + math.pow(abs(y - center_y),2))
+
+ #Intento de cambiar coordenadas cartesianas a coordenadas polares
+ displaced_x = x - center_x
+ displaced_y = center_y - y
+# rho = math.atan((displaced_y / displaced_x))
+
+ #Version inicial de calculo de puntaje de acuerdo a distancia al centro
+ if distance < radius_bullseye:
+ score = 10000 - distance * 10
+ elif distance < radius_bull:
+ score = 7500 - distance * 20
+ elif distance < radius_dartboard:
+ score = 5100 - distance * 30
+ else:
+ score = 0
+
+ #Impresiones para depurar valores utiles en el calculo de puntaje
+ logging.debug("X: " + str(x) + " Y: " + str(y))
+ logging.debug("__X: " + str(displaced_x) + " __Y: " + str(displaced_y))
+ logging.debug("DISTANCE: "+str(distance) + " RHO: "+str(rho))
+ logging.debug("SCORE: "+str(int(score)))
+
+ return int(score)
+
diff --git a/images/dartboard.png b/images/dartboard.png
index 1baaf1c..c065501 100644
--- a/images/dartboard.png
+++ b/images/dartboard.png
Binary files differ