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

Commit c960e95

Browse files
authored
Merge pull request #5 from Leterax/background
Background images and animation
2 parents 15f1e5f + 69fd790 commit c960e95

File tree

12 files changed

+163
-0
lines changed

12 files changed

+163
-0
lines changed
Loading
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#:import FadeTransition kivy.uix.screenmanager.FadeTransition
2+
3+
4+
<Dino>:
5+
canvas:
6+
Rectangle:
7+
source: "dino.png"
8+
size: 750, 600
9+
pos: self.pos
10+
11+
<RootScreen>:
12+
dino: dino
13+
14+
transition: FadeTransition()
15+
16+
StartScreen:
17+
name: "start"
18+
FloatLayout:
19+
Image:
20+
size_hint: 1, 1
21+
pos_hint: {"center_x": 0.5, "center_y": 0.5}
22+
keep_ratio: False
23+
allow_stretch: True
24+
canvas.before:
25+
Color:
26+
rgb: 0,0,0
27+
Rectangle:
28+
size: self.size
29+
pos: self.pos
30+
source: 'ui_background_half.png'
31+
Button:
32+
text: "PLAY!"
33+
color: 0, 0, 0, 1
34+
size_hint: 0.3, 0.1
35+
pos_hint: {'center_x':0.5, 'center_y':0.6}
36+
font_size: 50
37+
on_release: root.current = "game"
38+
background_normal: 'ui_box_medium.png'
39+
Button:
40+
text: "OPTION!"
41+
color: 0, 0, 0, 1
42+
size_hint: 0.3, 0.1
43+
pos_hint: {'center_x':.5, 'center_y':.48}
44+
font_size: 50
45+
on_release: root.current = "game"
46+
background_normal: 'ui_box_medium.png'
47+
48+
GameScreen:
49+
name: "game"
50+
FloatLayout:
51+
Image:
52+
size_hint: 1, 1
53+
keep_ratio: False
54+
allow_stretch: True
55+
canvas.before:
56+
Color:
57+
rgb: 1,1,1
58+
Rectangle:
59+
size: self.size
60+
pos: self.pos
61+
source: 'background.png'
62+
Dino:
63+
id: dino
64+
pos: -100 , -205
65+
Image:
66+
source: "mountains_2.png"
67+
pos_hint: {'center_x': 0.5, 'center_y': 0.4}
68+
keep_ratio: False
69+
allow_stretch: True
70+
size_hint: 1, 0.7
71+
Image:
72+
size_hint: 1.2, 0.6
73+
pos_hint: {'x': 0, 'y': 0}
74+
keep_ratio: False
75+
allow_stretch: True
76+
source: "forest.png"
77+
Image:
78+
size_hint: 1, 1
79+
source: "sun.png"
80+
allow_stretch: True
81+
keep_ratio: False
82+
Image:
83+
size_hint: 0.5, 0.5
84+
pos_hint: {'center_x': 0.2, 'center_y': 0.8}
85+
keep_ratio: False
86+
allow_stretch: True
87+
source: "clouds.png"
88+
Image:
89+
size_hint: 0.5, 0.5
90+
pos_hint: {'center_x': 0.75, 'center_y': 0.8}
91+
keep_ratio: False
92+
allow_stretch: True
93+
source: "clouds.png"
94+
Image:
95+
source: "grass_platform.png"
96+
pos_hint: {'center_x': 0.5, 'center_y': 0.3}
97+
keep_ratio: False
98+
allow_stretch: True
99+
size_hint: 1, 0.6
100+
Image:
101+
source: "cloud_platform_2.png"
102+
keep_ratio: True
103+
allow_stretch: True
104+
pos_hint: {'center_x': 0.5, 'top': 0.8}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
from kivy.app import App
2+
from kivy.clock import Clock
3+
from kivy.properties import (
4+
NumericProperty, ObjectProperty, ReferenceListProperty
5+
)
6+
from kivy.uix.screenmanager import Screen, ScreenManager
7+
from kivy.uix.widget import Widget
8+
from kivy.vector import Vector
9+
10+
11+
class Dino(Widget):
12+
'''Widget for the dinosaur'''
13+
velocity_x = NumericProperty(0)
14+
velocity_y = NumericProperty(0)
15+
16+
# referencelist property so we can use ball.velocity as
17+
# a shorthand, just like e.g. w.pos for w.x and w.y
18+
velocity = ReferenceListProperty(velocity_x, velocity_y)
19+
20+
# ``move`` function will move the ball one step. This
21+
# will be called in equal intervals to animate the ball
22+
23+
def move(self) -> None:
24+
self.pos = Vector(*self.velocity) + self.pos
25+
26+
27+
class RootScreen(ScreenManager):
28+
dino = ObjectProperty(None)
29+
30+
def dino_move(self, vel: list = (3, 0)) -> None:
31+
self.dino.velocity = vel
32+
33+
def update(self, dt: float) -> None:
34+
# call dino.move and other stuff
35+
self.dino.move()
36+
37+
# return the dino to the beginning
38+
if self.dino.x > self.x + 1300:
39+
self.dino.pos = -350, -250
40+
41+
42+
class StartScreen(Screen):
43+
pass
44+
45+
46+
class GameScreen(Screen):
47+
pass
48+
49+
50+
class backgroundApp(App):
51+
def build(self) -> None:
52+
game = RootScreen()
53+
game.dino_move()
54+
Clock.schedule_interval(game.update, 60.0 / 60.0)
55+
return game
56+
57+
58+
if __name__ == "__main__":
59+
backgroundApp().run()
Loading
Loading
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)