Skip to content

Commit

Permalink
Improved settings mechanism, new menu style.
Browse files Browse the repository at this point in the history
  • Loading branch information
gandie committed Jul 15, 2017
1 parent d86a1f3 commit ed2d44a
Show file tree
Hide file tree
Showing 30 changed files with 149 additions and 133 deletions.
2 changes: 1 addition & 1 deletion buildozer.spec
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ source.include_exts = py,png,jpg,kv,atlas,pyx,h,c
#version.filename = %(source.dir)s/main.py

# (str) Application versioning (method 2)
version = 0.4.1
version = 0.4.2

# (list) Application requirements
# comma seperated e.g. requirements = sqlite3,kivy
Expand Down
6 changes: 3 additions & 3 deletions creditsscreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ def build_interface(self):
self.creditslayout.add_widget(creditline)

self.menubutton = RealButton(
'./media/icons/menu.png',
'./media/icons/menu_pressed.png',
'./media/icons/arrowleft.png',
'./media/icons/arrowleft_pressed.png',
self.switchto_menu,
size_hint=(None, None),
size=(self.iconsize, self.iconsize),
pos_hint={'x': 0, 'y': 0},
source='./media/icons/menu.png',
source='./media/icons/arrowleft.png',
always_release=True
)

Expand Down
7 changes: 5 additions & 2 deletions game_modi.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# KIVY
from kivy.uix.screenmanager import Screen
from kivy.app import App
from kivy.properties import *
from kivy.vector import Vector
from kivy.graphics import Line, Color

# BUILTIN
from random import randint
import random

# CUSTOM
from gamezone import Gamezone

