froechrissi

Untitled

Jan 23rd, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.75 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.  
  39. class conquest(App):
  40.  
  41.  
  42.   def build(self):
  43.  
  44.       EventLoop.ensure_window()
  45.  
  46.    
  47.       self.root = GridLayout(cols=2)
  48.      
  49.       new_game_btn = Button(text='New Game')
  50.       self.root.add_widget(new_game_btn)
  51.       new_game_btn.bind(on_press=self.new_game)
  52.  
  53.       continue_btn = Button(text='Continue')
  54.       self.root.add_widget(continue_btn)
  55.       continue_btn.bind(on_press=self.init_ingame)
  56.  
  57.      
  58.       return self.root
  59.  
  60.   def new_game(self, instance):
  61.     pass
  62.  
  63.  
  64.  
  65.   # prepares ingame widgets
  66.   def init_ingame(self, instance):
  67.  
  68.     self.root.clear_widgets()
  69.  
  70.    
  71.     layout = Scatter(do_rotation=False)
  72.     floating = FloatLayout()
  73.     map_image = Image(source='map.jpg', size=(800,1000))
  74.     floating.add_widget(map_image)
  75.     #self.root.bind(on_touch_down=self.on_touch_down)
  76.  
  77.     self.laender = {"Noerdliche Oednis" : (600,600), "Rohan" : (400,400)}
  78.    
  79.     tuerme = []
  80.     for name,pos in self.laender.items():
  81.       element = Turm(pos[0], pos[1], name)
  82.       tuerme.append(element)
  83.       floating.add_widget(tuerme[-1])
  84.  
  85.     self.tuerme = tuerme
  86.    
  87.     layout.add_widget(floating)
  88.  
  89.     #navigation = Label(text='Conquest')
  90.  
  91.     #self.root.add_widget(navigation)
  92.    
  93.     self.root.add_widget(layout)
  94.  
  95.  
  96.   def on_touch_down(self, obj, touch):
  97.     #binded to on_touch_down event of the root Grid layout
  98.    
  99.     obj = obj.children[0]
  100.     #print obj
  101.     #print touch.x, touch.y
  102.     (x,y) = obj.to_local(touch.x, touch.y)
  103.     #print x,y
  104.     for turm in self.tuerme:
  105.       if turm.collide_point(x, y) == True:
  106.         #print "touch"
  107.         #print "touch auf turm in land ",turm.land
  108.         x = 0
  109.  
  110.    
  111.  
  112.    
  113. def in_rectangle(rx, ry, px, py, size_x, size_y):
  114.   if px <= rx + size_x and px >= rx and py <= ry + size_y and py >= ry:
  115.     return True
  116.   else:
  117.     #print str([rx, ry, px, py, size_x, size_y])
  118.     return False
  119.  
  120. if __name__ in ('__android__','__main__'):
  121.   conquest().run()
Advertisement
Add Comment
Please, Sign In to add comment