Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
moosichu committed Aug 6, 2015
1 parent f71a527 commit bc6dd7d
Show file tree
Hide file tree
Showing 24 changed files with 315 additions and 136 deletions.
3 changes: 1 addition & 2 deletions LICENSE
@@ -1,7 +1,7 @@
All code, unless otherwise specified is released under the MIT license
(reproduced below):

Copyright (c) 2014 Ben Catterall, Heidi Howard, Joshua Landau, Ashley Newson,
Copyright (c) 2014 Ben Catterall, Heidi Howard, Joshua Landau, Ashley Newson,
Anindya Sharma, Tom Read-Cutting, Alexander Day and CONTRIBUTORS

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down Expand Up @@ -30,4 +30,3 @@ license can be found here: <https://creativecommons.org/licenses/by-sa/4.0/>.

All music Copyright (c) 2015 Alexander Day and released under the Creative
Commons Attribution-ShareAlike 4.0 International license

7 changes: 5 additions & 2 deletions README.md
Expand Up @@ -58,9 +58,12 @@ git clone http://github.com/pyland/pyland
For compiling on the Raspberry Pi, use:

```bash
cd pyland
cd pyland/src/
#Put your python version here (change both PYTHON_VERSION and LIBBOOST_PYTHON). Need at least 3.2.
COMPILER=g++-4.7 PYTHON_VERSION=3.2 LIBBOOST_PYTHON=boost_python-py32 make
cd jsonnet/
make
cd ..
```

#### Compiling on Desktop - Unix
Expand Down Expand Up @@ -99,7 +102,7 @@ Please note that desktop support is secondary, and may be incomplete. At the mom
To launch :

```bash
cd src
#Must be in the src folder
./main.bin
```

Expand Down
19 changes: 1 addition & 18 deletions docs/design/Art Requests.txt
Expand Up @@ -100,7 +100,6 @@ World 7 - Monkey Kingdom
Main character sprite
Male/Female
Different Ethnicities
Different hair/eye colour

Story characters
Napper 1
Expand All @@ -109,22 +108,6 @@ Story characters

****** ITEMS ******

& Door locking mechanisms (crack the code)
Rock tablet (read messages from)
& Sliding door
Totem

PyVice
Tile sized
Scripts
Tile sized
Larger version for shop display
PyAutoCompleter
Tile sized
Larger version for shop display




****** CLOTHING ******

