diff options
-rw-r--r-- | game.py | 14 | ||||
-rw-r--r-- | glucosa.py | 63 | ||||
-rw-r--r-- | images/aurora.png | bin | 0 -> 50948 bytes | |||
-rw-r--r-- | images/aurora.svg | 140 | ||||
-rw-r--r-- | images/backgroud.png | bin | 4096 -> 0 bytes | |||
-rw-r--r-- | images/evening.png | bin | 0 -> 40505 bytes | |||
-rw-r--r-- | images/evening.svg | 140 | ||||
-rw-r--r-- | images/night.png | bin | 0 -> 17193 bytes | |||
-rw-r--r-- | images/night.svg | 139 |
9 files changed, 466 insertions, 30 deletions
@@ -1,15 +1,20 @@ #!/usr/bin/env python import glucosa +import gtk + +AURORA = 'images/aurora.png' +EVENING = 'images/evening.png' +NIGHT = 'images/night.png' class AntFarm(glucosa.GameArea): def __init__(self): glucosa.GameArea.__init__(self) - - self.backgroud = glucosa.Image('images/backgroud.png') + self._set_background(NIGHT) + image = glucosa.Image('images/aceituna.png') sprite = glucosa.Sprite(image, 100, 100, 18, 18, scale=2) self.add_sprite(sprite) @@ -17,6 +22,11 @@ class AntFarm(glucosa.GameArea): self._events = glucosa.Events(self) self._events.connect('mouse-moved', self._mouse_move, sprite) + def _mouse_move(self, widget, event, sprite): sprite.x, sprite.y = event['x'], event['y'] + def _set_background(self, bg): + alloc = self.get_allocation() + self.set_background(bg, alloc.width, alloc.height) + @@ -363,7 +363,7 @@ class Sprite(gobject.GObject): x = property(get_x, set_x, doc="Define la posicion horizonal") y = property(get_y, set_y, doc="Define la posicion vertical") - + def get_left(self): return self.x - (self.image.width * self.scale / 2) @@ -393,8 +393,8 @@ class Sprite(gobject.GObject): top = property(get_top, set_top, doc="Define la posición superior del Sprite") bottom = property(get_bottom, set_bottom, doc="Define la posición inferior del Sprite") - - + + class Text: """Muestra un texto en la pantalla. @@ -479,17 +479,17 @@ class Events(gobject.GObject): """ - # No funciona con gobject: + # No funciona con gobject: # Solo puede existir una instancia de este objeto en el programa. #__metaclass__ = Singleton __gsignals__ = {'mouse-moved': (gobject.SIGNAL_RUN_FIRST, None, [object]), - 'mouse-button-pressed': (gobject.SIGNAL_RUN_FIRST, None, [object]), - 'mouse-button-released': (gobject.SIGNAL_RUN_FIRST, None, [object]), - 'mouse-scroll-up': (gobject.SIGNAL_RUN_FIRST, None, [object]), - 'mouse-scroll-down': (gobject.SIGNAL_RUN_FIRST, None, [object]), - 'key-pressed': (gobject.SIGNAL_RUN_FIRST, None, []), - 'key-released': (gobject.SIGNAL_RUN_FIRST, None, [])} + 'mouse-button-pressed': (gobject.SIGNAL_RUN_FIRST, None, [object]), + 'mouse-button-released': (gobject.SIGNAL_RUN_FIRST, None, [object]), + 'mouse-scroll-up': (gobject.SIGNAL_RUN_FIRST, None, [object]), + 'mouse-scroll-down': (gobject.SIGNAL_RUN_FIRST, None, [object]), + 'key-pressed': (gobject.SIGNAL_RUN_FIRST, None, []), + 'key-released': (gobject.SIGNAL_RUN_FIRST, None, [])} def __init__(self, widget): gobject.GObject.__init__(self) @@ -497,17 +497,17 @@ class Events(gobject.GObject): self._widget = widget # Conectamos los eventos de GTK. - self._widget.connect('motion-notify-event', + self._widget.area.connect('motion-notify-event', self._mouse_move) - self._widget.connect('button-press-event', + self._widget.area.connect('button-press-event', self._mouse_button_press) - self._widget.connect('button-release-event', + self._widget.area.connect('button-release-event', self._mouse_button_released) - self._widget.connect('key-press-event', + self._widget.area.connect('key-press-event', self._key_pressed) - self._widget.connect('key-release-event', + self._widget.area.connect('key-release-event', self._key_released) - self._widget.connect('scroll-event', + self._widget.area.connect('scroll-event', self._mouse_scroll) self._keys_pressed = [] @@ -736,7 +736,8 @@ class Pencil: context.stroke() -class GameArea(gtk.DrawingArea): + +class GameArea(gtk.Fixed): """Es el area donde el juego se dibujará Permite ser embebida en cualquier contenedor de gtk, ya que es un @@ -754,28 +755,39 @@ class GameArea(gtk.DrawingArea): } def __init__(self): - gtk.DrawingArea.__init__(self) + gtk.Fixed.__init__(self) self.sprites = [] self._timeout = None - self.backgroud = None + self.background = gtk.Image() + self.add(self.background) - self.connect("expose-event", self._on_draw) + self.area = gtk.DrawingArea() + self.add(self.area) - self.set_events( gtk.gdk.BUTTON_PRESS_MASK + self.area.connect("expose-event", self._on_draw) + + self.area.set_events(gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.KEY_RELEASE_MASK | gtk.gdk.KEY_PRESS_MASK | gtk.gdk.POINTER_MOTION_MASK) - self.set_flags (gtk.CAN_FOCUS) + self.area.set_flags(gtk.CAN_FOCUS) + + self.show_all() def add_sprite(self, sprite): """Agrega un sprite a el area de juego""" self.sprites.append(sprite) sprite.connect('update', self._update) + def set_background(self, path, width, height): + """Define el fondo del area de juego""" + pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(path, width, height) + self.background.set_from_pixbuf(pixbuf) + def set_update_loop(self, fps=60): """Define un bucle de actualizacion si fps = -1 el bucle se detendra y dibujara solo cuando un sprite cambie""" @@ -793,7 +805,7 @@ class GameArea(gtk.DrawingArea): for sprite in self.sprites: sprite.update() - gobject.idle_add(self.queue_draw) + gobject.idle_add(self.area.queue_draw) return True def _on_draw(self, widget, event): @@ -801,11 +813,6 @@ class GameArea(gtk.DrawingArea): window_size = self.get_window().get_size() fill(context, (50,50,50), window_size) - # Dibuja el fondo - if not self.backgroud == None: - self.backgroud.blit(context, 0, 0, scale=1, rotation=0, anchor_x=0, - anchor_y=0, flip=False) - # Se encarga de dibujar los sprites for sprite in self.sprites: sprite.draw(context) diff --git a/images/aurora.png b/images/aurora.png Binary files differnew file mode 100644 index 0000000..64d3371 --- /dev/null +++ b/images/aurora.png diff --git a/images/aurora.svg b/images/aurora.svg new file mode 100644 index 0000000..c787ee9 --- /dev/null +++ b/images/aurora.svg @@ -0,0 +1,140 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- 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:xlink="http://www.w3.org/1999/xlink" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + id="svg3087" + version="1.1" + inkscape:version="0.48.2 r9819" + width="1920" + height="980" + sodipodi:docname="aurora.png"> + <metadata + id="metadata3093"> + <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> + <defs + id="defs3091"> + <linearGradient + id="linearGradient3924"> + <stop + style="stop-color:#ffff3f;stop-opacity:1;" + offset="0" + id="stop3926" /> + <stop + style="stop-color:#ffff83;stop-opacity:0;" + offset="1" + id="stop3928" /> + </linearGradient> + <linearGradient + id="linearGradient3914"> + <stop + style="stop-color:#ffcb00;stop-opacity:1;" + offset="0" + id="stop3916" /> + <stop + style="stop-color:#ff9d00;stop-opacity:1;" + offset="1" + id="stop3918" /> + </linearGradient> + <linearGradient + id="linearGradient3902"> + <stop + style="stop-color:#00a1ff;stop-opacity:1;" + offset="0" + id="stop3904" /> + <stop + id="stop3961" + offset="0.85915494" + style="stop-color:#ff8700;stop-opacity:1;" /> + <stop + style="stop-color:#ffb13f;stop-opacity:1;" + offset="1" + id="stop3906" /> + </linearGradient> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3902" + id="linearGradient3908" + x1="-4.3478255" + y1="490.86959" + x2="1921.7392" + y2="490.86959" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(0.50910985,0,0,1.9688888,1.082948,-1925.8591)" /> + <radialGradient + inkscape:collect="always" + xlink:href="#linearGradient3924" + id="radialGradient3930" + cx="923.91302" + cy="658.26086" + fx="923.91302" + fy="658.26086" + r="180.43478" + gradientTransform="matrix(1,0,0,0.8674699,0,87.239379)" + gradientUnits="userSpaceOnUse" /> + </defs> + <sodipodi:namedview + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1" + objecttolerance="10" + gridtolerance="10" + guidetolerance="10" + inkscape:pageopacity="0" + inkscape:pageshadow="2" + inkscape:window-width="1024" + inkscape:window-height="541" + id="namedview3089" + showgrid="false" + inkscape:zoom="0.23" + inkscape:cx="1013.2847" + inkscape:cy="323.89361" + inkscape:window-x="0" + inkscape:window-y="27" + inkscape:window-maximized="1" + inkscape:current-layer="svg3087" /> + <rect + style="fill:url(#linearGradient3908);fill-opacity:1;stroke:none" + id="rect3132" + width="980.58984" + height="1926.0869" + x="-1.130573" + y="-1922.4347" + transform="matrix(0,1,-1,0,0,0)" /> + <path + sodipodi:type="arc" + style="fill:url(#radialGradient3930);fill-opacity:1;stroke:none" + id="path3922" + sodipodi:cx="923.91302" + sodipodi:cy="658.26086" + sodipodi:rx="180.43478" + sodipodi:ry="156.52174" + d="m 1104.3478,658.26086 a 180.43478,156.52174 0 1 1 -360.86956,0 180.43478,156.52174 0 1 1 360.86956,0 z" + transform="matrix(1.4039285,0,0,1.342474,-376.9372,-34.955022)" /> + <path + sodipodi:type="arc" + style="fill:#fffa7d;fill-opacity:1;stroke:none" + id="path3912" + sodipodi:cx="967.3913" + sodipodi:cy="906.08698" + sodipodi:rx="128.26086" + sodipodi:ry="117.3913" + d="m 1095.6522,906.08698 a 128.26086,117.3913 0 1 1 -256.52177,0 128.26086,117.3913 0 1 1 256.52177,0 z" + transform="matrix(1.0045352,0,0,1.006856,-49.424036,-63.555568)" /> +</svg> diff --git a/images/backgroud.png b/images/backgroud.png Binary files differdeleted file mode 100644 index 441ebec..0000000 --- a/images/backgroud.png +++ /dev/null diff --git a/images/evening.png b/images/evening.png Binary files differnew file mode 100644 index 0000000..8a65a0a --- /dev/null +++ b/images/evening.png diff --git a/images/evening.svg b/images/evening.svg new file mode 100644 index 0000000..5d03a4c --- /dev/null +++ b/images/evening.svg @@ -0,0 +1,140 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- 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:xlink="http://www.w3.org/1999/xlink" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + id="svg3087" + version="1.1" + inkscape:version="0.48.2 r9819" + width="1920" + height="980" + sodipodi:docname="evening.svg"> + <metadata + id="metadata3093"> + <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 /> + </cc:Work> + </rdf:RDF> + </metadata> + <defs + id="defs3091"> + <linearGradient + id="linearGradient3924"> + <stop + style="stop-color:#ffff64;stop-opacity:1;" + offset="0" + id="stop3926" /> + <stop + style="stop-color:#ffff83;stop-opacity:0;" + offset="1" + id="stop3928" /> + </linearGradient> + <linearGradient + id="linearGradient3914"> + <stop + style="stop-color:#ffcb00;stop-opacity:1;" + offset="0" + id="stop3916" /> + <stop + style="stop-color:#ff9d00;stop-opacity:1;" + offset="1" + id="stop3918" /> + </linearGradient> + <linearGradient + id="linearGradient3902"> + <stop + style="stop-color:#ffff00;stop-opacity:1;" + offset="0" + id="stop3904" /> + <stop + id="stop3910" + offset="0.70422536" + style="stop-color:#ffb400;stop-opacity:1;" /> + <stop + style="stop-color:#ff6900;stop-opacity:1;" + offset="1" + id="stop3906" /> + </linearGradient> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient3902" + id="linearGradient3908" + x1="-4.3478255" + y1="490.86959" + x2="1921.7392" + y2="490.86959" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(0.50970651,0,0,1.9688817,1.0851159,-1925.8792)" /> + <radialGradient + inkscape:collect="always" + xlink:href="#linearGradient3924" + id="radialGradient3930" + cx="923.91302" + cy="658.26086" + fx="923.91302" + fy="658.26086" + r="180.43478" + gradientTransform="matrix(1,0,0,0.8674699,0,87.239379)" + gradientUnits="userSpaceOnUse" /> + </defs> + <sodipodi:namedview + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1" + objecttolerance="10" + gridtolerance="10" + guidetolerance="10" + inkscape:pageopacity="0" + inkscape:pageshadow="2" + inkscape:window-width="1024" + inkscape:window-height="541" + id="namedview3089" + showgrid="false" + inkscape:zoom="0.23" + inkscape:cx="1013.2847" + inkscape:cy="388.19286" + inkscape:window-x="0" + inkscape:window-y="27" + inkscape:window-maximized="1" + inkscape:current-layer="svg3087" /> + <rect + style="fill:url(#linearGradient3908);fill-opacity:1;stroke:none" + id="rect3132" + width="981.73914" + height="1926.08" + x="-1.1309967" + y="-1922.455" + transform="matrix(0,1,-1,0,0,0)" /> + <path + sodipodi:type="arc" + style="fill:url(#radialGradient3930);fill-opacity:1;stroke:none" + id="path3922" + sodipodi:cx="923.91302" + sodipodi:cy="658.26086" + sodipodi:rx="180.43478" + sodipodi:ry="156.52174" + d="m 1104.3478,658.26086 a 180.43478,156.52174 0 1 1 -360.86956,0 180.43478,156.52174 0 1 1 360.86956,0 z" + transform="matrix(1.4039235,0,0,1.3440476,-361.70963,-171.47435)" /> + <path + sodipodi:type="arc" + style="fill:#fffa7d;fill-opacity:1;stroke:none" + id="path3912" + sodipodi:cx="967.3913" + sodipodi:cy="906.08698" + sodipodi:rx="128.26086" + sodipodi:ry="117.3913" + d="m 1095.6522,906.08698 a 128.26086,117.3913 0 1 1 -256.52177,0 128.26086,117.3913 0 1 1 256.52177,0 z" + transform="matrix(1.0045315,0,0,1.0080357,-34.19765,-200.10842)" /> +</svg> diff --git a/images/night.png b/images/night.png Binary files differnew file mode 100644 index 0000000..0d84dd4 --- /dev/null +++ b/images/night.png diff --git a/images/night.svg b/images/night.svg new file mode 100644 index 0000000..1c30ecc --- /dev/null +++ b/images/night.svg @@ -0,0 +1,139 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!-- 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:xlink="http://www.w3.org/1999/xlink" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + id="svg3087" + version="1.1" + inkscape:version="0.48.2 r9819" + width="1920" + height="980" + sodipodi:docname="night.svg"> + <metadata + id="metadata3093"> + <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 /> + </cc:Work> + </rdf:RDF> + </metadata> + <defs + id="defs3091"> + <linearGradient + id="linearGradient4021"> + <stop + style="stop-color:#8c0090;stop-opacity:0.77536231;" + offset="0" + id="stop4023" /> + <stop + style="stop-color:#000057;stop-opacity:1;" + offset="1" + id="stop4025" /> + </linearGradient> + <linearGradient + id="linearGradient3924"> + <stop + style="stop-color:#ffff3f;stop-opacity:1;" + offset="0" + id="stop3926" /> + <stop + style="stop-color:#ffff83;stop-opacity:0;" + offset="1" + id="stop3928" /> + </linearGradient> + <linearGradient + id="linearGradient3914"> + <stop + style="stop-color:#ffcb00;stop-opacity:1;" + offset="0" + id="stop3916" /> + <stop + style="stop-color:#ff9d00;stop-opacity:1;" + offset="1" + id="stop3918" /> + </linearGradient> + <linearGradient + id="linearGradient3902"> + <stop + style="stop-color:#00a1ff;stop-opacity:1;" + offset="0" + id="stop3904" /> + <stop + id="stop3961" + offset="0.85915494" + style="stop-color:#ff8700;stop-opacity:1;" /> + <stop + style="stop-color:#ffb13f;stop-opacity:1;" + offset="1" + id="stop3906" /> + </linearGradient> + <radialGradient + inkscape:collect="always" + xlink:href="#linearGradient3924" + id="radialGradient3930" + cx="923.91302" + cy="658.26086" + fx="923.91302" + fy="658.26086" + r="180.43478" + gradientTransform="matrix(1,0,0,0.8674699,0,87.239379)" + gradientUnits="userSpaceOnUse" /> + <linearGradient + inkscape:collect="always" + xlink:href="#linearGradient4021" + id="linearGradient4029" + x1="6.0869093" + y1="-963.04346" + x2="980" + y2="-963.04346" + gradientUnits="userSpaceOnUse" + gradientTransform="matrix(1.0303571,0,0,1.0045315,-1008.6189,7.9924802)" /> + </defs> + <sodipodi:namedview + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1" + objecttolerance="10" + gridtolerance="10" + guidetolerance="10" + inkscape:pageopacity="0" + inkscape:pageshadow="2" + inkscape:window-width="1024" + inkscape:window-height="541" + id="namedview3089" + showgrid="false" + inkscape:zoom="0.23" + inkscape:cx="946.67882" + inkscape:cy="388.19286" + inkscape:window-x="0" + inkscape:window-y="27" + inkscape:window-maximized="1" + inkscape:current-layer="svg3087" + showguides="true" + inkscape:guide-bbox="true" /> + <rect + style="fill:url(#linearGradient4029);fill-opacity:1;stroke:none" + id="rect3132" + width="1003.4783" + height="1926.08" + x="-1002.3473" + y="-1922.455" + transform="matrix(0,-1,-1,0,0,0)" /> + <path + style="fill:#ffffff;stroke:none" + d="m 1598.0356,103.53326 c 0.6905,-2.83332 118.2425,68.61356 103.016,181.63336 -3.5613,26.4337 -16.5537,48.94654 -34.5102,68.25604 -24.5337,26.38225 -151.5176,1.94634 -151.5176,1.94634 0,0 117.7877,67.34894 170.8274,61.17407 35.8763,-4.17671 95.4135,-45.3719 113.9205,-109.16793 14.2933,-49.27091 1.6063,-78.69498 -47.6381,-138.46583 -37.4733,-45.48368 -154.098,-65.37605 -154.098,-65.37605 z" + id="path4033" + inkscape:connector-curvature="0" + sodipodi:nodetypes="csscsssc" /> +</svg> |