Guest User

Untitled

a guest
Apr 23rd, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.73 KB | None | 0 0
  1. class Level1(Screen):
  2. posx = NumericProperty(0)
  3. posy = NumericProperty(0)
  4. moving = True
  5. i = 0
  6. def __init__(self, **kwargs):
  7. super(Level1, self).__init__(**kwargs)
  8.  
  9. def rightmove(self):
  10. self.posx = self.posx+1
  11. time.sleep(10)
  12.  
  13. def goright(self):
  14. while self.moving == True:
  15. self.rightmove()
  16. i += 1
  17. if i == 10:
  18. break
  19.  
  20.  
  21. def stopright(self):
  22. self.moving == False
  23.  
  24. from kivy.app import App
  25. from kivy.lang import Builder
  26. from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition, SlideTransition
  27. from kivy.config import Config
  28. from kivy.core.window import Window
  29. from kivy.uix.label import Label
  30. from kivy.uix.image import Image
  31. from kivy.uix.widget import Widget
  32. from kivy.properties import ObjectProperty, NumericProperty
  33. from kivy.clock import Clock
  34. from kivy.uix.floatlayout import FloatLayout
  35. import time
  36. Config.set('graphics','resizable',0) #don't make the app re-sizeable
  37. #Graphics fix
  38. #this fixes drawing issues on some phones
  39. Window.clearcolor = (0,0,0,1.)
  40.  
  41. language = "english"
  42. curr1msg = 1
  43.  
  44. class HomeScreen(Screen):
  45. pass
  46.  
  47. class OptionsScreen(Screen):
  48. pass
  49.  
  50. class GameScreen(Screen):
  51. pass
  52.  
  53. class LevelScreen(Screen):
  54. pass
  55.  
  56. class Level1intro(Screen):
  57. global language
  58. global curr1msg
  59. if language == "english" and curr1msg == 1:
  60. pName = "Pedro"
  61. msg1 = """Hello my friend!
  62. My name is Pedro and I have a problem. Will you help me?
  63. My spanish studens have a spanish test tomorrow, but I lost the exams!
  64. You are the only one who can help me!"""
  65. cont = "Press anywhere to continue..."
  66. elif language == "swedish" and curr1msg == 1:
  67. pName = "Pedro"
  68. msg1 = """Hejsan!
  69. Jag är Pedro och jag har ett problem. Kan du hjälpa mig?
  70. Mina spanska-elever har ett spanskaprov imorgon men jag har tappat bort proven!
  71. Du är den enda som kan hjälpa mig!"""
  72. cont = "Tryck på skärmen för att fortsätta..."
  73.  
  74. class Level1(Screen):
  75. posx = NumericProperty(0)
  76. posy = NumericProperty(0)
  77. moving = True
  78. i = 0
  79. def __init__(self, **kwargs):
  80. super(Level1, self).__init__(**kwargs)
  81.  
  82. def rightmove(self):
  83. self.posx = self.posx+1
  84. time.sleep(10)
  85.  
  86. def goright(self):
  87. while self.moving == True:
  88. self.rightmove()
  89. i += 1
  90. if i == 10:
  91. break
  92.  
  93.  
  94. def stopright(self):
  95. self.moving == False
  96.  
  97.  
  98. class ScreenManagement(ScreenManager):
  99. pass
  100.  
  101.  
  102. presentation = Builder.load_file("main.kv")
  103.  
  104. class MainApp(App):
  105. def build(self):
  106. return presentation
  107.  
  108. if __name__ == "__main__":
  109. MainApp().run()
  110.  
  111. #: import FadeTransition kivy.uix.screenmanager.FadeTransition
  112. #: import SlideTransition kivy.uix.screenmanager.SlideTransition
  113. ScreenManagement:
  114. transition: FadeTransition()
  115. HomeScreen:
  116. OptionsScreen:
  117. LevelScreen:
  118. Level1intro:
  119. Level1:
  120.  
  121. <HomeScreen>:
  122. name: 'home'
  123.  
  124. FloatLayout:
  125. canvas:
  126. Rectangle:
  127. source:"images/home_background.jpg"
  128. size: self.size
  129. Image:
  130. source:"images/logo.png"
  131. allow_stretch: False
  132. keep_ratio: False
  133. opacity: 1.0
  134. size_hint: 0.7, 0.8
  135. pos_hint: {'center_x': 0.5, 'center_y': 0.9}
  136. Button:
  137. size_hint: 0.32,0.32
  138. pos_hint: {"x":0.34, "y":0.4}
  139. on_press:
  140. app.root.transition = SlideTransition(direction="left")
  141. app.root.current = "level"
  142. background_normal: "images/play_button.png"
  143. allow_stretch: False
  144. Button:
  145. size_hint: 0.25,0.25
  146. pos_hint: {"x":0.38, "y":0.15}
  147. on_press:
  148. app.root.transition = SlideTransition(direction="left")
  149. app.root.current = 'options'
  150. background_normal: "images/settings_button.png"
  151.  
  152. <OptionsScreen>:
  153. name: 'options'
  154.  
  155. <LevelScreen>
  156. name: "level"
  157.  
  158. FloatLayout:
  159. canvas:
  160. Rectangle:
  161. source:"images/home_background.jpg"
  162. size: self.size
  163. Label:
  164. text: "[b]Choose Level[/b]"
  165. markup: 1
  166. font_size: 40
  167. color: 1,0.5,0,1
  168. pos: 0,250
  169. Button:
  170. size_hint: 0.1,0.1
  171. pos_hint: {"x": 0.1, "y": 0.8}
  172. on_press:
  173. app.root.current = "level1intro"
  174. Image:
  175. source:"images/level1.png"
  176. allow_stretch: True
  177. y: self.parent.y + self.parent.height - 70
  178. x: self.parent.x
  179. height: 80
  180. width: 80
  181.  
  182. Button:
  183. background_normal: "images/menu_button.png"
  184. pos_hint: {"x": 0.4, "y": 0}
  185. size_hint: 0.3,0.3
  186. pos_hint: {"x": 0.35}
  187. on_press:
  188. app.root.transition = SlideTransition(direction="right")
  189. app.root.current = "home"
  190.  
  191. <Level1intro>
  192. name: "level1intro"
  193.  
  194. canvas:
  195. Rectangle:
  196. source: "images/background.png"
  197. size: self.size
  198. Image:
  199. source: "images/dialog.png"
  200. pos_hint: {"y": -0.35}
  201. size_hint: 0.7,1.0
  202. Label:
  203. font_size: 20
  204. color: 1,1,1,1
  205. pos_hint: {"x": -0.385, "y": -0.285}
  206. text: root.pName
  207. Label:
  208. font_size: 15
  209. color: 1,1,1,1
  210. pos_hint: {"x": -0.15, "y": -0.4}
  211. text: root.msg1
  212. Label:
  213. font_size: 15
  214. color: 0.7,0.8,1,1
  215. pos_hint: {"x": 0.025, "y": -0.449}
  216. text: root.cont
  217. on_touch_down:
  218. app.root.transition = FadeTransition()
  219. app.root.current = "level1"
  220.  
  221. <Level1>
  222. name: "level1"
  223. canvas:
  224. Rectangle:
  225. source: "images/background.png"
  226. size: self.size
  227.  
  228. Button:
  229. text: ">"
  230. size_hint: 0.1,0.1
  231. pos_hint: {"x":0.9, "y":0.0}
  232. on_press:
  233. root.goright()
  234. on_release:
  235. root.stopright()
  236. Button:
  237. text: "<"
  238. size_hint: 0.1,0.1
  239. pos_hint: {"x": 0.0, "y": 0.0}
  240. on_press:
  241. root.posx = root.posx-1
  242.  
  243. Image:
  244. id: char
  245. source: "images/idle1.png"
  246. size: self.size
  247. pos: root.posx,root.posy
  248.  
  249. #!/usr/bin/env python3.5
  250. # -*- coding: utf-8 -*-
  251. from kivy.app import App
  252. from kivy.lang import Builder
  253. from kivy.uix.boxlayout import BoxLayout
  254. from kivy.uix.floatlayout import FloatLayout
  255. from kivy.clock import mainthread, Clock
  256.  
  257. gui = '''
  258. Root:
  259. orientation: 'vertical'
  260.  
  261. arena: arena
  262. control_button: control_button
  263.  
  264. Arena:
  265. id: arena
  266.  
  267. Button
  268. id: control_button
  269. size_hint_y: None
  270. height: dp(50)
  271. text: 'move'
  272.  
  273.  
  274. <Arena@FloatLayout>:
  275. player: player
  276.  
  277. Button:
  278. id: player
  279. pos: 150, 300
  280. text: 'elf warrior\nlevel 1'
  281. size_hint: None, None
  282. size: 100, 100
  283. '''
  284.  
  285.  
  286. class Root(BoxLayout):
  287.  
  288. def __init__(self, **kwargs):
  289. super().__init__(**kwargs)
  290.  
  291. @mainthread
  292. def job():
  293. self.control_button.bind(on_press=self._on_press)
  294. self.control_button.bind(on_release=self._on_release)
  295.  
  296. job()
  297.  
  298. def _on_press(self, button):
  299. self.arena.start_movement()
  300.  
  301. def _on_release(self, button):
  302. self.arena.stop_movement()
  303.  
  304.  
  305. class Arena(FloatLayout):
  306.  
  307. def start_movement(self):
  308. Clock.schedule_interval(self._move_right, 0.01)
  309.  
  310. def stop_movement(self):
  311. Clock.unschedule(self._move_right)
  312.  
  313. def _move_right(self, dt):
  314. self.player.x += 1
  315.  
  316.  
  317. class Test(App):
  318.  
  319. def build(self):
  320. return Builder.load_string(gui)
  321.  
  322.  
  323. Test().run()
Add Comment
Please, Sign In to add comment