Skip to content

Commit

Permalink
add sound and music support, add various keyid forks
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasTheSpaceFox committed Feb 10, 2017
1 parent 14b3b14 commit eb169a0
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 26 deletions.
Binary file added BGM1.ogg
Binary file not shown.
9 changes: 6 additions & 3 deletions DOCS/overview.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
Desutezeoid Technical Documentation.
Overview:
Desutezeoid v1.0.1
(c) 2015-2016 Thomas Leathers
Desutezeoid v1.1.0
(c) 2015-2017 Thomas Leathers


-Desutezeoid is an arbitrary point and click engine written in python and pygame. It is designed to be driven using a series of xml files. Each "screen" is an xml file.

-The engine uses a boolean "keyid" and "forking" scripting structure that is parsed each code cycle.


/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
programmer note: see comments in included example xml pages. especially "test0.xml"
this documentation is not exactly done yet.
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
index:

page format:
Expand Down
2 changes: 1 addition & 1 deletion DOCS/page_xml_format.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ example with notes. this is based on the test pages.
<con>QUIT</con>
<act type="quit" ref="test1.xml"/> special engine quit type note how ref still is present
</label>
<!--a nice tiggle example is shown in the next two.
<!--a nice toggle example is shown in the next two.
<label x="150" y="230" size="24" BGCOLOR="#880000" FGCOLOR="#FFFFFF" keyid="switch2" offkey="switch2">
<con>(off)</con>
<act type="key" ref="test1.xml"/>
Expand Down
Binary file modified DOCS/screenshot0.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
94 changes: 79 additions & 15 deletions DZU-ENG1.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
import xml.etree.ElementTree as ET
pygame.display.init()
pygame.font.init()
print "Desutezeoid arbitrary point and click engine v1.0.1"
pygame.mixer.init()
print "Desutezeoid arbitrary point and click engine v1.1.0"
conftree = ET.parse("ENGSYSTEM.xml")
confroot = conftree.getroot()
screentag=confroot.find("screen")
Expand All @@ -21,21 +22,26 @@
beginref=(confroot.find("beginref")).text
titlebase=titletag.attrib.get("base", "Desutezeoid: ")
class clicktab:
def __init__(self, box, reftype, ref, keyid, takekey):
def __init__(self, box, reftype, ref, keyid, takekey, sfxclick, sound):
self.box=box
self.ref=ref
self.keyid=keyid
self.takekey=takekey
self.reftype=reftype
self.sfxclick=sfxclick
self.sound=sound
class timeouttab:
def __init__(self, seconds, keyid):
self.keyid=keyid
self.regtime=time.time()
self.seconds=seconds
DEBUG=1

def debugmsg(msg, printplaypos=0):
#class keyobj:
# def __init__(self, keyid):
# self=keyid
def debugmsg(msg):
if DEBUG==1:

