コード例 #1
0
def load_database(cont):
    """ Initialize data saved in database file. """

    own = cont.owner
    path = expandPath("//")

    # Sensors
    s_always = [
        sen for sen in cont.sensors if type(sen) == bge.types.SCA_AlwaysSensor
    ][0].positive

    ############################
    ######## INITIALIZE ########
    ############################

    if s_always:

        if not "state" in globalDict.keys():
            globalDict["state"] = {"player": {}, "actors": {}, "world": {}}

        try:
            with open(path + "database.json", "r") as open_file:

                # Initialize database in globalDict
                globalDict["database"] = json.load(open_file)

                # Warning message
                print("Database loaded from database.json")

        except:
            print("Error loading database.json. Try to reinstall the game")

    pass
コード例 #2
0
def save_options(cont):
    """ Save options from the globalDict to file. """

    path = expandPath("//")

    ############################
    ######## INITIALIZE ########
    ############################

    for sen in cont.sensors:

        if type(
                sen
        ) == bge.types.SCA_MouseSensor and "options" in globalDict.keys():

            try:

                # Open file from disk
                with open(path + "options.json", "w") as open_file:

                    # Write file to disk
                    json.dump(globalDict["options"], open_file)

                    # Warning message
                    print("Options saved to options.json")

            except:

                # Warning message
                print("Can't save options to options.json")

    pass
コード例 #3
0
ファイル: minimap.py プロジェクト: joelgomes1994/bgarmor
def updateArrow(cont):
    ''' Constantly updates the map arrow's position and rotation 
	from values previously stored on globalDict.
	
	Blend: Main.blend / Scene: Minimap / Object: PlayerArrow '''

    # Objects
    own = cont.owner

    # Sensors
    sensor = cont.sensors[0]

    ### PROCESS ###
    if sensor.positive:

        # Check if values are present in globalDict
        if 'Position' in globalDict.keys() and 'Rotation' in globalDict.keys():

            # Update arrow's position and rotation
            own.worldPosition = globalDict['Position']
            own.localOrientation = globalDict['Rotation']
コード例 #4
0
def processCursorAppearence(cont):
	own = cont.owner
	mouseOver = cont.sensors["MouseOver"]
	
	if "Game" in bgf.currentContext:
				
		if "Paused" in globalDict.keys():
			if not globalDict["Paused"] and not own["Aim"]:
				own["Aim"] = True
				own.replaceMesh("MouseAim")
				
			elif globalDict["Paused"] and own["Aim"]:
				own["Aim"] = False
				own.color = bgf.database["Gui"]["MouseCursor"]["CursorColorNormal"]
				own.replaceMesh("MouseCursor")
				
			if "TargetType" in globalDict.keys() and not globalDict["Paused"]:
				if globalDict["TargetType"] == "None":
					own.color = bgf.database["Gui"]["MouseCursor"]["AimColorNormal"]
				elif globalDict["TargetType"] == "Ally":
					own.color = bgf.database["Gui"]["MouseCursor"]["AimColorAlly"]
				elif globalDict["TargetType"] == "Enemy":
					own.color = bgf.database["Gui"]["MouseCursor"]["AimColorEnemy"]
コード例 #5
0
ファイル: map_loader.py プロジェクト: DarthMoulByte/dark-war
def init_new_data():
	
	scene = bge.logic.getCurrentScene()
	
	if not 'map' in globalDict.keys():
		
		first_map = expandPath('//maps/') + [m for m in os.listdir(expandPath('//maps/')) if m.endswith('.dwmap')][0]
		
		with open(first_map, 'r') as open_file:
			globalDict['map'] = litev(open_file.read())
	
	# Map
	if globalDict['map'] == {}:
		globalDict['map'] = default_map.copy()
	
	#pprint(globalDict)
	pass
コード例 #6
0
def load_strings(cont):
    """ Initialize data saved in option file. """

    own = cont.owner
    path = expandPath("//lang/")
    ext = ".json"

    # Sensors
    s_always = [
        sen for sen in cont.sensors if type(sen) == bge.types.SCA_AlwaysSensor
    ][0].positive

    # Properties
    p_lang = "English"

    ############################
    ######## INITIALIZE ########
    ############################

    if s_always:

        # If options was loaded
        if "options" in globalDict.keys():

            # Get language from options
            p_lang = globalDict["options"]["language"]

            try:
                with open(path + p_lang + ext, "r") as open_file:

                    # Initialize strings in globalDict
                    globalDict["strings"] = json.load(open_file)

            except:
                print(
                    "Error loading language file. Try to reinstall the game.")

        else:
            print("Can't find any language config.")

    pass