'''
Expand All @@ -20,7 +23,7 @@ class GameMode(Screen):

logic = ObjectProperty(None)

def __init__(self, gamezone, body='', draw_trajectory=False,
def __init__(self, gamezone, logic_settings, body='', draw_trajectory=False,
sizeable=False, slider_label='', **kwargs):
super(GameMode, self).__init__(**kwargs)
self.gamezone = gamezone
Expand Down
80 changes: 42 additions & 38 deletions logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ class Logic(Screen):
selplanet_index = NumericProperty(None, allownone=True)

# this is called when app is built!
def __init__(self):
def __init__(self, settings):

# set up dicts to be filled
self.planets = {}
self.settings = {}
self.settings = settings

# initialize planetkeeper
self.keeper = CPlanetKeeper()
Expand All @@ -55,58 +55,47 @@ def __init__(self):

# time per time ratio
self.tick_ratio = 1.0

self.slider_value = 10

# load textures for body-categories
self.moon_textures = self.load_textures('./media/textures/moons/')
self.planet_textures = self.load_textures('./media/textures/planets/')
self.gasgiant_textures = self.load_textures('./media/textures/gasgiants/')
self.sun_textures = self.load_textures('./media/textures/suns/')
self.bigsun_textures = self.load_textures('./media/textures/bigsuns/')
self.giantsun_textures = self.load_textures('./media/textures/giantsuns/')
self.blackhole_textures = self.load_textures('./media/textures/blackholes/')
self.texture_mapping = {
'moon': self.load_textures('./media/textures/moons/'),
'planet': self.load_textures('./media/textures/planets/'),
'gasgiant': self.load_textures('./media/textures/gasgiants/'),
'sun': self.load_textures('./media/textures/suns/'),
'bigsun': self.load_textures('./media/textures/bigsuns/'),
'giantsun': self.load_textures('./media/textures/giantsuns/'),
'blackhole': self.load_textures('./media/textures/blackholes/'),
}

# observe selplanet
self.bind(selplanet=self.on_selplanet)

# called after loading setting by app
def load_transitions(self):
def apply_settings(self):
self.planet_transitions = {
'moon': {'nextbody': 'planet',
'mass': self.settings['min_planet_mass'],
'density': self.settings['planet_density'],
'textures': self.planet_textures},
'textures': self.texture_mapping['planet']},
'planet': {'nextbody': 'gasgiant',
'mass': self.settings['min_gasgiant_mass'],
'density': self.settings['gasgiant_density'],
'textures': self.gasgiant_textures},
'textures': self.texture_mapping['gasgiant']},
'gasgiant': {'nextbody': 'sun',
'mass': self.settings['min_sun_mass'],
'density': self.settings['sun_density'],
'textures': self.sun_textures},
'textures': self.texture_mapping['sun']},
'sun': {'nextbody': 'bigsun',
'mass': self.settings['min_bigsun_mass'],
'density': self.settings['bigsun_density'],
'textures': self.bigsun_textures},
'textures': self.texture_mapping['bigsun']},
'bigsun': {'nextbody': 'giantsun',
'mass': self.settings['min_giantsun_mass'],
'density': self.settings['giantsun_density'],
'textures': self.giantsun_textures},
'textures': self.texture_mapping['giantsun']},
'giantsun': {'nextbody': 'blackhole',
'mass': self.settings['min_blackhole_mass'],
'density': self.settings['blackhole_density'],
'textures': self.blackhole_textures}
}

self.texture_mapping = {
'moon': self.moon_textures,
'planet': self.planet_textures,
'gasgiant': self.gasgiant_textures,
'sun': self.sun_textures,
'bigsun': self.bigsun_textures,
'giantsun': self.giantsun_textures,
'blackhole': self.blackhole_textures
'textures': self.texture_mapping['blackhole']}
}

self.mode_setting = {
Expand Down Expand Up @@ -135,38 +124,45 @@ def load_transitions(self):
self.mode_map = {
'zoom': ZoomMode(
self.gamezone,
self.settings,
sizeable=True,
settings=self.mode_setting['zoom'],
slider_label='Time Ratio'
),
'add_planet': AddBodyMode(
self.gamezone, body='planet',
self.gamezone,
self.settings,
body='planet',
draw_trajectory=True,
sizeable=True,
settings=self.mode_setting['add_planet'],
slider_label='Body Mass'
),
'add_sun': AddBodyMode(
self.gamezone, body='sun',
self.gamezone,
self.settings,
body='sun',
draw_trajectory=True,
sizeable=True,
settings=self.mode_setting['add_sun'],
slider_label='Sun Mass'
),
'multi': AddBodyMode_Multi(
self.gamezone, body='moon',
self.gamezone,
self.settings,
body='moon',
draw_trajectory=True,
sizeable=True,
settings=self.mode_setting['multi'],
slider_label='Body Count'
),
'del': DelMode(self.gamezone)
'del': DelMode(self.gamezone, self.settings)
}

#if self.cur_guimode is None:
self.cur_guimode = self.mode_map['add_planet']
if self.cur_guimode is None:
self.cur_guimode = self.mode_map['add_planet']
self.mainscreen.add_value_slider(self.cur_guimode)
self.bind(cur_guimode=self.on_cur_guimode)
self.mainscreen.add_value_slider(self.cur_guimode)

def on_cur_guimode(self, instance, value):
# ask mode wether slider values have to be set
Expand Down Expand Up @@ -205,7 +201,7 @@ def add_body(self, body='planet', pos=(0, 0), texture_index=None,
newplanet = Planet()

# texture of new body, defaults to planet
texture_list = self.texture_mapping.get(body, self.planet_textures)
texture_list = self.texture_mapping[body]
texture_index = texture_index or randint(0, len(texture_list) - 1)
newplanet_texture = texture_list[texture_index]
newplanet.set_base_image(newplanet_texture)
Expand Down Expand Up @@ -296,6 +292,14 @@ def update_game(self, dt):
vel_x = self.keeper.get_planet_vel_x(index)
vel_y = self.keeper.get_planet_vel_y(index)

# cleanup garbage
if pos_x > self.gamezone.size[0] or pos_x < 0:
del_indexes.append(index)
continue
if pos_y > self.gamezone.size[1] or pos_y < 0:
del_indexes.append(index)
continue

# update physics data
self.planets[index]['position_x'] = pos_x
self.planets[index]['position_y'] = pos_y
Expand Down Expand Up @@ -327,7 +331,7 @@ def update_game(self, dt):
for index in del_indexes:
self.delete_planet(index)

if self.selplanet_index != None and self.fixview_mode:
if self.selplanet_index is not None and self.fixview_mode:
self.center_planet(self.selplanet_index)

def load_textures(self, path):
Expand Down
21 changes: 11 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class PlanetApp(App):

def build(self):
self.calc_iconsize()
self.logic = Logic()
self.logic = Logic(settings=self.load_settings())
self.screenmanager = ScreenManager()

self.mainscreen = MainScreen(
Expand Down Expand Up @@ -79,12 +79,13 @@ def build(self):
self.screenmanager.add_widget(self.settingsscreen)
self.screenmanager.add_widget(self.savegamescreen)
self.screenmanager.add_widget(self.creditsscreen)
self.logic.apply_settings()

return self.screenmanager

def on_start(self):
self.load_settings()
self.logic.load_transitions()
# self.load_settings()
# self.logic.load_transitions()
self.load_game()

def on_stop(self):
Expand All @@ -93,13 +94,12 @@ def on_stop(self):

def load_settings(self):
try:
f = open('settings.json', 'r')
json_d = f.readline()
D = json.loads(json_d)
f.close
except:
with open('settings.json', 'r') as settingsfile:
json_d = settingsfile.readline()
settings = json.loads(json_d)
except Exception:
# default settings
D = {
settings = {
'min_moon_mass': 0,
'min_planet_mass': 30,
'min_gasgiant_mass': 2000,
Expand All @@ -117,11 +117,12 @@ def load_settings(self):
'blackhole_density': 20,

'background': True,
'show_tutorial': True,

'multi_shot_min': 10,
'multi_shot_max': 50,
}
self.logic.settings = D
return settings

def save_settings(self):
f = open('settings.json', 'w')
Expand Down
16 changes: 11 additions & 5 deletions mainscreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,14 @@ def on_enter(self):

if not self.menupanel.paused:
self.logic.start_game()
if self.logic.tutorial_mode:
self.add_widget(self.tutorial_label)

# check tutorial setting
if self.logic.settings['show_tutorial'] is True:
if self.tutorial_label not in self.children:
self.add_widget(self.tutorial_label)
else:
if self.tutorial_label in self.children:
self.remove_widget(self.tutorial_label)

def add_seltoggles(self):
if self.seltoggles not in self.children:
Expand Down Expand Up @@ -178,9 +184,9 @@ def build_interface(self):
# do_translation_y=False,
# do_translation_x=False,
auto_bring_to_front=False,
scale_min=0.01,
scale_max=50,
size_hint=(100, 100)
scale_min=0.15,
scale_max=10,
size_hint=(25, 25)
)
self.add_widget(self.gamezone)

Expand Down
Binary file modified media/background/background_menu.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified media/background/background_savegame.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified media/background/background_settings.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed media/background/background_settings_old.png
Binary file not shown.
Binary file added media/buttons/credits.png
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 media/buttons/credits_pressed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified media/buttons/play.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified media/buttons/play_pressed.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified media/buttons/saves.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified media/buttons/saves_pressed.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified media/buttons/settings.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified media/buttons/settings_pressed.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed media/buttons/tutorial.png
Binary file not shown.
Binary file removed media/buttons/tutorial_pressed.png
Binary file not shown.
Binary file added media/icons/check.png
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 media/icons/checkpressed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified media/icons/main.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified media/splashscreen/splashscreen.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 17 additions & 19 deletions menuscreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class MenuScreen(Screen):

startbutton = ObjectProperty(None)
tutorialbutton = ObjectProperty(None)
creditsbutton = ObjectProperty(None)
settingsbutton = ObjectProperty(None)
savegamebutton = ObjectProperty(None)
mainlayout = ObjectProperty(None)
Expand All @@ -43,11 +43,9 @@ def switchto_savegames(self, instance):
self.manager.transition = FadeTransition()
self.manager.current = 'savegames'

def switchto_tutorial(self, instance):
self.logic.tutorial_mode = True
self.logic.reset_planets(self)
def switchto_credits(self, instance):
self.manager.transition = FadeTransition()
self.manager.current = 'main'
self.manager.current = 'credits'

def build_interface(self):
self.mainlayout = FloatLayout()
Expand All @@ -56,8 +54,8 @@ def build_interface(self):
'./media/buttons/play.png',
'./media/buttons/play_pressed.png',
self.switchto_main,
size_hint=(0.4, 0.4),
pos_hint={'x': 0.6, 'y': 0.3},
size_hint=(0.4, 0.3),
pos_hint={'x': 0, 'y': 0.6},
source='./media/buttons/play.png',
always_release=True
)
Expand All @@ -66,8 +64,8 @@ def build_interface(self):
'./media/buttons/settings.png',
'./media/buttons/settings_pressed.png',
self.switchto_settings,
size_hint=(0.2, 0.2),
pos_hint={'x': 0.32, 'y': 0.7},
size_hint=(0.4, 0.3),
pos_hint={'x': 0.6, 'y': 0.6},
source='./media/buttons/settings.png',
always_release=True
)
Expand All @@ -76,24 +74,24 @@ def build_interface(self):
'./media/buttons/saves.png',
'./media/buttons/saves_pressed.png',
self.switchto_savegames,
size_hint=(0.2, 0.2),
pos_hint={'x': 0.07, 'y': 0.4},
size_hint=(0.4, 0.3),
pos_hint={'x': 0, 'y': 0.1},
source='./media/buttons/saves.png',
always_release=True
)

self.tutorialbutton = RealButton(
'./media/buttons/tutorial.png',
'./media/buttons/tutorial_pressed.png',
self.switchto_tutorial,
size_hint=(0.2, 0.2),
pos_hint={'x': 0.57, 'y': 0.06},
source='./media/buttons/tutorial.png',
self.creditsbutton = RealButton(
'./media/buttons/credits.png',
'./media/buttons/credits_pressed.png',
self.switchto_credits,
size_hint=(0.4, 0.3),
pos_hint={'x': 0.6, 'y': 0.1},
source='./media/buttons/credits.png',
always_release=True
)

self.mainlayout.add_widget(self.startbutton)
self.mainlayout.add_widget(self.tutorialbutton)
self.mainlayout.add_widget(self.creditsbutton)
self.mainlayout.add_widget(self.settingsbutton)
self.mainlayout.add_widget(self.savegamebutton)
self.add_widget(self.mainlayout)
Loading

0 comments on commit ed2d44a

Please sign in to comment.