if printplaypos==1:
print (msg + " x(" + str(playx) + "),y(" + str(playy) + ")")
else:
print msg
print msg
prevpage="NULL"
#point this to your first screen c: no menu program really needed :o
curpage=beginref
Expand All @@ -44,6 +50,7 @@ def debugmsg(msg, printplaypos=0):
quitflag=0
clicklist=list()
keylist=list(["0"])
timeoutlist=list()
keybak=list(keylist)
forksanitycheck=0
forksanity=0
Expand All @@ -55,6 +62,7 @@ def debugmsg(msg, printplaypos=0):
#print "tic"
if curpage!=prevpage:
print "preparsing page"
pygame.mixer.music.stop()
tree = ET.parse(curpage)
root = tree.getroot()
prevpage=curpage
Expand All @@ -63,6 +71,11 @@ def debugmsg(msg, printplaypos=0):
pageconf=root.find('pageconf')
pagetitle=(pageconf.find('title')).text
BGon=int(pageconf.attrib.get("BGimg", "0"))
BGMon=int(pageconf.attrib.get("BGM", "0"))
if BGMon==1:
BGMtrack=(pageconf.find('BGM')).text
pygame.mixer.music.load(BGMtrack)
pygame.mixer.music.play(-1)
pygame.display.set_caption((titlebase + pagetitle), (titlebase + pagetitle))
print ("Page title: '" + pagetitle + "'")
if BGon==1:
Expand Down Expand Up @@ -131,13 +144,51 @@ def debugmsg(msg, printplaypos=0):
keylist.remove(subkeyid)
print keylist
forksanity=1
for fork in forktag.findall("timeout"):
masterkey=fork.attrib.get("keyid")
if masterkey in keylist:
notinlist=1
for tif in timeoutlist:
if tif.keyid==masterkey:
notinlist=0
if notinlist==1:
seconds=float(fork.attrib.get("seconds"))
timeoutlist.extend([timeouttab(seconds, masterkey)])
for fork in forktag.findall("triggerlock"):
masterkey=fork.attrib.get("keyid")
triggerkey=fork.attrib.get("trigger")
lockkey=fork.attrib.get("lock")
if masterkey in keylist:
#keylist.remove(masterkey)
if lockkey not in keylist:
if triggerkey not in keylist:
keylist.extend([triggerkey])
keylist.extend([lockkey])


for fork in forktag.findall("sound"):
masterkey=fork.attrib.get("keyid")
soundname=fork.attrib.get("sound")
if masterkey in keylist:
keylist.remove(masterkey)
soundobj=pygame.mixer.Sound(soundname)
soundobj.play()
if forksanity==1:
forksanitycheck=1
forksanity=0
#skiploop=1
else:
forksanitycheck=0

for tif in timeoutlist:
if tif.keyid not in keylist:

timeoutlist.remove(tif)
elif ((time.time()) - tif.regtime) > tif.seconds:
keylist.remove(tif.keyid)
print keylist
timeoutlist.remove(tif)

