diff --git a/images/player.png b/assets/images/player.png similarity index 100% rename from images/player.png rename to assets/images/player.png diff --git a/assets/sounds/151390__reinsamba__nightingale-brook-mix.wav b/assets/sounds/151390__reinsamba__nightingale-brook-mix.wav new file mode 100644 index 0000000..ed38e47 Binary files /dev/null and b/assets/sounds/151390__reinsamba__nightingale-brook-mix.wav differ diff --git a/assets/sounds/402733__samwd__kingston-ny-late-summer-midnight-crickets-with-distant-train.wav b/assets/sounds/402733__samwd__kingston-ny-late-summer-midnight-crickets-with-distant-train.wav new file mode 100644 index 0000000..f9e558d Binary files /dev/null and b/assets/sounds/402733__samwd__kingston-ny-late-summer-midnight-crickets-with-distant-train.wav differ diff --git a/assets/sounds/ambience1.mp3 b/assets/sounds/ambience1.mp3 new file mode 100644 index 0000000..95aef91 Binary files /dev/null and b/assets/sounds/ambience1.mp3 differ diff --git a/main.kv b/main.kv new file mode 100644 index 0000000..9ce64ef --- /dev/null +++ b/main.kv @@ -0,0 +1,10 @@ +#: import sm kivy.uix.screenmanager +: + transition: sm.FadeTransition() + MainScreen: + AboutScreen: + +: + + +: \ No newline at end of file diff --git a/main.py b/main.py index 1ac8592..bb687a4 100644 --- a/main.py +++ b/main.py @@ -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): + 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): diff --git a/music.kv b/music.kv new file mode 100644 index 0000000..3187e51 --- /dev/null +++ b/music.kv @@ -0,0 +1,11 @@ +#:kivy 1.11.1 + +: + + Button: + bold:True + size_hint:.8,.3 + text:'Play Music' + background_color:0,1,1,1 + pos_hint: {'right':1, 'y':0} + \ No newline at end of file diff --git a/music.py b/music.py new file mode 100644 index 0000000..d852ad4 --- /dev/null +++ b/music.py @@ -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()