froechrissi

Untitled

Jan 21st, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.81 KB | None | 0 0
  1. #### kivy imports
  2.  
  3. import kivy
  4.  
  5. from kivy.app import App
  6. from kivy.uix.floatlayout import FloatLayout
  7. from kivy.uix.button import Button
  8. from kivy.uix.gridlayout import GridLayout
  9.  
  10. from kivy.uix.modalview import ModalView
  11.  
  12. from kivy.uix.scatter import Scatter
  13. from kivy.uix.image import *
  14. from kivy.graphics import Color, Ellipse
  15. from kivy.uix.widget import Widget
  16. from kivy.uix.label import Label
  17. from kivy.uix.image import Image
  18.  
  19. from kivy.base import EventLoop
  20.  
  21.  
  22. ### third party imports
  23. import sqlite3
  24. conn = sqlite3.connect("conquest.db")
  25.  
  26. TURM_X = 20
  27. TURM_Y = 20
  28.  
  29.  
  30. class Turm(Image):
  31.   def __init__(self, pos1, pos2, land):
  32.     self.land = land
  33.     self.pos1 = pos1
  34.     self.pos2 = pos2
  35.    
  36.     return Image.__init__(self, source='turm.png', pos=(pos1,pos2), size=(TURM_X, TURM_Y))
  37.  
  38.   def on_touch_down(self, touch):
  39.     if self.collide_point(touch.x, touch.y) == True:
  40.       print "touch"
  41.  
  42. class conquest(App):
  43.  
  44.  
  45.   def build(self):
  46.  
  47.       EventLoop.ensure_window()
  48.  
  49.    
  50.       self.root = GridLayout(cols=2)
  51.      
  52.       new_game_btn = Button(text='New Game')
  53.       self.root.add_widget(new_game_btn)
  54.       new_game_btn.bind(on_press=self.new_game)
  55.  
  56.       continue_btn = Button(text='Continue')
  57.       self.root.add_widget(continue_btn)
  58.       continue_btn.bind(on_press=self.init_ingame)
  59.  
  60.       #setattr(Image, 'type', property(func))
  61.  
  62.      
  63.       return self.root
  64.  
  65.   def new_game(self, instance):
  66.     pass
  67.  
  68.  
  69.  
  70.   # prepares ingame widgets
  71.   def init_ingame(self, instance):
  72.  
  73.     self.root.clear_widgets()
  74.  
  75.    
  76.     layout = Scatter(do_rotation=False)
  77.     floating = GridLayout()
  78.     map_image = Image(source='map.jpg', size=(800,1000))
  79.     floating.add_widget(map_image)
  80.  
  81.     self.laender = {"Noerdliche Oednis" : (600,600), "Rohan" : (400,400)}
  82.    
  83.     tuerme = []
  84.     for name,pos in self.laender.items():
  85.       element = Turm(pos[0], pos[1], name)
  86.       tuerme.append(element)
  87.       tuerme[-1].bind(on_touch_down=self.my_touch_down)
  88.       floating.add_widget(tuerme[-1])
  89.  
  90.     self.tuerme = tuerme
  91.    
  92.     layout.add_widget(floating)
  93.  
  94.     #navigation = Label(text='Conquest')
  95.  
  96.     #self.root.add_widget(navigation)
  97.    
  98.     self.root.add_widget(layout)
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.   def my_touch_down(self, obj, touch):
  106.     print str(obj)
  107.     print str(touch)
  108.  
  109.     # check ob es ein turm ist
  110.     # herausfinden, um welchen turm es sich handelt und dann
  111.     # dort ellipse zeichne
  112.  
  113.     print "click"
  114.  
  115.     if obj.__class__.__name__ == 'Turm':
  116.       print "click auf turm"
  117.    
  118.  
  119.    
  120. def in_rectangle(rx, ry, px, py, size_x, size_y):
  121.   if px <= rx + size_x and px >= rx and py <= ry + size_y and py >= ry:
  122.     return True
  123.   else:
  124.     #print str([rx, ry, px, py, size_x, size_y])
  125.     return False
  126.  
  127. if __name__ in ('__android__','__main__'):
  128.   conquest().run()
Advertisement
Add Comment
Please, Sign In to add comment