Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #### kivy imports
- import kivy
- from kivy.app import App
- from kivy.uix.floatlayout import FloatLayout
- from kivy.uix.button import Button
- from kivy.uix.gridlayout import GridLayout
- from kivy.uix.modalview import ModalView
- from kivy.uix.scatter import Scatter
- from kivy.uix.image import *
- from kivy.graphics import Color, Ellipse
- from kivy.uix.widget import Widget
- from kivy.uix.label import Label
- from kivy.uix.image import Image
- from kivy.base import EventLoop
- ### third party imports
- import sqlite3
- conn = sqlite3.connect("conquest.db")
- TURM_X = 20
- TURM_Y = 20
- class Turm(Image):
- def __init__(self, pos1, pos2, land):
- self.land = land
- self.pos1 = pos1
- self.pos2 = pos2
- return Image.__init__(self, source='turm.png', pos=(pos1,pos2), size=(TURM_X, TURM_Y))
- class conquest(App):
- def build(self):
- EventLoop.ensure_window()
- self.root = GridLayout(cols=2)
- new_game_btn = Button(text='New Game')
- self.root.add_widget(new_game_btn)
- new_game_btn.bind(on_press=self.new_game)
- continue_btn = Button(text='Continue')
- self.root.add_widget(continue_btn)
- continue_btn.bind(on_press=self.init_ingame)
- return self.root
- def new_game(self, instance):
- pass
- # prepares ingame widgets
- def init_ingame(self, instance):
- self.root.clear_widgets()
- layout = Scatter(do_rotation=False)
- floating = FloatLayout()
- map_image = Image(source='map.jpg', size=(800,1000))
- floating.add_widget(map_image)
- #self.root.bind(on_touch_down=self.on_touch_down)
- self.laender = {"Noerdliche Oednis" : (600,600), "Rohan" : (400,400)}
- tuerme = []
- for name,pos in self.laender.items():
- element = Turm(pos[0], pos[1], name)
- tuerme.append(element)
- floating.add_widget(tuerme[-1])
- self.tuerme = tuerme
- layout.add_widget(floating)
- #navigation = Label(text='Conquest')
- #self.root.add_widget(navigation)
- self.root.add_widget(layout)
- def on_touch_down(self, obj, touch):
- #binded to on_touch_down event of the root Grid layout
- obj = obj.children[0]
- #print obj
- #print touch.x, touch.y
- (x,y) = obj.to_local(touch.x, touch.y)
- #print x,y
- for turm in self.tuerme:
- if turm.collide_point(x, y) == True:
- #print "touch"
- #print "touch auf turm in land ",turm.land
- x = 0
- def in_rectangle(rx, ry, px, py, size_x, size_y):
- if px <= rx + size_x and px >= rx and py <= ry + size_y and py >= ry:
- return True
- else:
- #print str([rx, ry, px, py, size_x, size_y])
- return False
- if __name__ in ('__android__','__main__'):
- conquest().run()
Advertisement
Add Comment
Please, Sign In to add comment