Expand All @@ -149,4 +132,4 @@ Full game window interfaces (solid colour/texture with pretty borders)
Bag
PyGuide
Shop
Look like actual shop/display
Look like actual shop/display
2 changes: 1 addition & 1 deletion experiments/new_integrated_editor/mainwindow.cpp
Expand Up @@ -439,7 +439,7 @@ void MainWindow::clearOutputPanels()
void MainWindow::createActions()
{
connect(buttonRun,SIGNAL(released()),this,SLOT (runCode()));
connect(buttonSpeed,SIGNAL(clicked()),this,SLOT (setGameFocus()));
connect(buttonSpeed,SIGNAL(pressed()),this,SLOT (setGameFocus()));
//connect(terminalDisplay,SIGNAL(clicked()),this,SLOT (setGameFocus()));
//connect(splitter,SIGNAL(splitterMoved()),this,SLOT (setGameFocus()));
//connect(textInfo,SIGNAL(selectionChanged()),this,SLOT (setGameFocus()));
Expand Down
2 changes: 2 additions & 0 deletions experiments/new_integrated_editor/mainwindow.h
Expand Up @@ -111,6 +111,8 @@ private slots:

QsciAPIs* api;

QsciLexerPython *lexer;

QsciScintilla *textEdit;
static const int workspace_max = 9;
QsciScintilla *workspaces[workspace_max];
Expand Down
Binary file added game/._game.py
Binary file not shown.
21 changes: 11 additions & 10 deletions game/bootstrapper.py
Expand Up @@ -8,7 +8,8 @@
import importlib

sys.path.insert(1, os.path.dirname(os.path.realpath(__file__)))
import game
sys.path.insert(1, os.path.dirname(os.path.realpath(__file__)) + '/engine')
from engine import Engine

from contextlib import closing
from io import BytesIO, TextIOWrapper
Expand Down Expand Up @@ -36,7 +37,7 @@ def cast(cast_type, value):
their parents.
"""
def create_execution_scope(game_objects, engine, RESTART, STOP, KILL):

""" imbued_locals is a python dictionary of python objects (variables, methods, class instances etc.)
eg. if there is an entry named "fart" whos entry is blob, then in the level script, any reference to fart
will be refering to what blob is known as here.
Expand All @@ -46,7 +47,6 @@ def create_execution_scope(game_objects, engine, RESTART, STOP, KILL):
for game_object in game_objects:
imbued_locals[game_object.get_name()] = game_object

imbued_locals["game"] = game #TODO: merge game and engine into a single cohesive class!!! (if needed?)
imbued_locals["engine"] = engine

class ScopedInterpreter(code.InteractiveInterpreter):
Expand Down Expand Up @@ -118,7 +118,7 @@ def wrap_entity_in_game_object(entity, engine):
game_object.set_entity(entity, engine) # initialise it and wrap the entity instance in it
return game_object

def start(entities, engine, RESTART, STOP, KILL, waiting):
def start(entities, cpp_engine, RESTART, STOP, KILL, waiting):
while waiting: #TODO: Work out why this waiting thing is here and in EntityThread: Ask Alex!!!
# Smallest reasonable wait while
# allowing fast interrupts.
Expand All @@ -127,6 +127,7 @@ def start(entities, engine, RESTART, STOP, KILL, waiting):
# for proper interrupts.
time.sleep(0.05)

engine = Engine(cpp_engine) #wrap the cpp engine in the python engine wrapper
#engine = DummyEngine(engine)
"""
Run the main bootstrapper loop! It's fun!
Expand All @@ -135,17 +136,18 @@ def start(entities, engine, RESTART, STOP, KILL, waiting):
game_objects = list()
print(entities)
"""Grab each entity in the entities list. Wrap them in the approperiate class :D (the classes defined in game)"""

for entity in entities:
game_object = wrap_entity_in_game_object(entity, engine)
game_object.initialise() #run the initialisation script on the object if anything needs to be initialised
game_objects.append(game_object)
engine.register_game_object(game_object)
engine.print_debug("Converted entity {} to game_object {}".format(entity, game_object))
engine.print_debug("whose name is {}".format(game_object.get_name()))

ScopedInterpreter = create_execution_scope(game_objects, engine, RESTART, STOP, KILL)
scoped_interpreter = ScopedInterpreter()

while True:
try:
script_filename = os.path.dirname(os.path.realpath(__file__)) + "/levels/{}/scripts/start.py".format(engine.get_level_location()); #TODO: implement this path stuff in a config (json) file!!!!!
Expand All @@ -156,9 +158,7 @@ def start(entities, engine, RESTART, STOP, KILL, waiting):


#entity.update_status("running"), all the update status stuff are from old version of bootstrapper TODO: work out what this should change to

scoped_interpreter.runcode(script)

#entity.update_status("finished")

except RESTART:
Expand All @@ -183,8 +183,9 @@ def start(entities, engine, RESTART, STOP, KILL, waiting):
# For all other errors, output and stop
except:
waiting = True
engine.print_terminal("Test",False);
#entity.update_status("failed")
engine.print_dialogue(traceback.format_exc());
engine.print_terminal(str(traceback.format_exc()),True);

else:
break
Binary file added game/engine/database.db
Binary file not shown.
118 changes: 118 additions & 0 deletions game/engine/engine.py
@@ -0,0 +1,118 @@

import sqlite3
import os

class Engine:
""" This class is a python wrapper for all the engine features that are exposed to the game.
As some features are implemented in python and some in C++, this consolidates both.
"""
#Represents the cplusplus engine
__cpp_engine = None
#A dictonary of all the game objects in the level (maps from object_id to object)
__game_objects = dict()

def getDialogue(self, identifier):
result = self.conn.execute("SELECT english, français, nederlands, hindi, pyrate FROM dialogue WHERE identifier=?;", (identifier, ))
row = result.fetchone()
dialogue = "invalid dialogue identifier" #TODO: Make it so that game complains much more about this in debug mode!!!!
if(row != None):
english, français, nederlands, hindi, pyrate = row
if(self.language == "english"):
dialogue = english
if(self.language == "français"):
dialogue = français
if(self.language == "nederlands"):
dialogue = nederlands
if(self.language == "hindi"):
dialogue = hindi
if(self.language == "pyrate"):
dialogue = pyrate
return dialogue

def __init__(self, cpp_engine):
#Database
#--------
self.all_languages = ["english", "français", "nederlands", "hindi", "pyrate"]
self.dblocation = os.path.dirname(os.path.realpath(__file__)) + "/database.db"
self.language = "english"
self.conn = sqlite3.connect(self.dblocation)
""" On initialisation, the cplusplus engine is passed to this class to enable it to access the api of the game.
Parameters
----------
cpp_engine : C++GameEngine
Represents an instance of the C++ engein. All of whom's properties are inherited by Engine
"""
self.__cpp_engine = cpp_engine
#Use some magic trickery to give the Engine class all the methods of the C++GameEngine with their functionality
engine_properties = [a for a in dir(self.__cpp_engine) if not a.startswith('__')] #get all the engine properties with the magic and private methods filtered out
for engine_property in engine_properties: #loop over all the engine properties
if not hasattr(self, engine_property): #only add the property if the engine doesn't have something by that name
setattr(self, engine_property, getattr(self.__cpp_engine, engine_property)) #set the all the properties of Engine to match cpp_engine.

def __del__(self):
self.conn.close()

def set_language(self, language_to_set):
if(language_to_set in self.all_languages):
self.language = language_to_set
else:
print("Not a valid language!")

def get_language(self):
return self.language

def register_game_object(self, game_object):
""" Register a game object.
Parmeters
---------
game_object : GameObject
The game object you wish to register
"""
self.__game_objects[game_object.get_id()] = game_object # associate each game_object with it's id

def get_objects_at(self, position):
""" Returns a list of all the objects at a given position
Overrides the get_objects_at method inherited from cpp engine, as that version returns a list of object ids and this returns
the actual instances.
Parameters
----------
position : 2-tuple of int
The position you want to check for the objects. (x, y)
Returns
-------
list of GameObject
returns a list of the objects at the given position
"""
x, y = position #Extract the position x and y coordinates
game_objects= list() #initialise the list that will be returned giving the objects at the position
object_ids = self.__cpp_engine.get_objects_at(x, y) #get a list of the ids of all the objects at the given position from the game engine
for object_id in object_ids: #iterate over all the object_ids and grab the object associated with each one.
game_objects.append(self.__game_objects[object_id])

#return a list of the objects at the given position
return game_objects

def print_terminal(self, message, highlighted = False):
""" print the given message to in-game terminal
Parameters
----------
message
the message that you wish to print (python will attempt to convert it to a string before printing if possible using the str() method)
highlighted : bool
if true the message is printed red, else it printed in black
"""
self.__cpp_engine.print_terminal(str(message), highlighted)






2 changes: 1 addition & 1 deletion game/game.py
Expand Up @@ -15,7 +15,7 @@ def getDialogue(identifier):
dialogue = "invalid dialogue identifier" #TODO: Make it so that game complains much more about this in debug mode!!!!
if(row != None):
english, français, nederlands, hindi, pyrate = row
dialogue = pyrate
dialogue = nederlands
conn.close()
return dialogue

Expand Down
3 changes: 0 additions & 3 deletions game/levels/test_world/new_challenge/main/scripts/start.py
Expand Up @@ -34,9 +34,6 @@
engine.add_button("gui/head/monkey", "Ben", player_one.focus)
engine.add_button("gui/head/monkey", "Rock1", boulder_one.focus)
engine.add_button("gui/head/monkey", "Rock2", boulder_two.focus)
engine.add_button("gui/head/monkey", "Rock3", boulder_three.focus)
engine.add_button("gui/head/monkey", "Rock4", boulder_four.focus)
engine.add_button("gui/head/monkey", "Rock5", boulder_five.focus)
engine.add_button("gui/head/monkey", "Portal", portal_one.focus)

engine.play_music("beach")
Expand Down
23 changes: 12 additions & 11 deletions game/levels/test_world/yingischallenged/main/layout.tmx
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" renderorder="right-down" width="41" height="21" tilewidth="64" tileheight="64" nextobjectid="25">
<map version="1.0" orientation="orthogonal" width="41" height="21" tilewidth="64" tileheight="64">
<tileset firstgid="1" name="water" tilewidth="64" tileheight="64">
<image source="../../../../tiles/water.png" width="320" height="1216"/>
</tileset>
Expand Down Expand Up @@ -46,15 +46,16 @@
eJxjYBgFo2BogqtEqLlGJXNGwSgYBSMLXBlg+y8PsP2jYBSQCgY6zQ50nh0Fo4AQAABaPwXP
</data>
</layer>
<objectgroup name="Object Layer 1">
<object id="11" name="portal/exit_portal" gid="293" x="2432" y="320" width="64" height="64"/>
<object id="13" name="coconut/coconut_two" gid="287" x="128" y="768" width="64" height="64"/>
<object id="14" name="coconut/coconut_three" gid="287" x="704" y="256" width="64" height="64"/>
<object id="15" name="coconut/coconut_four" gid="287" x="1280" y="256" width="64" height="64"/>
<object id="16" name="coconut/coconut_five" gid="287" x="1856" y="256" width="64" height="64"/>
<object id="17" name="coconut/coconut_six" gid="287" x="2368" y="768" width="64" height="64"/>
<object id="18" name="coconut/coconut_seven" gid="287" x="2368" y="1088" width="64" height="64"/>
<object id="19" name="coconut/coconut_one" gid="287" x="128" y="1088" width="64" height="64"/>
<object id="22" name="characters/player/player_one" gid="286" x="1278.24" y="905.25" width="64" height="64"/>
<objectgroup name="Object Layer 1" width="0" height="0">
<object name="portal/exit_portal" gid="293" x="2432" y="320" width="64" height="64"/>
<object name="coconut/coconut_two" gid="287" x="128" y="768" width="64" height="64"/>
<object name="coconut/coconut_three" gid="287" x="704" y="256" width="64" height="64"/>
<object name="coconut/coconut_four" gid="287" x="1280" y="256" width="64" height="64"/>
<object name="coconut/coconut_five" gid="287" x="1856" y="256" width="64" height="64"/>
<object name="coconut/coconut_six" gid="287" x="2368" y="768" width="64" height="64"/>
<object name="coconut/coconut_seven" gid="287" x="2368" y="1088" width="64" height="64"/>
<object name="coconut/coconut_one" gid="287" x="128" y="1088" width="64" height="64"/>
<object name="characters/player/player_one" gid="286" x="1152" y="960" width="64" height="64"/>
<object name="characters/player/player_two" gid="286" x="1280" y="960" width="64" height="64"/>
</objectgroup>
</map>
35 changes: 34 additions & 1 deletion game/levels/test_world/yingischallenged/main/scripts/start.py
@@ -1,6 +1,8 @@
""" Load in saved states """

player_one.focus()
player_one.set_character_name("Benjo")
player_two.set_character_name("That Annoying Kid from Up")
engine.print_terminal(str(player_one._GameObject__entity.get_number_of_animation_frames()), False)

coconut_one.set_weight(1)
Expand All @@ -11,6 +13,37 @@
coconut_six.set_weight(32)
coconut_seven.set_weight(64)

engine.print_terminal(str(coconut_seven.get_weight()), False)
coconut_one.set_solidity(False);

engine.print_terminal(coconut_one.get_weight(), False)

engine.play_music("beach")
engine.get_objects_at((7, 2))
engine.get_objects_at((4, 4))
engine.get_objects_at((5, 4))
engine.get_objects_at((6, 4))
engine.get_objects_at((1, 1))
engine.get_objects_at((7, 4))
engine.get_objects_at((8, 4))
engine.get_objects_at((9, 4))
engine.get_objects_at(player_one.get_position())

engine.add_button("gui/head/monkey", player_one.get_character_name(), player_one.focus)
engine.add_button("gui/head/monkey", player_two.get_character_name(), player_two.focus)
"""
engine.add_button("gui/head/monkey", "Rock1", coconut_one.focus)
engine.add_button("gui/head/monkey", "Rock2", coconut_two.focus)
engine.add_button("gui/head/monkey", "Rock3", coconut_three.focus)
engine.add_button("gui/head/monkey", "Rock4", coconut_four.focus)
engine.add_button("gui/head/monkey", "Rock5", coconut_five.focus)
engine.add_button("gui/head/monkey", "Rock6", coconut_six.focus)
engine.add_button("gui/head/monkey", "Rock7", coconut_seven.focus)
engine.add_button("gui/head/monkey", "Portal", exit_portal.focus)
"""
engine.print_terminal(player_one.get_position(), False)

engine.print_terminal(engine.getDialogue("welcome"))
engine.set_language("français")
engine.print_terminal(engine.getDialogue("welcome"))
engine.set_language("hindi")
engine.print_terminal(engine.getDialogue("welcome"))

0 comments on commit bc6dd7d

Please sign in to comment.