Created
November 11, 2014 12:24
-
-
Save Exodus111/021675244a083a47c143 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.config import Config | |
xwidth, xheight = 1024, 960 | |
Config.set("graphics", "width", xwidth) | |
Config.set("graphics", "height", xheight) | |
Config.write() | |
from kivy.app import App | |
from kivy.core.window import Window | |
from kivy.uix.widget import Widget | |
from kivy.properties import NumericProperty, ObjectProperty | |
from kivy.vector import Vector | |
from kivy.clock import Clock | |
class MyKeyboardListener(Widget): | |
def __init__(self, **kwargs): | |
super(MyKeyboardListener, self).__init__() | |
self._keyboard = Window.request_keyboard(self._keyboard_closed,"text") | |
self._keyboard.bind(on_key_down=self._on_keyboard_down) | |
self._keyboard.bind(on_key_up=self._on_keyboard_up) | |
self.keyup = None | |
self.keydown = None | |
def _keyboard_closed(self): | |
print "Keyboard Closed" | |
self._keyboard.unbind(on_key_down=self._on_keyboard_down) | |
self._keyboard = None | |
def _on_keyboard_down(self, keyboard, keycode, text, modifiers): | |
if keycode[1] == "escape": | |
keyboard.release() | |
self.keydown = text | |
def _on_keyboard_up(self, keyboard, keycode): | |
pass | |
class MyPlayer(Widget): | |
pos = [450, 300] | |
def move(self, key): | |
if key == "w": | |
self.pos[1] += 5 | |
print self.pos | |
class MyGame(Widget): | |
player = ObjectProperty(None) | |
keyboard = ObjectProperty(None) | |
def __init__(self): | |
super(MyGame, self).__init__() | |
self.delta = 0.0 | |
def update(self, dt): | |
self.player.move(self.keyboard.keydown) | |
class MyApp(App): | |
def build(self): | |
game = MyGame() | |
Clock.schedule_interval(game.update, 1.0/60.0) | |
return game | |
MyApp().run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#:kivy 1.7.2 | |
<MyPlayer> | |
size: 20, 20 | |
canvas: | |
Color: | |
rgba: 1, 0, 0, 1 | |
Rectangle: | |
pos: self.pos | |
size: self.size | |
<MyGame> | |
player: player | |
keyboard: keyboard | |
MyPlayer: | |
id: player | |
MyKeyboardListener: | |
id: keyboard |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment