Skip to content

Commit

Permalink
Tank rebuilt with widget class instead of scatter
Browse files Browse the repository at this point in the history
  • Loading branch information
stocyr committed Jan 19, 2012
1 parent f257027 commit 0d6053a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion deflectouch.kv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
## IcarusTouch# # Copyright (C) 2012 Cyril Stoller# # For comments, suggestions or other messages, contact me at:# <cyril.stoller@gmail.com># # This file is part of Deflectouch.# # Deflectouch is free software: you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation, either version 3 of the License, or# (at your option) any later version.# # Deflectouch is distributed in the hope that it will be fun,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.# # You should have received a copy of the GNU General Public License# along with Deflectouch. If not, see <http://www.gnu.org/licenses/>.##:kivy 1.0
#:import kivy kivy#:import win kivy.core.window# Background description:<Background>: size: root.size source: 'graphics/beta/background_beta.jpg' allow_stretch: True keep_ratio: False# Tank description:<Tank>: tank_image: tank_image tank_tower_scatter: tank_tower_scatter size_hint: None, None do_rotation: False do_scale: False do_translation_x: False Image: id: tank_image source: 'graphics/beta/tank_beta.png' size: 92, 149 Scatter: id: tank_tower_scatter size_hint: None, None pos: -50, 37 do_rotation: False do_scale: False do_translation: False Image: source: 'graphics/beta/tank_tower_beta.png' size: 196, 76
#:import kivy kivy#:import win kivy.core.window# Background description:<Background>: source: 'graphics/beta/background_beta.jpg' allow_stretch: True keep_ratio: False size: 1920, 1200# Tank description:<Tank>: tank_tower_scatter: tank_tower_scatter source: 'graphics/beta/tank_beta.png' size: 92, 149 Scatter: id: tank_tower_scatter size_hint: None, None x: root.x - 50 y: root.y + 37 do_rotation: False do_scale: False do_translation: False Image: source: 'graphics/beta/tank_tower_beta.png' size: 196, 76
# Deflector description:<Deflector>: end_point1: end_point1 end_point2: end_point2 deflector_line: deflector_line Image: id: end_point1 size: 40, 40 source: 'graphics/beta/finger_point_blue_beta.png' Image: id: end_point2 size: 40, 40 source: 'graphics/beta/finger_point_blue_beta.png' Image: id: deflector_line # isn't really necessary: #source: 'graphics/beta/deflector_blue_beta.png' # This image consists only of a border image! Thus i can scale it as i want. canvas.before: BorderImage: source: 'graphics/beta/deflector_blue_beta.png' border: (10, 10, 10, 10) size: (self.width+10*2, self.height+10*2) pos: (self.x-10, self.y-10)# Bullet description:<Bullet>: source: 'graphics/bullet.png' size: 35, 35 size_hint: None, None# Main widget description:<DeflectouchWidget>: level_label: level_label lives_label: lives_label fire_button: fire_button reset_button: reset_button menu_button: menu_button # background image # tank rail image # tank widget Button: id: fire_button text: 'Fire' size_hint: None, None size: 100, 50 right: win.Window.width - 10 top: win.Window.height - 10 on_press: root.fire_button_pressed() Button: id: reset_button text: 'Reset' size_hint: None, None size: 100, 50 right: win.Window.width - 10 top: win.Window.height - 70 on_press: root.reset_button_pressed() Button: id: menu_button text: 'Menu' size_hint: None, None size: 100, 50 right: win.Window.width - 10 top: win.Window.height - 130 on_press: root.menu_button_pressed() Label: id: level_label text: 'Level: 1' Label: id: lives_label text: 'Lives: 3'
Expand Down
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
from kivy.properties import ObjectProperty, StringProperty

from kivy.uix.image import Image
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.widget import Widget

from math import sin
from math import cos
Expand Down Expand Up @@ -116,7 +116,7 @@ def delete_deflector(self, deflector):
##
####################################
'''
class DeflectouchWidget(FloatLayout):
class DeflectouchWidget(Widget):
app = ObjectProperty(None)
version = StringProperty(VERSION)

Expand Down
31 changes: 16 additions & 15 deletions tank.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

from kivy.properties import ObjectProperty
from kivy.graphics.transformation import Matrix
from kivy.uix.scatter import Scatter
from kivy.uix.image import Image

from kivy.utils import boundary
from math import radians
Expand All @@ -42,8 +42,7 @@
##
####################################
'''
class Tank(Scatter):
tank_image = ObjectProperty(None)
class Tank(Image):
tank_tower_scatter = ObjectProperty(None)

'''
Expand All @@ -54,14 +53,13 @@ class Tank(Scatter):
####################################
'''
def on_touch_down(self, touch):
#print self.bbox
if not self.collide_point(*touch.pos):
touch.ungrab(self)
return False
else:
touch.ud['tank_touch'] = True
return super(Tank, self).on_touch_down(touch)

#if not self.collide_point(*touch.pos):
# touch.ungrab(self)
# return False
#else:
print 'tank'
touch.ud['tank_touch'] = True
#return super(Tank, self).on_touch_down(touch)


'''
Expand Down Expand Up @@ -94,7 +92,11 @@ def on_touch_move(self, touch):
ud['tank_position'] = self.pos
self.do_translation_y = False

return super(Tank, self).on_touch_move(touch)
else:
print 'move'
# if 'normal' dragging (up and down) is performed, do it:
self.y += touch.dy
print touch.dy


'''
Expand All @@ -105,6 +107,5 @@ def on_touch_move(self, touch):
####################################
'''
def on_touch_up(self, touch):
# set translation_y to the initial state again
self.do_translation_y = True
return super(Tank, self).on_touch_up(touch)
pass

Binary file modified tank.pyc
Binary file not shown.
3 changes: 2 additions & 1 deletion todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
- settings: they keep not writing the GamePlay Variable into the ini file...
- register all the classes with Factory.register -> initialize the widget tree entirely in the kv file
- deflector = completeley build it with canvas instructions
- change deflector and tank classes from scatter to Widget classes
- change deflector classe from scatter to Widget classes
- tank bug: tower goes not with its roots position

0 comments on commit 0d6053a

Please sign in to comment.