Skip to content

Commit

Permalink
Finish version 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
wellington36 committed Jan 29, 2022
1 parent 9a7bcc0 commit 682dc60
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 9 deletions.
Binary file added images/dog2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/planet.webp
Binary file not shown.
14 changes: 13 additions & 1 deletion src/galaxy.kv
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ MainWidget:


<MainWidget>:
canvas.before:
Rectangle:
size: self.size
source: 'images/planet.webp'
menu_widget: menu_widget

MenuWidget:
id: menu_widget
id: menu_widget

Label:
text: root.score_text
font_size: dp(20)
font_name: 'fonts/Eurostile.ttf'
size_hint: .15, .10
pos_hint: {"x": 0, "top": 1}
30 changes: 26 additions & 4 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from kivy.uix.widget import Widget
from kivy.uix.relativelayout import RelativeLayout
from kivy.lang import Builder
from kivy.properties import ObjectProperty
from kivy.properties import ObjectProperty, StringProperty

Builder.load_file("menu.kv")

Expand Down Expand Up @@ -56,6 +56,10 @@ class MainWidget(RelativeLayout):
state_game_over = False
state_game_has_started = False

menu_title = StringProperty("G A L A X Y")
menu_button_title = StringProperty("START")
score_text = StringProperty("SCORE: 0")


def __init__(self, **kwargs):
super(MainWidget, self).__init__(**kwargs)
Expand All @@ -64,7 +68,7 @@ def __init__(self, **kwargs):

self.init_tiles()
self.init_ship()
self.pre_filltiles_coordinates()
self.pre_fill_tiles_coordinates()
self.generate_tile_coordinates()

if self.is_desktop():
Expand All @@ -75,6 +79,20 @@ def __init__(self, **kwargs):
Clock.schedule_interval(self.update, 1.0 / 60.0) # 60 fps


def reset_game(self):
self.current_offset_x = 0
self.current_offset_y = 0
self.current_y_loop = 0
self.current_speed_x = 0
self.score_text = "SCORE: 0"

self.tiles_coordinates = []
self.pre_fill_tiles_coordinates()
self.generate_tile_coordinates()

self.state_game_over = False


def is_desktop(self):
if platform in ('linux', 'win', 'macosc'):
return True
Expand Down Expand Up @@ -138,7 +156,7 @@ def init_tiles(self):
self.tiles.append(Quad())


def pre_filltiles_coordinates(self):
def pre_fill_tiles_coordinates(self):
for i in range(0, 10):
self.tiles_coordinates.append((0, i))

Expand Down Expand Up @@ -288,6 +306,7 @@ def update(self, dt):
while self.current_offset_y >= spacing_y:
self.current_offset_y -= spacing_y
self.current_y_loop += 1
self.score_text = "SCORE: " + str(self.current_y_loop)

self.generate_tile_coordinates()
print("loop: " + str(self.current_y_loop))
Expand All @@ -297,12 +316,15 @@ def update(self, dt):

if not self.check_ship_collision() and not self.state_game_over:
self.state_game_over = True
self.menu_widget_opacity = 1
self.menu_title = "G A M E R O V E R"
self.menu_button_title = "RESTART"
self.menu_widget.opacity = 1
print("GAME OVER")


def on_menu_button_pressed(self):
print("BUTTON")
self.reset_game()
self.state_game_has_started = True
self.menu_widget.opacity = 0

Expand Down
14 changes: 10 additions & 4 deletions src/menu.kv
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@
Rectangle:
size: self.size
Label:
text: "TITLE"
font_size: dp(60)
font_name: '/home/wellington/Documents/GalaxyPy/fonts/Eurostile.ttf'
text: root.parent.menu_title
pos_hint: { "center_x": .5, "center_y": .6 }
Button:
text: "OK"
pos_hint: { "center_x": .5, "center_y": .4 }
font_size: dp(20)
font_name: '/home/wellington/Documents/GalaxyPy/fonts/Eurostile.ttf'
text: root.parent.menu_button_title
pos_hint: { "center_x": .5, "center_y": .25 }
size_hint: .2, .1
on_press: root.parent.on_menu_button_pressed()
on_press: root.parent.on_menu_button_pressed()
background_normal: ''
background_color: .3, .1, .4, .85

0 comments on commit 682dc60

Please sign in to comment.