first commit
This commit is contained in:
commit
417e54da96
5696 changed files with 900003 additions and 0 deletions
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 5.3 KiB |
163
kivy_venv/share/kivy-examples/tutorials/notes/final/main.py
Normal file
163
kivy_venv/share/kivy-examples/tutorials/notes/final/main.py
Normal file
|
@ -0,0 +1,163 @@
|
|||
'''
|
||||
Notes
|
||||
=====
|
||||
|
||||
Simple application for reading/writing notes.
|
||||
|
||||
'''
|
||||
|
||||
__version__ = '1.0'
|
||||
|
||||
import json
|
||||
from os.path import join, exists
|
||||
from kivy.app import App
|
||||
from kivy.uix.screenmanager import ScreenManager, Screen, SlideTransition
|
||||
from kivy.properties import ListProperty, StringProperty, \
|
||||
NumericProperty, BooleanProperty, AliasProperty
|
||||
from kivy.uix.boxlayout import BoxLayout
|
||||
from kivy.uix.floatlayout import FloatLayout
|
||||
from kivy.clock import Clock
|
||||
|
||||
|
||||
class MutableTextInput(FloatLayout):
|
||||
|
||||
text = StringProperty()
|
||||
multiline = BooleanProperty(True)
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super(MutableTextInput, self).__init__(**kwargs)
|
||||
Clock.schedule_once(self.prepare, 0)
|
||||
|
||||
def prepare(self, *args):
|
||||
self.w_textinput = self.ids.w_textinput.__self__
|
||||
self.w_label = self.ids.w_label.__self__
|
||||
self.view()
|
||||
|
||||
def on_touch_down(self, touch):
|
||||
if self.collide_point(*touch.pos) and touch.is_double_tap:
|
||||
self.edit()
|
||||
return super(MutableTextInput, self).on_touch_down(touch)
|
||||
|
||||
def edit(self):
|
||||
self.clear_widgets()
|
||||
self.add_widget(self.w_textinput)
|
||||
self.w_textinput.focus = True
|
||||
|
||||
def view(self):
|
||||
self.clear_widgets()
|
||||
if not self.text:
|
||||
self.w_label.text = "Double tap/click to edit"
|
||||
self.add_widget(self.w_label)
|
||||
|
||||
def check_focus_and_view(self, textinput):
|
||||
if not textinput.focus:
|
||||
self.text = textinput.text
|
||||
self.view()
|
||||
|
||||
|
||||
class NoteView(Screen):
|
||||
|
||||
note_index = NumericProperty()
|
||||
note_title = StringProperty()
|
||||
note_content = StringProperty()
|
||||
|
||||
|
||||
class NoteListItem(BoxLayout):
|
||||
note_content = StringProperty()
|
||||
note_title = StringProperty()
|
||||
note_index = NumericProperty()
|
||||
|
||||
|
||||
class Notes(Screen):
|
||||
|
||||
data = ListProperty()
|
||||
|
||||
def _get_data_for_widgets(self):
|
||||
return [{
|
||||
'note_index': index,
|
||||
'note_content': item['content'],
|
||||
'note_title': item['title']}
|
||||
for index, item in enumerate(self.data)]
|
||||
|
||||
data_for_widgets = AliasProperty(_get_data_for_widgets, bind=['data'])
|
||||
|
||||
|
||||
class NoteApp(App):
|
||||
|
||||
def build(self):
|
||||
self.notes = Notes(name='notes')
|
||||
self.load_notes()
|
||||
|
||||
self.transition = SlideTransition(duration=.35)
|
||||
root = ScreenManager(transition=self.transition)
|
||||
root.add_widget(self.notes)
|
||||
return root
|
||||
|
||||
def load_notes(self):
|
||||
if not exists(self.notes_fn):
|
||||
return
|
||||
with open(self.notes_fn) as fd:
|
||||
data = json.load(fd)
|
||||
self.notes.data = data
|
||||
|
||||
def save_notes(self):
|
||||
with open(self.notes_fn, 'w') as fd:
|
||||
json.dump(self.notes.data, fd)
|
||||
|
||||
def del_note(self, note_index):
|
||||
del self.notes.data[note_index]
|
||||
self.save_notes()
|
||||
self.refresh_notes()
|
||||
self.go_notes()
|
||||
|
||||
def edit_note(self, note_index):
|
||||
note = self.notes.data[note_index]
|
||||
name = 'note{}'.format(note_index)
|
||||
|
||||
if self.root.has_screen(name):
|
||||
self.root.remove_widget(self.root.get_screen(name))
|
||||
|
||||
view = NoteView(
|
||||
name=name,
|
||||
note_index=note_index,
|
||||
note_title=note.get('title'),
|
||||
note_content=note.get('content'))
|
||||
|
||||
self.root.add_widget(view)
|
||||
self.transition.direction = 'left'
|
||||
self.root.current = view.name
|
||||
|
||||
def add_note(self):
|
||||
self.notes.data.append({'title': 'New note', 'content': ''})
|
||||
note_index = len(self.notes.data) - 1
|
||||
self.edit_note(note_index)
|
||||
|
||||
def set_note_content(self, note_index, note_content):
|
||||
self.notes.data[note_index]['content'] = note_content
|
||||
data = self.notes.data
|
||||
self.notes.data = []
|
||||
self.notes.data = data
|
||||
self.save_notes()
|
||||
self.refresh_notes()
|
||||
|
||||
def set_note_title(self, note_index, note_title):
|
||||
self.notes.data[note_index]['title'] = note_title
|
||||
self.save_notes()
|
||||
self.refresh_notes()
|
||||
|
||||
def refresh_notes(self):
|
||||
data = self.notes.data
|
||||
self.notes.data = []
|
||||
self.notes.data = data
|
||||
|
||||
def go_notes(self):
|
||||
self.transition.direction = 'right'
|
||||
self.root.current = 'notes'
|
||||
|
||||
@property
|
||||
def notes_fn(self):
|
||||
return join(self.user_data_dir, 'notes.json')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
NoteApp().run()
|
154
kivy_venv/share/kivy-examples/tutorials/notes/final/note.kv
Normal file
154
kivy_venv/share/kivy-examples/tutorials/notes/final/note.kv
Normal file
|
@ -0,0 +1,154 @@
|
|||
#:kivy 1.7.1
|
||||
#:import Factory kivy.factory.Factory
|
||||
|
||||
<Screen>:
|
||||
canvas:
|
||||
Color:
|
||||
rgb: .2, .2, .2
|
||||
Rectangle:
|
||||
size: self.size
|
||||
|
||||
<MutableLabelTextInput@MutableTextInput>:
|
||||
Label:
|
||||
id: w_label
|
||||
pos: root.pos
|
||||
text: root.text
|
||||
|
||||
TextInput:
|
||||
id: w_textinput
|
||||
pos: root.pos
|
||||
text: root.text
|
||||
multiline: root.multiline
|
||||
on_focus: root.check_focus_and_view(self)
|
||||
|
||||
<MutableRstDocumentTextInput@MutableTextInput>:
|
||||
RstDocument:
|
||||
id: w_label
|
||||
pos: root.pos
|
||||
text: root.text
|
||||
|
||||
TextInput:
|
||||
id: w_textinput
|
||||
pos: root.pos
|
||||
text: root.text
|
||||
multiline: root.multiline
|
||||
on_focus: root.check_focus_and_view(self)
|
||||
|
||||
|
||||
<NoteView>:
|
||||
|
||||
on_note_content: app.set_note_content(self.note_index, self.note_content)
|
||||
on_note_title: app.set_note_title(self.note_index, self.note_title)
|
||||
|
||||
BoxLayout:
|
||||
|
||||
orientation: 'vertical'
|
||||
|
||||
BoxLayout:
|
||||
|
||||
orientation: 'horizontal'
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
padding: '5dp'
|
||||
|
||||
canvas:
|
||||
Color:
|
||||
rgb: .3, .3, .3
|
||||
Rectangle:
|
||||
pos: self.pos
|
||||
size: self.size
|
||||
|
||||
Button:
|
||||
text: '<'
|
||||
size_hint_x: None
|
||||
width: self.height
|
||||
on_release: app.go_notes()
|
||||
|
||||
MutableLabelTextInput:
|
||||
text: root.note_title
|
||||
font_size: '16sp'
|
||||
multiline: False
|
||||
on_text: root.note_title = self.text
|
||||
|
||||
Button:
|
||||
text: 'X'
|
||||
size_hint_x: None
|
||||
width: self.height
|
||||
on_release: app.del_note(root.note_index)
|
||||
|
||||
|
||||
MutableRstDocumentTextInput:
|
||||
text: root.note_content
|
||||
on_text: root.note_content = self.text
|
||||
|
||||
<NoteListItem>:
|
||||
|
||||
height: '48sp'
|
||||
size_hint_y: None
|
||||
|
||||
canvas:
|
||||
Color:
|
||||
rgb: .3, .3, .3
|
||||
Rectangle:
|
||||
pos: self.pos
|
||||
size: self.width, 1
|
||||
|
||||
BoxLayout:
|
||||
|
||||
padding: '5dp'
|
||||
|
||||
Label:
|
||||
text: root.note_title
|
||||
|
||||
Button:
|
||||
text: '>'
|
||||
size_hint_x: None
|
||||
width: self.height
|
||||
on_release: app.edit_note(root.note_index)
|
||||
|
||||
<Notes>:
|
||||
|
||||
BoxLayout:
|
||||
|
||||
orientation: 'vertical'
|
||||
|
||||
BoxLayout:
|
||||
|
||||
orientation: 'horizontal'
|
||||
size_hint_y: None
|
||||
height: '48dp'
|
||||
padding: '5dp'
|
||||
|
||||
canvas:
|
||||
Color:
|
||||
rgb: .3, .3, .3
|
||||
Rectangle:
|
||||
pos: self.pos
|
||||
size: self.size
|
||||
|
||||
Image:
|
||||
source: 'data/icon.png'
|
||||
mipmap: True
|
||||
size_hint_x: None
|
||||
width: self.height
|
||||
|
||||
Label:
|
||||
text: 'Notes'
|
||||
font_size: '16sp'
|
||||
|
||||
Button:
|
||||
text: '+'
|
||||
size_hint_x: None
|
||||
width: self.height
|
||||
on_release: app.add_note()
|
||||
|
||||
RecycleView:
|
||||
data: root.data_for_widgets
|
||||
viewclass: 'NoteListItem'
|
||||
RecycleBoxLayout:
|
||||
default_size: None, dp(56)
|
||||
default_size_hint: 1, None
|
||||
size_hint_y: None
|
||||
height: self.minimum_height
|
||||
orientation: 'vertical'
|
||||
spacing: dp(2)
|
Binary file not shown.
82
kivy_venv/share/kivy-examples/tutorials/pong/main.py
Normal file
82
kivy_venv/share/kivy-examples/tutorials/pong/main.py
Normal file
|
@ -0,0 +1,82 @@
|
|||
import kivy
|
||||
kivy.require('1.1.1')
|
||||
|
||||
from kivy.app import App
|
||||
from kivy.uix.widget import Widget
|
||||
from kivy.properties import (
|
||||
NumericProperty, ReferenceListProperty, ObjectProperty, BooleanProperty
|
||||
)
|
||||
from kivy.vector import Vector
|
||||
from kivy.clock import Clock
|
||||
|
||||
|
||||
class PongPaddle(Widget):
|
||||
score = NumericProperty(0)
|
||||
can_bounce = BooleanProperty(True)
|
||||
|
||||
def bounce_ball(self, ball):
|
||||
if self.collide_widget(ball) and self.can_bounce:
|
||||
vx, vy = ball.velocity
|
||||
offset = (ball.center_y - self.center_y) / (self.height / 2)
|
||||
bounced = Vector(-1 * vx, vy)
|
||||
vel = bounced * 1.1
|
||||
ball.velocity = vel.x, vel.y + offset
|
||||
self.can_bounce = False
|
||||
elif not self.collide_widget(ball) and not self.can_bounce:
|
||||
self.can_bounce = True
|
||||
|
||||
|
||||
class PongBall(Widget):
|
||||
velocity_x = NumericProperty(0)
|
||||
velocity_y = NumericProperty(0)
|
||||
velocity = ReferenceListProperty(velocity_x, velocity_y)
|
||||
|
||||
def move(self):
|
||||
self.pos = Vector(*self.velocity) + self.pos
|
||||
|
||||
|
||||
class PongGame(Widget):
|
||||
ball = ObjectProperty(None)
|
||||
player1 = ObjectProperty(None)
|
||||
player2 = ObjectProperty(None)
|
||||
|
||||
def serve_ball(self, vel=(4, 0)):
|
||||
self.ball.center = self.center
|
||||
self.ball.velocity = vel
|
||||
|
||||
def update(self, dt):
|
||||
self.ball.move()
|
||||
|
||||
# bounce ball off paddles
|
||||
self.player1.bounce_ball(self.ball)
|
||||
self.player2.bounce_ball(self.ball)
|
||||
|
||||
# bounce ball off bottom or top
|
||||
if (self.ball.y < self.y) or (self.ball.top > self.top):
|
||||
self.ball.velocity_y *= -1
|
||||
|
||||
# went off a side to score point?
|
||||
if self.ball.x < self.x:
|
||||
self.player2.score += 1
|
||||
self.serve_ball(vel=(4, 0))
|
||||
if self.ball.right > self.width:
|
||||
self.player1.score += 1
|
||||
self.serve_ball(vel=(-4, 0))
|
||||
|
||||
def on_touch_move(self, touch):
|
||||
if touch.x < self.width / 3:
|
||||
self.player1.center_y = touch.y
|
||||
if touch.x > self.width - self.width / 3:
|
||||
self.player2.center_y = touch.y
|
||||
|
||||
|
||||
class PongApp(App):
|
||||
def build(self):
|
||||
game = PongGame()
|
||||
game.serve_ball()
|
||||
Clock.schedule_interval(game.update, 1.0 / 60.0)
|
||||
return game
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
PongApp().run()
|
53
kivy_venv/share/kivy-examples/tutorials/pong/pong.kv
Normal file
53
kivy_venv/share/kivy-examples/tutorials/pong/pong.kv
Normal file
|
@ -0,0 +1,53 @@
|
|||
#:kivy 1.0.9
|
||||
|
||||
<PongBall>:
|
||||
size: 50, 50
|
||||
canvas:
|
||||
Ellipse:
|
||||
pos: self.pos
|
||||
size: self.size
|
||||
|
||||
<PongPaddle>:
|
||||
size: 25, 200
|
||||
canvas:
|
||||
Rectangle:
|
||||
pos:self.pos
|
||||
size:self.size
|
||||
|
||||
<PongGame>:
|
||||
ball: pong_ball
|
||||
player1: player_left
|
||||
player2: player_right
|
||||
|
||||
canvas:
|
||||
Rectangle:
|
||||
pos: self.center_x - 5, 0
|
||||
size: 10, self.height
|
||||
|
||||
Label:
|
||||
font_size: 70
|
||||
center_x: root.width / 4
|
||||
top: root.top - 50
|
||||
text: str(root.player1.score)
|
||||
|
||||
Label:
|
||||
font_size: 70
|
||||
center_x: root.width * 3 / 4
|
||||
top: root.top - 50
|
||||
text: str(root.player2.score)
|
||||
|
||||
PongBall:
|
||||
id: pong_ball
|
||||
center: self.parent.center
|
||||
|
||||
PongPaddle:
|
||||
id: player_left
|
||||
x: root.x
|
||||
center_y: root.center_y
|
||||
|
||||
PongPaddle:
|
||||
id: player_right
|
||||
x: root.width - self.width
|
||||
center_y: root.center_y
|
||||
|
||||
|
Binary file not shown.
|
@ -0,0 +1,15 @@
|
|||
from kivy.app import App
|
||||
from kivy.uix.widget import Widget
|
||||
|
||||
|
||||
class PongGame(Widget):
|
||||
pass
|
||||
|
||||
|
||||
class PongApp(App):
|
||||
def build(self):
|
||||
return PongGame()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
PongApp().run()
|
|
@ -0,0 +1,2 @@
|
|||
#:kivy 1.0.9
|
||||
|
Binary file not shown.
|
@ -0,0 +1,15 @@
|
|||
from kivy.app import App
|
||||
from kivy.uix.widget import Widget
|
||||
|
||||
|
||||
class PongGame(Widget):
|
||||
pass
|
||||
|
||||
|
||||
class PongApp(App):
|
||||
def build(self):
|
||||
return PongGame()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
PongApp().run()
|
|
@ -0,0 +1,21 @@
|
|||
#:kivy 1.0.9
|
||||
|
||||
<PongGame>:
|
||||
canvas:
|
||||
Rectangle:
|
||||
pos: self.center_x - 5, 0
|
||||
size: 10, self.height
|
||||
|
||||
Label:
|
||||
font_size: 70
|
||||
center_x: root.width / 4
|
||||
top: root.top - 50
|
||||
text: "0"
|
||||
|
||||
Label:
|
||||
font_size: 70
|
||||
center_x: root.width * 3 / 4
|
||||
top: root.top - 50
|
||||
text: "0"
|
||||
|
||||
|
Binary file not shown.
|
@ -0,0 +1,26 @@
|
|||
from kivy.app import App
|
||||
from kivy.uix.widget import Widget
|
||||
from kivy.properties import NumericProperty, ReferenceListProperty
|
||||
from kivy.vector import Vector
|
||||
|
||||
|
||||
class PongBall(Widget):
|
||||
velocity_x = NumericProperty(0)
|
||||
velocity_y = NumericProperty(0)
|
||||
velocity = ReferenceListProperty(velocity_x, velocity_y)
|
||||
|
||||
def move(self):
|
||||
self.pos = Vector(*self.velocity) + self.pos
|
||||
|
||||
|
||||
class PongGame(Widget):
|
||||
pass
|
||||
|
||||
|
||||
class PongApp(App):
|
||||
def build(self):
|
||||
return PongGame()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
PongApp().run()
|
|
@ -0,0 +1,31 @@
|
|||
#:kivy 1.0.9
|
||||
|
||||
<PongBall>:
|
||||
size: 50, 50
|
||||
canvas:
|
||||
Ellipse:
|
||||
pos: self.pos
|
||||
size: self.size
|
||||
|
||||
<PongGame>:
|
||||
canvas:
|
||||
Rectangle:
|
||||
pos: self.center_x - 5, 0
|
||||
size: 10, self.height
|
||||
|
||||
Label:
|
||||
font_size: 70
|
||||
center_x: root.width / 4
|
||||
top: root.top - 50
|
||||
text: "0"
|
||||
|
||||
Label:
|
||||
font_size: 70
|
||||
center_x: root.width * 3 / 4
|
||||
top: root.top - 50
|
||||
text: "0"
|
||||
|
||||
PongBall:
|
||||
center: self.parent.center
|
||||
|
||||
|
Binary file not shown.
|
@ -0,0 +1,48 @@
|
|||
from kivy.app import App
|
||||
from kivy.uix.widget import Widget
|
||||
from kivy.properties import (
|
||||
NumericProperty, ReferenceListProperty, ObjectProperty
|
||||
)
|
||||
from kivy.vector import Vector
|
||||
from kivy.clock import Clock
|
||||
from random import randint
|
||||
|
||||
|
||||
class PongBall(Widget):
|
||||
velocity_x = NumericProperty(0)
|
||||
velocity_y = NumericProperty(0)
|
||||
velocity = ReferenceListProperty(velocity_x, velocity_y)
|
||||
|
||||
def move(self):
|
||||
self.pos = Vector(*self.velocity) + self.pos
|
||||
|
||||
|
||||
class PongGame(Widget):
|
||||
ball = ObjectProperty(None)
|
||||
|
||||
def serve_ball(self):
|
||||
self.ball.center = self.center
|
||||
self.ball.velocity = Vector(4, 0).rotate(randint(0, 360))
|
||||
|
||||
def update(self, dt):
|
||||
self.ball.move()
|
||||
|
||||
# bounce off top and bottom
|
||||
if (self.ball.y < 0) or (self.ball.top > self.height):
|
||||
self.ball.velocity_y *= -1
|
||||
|
||||
# bounce off left and right
|
||||
if (self.ball.x < 0) or (self.ball.right > self.width):
|
||||
self.ball.velocity_x *= -1
|
||||
|
||||
|
||||
class PongApp(App):
|
||||
def build(self):
|
||||
game = PongGame()
|
||||
game.serve_ball()
|
||||
Clock.schedule_interval(game.update, 1.0 / 60.0)
|
||||
return game
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
PongApp().run()
|
|
@ -0,0 +1,34 @@
|
|||
#:kivy 1.0.9
|
||||
|
||||
<PongBall>:
|
||||
size: 50, 50
|
||||
canvas:
|
||||
Ellipse:
|
||||
pos: self.pos
|
||||
size: self.size
|
||||
|
||||
<PongGame>:
|
||||
ball: pong_ball
|
||||
|
||||
canvas:
|
||||
Rectangle:
|
||||
pos: self.center_x - 5, 0
|
||||
size: 10, self.height
|
||||
|
||||
Label:
|
||||
font_size: 70
|
||||
center_x: root.width / 4
|
||||
top: root.top - 50
|
||||
text: "0"
|
||||
|
||||
Label:
|
||||
font_size: 70
|
||||
center_x: root.width * 3 / 4
|
||||
top: root.top - 50
|
||||
text: "0"
|
||||
|
||||
PongBall:
|
||||
id: pong_ball
|
||||
center: self.parent.center
|
||||
|
||||
|
Binary file not shown.
|
@ -0,0 +1,75 @@
|
|||
from kivy.app import App
|
||||
from kivy.uix.widget import Widget
|
||||
from kivy.properties import (
|
||||
NumericProperty, ReferenceListProperty, ObjectProperty
|
||||
)
|
||||
from kivy.vector import Vector
|
||||
from kivy.clock import Clock
|
||||
|
||||
|
||||
class PongPaddle(Widget):
|
||||
score = NumericProperty(0)
|
||||
|
||||
def bounce_ball(self, ball):
|
||||
if self.collide_widget(ball):
|
||||
vx, vy = ball.velocity
|
||||
offset = (ball.center_y - self.center_y) / (self.height / 2)
|
||||
bounced = Vector(-1 * vx, vy)
|
||||
vel = bounced * 1.1
|
||||
ball.velocity = vel.x, vel.y + offset
|
||||
|
||||
|
||||
class PongBall(Widget):
|
||||
velocity_x = NumericProperty(0)
|
||||
velocity_y = NumericProperty(0)
|
||||
velocity = ReferenceListProperty(velocity_x, velocity_y)
|
||||
|
||||
def move(self):
|
||||
self.pos = Vector(*self.velocity) + self.pos
|
||||
|
||||
|
||||
class PongGame(Widget):
|
||||
ball = ObjectProperty(None)
|
||||
player1 = ObjectProperty(None)
|
||||
player2 = ObjectProperty(None)
|
||||
|
||||
def serve_ball(self, vel=(4, 0)):
|
||||
self.ball.center = self.center
|
||||
self.ball.velocity = vel
|
||||
|
||||
def update(self, dt):
|
||||
self.ball.move()
|
||||
|
||||
# bounce off paddles
|
||||
self.player1.bounce_ball(self.ball)
|
||||
self.player2.bounce_ball(self.ball)
|
||||
|
||||
# bounce ball off bottom or top
|
||||
if (self.ball.y < self.y) or (self.ball.top > self.top):
|
||||
self.ball.velocity_y *= -1
|
||||
|
||||
# went off to a side to score point?
|
||||
if self.ball.x < self.x:
|
||||
self.player2.score += 1
|
||||
self.serve_ball(vel=(4, 0))
|
||||
if self.ball.right > self.width:
|
||||
self.player1.score += 1
|
||||
self.serve_ball(vel=(-4, 0))
|
||||
|
||||
def on_touch_move(self, touch):
|
||||
if touch.x < self.width / 3:
|
||||
self.player1.center_y = touch.y
|
||||
if touch.x > self.width - self.width / 3:
|
||||
self.player2.center_y = touch.y
|
||||
|
||||
|
||||
class PongApp(App):
|
||||
def build(self):
|
||||
game = PongGame()
|
||||
game.serve_ball()
|
||||
Clock.schedule_interval(game.update, 1.0 / 60.0)
|
||||
return game
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
PongApp().run()
|
|
@ -0,0 +1,53 @@
|
|||
#:kivy 1.0.9
|
||||
|
||||
<PongBall>:
|
||||
size: 50, 50
|
||||
canvas:
|
||||
Ellipse:
|
||||
pos: self.pos
|
||||
size: self.size
|
||||
|
||||
<PongPaddle>:
|
||||
size: 25, 200
|
||||
canvas:
|
||||
Rectangle:
|
||||
pos: self.pos
|
||||
size: self.size
|
||||
|
||||
<PongGame>:
|
||||
ball: pong_ball
|
||||
player1: player_left
|
||||
player2: player_right
|
||||
|
||||
canvas:
|
||||
Rectangle:
|
||||
pos: self.center_x - 5, 0
|
||||
size: 10, self.height
|
||||
|
||||
Label:
|
||||
font_size: 70
|
||||
center_x: root.width / 4
|
||||
top: root.top - 50
|
||||
text: str(root.player1.score)
|
||||
|
||||
Label:
|
||||
font_size: 70
|
||||
center_x: root.width * 3 / 4
|
||||
top: root.top - 50
|
||||
text: str(root.player2.score)
|
||||
|
||||
PongBall:
|
||||
id: pong_ball
|
||||
center: self.parent.center
|
||||
|
||||
PongPaddle:
|
||||
id: player_left
|
||||
x: root.x
|
||||
center_y: root.center_y
|
||||
|
||||
PongPaddle:
|
||||
id: player_right
|
||||
x: root.width - self.width
|
||||
center_y: root.center_y
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue