add additional files to play with

This commit is contained in:
Daniel afx 2020-09-25 17:20:37 +03:00
parent a1c838d300
commit 5d10bd2e80
8 changed files with 102 additions and 2 deletions

View file

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

BIN
assets/sounds/ambience1.mp3 Normal file

Binary file not shown.

10
main.kv Normal file
View file

@ -0,0 +1,10 @@
#: import sm kivy.uix.screenmanager
<ScreenManagement>:
transition: sm.FadeTransition()
MainScreen:
AboutScreen:
<MainScreen>:
<AboutScreen>:

70
main.py
View file

@ -1,16 +1,84 @@
from random import randrange
from kivy.app import App
from kivy.clock import Clock
from kivy.core.window import Window
from kivy.uix.label import Label
from kivy.uix.widget import Widget
from kivy.graphics import Rectangle
def collides(rect1, rect2):
r1x = rect1[0][0]
r1y = rect1[0][1]
r2x = rect2[0][0]
r2y = rect2[0][1]
r1w = rect1[1][0]
r1h = rect1[1][1]
r2w = rect2[1][0]
r2h = rect2[1][1]
if (r1x < r2x + r2w and r1x + r1w > r2x and r1y < r2y + r2h and r1y + r1h > r2y):
return True
else:
return False
class GameWidget(Widget):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self._keyboard = Window.request_keyboard(self._on_keyboard_closed, self)
self._keyboard.bind(on_key_down=self._on_key_down)
self._keyboard.bind(on_key_up=self._on_key_up)
self.nearbyobj = []
#for obj in range(10):
with self.canvas:
Rectangle(source="images/player.png", pos=(0,0), size=(100,100))
self.player = Rectangle(source="assets/images/player.png", pos=(0,0), size=(100,100))
self.enemy = Rectangle(pos=(300,300), size=(80,80))
self.keysPressed = set()
Clock.schedule_interval(self.move_step,0)
def _on_keyboard_closed(self):
self._keyboard.unbind(on_key_down=self._on_key_down)
self._keyboard.unbind(on_key_up=self._on_key_up)
self._keyboard = None
def _on_key_down(self, keyboard, keycode, text, modifiers):
self.keysPressed.add(text)
def _on_key_up(self,keyboard,keycode):
text = keycode[1]
if text in self.keysPressed:
self.keysPressed.remove(text)
def move_step(self,dt):
currentx = self.player.pos[0]
currenty = self.player.pos[1]
step_size = 200 * dt
if "w" in self.keysPressed:
currenty += step_size
if "s" in self.keysPressed:
currenty -= step_size
if "a" in self.keysPressed:
currentx -= step_size
if "d" in self.keysPressed:
currentx += step_size
self.player.pos = (currentx, currenty)
if collides((self.player.pos,self.player.size),(self.enemy.pos,self.size)):
print("X")
else:
print('.')
class GlobalForest(App):
def build(self):

11
music.kv Normal file
View file

@ -0,0 +1,11 @@
#:kivy 1.11.1
<MyFloatLayout>:
Button:
bold:True
size_hint:.8,.3
text:'Play Music'
background_color:0,1,1,1
pos_hint: {'right':1, 'y':0}

11
music.py Normal file
View file

@ -0,0 +1,11 @@
from kivy.app import App
from kivy.core.audio import SoundLoader
from kivy.uix.floatlayout import FloatLayout
class MyFloatLayout(FloatLayout):
pass
class MusicWindows(App):
def build(self):
return MyFloatLayout()