Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
934 B
1
Indexable
Never
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.graphics import Rectangle
from kivy.core.window import Window

class Player(Widget):
    def __init__(self, **kwargs):
        super(Player, self).__init__(**kwargs)
        self.size = (50, 50)
        self.pos = (Window.width / 2 - self.width / 2, Window.height / 2 - self.height / 2)

    def move(self, dx, dy):
        self.pos = (self.x + dx, self.y + dy)

class Game(Widget):
    def __init__(self, **kwargs):
        super(Game, self).__init__(**kwargs)
        self.player = Player()
        self.add_widget(self.player)

    def on_touch_down(self, touch):
        if touch.x < self.width / 2:
            self.player.move(-5, 0)
        else:
            self.player.move(5, 0)

class AdventureApp(App):
    def build(self):
        game = Game()
        Window.size = (800, 600)
        return game

if __name__ == '__main__':
    AdventureApp().run()
Leave a Comment