Skip to content
This repository was archived by the owner on Feb 22, 2020. It is now read-only.

Commit a875418

Browse files
Add example demo game screen
1 parent def1795 commit a875418

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

excellent-exorcists/src/screens/__init__.py

Whitespace-only changes.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from kivy.graphics.vertex_instructions import Rectangle
2+
from kivy.graphics import Color
3+
from kivy.uix.label import Label
4+
from src.core.screen import Screen
5+
6+
import random
7+
8+
9+
class GameScreen(Screen):
10+
def __init__(self, **kwargs):
11+
super().__init__(**kwargs)
12+
13+
self.fps = 0
14+
self.positions = [(random.randint(0, 600), random.randint(0, 300)) for _ in range(100)]
15+
16+
def on_resize(self, width: int, height: int):
17+
pass
18+
19+
def render(self, delta: float):
20+
self.clear()
21+
Color(1., 1., 0)
22+
23+
for pos in self.positions:
24+
Rectangle(pos=pos, size=(50, 50))
25+
26+
Color(0, 1, 0)
27+
Label(text=f'FPS: {self.fps}')
28+
29+
def update(self, delta: float):
30+
speed = 10
31+
self.fps = round(1 / delta)
32+
33+
for i in range(len(self.positions)):
34+
x, y = self.positions[i]
35+
self.positions[i] = (x + speed * delta, y + speed * delta)

0 commit comments

Comments
 (0)