コード例 #7
0
ファイル: map_editor.py プロジェクト: DarthMoulByte/dark-war
def init_new_data():
	
	scene = bge.logic.getCurrentScene()
	
	if not 'database' in globalDict.keys():
		with open(expandPath('//map_editor.dat'), 'r') as open_file:
			globalDict['database'] = litev( open_file.read() )
			print('Loaded database from', open_file.name)
	
	# Global state
	globalDict['state'] = default_state.copy()
	print('State initialized from default')
	
	# Map
	globalDict['map'] = default_map.copy()
	print('Map initialized from empty default')
	
	# Tools and its specific settings
	globalDict[ 'tool_ground' ] = { 'current_tile' : 0,	'tile_depth' : 1, 'current_rotation' : 0 }
	globalDict[ 'tool_buildings' ] = { 'current_tile' : 0,	'tile_depth' : 2, 'floors' : 1, 'current_rotation' : 0 }
	globalDict[ 'tool_props' ] = { 'current_tile' : 0, 'tile_depth' : 3, 'current_rotation' : 0 }
	globalDict[ 'tool_spawns' ] = { 'current_tile' : 0, 'tile_depth' : 4, 'current_rotation' : 0}
	print('Tools settings initialized from default')
コード例 #8
0
def load_options(cont):
    """ Initialize data saved in option file. """

    own = cont.owner
    path = expandPath("//")

    # Sensors
    s_always = [
        sen for sen in cont.sensors if type(sen) == bge.types.SCA_AlwaysSensor
    ][0].positive

    ############################
    ######## INITIALIZE ########
    ############################

    if s_always:

        ### Initialize options in globalDict ###
        if not "options" in globalDict.keys():

            # Fallback values
            globalDict["options"] = {}

            options = {
                'key_up': 119,
                'key_use': 101,
                'key_left': 97,
                'key_menu': 32,
                'key_run': 106,
                'key_crouch': 105,
                'key_right': 10,
                'mouse_sensitivity': 1.0,
                'mouse_invert': 0,
                'key_down': 115,
                'fullscreen': 0,
                'vsync': 1,
                'resolution': 3,
                'vol_music': 1.0,
                'vol_sfx': 1.0,
                'language': 'English'
            }

            ### Set falback to globalDict ###
            globalDict["options"] = options

            ### Load options from file ###
            try:
                with open(path + "options.json", "r") as open_file:

                    globalDict["options"] = json.load(open_file)

                    print("Game options loaded from options.json")

            ### Write default options file ###
            except:
                with open(path + "options.json", "w") as open_file:

                    json.dump(options, open_file)

                    print(
                        "Error loading options.json, create file and use default values"
                    )

    pass
コード例 #9
0
ファイル: player.py プロジェクト: bgempire/old-new-world
from .utils import roundVector

DEFAULT_PLAYER = {
	"CurPlayer" : "Astronaut",
	"CurPosAstronaut" : [0, 0, 0],
	"CurPosRobot" : [0, 0, 0],
	"CurDirX" : 1,
	"CurDirY" : 0,
	"RobotUnlocked" : False,
	"Map" : {}
}

ASTRONAUT_MOV_SPEED = 0.070
ROBOT_MOV_SPEED = 0.08

if not "Player" in globalDict.keys():
	globalDict["Player"] = DEFAULT_PLAYER

def main(cont):
	own = cont.owner
	group = own.groupObject
	camera = own.scene.active_camera
	
	always = cont.sensors["Always"]
	
	player = globalDict["Player"]
	
	if group is None:
		own.endObject()
		return
		
コード例 #10
0
import bge, json
from bge.logic import globalDict
from random import choice, random
from pprint import pprint
from ast import literal_eval as litev

if not 'player_active' in globalDict.keys():
    globalDict['player_active'] = False


def init(cont):
    """ Initializes the character. """

    own = cont.owner
    scene = own.scene

    # Sensors
    autostart = cont.sensors['autostart'].positive

    # Actuators
    track_to = cont.actuators['track_to']

    # Objects
    track_direction = own.childrenRecursive['track_direction']

    # Properties

    #### INITIALIZE ####
    if autostart:

        if track_to.object == None: