Skip to content

Commit

Permalink
update build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhduong95 committed Mar 3, 2017
1 parent c83fd3e commit 0a6c7ea
Show file tree
Hide file tree
Showing 13 changed files with 218 additions and 219 deletions.
15 changes: 10 additions & 5 deletions INSTALL
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
1. Method 1 (no installation required, only applies to released versions)
# Installation instructions

You can run the game by opening the executable file named "game" / "game.exe" / "game.app" (no Blender required)
The following instructions apply for building from source only. For binary versions, you can run the game by opening the executable file named "game" / "game.exe" / "game.app" (no Blender required)

2. Method 2

You need to install Blender first ( https://www.blender.org/ ), then open the game.blend file with Blender (or game_test.blend if you wish to modify the source), enable the addon to export game runtime (File > User Preferences > Addons > Game Engine: Save As Game Engine Runtime) and export it as game engine runtime (File > Export > Save As Game Engine Runtime)
- You need to install Blender first ( https://www.blender.org/ )
- Open the command window and cd to the game main directory (which contains .blend files)
- Run the following commands in the right order:
<path/to/Blender/executable> -b terrain_src.blend -P build_terrain.py
<path/to/Blender/executable> -b items_src.blend -P build_item.py
<path/to/Blender/executable> -b penguin_src.blend -P build_penguin.py
<path/to/Blender/executable> -b game.blend -P install.py
- Now you can run the game by opening the file named "game" / "game.exe" / "game.app" (which depends on the OS)
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ R (when dead) - respawn

Esc - exit game

# Installation instructions (for building from source only)

See INSTALL file for more details.

# License

Copyright (C) 2016 Dang Duong
Expand Down
25 changes: 25 additions & 0 deletions build_item.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import bpy

objects = bpy.data.objects
ops = bpy.ops
context = bpy.context
scene = context.scene
logic = ops.logic

ops.object.mode_set(mode='OBJECT')

fish = objects["fish"]
ice = objects["ice_cube"]
snow = objects["snow_ball"]

def smooth(obj):
ops.object.select_all(action="DESELECT")
scene.objects.active = obj
obj.select = True
ops.object.shade_smooth()

for obj in [fish, ice, snow]:
smooth(obj)

ops.wm.save_as_mainfile(filepath=bpy.path.abspath("//")+"items.blend")
ops.wm.quit_blender()
36 changes: 36 additions & 0 deletions build_penguin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import bpy

objects = bpy.data.objects
ops = bpy.ops
context = bpy.context
scene = context.scene
logic = ops.logic
layers = scene.layers
ops.object.mode_set(mode='OBJECT')

player = objects["body"]
AI = objects["AI_body"]

def smooth(obj):
ops.object.select_all(action="DESELECT")
scene.objects.active = obj
obj.select = True
ops.object.modifier_apply(apply_as="DATA", modifier="Mirror")
ops.object.shade_smooth()
ops.object.select_all(action="DESELECT")

def select_layer(index):
ops.object.select_all(action="DESELECT")
layers[index] = True
for i in range(10):
if i != index:
layers[i] = False

select_layer(1)
smooth(player)

select_layer(3)
smooth(AI)

ops.wm.save_as_mainfile(filepath=bpy.path.abspath("//")+"penguin.blend")
ops.wm.quit_blender()
128 changes: 128 additions & 0 deletions build_terrain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import bpy
import bmesh
import pickle

obj_list = []
objects = bpy.data.objects
ops = bpy.ops
context = bpy.context
scene = context.scene
logic = ops.logic
layers = scene.layers

ops.object.mode_set(mode='OBJECT')

for ob in objects:
if ob not in obj_list:
obj_list.append(ob)

terrain_list = []

def select_layer(index):
ops.object.select_all(action="DESELECT")
layers[index] = True
for i in range(10):
if i != index:
layers[i] = False

def smooth(obj):
ops.object.select_all(action="DESELECT")
scene.objects.active = obj
obj.select = True
ops.object.shade_smooth()
ops.object.select_all(action="DESELECT")

def add_logic_bricks(obj_name, obj_suffix):
terrain = objects[obj_name+obj_suffix]
logic.sensor_add(type="ALWAYS", object=obj_name+obj_suffix)
logic.controller_add(type="PYTHON", object=obj_name+obj_suffix)
sensor = terrain.game.sensors[-1]
controller = terrain.game.controllers[-1]
controller.mode = "MODULE"
controller.module = "scripts.terrain.terrain"+obj_suffix+"_main"
sensor.link(controller)
if obj_suffix == "_physics":
ops.object.select_all(action="DESELECT")
scene.objects.active = terrain
terrain.select = True
ops.object.game_property_new(name="barrier", type="BOOL")
terrain.game.properties["barrier"].value = True
ops.object.select_all(action="DESELECT")

def cut_terrain(obj_name, obj_length, obj_width, obj_suffix):
if obj_length >= obj_width:
sub_obj_length = int(obj_length/3)
sub_obj_width = int(obj_width/2)
else:
sub_obj_length = int(obj_length/2)
sub_obj_width = int(obj_width/3)
terrain = objects[obj_name+obj_suffix]
scene.objects.active = terrain
terrain.select = True
ops.object.origin_set(type='ORIGIN_GEOMETRY')
terrain_loc_rot = [[terrain.location[0], terrain.location[1], terrain.location[2]], []]
ops.object.select_all(action='DESELECT')
cut_n = 0
global obj_list
if obj_length > 9:
for i in range(6):
scene.objects.active = terrain
terrain.select = True
ops.object.mode_set(mode='EDIT')
obj = context.object
me = obj.data
bm = bmesh.from_edit_mesh(me)
ops.mesh.select_all(action='DESELECT')
########################
for m in range(sub_obj_width):
for n in range(sub_obj_length):
bm.faces.ensure_lookup_table()
bm.faces[m + n*(obj_width - cut_n)].select = True
bmesh.update_edit_mesh(me, True)
bm.faces.ensure_lookup_table()
########################
bpy.ops.mesh.separate(type='SELECTED')
if cut_n < obj_width - sub_obj_width:
cut_n += sub_obj_width
else:
cut_n = 0
########################
sub_obj_name = obj_name+"_"+str(i)
ops.object.mode_set(mode='OBJECT')
ops.object.select_all(action='DESELECT')
for ob in bpy.data.objects:
if ob not in obj_list:
ob.name = sub_obj_name+obj_suffix
obj_list.append(ob)
break
########################
terrain_loc_rot[1].append(cut_terrain(sub_obj_name, sub_obj_length, sub_obj_width, obj_suffix))
########################
ops.object.select_all(action='DESELECT')
scene.objects.active = terrain
terrain.select = True
ops.object.delete()
obj_list.remove(terrain)
else:
add_logic_bricks(obj_name, obj_suffix)
terrain_loc_rot.append([terrain.rotation_euler[0], terrain.rotation_euler[1], terrain.rotation_euler[2]])
terrain_loc_rot.append([terrain.scale[0], terrain.scale[1], terrain.scale[2]])
ops.object.select_all(action='DESELECT')
return terrain_loc_rot

ops.object.select_all(action='DESELECT')

terrain_list = cut_terrain("terrain", 216, 216, "")
pickle.dump(terrain_list, open(bpy.path.abspath("//")+"terrain_loc_rot.p", "wb"))

cut_terrain("terrain", 216, 216, "_physics")

house = objects["house_image"]
sky = objects["Sky"]
select_layer(1)
smooth(sky)
select_layer(2)
smooth(house)

ops.wm.save_as_mainfile(filepath=bpy.path.abspath("//")+"terrain.blend")
ops.wm.quit_blender()
Binary file added game.blend
Binary file not shown.
Binary file removed game_src.blend
Binary file not shown.
122 changes: 13 additions & 109 deletions install.py
Original file line number Diff line number Diff line change
@@ -1,110 +1,14 @@
import bpy
import bmesh
import pickle

bpy.ops.object.mode_set(mode='OBJECT')
obj_list = []
for ob in bpy.data.objects:
if ob not in obj_list:
obj_list.append(ob)

terrain_list = []

def add_logic_bricks(obj_name, obj_suffix):
terrain = bpy.data.objects[obj_name+obj_suffix]
bpy.ops.logic.sensor_add(type="ALWAYS", object=obj_name+obj_suffix)
bpy.ops.logic.controller_add(type="PYTHON", object=obj_name+obj_suffix)
sensor = terrain.game.sensors[-1]
controller = terrain.game.controllers[-1]
controller.mode = "MODULE"
controller.module = "scripts.terrain.terrain"+obj_suffix+"_main"
sensor.link(controller)
if obj_suffix == "_physics":
bpy.ops.object.select_all(action="DESELECT")
bpy.context.scene.objects.active = terrain
terrain.select = True
bpy.ops.object.game_property_new(name="barrier", type="BOOL")
terrain.game.properties["barrier"].value = True
bpy.ops.object.select_all(action="DESELECT")

def cut_terrain(obj_name, obj_length, obj_width, obj_suffix):
if obj_length >= obj_width:
sub_obj_length = int(obj_length/3)
sub_obj_width = int(obj_width/2)
else:
sub_obj_length = int(obj_length/2)
sub_obj_width = int(obj_width/3)
terrain = bpy.data.objects[obj_name+obj_suffix]
bpy.context.scene.objects.active = terrain
terrain.select = True
bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY')
terrain_loc_rot = [[terrain.location[0], terrain.location[1], terrain.location[2]], []]
bpy.ops.object.select_all(action='DESELECT')
cut_n = 0
global obj_list
if (obj_length > 9):
for i in range(6):
bpy.context.scene.objects.active = terrain
terrain.select = True
bpy.ops.object.mode_set(mode='EDIT')
obj = bpy.context.object
me = obj.data
bm = bmesh.from_edit_mesh(me)
bpy.ops.mesh.select_all(action='DESELECT')
########################
#sub_obj_index = i+1
for m in range(sub_obj_width):
for n in range(sub_obj_length):
bm.faces.ensure_lookup_table()
bm.faces[m + n*(obj_width - cut_n)].select = True
bmesh.update_edit_mesh(me, True)
bm.faces.ensure_lookup_table()
########################
bpy.ops.mesh.separate(type='SELECTED')
if cut_n < obj_width - sub_obj_width:
cut_n += sub_obj_width
else:
cut_n = 0
########################
sub_obj_name = obj_name+"_"+str(i)
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')
for ob in bpy.data.objects:
if ob not in obj_list:
ob.name = sub_obj_name+obj_suffix
obj_list.append(ob)
break
########################
terrain_loc_rot[1].append(cut_terrain(sub_obj_name, sub_obj_length, sub_obj_width, obj_suffix))
########################
bpy.ops.object.select_all(action='DESELECT')
bpy.context.scene.objects.active = terrain
terrain.select = True
bpy.ops.object.delete()
obj_list.remove(terrain)
else:
add_logic_bricks(obj_name, obj_suffix)
terrain_loc_rot.append([terrain.rotation_euler[0], terrain.rotation_euler[1], terrain.rotation_euler[2]])
terrain_loc_rot.append([terrain.scale[0], terrain.scale[1], terrain.scale[2]])
bpy.ops.object.select_all(action='DESELECT')
#terrain_list.append(terrain_loc_rot)
return terrain_loc_rot

#terrain_list_x = ["0", "1", "2", "3"]
#terrain_list_y = ["0", "1", "2"]

bpy.ops.object.select_all(action='DESELECT')

#for t_l_x in range(4):
# for t_l_y in range(3):
# terrain_list.append(cut_terrain("terrain_"+str(t_l_x)+"_"+str(t_l_y), 81, ""))

terrain_list = cut_terrain("terrain", 216, 216, "")
pickle.dump(terrain_list, open(bpy.path.abspath("//")+"terrain_loc_rot.p", "wb"))

#for t_l_x in range(4):
# for t_l_y in range(3):
# cut_terrain("terrain_"+str(t_l_x)+"_"+str(t_l_y), 81, "_physics")
cut_terrain("terrain", 216, 216, "_physics")


import platform

os_name = platform.system()
if os_name == "Windows":
exe_extension = ".exe"
elif os_name == "MacOS":
exe_extension = ".app"
else:
exe_extension = ""

bpy.ops.wm.addon_enable(module="game_engine_save_as_runtime")
bpy.ops.wm.save_as_runtime(filepath=bpy.path.abspath("//")+"game"+exe_extension)
bpy.ops.wm.quit_blender()
Binary file modified items_src.blend
Binary file not shown.
Binary file modified penguin_src.blend
Binary file not shown.
4 changes: 2 additions & 2 deletions scripts/AI_brain.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
# You should have received a copy of the GNU General Public License
# along with Open Tux World. If not, see <http://www.gnu.org/licenses/>.
#
from bge import logic
from scripts import AI_motion, switch_item, eat
from scripts import common_functions as cf, AI_motion, switch_item, eat
from random import randint, choice

logic = cf.logic
scene = logic.getCurrentScene()

def attacked_state(cont, own, brain, armature, front_sensor, attacker):
Expand Down
Loading

0 comments on commit 0a6c7ea

Please sign in to comment.