keybak=list(keylist)
#print keylist
for labref in coretag.findall("img"):
Expand All @@ -146,6 +197,8 @@ def debugmsg(msg, printplaypos=0):
onkey=labref.attrib.get('onkey', "0")
offkey=labref.attrib.get('offkey', "0")
hoverkey=labref.attrib.get('hoverkey', "0")
clicksoundflg=int(labref.attrib.get('sfxclick', "0"))
soundname=(labref.attrib.get('sound', "0"))
if ((onkey=="0" and offkey=="0") or (onkey=="0" and offkey not in keylist) or (onkey in keylist and offkey=="0") or (onkey in keylist and offkey not in keylist)):
imgx=int(labref.attrib.get("x"))
imgy=int(labref.attrib.get("y"))
Expand Down Expand Up @@ -178,7 +231,7 @@ def debugmsg(msg, printplaypos=0):
#if clickref.collidepoint(pos)==1 and (pygame.mouse.get_pressed()[0])==1:
# curpage=ref
# break
datstr=clicktab(clickref, "iref", ref, keyid, takekey)
datstr=clicktab(clickref, "iref", ref, keyid, takekey, clicksoundflg, soundname)
clicklist.extend([datstr])
if acttype=="quit":
ref=act.attrib.get("ref")
Expand All @@ -187,7 +240,7 @@ def debugmsg(msg, printplaypos=0):
#if clickref.collidepoint(pos)==1 and (pygame.mouse.get_pressed()[0])==1:
# quitflag=1
# break
datstr=clicktab(clickref, "quit", ref, keyid, takekey)
datstr=clicktab(clickref, "quit", ref, keyid, takekey, clicksoundflg, soundname)
clicklist.extend([datstr])
if acttype=="key":
ref=act.attrib.get("ref")
Expand All @@ -196,14 +249,16 @@ def debugmsg(msg, printplaypos=0):
#if clickref.collidepoint(pos)==1 and (pygame.mouse.get_pressed()[0])==1:
# quitflag=1
# break
datstr=clicktab(clickref, "key", ref, keyid, takekey)
datstr=clicktab(clickref, "key", ref, keyid, takekey, clicksoundflg, soundname)
clicklist.extend([datstr])
for labref in coretag.findall("label"):
keyid=labref.attrib.get('keyid', "0")
takekey=labref.attrib.get('takekey', "0")
onkey=labref.attrib.get('onkey', "0")
offkey=labref.attrib.get('offkey', "0")
hoverkey=labref.attrib.get('hoverkey', "0")
clicksoundflg=int(labref.attrib.get('sfxclick', "0"))
soundname=(labref.attrib.get('sound', "0"))
if ((onkey=="0" and offkey=="0") or (onkey=="0" and offkey not in keylist) or (onkey in keylist and offkey=="0") or (onkey in keylist and offkey not in keylist)):
labx=int(labref.attrib.get("x"))
laby=int(labref.attrib.get("y"))
Expand Down Expand Up @@ -236,7 +291,7 @@ def debugmsg(msg, printplaypos=0):
#if clickref.collidepoint(pos)==1 and (pygame.mouse.get_pressed()[0])==1:
# curpage=ref
# break
datstr=clicktab(clickref, "iref", ref, keyid, takekey)
datstr=clicktab(clickref, "iref", ref, keyid, takekey, clicksoundflg, soundname)
clicklist.extend([datstr])
if acttype=="quit":
ref=act.attrib.get("ref")
Expand All @@ -245,7 +300,7 @@ def debugmsg(msg, printplaypos=0):
#if clickref.collidepoint(pos)==1 and (pygame.mouse.get_pressed()[0])==1:
# quitflag=1
# break
datstr=clicktab(clickref, "quit", ref, keyid, takekey)
datstr=clicktab(clickref, "quit", ref, keyid, takekey, clicksoundflg, soundname)
clicklist.extend([datstr])
if acttype=="key":
ref=act.attrib.get("ref")
Expand All @@ -254,12 +309,14 @@ def debugmsg(msg, printplaypos=0):
#if clickref.collidepoint(pos)==1 and (pygame.mouse.get_pressed()[0])==1:
# quitflag=1
# break
datstr=clicktab(clickref, "key", ref, keyid, takekey)
datstr=clicktab(clickref, "key", ref, keyid, takekey, clicksoundflg, soundname)
clicklist.extend([datstr])
#else:
#time.sleep(0.04)
eventhappen=0
for event in pygame.event.get():
#print "nominal"
eventhappen=1
if event.type == QUIT:
quitflag=1
print ("quit: OS or WM quit")
Expand All @@ -269,6 +326,9 @@ def debugmsg(msg, printplaypos=0):
for f in clicklist:
#print "nominal3"
if f.box.collidepoint(event.pos)==1 and event.button==1:
if f.sfxclick==1:
clicksound=pygame.mixer.Sound(f.sound)
clicksound.play()
if f.keyid!="0":
if not f.keyid in keylist:
keylist.extend([f.keyid])
Expand All @@ -285,6 +345,10 @@ def debugmsg(msg, printplaypos=0):
print ("quit: onclick quit")
quitflag=1
break
if eventhappen==0:
time.sleep(0.1)


pygame.display.update()
pygame.event.pump()
pygame.event.clear()
Expand Down
2 changes: 1 addition & 1 deletion ENGSYSTEM.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<conf>
<screen x="800" y="600"/>
<title base="Desutezeoid v1.0 test program." />
<title base="Desutezeoid v1.1.0 test program. " />
<beginref>test0.xml</beginref>
</conf>
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Desutezeoid
v1.0
v1.1.0
an arbitrary point and click engine.
(c) 2015-2016 Thomas Leathers
(c) 2015-2017 Thomas Leathers


Desutezeoid is free software: you can redistribute it and/or modify
Expand Down
Binary file added mip.ogg
Binary file not shown.
40 changes: 36 additions & 4 deletions test0.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<main>
<pageconf BGimg="1">
<pageconf BGimg="1" BGM="1">
<title>Main Page</title>
<BG>BGseaside.jpg</BG>
<BGM>BGM1.ogg</BGM>
</pageconf>
<forks>
<batchtrig keyid="alpha">
Expand All @@ -17,14 +18,27 @@
<k if="1" keyid="switch1"/>
<k if="1" keyid="switch2"/>
</batchtrig>
<!--notice how this trigger lock triggers a sound event. note how the
lock keyid prevents the trigger keyid from re-triggering, thus the sound
triggered by the two toggle switches being on plays only once, and only the
first time those toggle switches are in that state.-->
<triggerlock keyid="alpha3" lock="soundfx1lock1" trigger="soundfx1"/>
<sound keyid="soundfx1" sound="mip.ogg"/>
<batchset keyid="predelta" set="1">
<k keyid="thisisatest1"/>
<k keyid="thisisatest2"/>
<k keyid="thisisatest3"/>
<k keyid="delta"/>
</batchset>
<!-- did you notice that label that says "timer" triggers a label that has a dissapearing act?
here is how that works. after the seconds specified in "seconds" lapses, the keyid specified is removed.
but only after the keyid is present will the countdown begin. it is safe to remove a keyid when it has a
timeout fork associated with it. as the timeout instance in question will be removed automatically.
The timeout instance is also removed after the specified time lapses.-->
<timeout keyid="prototime" seconds="3.5"/>
</forks>
<core>
<!--note the "hoverkey" attribute. this toggles in and out of the keyidlist based on wether the curser is over the label/img instance. this one triggers a label further down.-->
<label x="300" y="400" size="40" transp="1" FGCOLOR="#FFFFFF" hoverkey="onhov2">
<con>Hello world! :D</con>
<act type="none"/>
Expand All @@ -33,6 +47,12 @@
<con>Hey... an on-hover event. :o</con>
<act type="none"/>
</label>
<!--this is the label thats triggered by that timeout fork-->
<label x="80" y="150" size="24" transp="1" FGCOLOR="#000000" onkey="prototime">
<con>this should dissapear in 3.5 seconds</con>
<act type="none"/>
</label>
<!--here we have the label thats triggered in the hoverkey example above.-->
<label x="300" y="450" size="24" transp="1" FGCOLOR="#000000" onkey="onhov2">
<con>Hey... an on-hover event. :o</con>
<act type="none"/>
Expand All @@ -49,6 +69,15 @@
<con>or here!</con>
<act type="iref" ref="test1.xml"/>
</label>
<!--this is the label that triggeres that timeout fork.-->
<label x="0" y="180" size="24" BGCOLOR="#000088" FGCOLOR="#FFFFFF" keyid="prototime">
<con>timer (click me!)</con>
<act type="key" ref="test1.xml"/>
</label>
<!--take note how these toggle switches work.
see how, in each toggle switch, the "keyid" and "offkey" atributes in the "(off)" labels
and the "takekey" and "onkey" in the "(on)" labels all have the same keyid.
thats why only one label per switch, is visible at a time.-->
<label x="100" y="230" size="24" BGCOLOR="#880000" FGCOLOR="#FFFFFF" keyid="switch1" offkey="switch1">
<con>(off)</con>
<act type="key" ref="test1.xml"/>
Expand Down Expand Up @@ -77,9 +106,12 @@
<con>Greetings!</con>
<act type="key" ref="test1.xml"/>
</label>
<label x="0" y="0" size="12">
<con>Hello world! :D</con>
<act type="none"/>
<!--this next label instance uses an "onclick" sound fx. img instances can also do this
do note that setting the act type to "none" will cause the sound to not play.
plese use either "iref" or "key"-->
<label x="0" y="0" size="16" sfxclick="1" sound="mip.ogg">
<con>click me for a sound fx!</con>
<act type="key"/>
</label>
<label x="0" y="580" size="20" BGCOLOR="#880000" FGCOLOR="#FFFFFF" >
<con>QUIT</con>
Expand Down

0 comments on commit eb169a0

Please sign in to comment.