diff --git a/.gitignore b/.gitignore
index 29a96fe..360c87d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -24,3 +24,6 @@ website/
#the release
release/
+
+#The website
+website/
diff --git a/documentation/API/app.txt b/documentation/API/app.md
similarity index 100%
rename from documentation/API/app.txt
rename to documentation/API/app.md
diff --git a/documentation/basic/index.html b/documentation/basic/index.html
index 385e998..e564863 100644
--- a/documentation/basic/index.html
+++ b/documentation/basic/index.html
@@ -9,8 +9,8 @@
chapters
lesson 3: but what if
lesson 4: wait, is that math?
lesson 5: No, I didn't say my jewels
-lesson 6: game1
-lesson 7: balista!
+lesson 6: balista!
+lesson 7: game1
lesson 8: dict ... hey! get your mind out of the gutter!
lesson 9: shhh, it's classified
diff --git a/documentation/basic/index.txt b/documentation/basic/index.md
similarity index 96%
rename from documentation/basic/index.txt
rename to documentation/basic/index.md
index 5006821..f9b308a 100644
--- a/documentation/basic/index.txt
+++ b/documentation/basic/index.md
@@ -9,8 +9,8 @@
[lesson 3: but what if](lesson3.html)
[lesson 4: wait, is that math?](lesson4.html)
[lesson 5: No, I didn't say my jewels](lesson5.html)
-[lesson 6: game1](lesson6.html)
-[lesson 7: balista!](lesson7.html)
+[lesson 6: balista!](lesson6.html)
+[lesson 7: game1](lesson7.html)
[lesson 8: dict ... hey! get your mind out of the gutter!](lesson8.html)
[lesson 9: shhh, it's classified](lesson9.html)
diff --git a/documentation/basic/lesson4.html b/documentation/basic/lesson4.html
new file mode 100644
index 0000000..2df6284
--- /dev/null
+++ b/documentation/basic/lesson4.html
@@ -0,0 +1,199 @@
+Lesson 4: wait, is that math? -- Basic Tutorial
+
+Back to Index
+
+
+
+code
+
+#ATTACK!!!
+import pyaudiogame
+spk = pyaudiogame.speak
+MyApp = pyaudiogame.App("My Application")
+
+#Lets create a storage box so we can put our draggon's hp in there
+storage = pyaudiogame.cash
+
+#Now lets make our draggon's hp in the storage
+storage.dragon_hp = 100
+
+#Now lets make our hero's hit strength
+hero_hit = 10
+
+#An attack function
+def attack():
+ #When the hero attacks he takes the dragon's hp
+ storage.dragon_hp = storage.dragon_hp - hero_hit
+
+#Now lets make a way for our hero to attack
+def logic(actions):
+ key = actions['key']
+ if key == "space" and storage.dragon_hp > 0:
+ attack()
+ spk("You, the hero of our tail swing your sword. You hit the dragon for %s damage! Now our poor dragon has %s hp left" % (hero_hit, storage.dragon_hp))
+ if storage.dragon_hp <= 0:
+ spk("You, the hero of our story killed the dragon. The whole town thanks you!")
+ spk("Press escape to go back home")
+
+MyApp.logic = logic
+MyApp.run()
+
+
+What you should see
+
+Press space and you should hear:
+"You, the hero of our tail swing your sword. You hit the dragon for 10 damage! Now our poor dragon has 90 hp left"
+hit space again and you hear
+"You, the hero of our tail swing your sword. You hit the dragon for 10 damage! Now our poor dragon has 80 hp left"
+Hit space 8 more times and you will hear:
+"You, the hero of our tail swing your sword. You hit the dragon for 10 damage! Now our poor dragon has 0 hp left"
+"You, the hero of our story killed the dragon. The whole town thanks you!"
+"Press escape to go back home"
+
+What just happened?
+
+Lets go through the code line by line:
+
+#ATTACK!!!
+import pyaudiogame
+spk = pyaudiogame.speak
+MyApp = pyaudiogame.App("My Application")
+
+
+These are just the normal magical lines we have had all throughout.
+
+#Lets create a storage box so we can put our draggon's hp in there
+storage = pyaudiogame.cash
+
+
+pyaudiogame has a module for storing data. That probably makes no sense right now, but in the next few lessons you will learn all about this. Just know that after writing this line, you can store variables in storage. People may say something about "global" variables and those are used, but this way is more "pythonic" and safer as there is no way you will mistake storage.dragon_hp
for anything except for what it is. In pyaudiogame.cash there is also some features for saving data from one session to the next you will learn about later.
+
+#Now lets make our draggon's hp in the storage
+storage.dragon_hp = 100
+
+
+Here is how we store our variable that we will be accessing later in the program. You can store any variable in storage, it is just like what we do with normal variables, but we can change this variable.
+
+#Now lets make our hero's hit strength
+hero_hit = 10
+
+
+This is a variable we've seen before. Here is another term: "constant" The hero_hit will not be changed throughout the life of our program, so it is called a "constant variable".
+
+#An attack function
+def attack():
+ #When the hero attacks he takes the dragon's hp
+ storage.dragon_hp = storage.dragon_hp - hero_hit
+
+
+Here is what seperates a constant from a variable in storage. The variable in storage can be added to or subtracted or changed completely where as the constant must stay the same. Go ahead and try to make dragon_hp
a constant and run the program. Do you see that error? It is saying that there is no variable named dragon_hp
even though you wrote it right above. This is because there is a thing in python called a "namespace". This means that a file has a namespace and a function has its own namespace. The function can see the file's namespace, but only on a read-only basis. The file can't see the function's namespace at all.
+This is to help you keep your program organized and easy to read. It also allows for great functionality when you start writing your game in many files (what we will go over later).
+
+#Now lets make a way for our hero to attack
+def logic(actions):
+ key = actions['key']
+ if key == "space" and storage.dragon_hp > 0:
+ attack()
+ spk("You, the hero of our tail swing your sword. You hit the dragon for %s damage! Now our poor dragon has %s hp left" % (hero_hit, storage.dragon_hp))
+ if storage.dragon_hp <= 0:
+ spk("You, the hero of our story killed the dragon. The whole town thanks you!")
+ spk("Press escape to go back home")
+
+
+Here we are using 2 if statements. 1 will remove hp and run the attack function if the dragon's hp is above 0. The other if statement will run only if the dragon's hp is 0 or below.
+
+MyApp.logic = logic
+MyApp.run()
+
+
+Our last two magic statements. But notice that MyApp.logic, MyApp.run() and pyaudiogame.cash look the same. They are all methods of storage. You can save functions into storage by just treating them like variables and using them without the (). So go ahead and change it so that all the code accesses attack from storage.attack(). Look at these last two lines if you don't know how to get attack into storage.
+
+Changing variables
+
+One of the pillars of programming is the ability to change variables. You can do this with several operators:
+
+
+
++ |
+Adds together variables |
+
+
+- |
+subtracts variables from one another |
+
+
+* |
+multiplies variables together |
+
+
+/ |
+divides variables by one another |
+
+
+% |
+Will give the remaindor of 2 variables divided together |
+
+
+** |
+Finds to the power of |
+
+
+
+Along with the above you can combine = with +-*/
to get something that looks like x += y. This is short-hand for writing:
+x = x + y
+Short-hand:
+x += y
+
+Types
+
+Variables are classified into several types. There are 4 that people run into all the time:
+string (str)
+intiger (int)
+float (float)
+bool (bool)
+We looked at strings the first lesson. They are characters like what you are reading now, but between quotes.
+string1 = "This is a string"
+Intigers are any number that is not in a quote.
+num = 10
+floating-point numbers are numbers with a point:
+float1 = 2.789
+A bool is what we looked at in the last lesson, it is a True or False value:
+bool1 = False
+You can use the operators on ints, floats and strings. Ints and floats can be combined to create a float, but strings can only be added to other strings or multiplied by ints. Bools can't be combined with anything.
+
+string formatting
+
+Strings have this nice feature called "string formatting" that allows us to insert variables of other types into a string. There is a huge list of string formatting commands, but the one that is most used is:
+%s
+This converts all variables to a string. Here is an example:
+
+age = 10
+weight = 100.35
+name = "Fred"
+"%s is %s years old and has a weight of %s lbs" % (name, age, weight)
+
+"Hello, I am %s" % name
+
+"If you are %s pounds, I'll pull you out of that bed so we can go walking %s Greggery James!" % (weight, name)
+
+
+If you inserted the lines with quotes into spk(), they will run just fine.
+
+assignment
+
+
+- Change the attack function so it is stored in storage and called out of storage.
+- Go through the last example and above each variable, write what type it is.
+- Add a level variable, name variable and hp variable to our hero and anounce them.
+- Convert all the long-hand addition and subtraction we used in the above code to the short-hand. People never use the long-hand code, so get used to using x -= y.
+- Go read up on namespaces in python.
+
+
+Extra credit
+
+
+- Go read about string formatting. See what the difference is between .format and
%s
. Also see what all the different types are. Also find why people would use the other %
characters and not just stick to %s
when %s
works all the time.
+- Make the dragon attack and take hp away from our hero.
+- Add a key to check the health of the hero
+- Add some messages as the dragon reaches a sertan amount of hp, explaining what the dragon is doing.
+
diff --git a/documentation/basic/lesson4.md b/documentation/basic/lesson4.md
new file mode 100644
index 0000000..ea0de12
--- /dev/null
+++ b/documentation/basic/lesson4.md
@@ -0,0 +1,177 @@
+Lesson 4: wait, is that math? -- Basic Tutorial
+
+[Back to Index](index.html)
+
+__________
+
+#code
+
+ #ATTACK!!!
+ import pyaudiogame
+ spk = pyaudiogame.speak
+ MyApp = pyaudiogame.App("My Application")
+
+ #Lets create a storage box so we can put our draggon's hp in there
+ storage = pyaudiogame.cash
+
+ #Now lets make our draggon's hp in the storage
+ storage.dragon_hp = 100
+
+ #Now lets make our hero's hit strength
+ hero_hit = 10
+
+ #An attack function
+ def attack():
+ #When the hero attacks he takes the dragon's hp
+ storage.dragon_hp = storage.dragon_hp - hero_hit
+
+ #Now lets make a way for our hero to attack
+ def logic(actions):
+ key = actions['key']
+ if key == "space" and storage.dragon_hp > 0:
+ attack()
+ spk("You, the hero of our tail swing your sword. You hit the dragon for %s damage! Now our poor dragon has %s hp left" % (hero_hit, storage.dragon_hp))
+ if storage.dragon_hp <= 0:
+ spk("You, the hero of our story killed the dragon. The whole town thanks you!")
+ spk("Press escape to go back home")
+
+ MyApp.logic = logic
+ MyApp.run()
+
+#What you should see
+Press space and you should hear:
+"You, the hero of our tail swing your sword. You hit the dragon for 10 damage! Now our poor dragon has 90 hp left"
+hit space again and you hear
+"You, the hero of our tail swing your sword. You hit the dragon for 10 damage! Now our poor dragon has 80 hp left"
+Hit space 8 more times and you will hear:
+"You, the hero of our tail swing your sword. You hit the dragon for 10 damage! Now our poor dragon has 0 hp left"
+"You, the hero of our story killed the dragon. The whole town thanks you!"
+"Press escape to go back home"
+
+#What just happened?
+Lets go through the code line by line:
+
+ #ATTACK!!!
+ import pyaudiogame
+ spk = pyaudiogame.speak
+ MyApp = pyaudiogame.App("My Application")
+
+These are just the normal magical lines we have had all throughout.
+
+ #Lets create a storage box so we can put our draggon's hp in there
+ storage = pyaudiogame.cash
+
+pyaudiogame has a module for storing data. That probably makes no sense right now, but in the next few lessons you will learn all about this. Just know that after writing this line, you can store variables in storage. People may say something about "global" variables and those are used, but this way is more "pythonic" and safer as there is no way you will mistake `storage.dragon_hp` for anything except for what it is. In pyaudiogame.cash there is also some features for saving data from one session to the next you will learn about later.
+
+ #Now lets make our draggon's hp in the storage
+ storage.dragon_hp = 100
+
+Here is how we store our variable that we will be accessing later in the program. You can store any variable in storage, it is just like what we do with normal variables, but we can change this variable.
+
+ #Now lets make our hero's hit strength
+ hero_hit = 10
+
+This is a variable we've seen before. Here is another term: "constant" The hero_hit will not be changed throughout the life of our program, so it is called a "constant variable".
+
+ #An attack function
+ def attack():
+ #When the hero attacks he takes the dragon's hp
+ storage.dragon_hp = storage.dragon_hp - hero_hit
+
+Here is what seperates a constant from a variable in storage. The variable in storage can be added to or subtracted or changed completely where as the constant must stay the same. Go ahead and try to make `dragon_hp` a constant and run the program. Do you see that error? It is saying that there is no variable named `dragon_hp` even though you wrote it right above. This is because there is a thing in python called a "namespace". This means that a file has a namespace and a function has its own namespace. The function can see the file's namespace, but only on a read-only basis. The file can't see the function's namespace at all.
+This is to help you keep your program organized and easy to read. It also allows for great functionality when you start writing your game in many files (what we will go over later).
+
+ #Now lets make a way for our hero to attack
+ def logic(actions):
+ key = actions['key']
+ if key == "space" and storage.dragon_hp > 0:
+ attack()
+ spk("You, the hero of our tail swing your sword. You hit the dragon for %s damage! Now our poor dragon has %s hp left" % (hero_hit, storage.dragon_hp))
+ if storage.dragon_hp <= 0:
+ spk("You, the hero of our story killed the dragon. The whole town thanks you!")
+ spk("Press escape to go back home")
+
+Here we are using 2 if statements. 1 will remove hp and run the attack function if the dragon's hp is above 0. The other if statement will run only if the dragon's hp is 0 or below.
+
+ MyApp.logic = logic
+ MyApp.run()
+
+Our last two magic statements. But notice that MyApp.logic, MyApp.run() and pyaudiogame.cash look the same. They are all methods of storage. You can save functions into storage by just treating them like variables and using them without the (). So go ahead and change it so that all the code accesses attack from storage.attack(). Look at these last two lines if you don't know how to get attack into storage.
+##Changing variables
+One of the pillars of programming is the ability to change variables. You can do this with several operators:
+
+
+
++ |
+Adds together variables |
+
+
+- |
+subtracts variables from one another |
+
+
+* |
+multiplies variables together |
+
+
+/ |
+divides variables by one another |
+
+
+% |
+Will give the remaindor of 2 variables divided together |
+
+
+** |
+Finds to the power of |
+
+
+
+Along with the above you can combine = with `+-*/` to get something that looks like x += y. This is short-hand for writing:
+x = x + y
+Short-hand:
+x += y
+##Types
+Variables are classified into several types. There are 4 that people run into all the time:
+string (str)
+intiger (int)
+float (float)
+bool (bool)
+We looked at strings the first lesson. They are characters like what you are reading now, but between quotes.
+string1 = "This is a string"
+Intigers are any number that is not in a quote.
+num = 10
+floating-point numbers are numbers with a point:
+float1 = 2.789
+A bool is what we looked at in the last lesson, it is a True or False value:
+bool1 = False
+You can use the operators on ints, floats and strings. Ints and floats can be combined to create a float, but strings can only be added to other strings or multiplied by ints. Bools can't be combined with anything.
+##string formatting
+Strings have this nice feature called "string formatting" that allows us to insert variables of other types into a string. There is a huge list of string formatting commands, but the one that is most used is:
+`%s`
+This converts all variables to a string. Here is an example:
+
+
+ age = 10
+ weight = 100.35
+ name = "Fred"
+ "%s is %s years old and has a weight of %s lbs" % (name, age, weight)
+
+ "Hello, I am %s" % name
+
+ "If you are %s pounds, I'll pull you out of that bed so we can go walking %s Greggery James!" % (weight, name)
+
+
+If you inserted the lines with quotes into spk(), they will run just fine.
+#assignment
+1. Change the attack function so it is stored in storage and called out of storage.
+2. Go through the last example and above each variable, write what type it is.
+3. Add a level variable, name variable and hp variable to our hero and anounce them.
+4. Convert all the long-hand addition and subtraction we used in the above code to the short-hand. People never use the long-hand code, so get used to using x -= y.
+5. Go read up on namespaces in python.
+
+#Extra credit
+1. Go read about string formatting. See what the difference is between .format and `%s`. Also see what all the different types are. Also find why people would use the other `%` characters and not just stick to `%s` when `%s` works all the time.
+2. Make the dragon attack and take hp away from our hero.
+3. Add a key to check the health of the hero
+4. Add some messages as the dragon reaches a sertan amount of hp, explaining what the dragon is doing.
diff --git a/documentation/basic/lesson5.html b/documentation/basic/lesson5.html
new file mode 100644
index 0000000..689bd57
--- /dev/null
+++ b/documentation/basic/lesson5.html
@@ -0,0 +1,142 @@
+lesson 5: No, I didn't say my jewels -- Basic Tutorial
+
+Back to Index
+
+The module
+
+So just like with everything else, programmers like to shroud their craft with fancy words for things that probably don't need it.
+Module is one of these words.
+What is a module? A module is another file with code in it that you can use in your script. Why not call it a file? Because a file doesn't have code in it...
+So we call files with code in them modules.
+The module is something that python is particularly good at. You group functions and tasks into modules so you can manage and read your code better.
+
+How to use a module
+
+You call the module's functions or add the module to your namespace by doing two different things:
+For most things, it is best to always do the first as it will make your code cleaner in the end if you choose to use a lot of different functions from the imported module. The first is:
+import moduleName
+This will bring that moduleName into your current module so you can type
+moduleName.function()
+to run a function inside that module.
+The second way is only used if you are only using one function from a module. There is no real speed difference, it just takes up a name in your module's namespace. It is:
+from moduleName import function
+That way you can type:
+function()
+just as if you created it in your current module.
+The next example needs you to make 2 files. Name one
+ex5.py
+and the other
+ex5_1.py
+
+code for ex5_1.py
+
+#My first module!
+from pyaudiogame import speak as spk
+
+def func():
+ spk("This is the ex5_1 module!!! Hello world!!!")
+
+
+code for ex5.py
+
+#fraught with possibility
+import pyaudiogame
+import random
+import ex5_1
+spk = pyaudiogame.speak
+MyApp = pyaudiogame.App("My Application")
+
+def logic(actions):
+ key = actions['key']
+ if key == "space":
+ ex5_1.func()
+ elif key == "return":
+ spk("Your random number is: %s!" % random.randint(1,10))
+
+MyApp.logic = logic
+MyApp.run()
+
+
+What you should see
+
+When you press space you should hear:
+"This is the ex5_1 module!!! Hello world!!!"
+If you press return you should hear:
+"Your random number is: %s!"
+Where %s
is a random number.
+
+Built-in modules
+
+Python has something called The
+Python Standard Library
+Which is a group of modules that every python instilation comes with. These include a random module for generating random numbers, a time module for dealing with dates and time, a sys module with functions that deal with the computer, os which has functions to tell info about the current operating system, a math module with more complex math functions and somewhere around 100 modules filled with functions.
+In general, if you find that there is a built-in way of doing something, it will be faster for you to use that way than to write your own code for doing the same thing. Always google to see if you can already do something in python before trying to make it yourself.
+
+What is going on in our code
+
+ex5_1.py
+
+#My first module!
+from pyaudiogame import speak as spk
+
+
+Here we are using the second type of importing with a little fancy keyword:
+from pyaudiogame import speak as spk
+Instead of typing
+speak("text to speak")
+we are saying that we wish the variable spk to be assigned to speak. That way we have a free speak variable and because spk is something that is typed a lot, we can save our fingers the trouble of typing a 5 letter word. Just put that "as" keyword after the module name and then the new name.
+
+def func():
+ spk("This is the ex5_1 module!!! Hello world!!!")
+
+
+This is just a simple function with no call.
+
+ex5.py
+
+#fraught with possibility
+import pyaudiogame
+import random
+import ex5_1
+spk = pyaudiogame.speak
+MyApp = pyaudiogame.App("My Application")
+
+
+Sorry to burst your bubble of magical mystery, but these lines are no more than imports. We are just importing pyaudiogame, random and our ex5_1 module. We are also importing the speak function and we have one line of magic that we know is a variable and something that looks like a function in a module but I will tell you that it is not, it is something we will learn about in a couple lessons.
+
+def logic(actions):
+ key = actions['key']
+ if key == "space":
+ ex5_1.func()
+ elif key == "return":
+ spk("Your random number is: %s!" % random.randint(1,10))
+
+
+By typing the name of the module,
+ex51.func()
+We can use the function from ex51.
+
+MyApp.logic = logic
+MyApp.run()
+
+
+And our last two lines that look like modules, but are really not.
+
+assignment
+
+
+- Add some more functions to the program from the ex5_1 module.
+- Add another module.
+- Check out the python standard for writing code,
+pep8
+and read what it says about imports. Change any code you find or write to follow it. This will make you a better programmer than many.
+
+
+extra credit
+
+
+- Find what the difference between a module and a package is.
+- Read up on random and find all the different functions that are in it. *hint* I like random.choice, random.randint, random.randrange and random.uniform. Why would I like using these and not the others? Write some code that uses these.
+- Find another module from the Python Standard Library and use some functions from it in your code.
+- Play some games.
+
diff --git a/documentation/basic/lesson5.md b/documentation/basic/lesson5.md
new file mode 100644
index 0000000..c08e770
--- /dev/null
+++ b/documentation/basic/lesson5.md
@@ -0,0 +1,118 @@
+lesson 5: No, I didn't say my jewels -- Basic Tutorial
+
+[Back to Index](index.html)
+
+#The module
+So just like with everything else, programmers like to shroud their craft with fancy words for things that probably don't need it.
+Module is one of these words.
+What is a module? A module is another file with code in it that you can use in your script. Why not call it a file? Because a file doesn't have code in it...
+So we call files with code in them modules.
+The module is something that python is particularly good at. You group functions and tasks into modules so you can manage and read your code better.
+#How to use a module
+You call the module's functions or add the module to your namespace by doing two different things:
+For most things, it is best to always do the first as it will make your code cleaner in the end if you choose to use a lot of different functions from the imported module. The first is:
+import moduleName
+This will bring that moduleName into your current module so you can type
+moduleName.function()
+to run a function inside that module.
+The second way is only used if you are only using one function from a module. There is no real speed difference, it just takes up a name in your module's namespace. It is:
+from moduleName import function
+That way you can type:
+function()
+just as if you created it in your current module.
+The next example needs you to make 2 files. Name one
+ex5.py
+and the other
+ex5_1.py
+#code for ex5_1.py
+
+ #My first module!
+ from pyaudiogame import speak as spk
+
+ def func():
+ spk("This is the ex5_1 module!!! Hello world!!!")
+
+#code for ex5.py
+ #fraught with possibility
+ import pyaudiogame
+ import random
+ import ex5_1
+ spk = pyaudiogame.speak
+ MyApp = pyaudiogame.App("My Application")
+
+ def logic(actions):
+ key = actions['key']
+ if key == "space":
+ ex5_1.func()
+ elif key == "return":
+ spk("Your random number is: %s!" % random.randint(1,10))
+
+ MyApp.logic = logic
+ MyApp.run()
+
+#What you should see
+When you press space you should hear:
+"This is the ex5_1 module!!! Hello world!!!"
+If you press return you should hear:
+"Your random number is: %s!"
+Where `%s` is a random number.
+#Built-in modules
+Python has something called The
+[Python Standard Library](https://docs.python.org/2/library/)
+Which is a group of modules that every python instilation comes with. These include a random module for generating random numbers, a time module for dealing with dates and time, a sys module with functions that deal with the computer, os which has functions to tell info about the current operating system, a math module with more complex math functions and somewhere around 100 modules filled with functions.
+In general, if you find that there is a built-in way of doing something, it will be faster for you to use that way than to write your own code for doing the same thing. Always google to see if you can already do something in python before trying to make it yourself.
+#What is going on in our code
+##ex5_1.py
+
+ #My first module!
+ from pyaudiogame import speak as spk
+
+Here we are using the second type of importing with a little fancy keyword:
+from pyaudiogame import speak as spk
+Instead of typing
+speak("text to speak")
+we are saying that we wish the variable spk to be assigned to speak. That way we have a free speak variable and because spk is something that is typed a lot, we can save our fingers the trouble of typing a 5 letter word. Just put that "as" keyword after the module name and then the new name.
+
+ def func():
+ spk("This is the ex5_1 module!!! Hello world!!!")
+
+This is just a simple function with no call.
+
+##ex5.py
+ #fraught with possibility
+ import pyaudiogame
+ import random
+ import ex5_1
+ spk = pyaudiogame.speak
+ MyApp = pyaudiogame.App("My Application")
+
+Sorry to burst your bubble of magical mystery, but these lines are no more than imports. We are just importing pyaudiogame, random and our ex5_1 module. We are also importing the speak function and we have one line of magic that we know is a variable and something that looks like a function in a module but I will tell you that it is not, it is something we will learn about in a couple lessons.
+
+ def logic(actions):
+ key = actions['key']
+ if key == "space":
+ ex5_1.func()
+ elif key == "return":
+ spk("Your random number is: %s!" % random.randint(1,10))
+
+By typing the name of the module,
+ex5_1.func()
+We can use the function from ex5_1.
+
+ MyApp.logic = logic
+ MyApp.run()
+
+And our last two lines that look like modules, but are really not.
+
+#assignment
+1. Add some more functions to the program from the ex5_1 module.
+2. Add another module.
+3. Check out the python standard for writing code,
+[pep8](https://www.python.org/dev/peps/pep-0008/)
+and read what it says about imports. Change any code you find or write to follow it. This will make you a better programmer than many.
+
+#extra credit
+1. Find what the difference between a module and a package is.
+2. Read up on random and find all the different functions that are in it. \*hint\* I like random.choice, random.randint, random.randrange and random.uniform. Why would I like using these and not the others? Write some code that uses these.
+3. Find another module from the Python Standard Library and use some functions from it in your code.
+4. Play some games.
diff --git a/documentation/basic/lesson6.html b/documentation/basic/lesson6.html
new file mode 100644
index 0000000..e66e183
--- /dev/null
+++ b/documentation/basic/lesson6.html
@@ -0,0 +1,299 @@
+Lesson 6: Balista! -- Basic Tutorial
+
+Back to Index
+
+
+
+Bombs away!
+
+This is the last thing you need to learn before being able to make a game!
+
+Managing items
+
+In python we often need to be able to access items in order. For example, we need to know what sceen we're on. We have a variable that says that we are on sceen 14, but currently it would be really dificult to get from sceen 13 to 14. There is this lovely construct called a
+list
+Lists are used in many different ways, from checking to see if a key is in a list of keys to figuring out if a script has run before.
+Lists have a group of built-in functions that one can use to manage them. These include:
+
+
+
+append |
+Add the item passed to it to the end of the list |
+listName.append("Fred") |
+
+
+pop |
+remove the number of the item you passed to it from the list. If no number is given, remove the last item. |
+listName.pop(3) -> removed item |
+
+
+insert |
+Add an item at the position given. The order is position item. |
+listName.insert(4, "Fred") |
+
+
+remove |
+remove the item that is passed. So if the list has "pizza" in it and you pass "pizza" to the remove function, "pizza" will be removed from the list |
+listName.remove("pizza") |
+
+
+index |
+Find out what number in the list the item that is passed is in the list |
+listName.index("Fred") -> number in the list of "Fred" |
+
+
+
+To make a list you type brackets:
+[]
+around a list of things seperated by commas like:
+["fred", "sam", 42, "pizza"]
+A list is just like a string or an int, it can be assigned to a variable. So
+list1 = ["fred", "sam", 42, "pizza"]
+would be assigned to list1. Now you can type the above functions after list1 to have them run like:
+list1.pop()
+will remove pizza from the list.
+You can refer to an item in the list by typing:
+list1[0]
+list1[1]
+Wait, why is there a 0 there?
+lists are on the cardinal numbering system. This means that everything starts from 0 rather than 1. Doing things this way means that it's much easier to do equasions with numbers. For example, if you would like to check if a list of sceens have been run, you can type something like:
+if not scene_counter
:
+ scene_counter
+=1
+ run_scene()
+This is much clearer and concise than any other way you could write it.
+So when working with lists, just know that you need to subtract 1 always.
+
+before typing the code
+
+This code has a lot of strange things in it and it is really long, so type everything and get it running. Everything will be explained below.
+
+code
+
+#Pizza please
+import pyaudiogame
+from pyaudiogame import cash as storage
+spk = pyaudiogame.speak
+MyApp = pyaudiogame.App("Pizza Please")
+
+storage.screen = ["start"]
+storage.toppings = ["cheese", "olives", "mushrooms", "Pepperoni", "french fries"]
+storage.your_toppings = ["cheese"]
+storage.did_run = False
+
+def is_number(number, topping_list):
+ """Will check that what the user enters is really a number and not a letter, also that it is within our list"""
+ if number in "0123456789":
+ number = int(number)
+ if number <= len(topping_list)-1:
+ return number
+
+def say_message(message):
+ """Will check if the message has been read and if so, passes. Else, it will read the message"""
+ if not storage.did_run:
+ spk(message)
+ storage.did_run = True
+
+def add_topping(key):
+ """Will add a topping to your pizza"""
+ number = is_number(key, storage.toppings)
+ if number or number == 0:
+ storage.your_toppings.append(storage.toppings[number])
+ spk("You added %s to your pizza. Your pizza currently has %s on top" % (storage.toppings[number], storage.your_toppings))
+
+def remove_topping(key):
+ """Removes toppings from the pizza"""
+ number = is_number(key, storage.your_toppings)
+ if number or number == 0:
+ t = storage.your_toppings.pop(number)
+ if t == "cheese":
+ spk("You can't remove cheese, what are you, Italian?")
+ storage.your_toppings.insert(0, "cheese")
+ else:
+ spk("You removed %s from your pizza. Now your pizza has %s on top" % (t, storage.your_toppings))
+
+def logic(actions):
+ """Press a and d to switch from adding and removing toppings, press 0-9 to deal with the toppings and press space to eat the pizza"""
+ key = actions['key']
+ if key == "d":
+ spk("Press a number to remove a topping from your pizza, press a to add toppings again")
+ storage.screen[0] = "remove"
+ storage.did_run = False
+ elif key == "a":
+ spk("Press a number to add a topping to your pizza. Press d to remove a topping you don't like")
+ storage.screen[0] = "add"
+ storage.did_run = False
+ elif key == "space":
+ spk("You sit down to enjoy a yummy pizza. You eat... eat... eat... eat... and are finally done. That was good! Now it's time for another!")
+ storage.your_toppings = ['cheese']
+ storage.did_run = False
+ elif storage.screen[0] == "start":
+ spk("Welcom to pizza madness! Here you can build your own pizza to eat! Press a to add toppings, press d to remove them and when you are done, press space to eat your yummy pizza!!!")
+ storage.screen.remove("start")
+ storage.screen.append("add")
+ elif storage.screen[0] == "add":
+ say_message("Please choose a number of toppings to add! Press d to start removing toppings. Toppings are %s" % storage.toppings)
+ if key:
+ add_topping(key)
+ elif storage.screen[0] == "remove" and key:
+ remove_topping(key)
+
+MyApp.logic = logic
+MyApp.run()
+
+
+What you should see
+
+When you run the script, the screen will pop up and you will hear:
+"Welcom to pizza madness! Here you can build your own pizza to eat! Press a to add toppings, press d to remove them and when you are done, press space to eat your yummy pizza!!!"
+"Please choose a number of toppings to add! Press d to start removing toppings. Toppings are ["cheese", "olives", "mushrooms", "Pepperoni", "french fries"]"
+If you press 1 it will say:
+"You added olives to your pizza. Your pizza currently has ["cheese", "olives"] on top"
+if you press d it will say:
+"Press a number to remove a topping from your pizza, press a to add toppings again"
+Then if you press a number, it will remove that item from your pizza. If you press 0, it will say:
+"You can't remove cheese, what are you, Italian?"
+If you press space it will say:
+"You sit down to enjoy a yummy pizza. You eat... eat... eat... eat... and are finally done. That was good! Now it's time for another!"
+And your toppings will be reset.
+
+What is going on?
+
+Lets go through this code one step at a time:
+
+#Pizza please
+import pyaudiogame
+from pyaudiogame import cash as storage
+spk = pyaudiogame.speak
+MyApp = pyaudiogame.App("Pizza Please")
+
+
+We have our imports like always. We import pyaudiogame, we import pyaudiogame.cash with the title of storage, then we assign spk to the function pyaudiogame.speak. Finally we assign MyApp to pyaudiogame.App with the title "pizza please".
+
+storage.screen = ["start"]
+storage.toppings = ["cheese", "olives", "mushrooms", "Pepperoni", "french fries"]
+storage.your_toppings = ["cheese"]
+storage.did_run = False
+
+
+Here we create our variables. We have one constant, storage.toppings, but in order to make everything match, we put it in storage.
+storage.screen is a string inside a list that helps us keep track of where we are in the app. This is how one can figure out what what scene should be running and by making this accessible by all the modules in an app, any function can then change the screen of the program.
+storage.your_toppings
is the list that we change most, it is the player's list of toppings.
+storage.did_run
is the most checked variable, it is checked every time the game loop runs. It says if the message that is the instructions for each screen has run or not.
+
+def is_number(number, topping_list):
+ """Will check that what the user enters is really a number and not a letter, also that it is within our list"""
+ if number in "0123456789":
+ number = int(number)
+ if number <= len(topping_list)-1:
+ return number
+
+
+We have a lot of new things in this function, so lets go through it line by line:
+
+def is_number(number, topping_list):
+
+
+This function is what we call an error checkor. It checks that the program won't crash if the user enters a letter or a number that is out of range.
+
+ """Will check that what the user enters is really a number and not a letter, also that it is within our list"""
+
+
+This line is what we call a dockstring. It is what should always be placed on the first line of the function block. It describes why we have the function and a little of what it does. Up to this point we haven't been using so many dockstrings, but from now on, they should be in just about every function.
+
+ if number in "0123456789":
+
+
+This checks if the number we are checking is really a number. The in statement checks in lists and strings. It is much better than writing or statements. So if we wished, we could type something like:
+if number in ["1", "2", "3", "4", "5", "6"]
+This will check in a list rather than a string. But as we are checking one character that is a string, we can just use a larger string.
+
+ number = int(number)
+
+
+You can convert from one type to another by using the type function. There is an str function, there is a float function, there is an int function, there is a list function and a function for any other type you need. We need to convert to an int so we can access an item in a list.
+
+ if number <= len(topping_list)-1:
+
+
+One can't do <= with a string very well. Len is a built-in function that will give the amount of items in a list or string. But remember, lists begin from 0 rather than 1, so if we had the len without the 1, we would pass a number that is too high and will raise an error. You can also just say if number < len(topping_list)
:, but I think this way is clearer.
+
+ return number
+
+
+The return statement is not something we have done before. Return is a way for a function to become a value. So if a number was passed to the function is_number
and that number fit all the requirements, it would be returned. You can have a variable equal a function as well. We will see this later.
+Note that a function always returns something, but if nothing is given, it returns None.
+You can only return one value, but a list counts as one value and you can assign 2 or more variables to a list/function that returns a list like:
+name, age = ["Joe", 42]
+
+def say_message(message):
+ """Will check if the message has been read and if so, passes. Else, it will read the message"""
+ if not storage.did_run:
+ spk(message)
+ storage.did_run = True
+
+
+This function makes sure that we run a function that says a message only once. This function is run every loop and if we didn't have it, our screen reader would be speaking the message 30 times a second.
+
+def add_topping(key):
+ """Will add a topping to your pizza"""
+ number = is_number(key, storage.toppings)
+
+
+We define a function with the argument of the current key. Then we have the dockstring, then we run the function we created above, the is_number
function. We pass the key and the list that we are going to check the length of.
+
+ if number or number == 0:
+
+
+We check that there is a number that returned. We have a bug if we just say the first statement though as 0 is considered nothing, so will not be alowd through unless we say it is alowd explicitly.
+
+ storage.your_toppings.append(storage.toppings[number])
+
+
+Here we append to your_toppings
the topping from the toppings list.
+
+ spk("You added %s to your pizza. Your pizza currently has %s on top" % (storage.toppings[number], storage.your_toppings))
+
+
+Here we say the topping that we just added to the your_toppings
list and the list of your_toppings.
The reason why we can say the list of your_toppings
is because we converted it to a string with the %s
string formatter.
+
+def remove_topping(key):
+ """Removes toppings from the pizza"""
+ number = is_number(key, storage.your_toppings)
+ if number or number == 0:
+ t = storage.your_toppings.pop(number)
+
+
+The first half of this function is the same as the add_topping
function, but this last line brings a new function. The pop function. Pop will remove what ever number you tell it to remove and if there is no argument, it removes the last item. We are giving it the number that the player typed here.
+
+ if t == "cheese":
+ spk("You can't remove cheese, what are you, Italian?")
+
+
+The pop function will return the item that it popped, so that means that t is the popped item. Here we are checking if the pop item is cheese. If it is cheese, we will send a message saying that you can't remove cheese.
+
+ storage.your_toppings.insert(0, "cheese")
+
+
+The insert function does exactly what it sounds like. It inserts an item into the list at the location you specify. Here we are inserting an item at the top of the list. The argument order is the location and then the item you wish to insert.
+
+ else:
+ spk("You removed %s from your pizza. Now your pizza has %s on top" % (t, storage.your_toppings))
+
+
+If t is not equal to cheese, we will keep it removed and send a message that the user removed the item and then say what toppings are left on the pizza.
+
+assignment
+
+
+- Read the python documentation on lists.
+- Add another option for changing the sauce to be either pesto, white or red.
+
+
+Extra credit
+
+
+- Make it so that you can remove extra cheese, but not the first cheese. *hint* check out len.
+- make it so you can't add more than one of each topping, but double cheese.
+- This looks almost like a game. Make it into a game somehow.
+- Use every list operation in some way, either in this program, or in another.
+
diff --git a/documentation/basic/lesson6.md b/documentation/basic/lesson6.md
new file mode 100644
index 0000000..6c024bf
--- /dev/null
+++ b/documentation/basic/lesson6.md
@@ -0,0 +1,268 @@
+Lesson 6: Balista! -- Basic Tutorial
+
+[Back to Index](index.html)
+
+__________
+
+#Bombs away!
+This is the last thing you need to learn before being able to make a game!
+
+#Managing items
+In python we often need to be able to access items in order. For example, we need to know what sceen we're on. We have a variable that says that we are on sceen 14, but currently it would be really dificult to get from sceen 13 to 14. There is this lovely construct called a
+list
+Lists are used in many different ways, from checking to see if a key is in a list of keys to figuring out if a script has run before.
+Lists have a group of built-in functions that one can use to manage them. These include:
+
+
+
+append |
+Add the item passed to it to the end of the list |
+listName.append("Fred") |
+
+
+pop |
+remove the number of the item you passed to it from the list. If no number is given, remove the last item. |
+listName.pop(3) -> removed item |
+
+
+insert |
+Add an item at the position given. The order is position item. |
+listName.insert(4, "Fred") |
+
+
+remove |
+remove the item that is passed. So if the list has "pizza" in it and you pass "pizza" to the remove function, "pizza" will be removed from the list |
+listName.remove("pizza") |
+
+
+index |
+Find out what number in the list the item that is passed is in the list |
+listName.index("Fred") -> number in the list of "Fred" |
+
+
+
+To make a list you type brackets:
+[]
+around a list of things seperated by commas like:
+["fred", "sam", 42, "pizza"]
+A list is just like a string or an int, it can be assigned to a variable. So
+list1 = ["fred", "sam", 42, "pizza"]
+would be assigned to list1. Now you can type the above functions after list1 to have them run like:
+list1.pop()
+will remove pizza from the list.
+You can refer to an item in the list by typing:
+list1[0]
+list1[1]
+Wait, why is there a 0 there?
+lists are on the cardinal numbering system. This means that everything starts from 0 rather than 1. Doing things this way means that it's much easier to do equasions with numbers. For example, if you would like to check if a list of sceens have been run, you can type something like:
+if not `scene_counter`:
+ `scene_counter` +=1
+ `run_scene()`
+This is much clearer and concise than any other way you could write it.
+So when working with lists, just know that you need to subtract 1 always.
+
+#before typing the code
+This code has a lot of strange things in it and it is really long, so type everything and get it running. Everything will be explained below.
+
+#code
+ #Pizza please
+ import pyaudiogame
+ from pyaudiogame import cash as storage
+ spk = pyaudiogame.speak
+ MyApp = pyaudiogame.App("Pizza Please")
+
+ storage.screen = ["start"]
+ storage.toppings = ["cheese", "olives", "mushrooms", "Pepperoni", "french fries"]
+ storage.your_toppings = ["cheese"]
+ storage.did_run = False
+
+ def is_number(number, topping_list):
+ """Will check that what the user enters is really a number and not a letter, also that it is within our list"""
+ if number in "0123456789":
+ number = int(number)
+ if number <= len(topping_list)-1:
+ return number
+
+ def say_message(message):
+ """Will check if the message has been read and if so, passes. Else, it will read the message"""
+ if not storage.did_run:
+ spk(message)
+ storage.did_run = True
+
+ def add_topping(key):
+ """Will add a topping to your pizza"""
+ number = is_number(key, storage.toppings)
+ if number or number == 0:
+ storage.your_toppings.append(storage.toppings[number])
+ spk("You added %s to your pizza. Your pizza currently has %s on top" % (storage.toppings[number], storage.your_toppings))
+
+ def remove_topping(key):
+ """Removes toppings from the pizza"""
+ number = is_number(key, storage.your_toppings)
+ if number or number == 0:
+ t = storage.your_toppings.pop(number)
+ if t == "cheese":
+ spk("You can't remove cheese, what are you, Italian?")
+ storage.your_toppings.insert(0, "cheese")
+ else:
+ spk("You removed %s from your pizza. Now your pizza has %s on top" % (t, storage.your_toppings))
+
+ def logic(actions):
+ """Press a and d to switch from adding and removing toppings, press 0-9 to deal with the toppings and press space to eat the pizza"""
+ key = actions['key']
+ if key == "d":
+ spk("Press a number to remove a topping from your pizza, press a to add toppings again")
+ storage.screen[0] = "remove"
+ storage.did_run = False
+ elif key == "a":
+ spk("Press a number to add a topping to your pizza. Press d to remove a topping you don't like")
+ storage.screen[0] = "add"
+ storage.did_run = False
+ elif key == "space":
+ spk("You sit down to enjoy a yummy pizza. You eat... eat... eat... eat... and are finally done. That was good! Now it's time for another!")
+ storage.your_toppings = ['cheese']
+ storage.did_run = False
+ elif storage.screen[0] == "start":
+ spk("Welcom to pizza madness! Here you can build your own pizza to eat! Press a to add toppings, press d to remove them and when you are done, press space to eat your yummy pizza!!!")
+ storage.screen.remove("start")
+ storage.screen.append("add")
+ elif storage.screen[0] == "add":
+ say_message("Please choose a number of toppings to add! Press d to start removing toppings. Toppings are %s" % storage.toppings)
+ if key:
+ add_topping(key)
+ elif storage.screen[0] == "remove" and key:
+ remove_topping(key)
+
+ MyApp.logic = logic
+ MyApp.run()
+
+#What you should see
+When you run the script, the screen will pop up and you will hear:
+"Welcom to pizza madness! Here you can build your own pizza to eat! Press a to add toppings, press d to remove them and when you are done, press space to eat your yummy pizza!!!"
+"Please choose a number of toppings to add! Press d to start removing toppings. Toppings are ["cheese", "olives", "mushrooms", "Pepperoni", "french fries"]"
+If you press 1 it will say:
+"You added olives to your pizza. Your pizza currently has ["cheese", "olives"] on top"
+if you press d it will say:
+"Press a number to remove a topping from your pizza, press a to add toppings again"
+Then if you press a number, it will remove that item from your pizza. If you press 0, it will say:
+"You can't remove cheese, what are you, Italian?"
+If you press space it will say:
+"You sit down to enjoy a yummy pizza. You eat... eat... eat... eat... and are finally done. That was good! Now it's time for another!"
+And your toppings will be reset.
+
+#What is going on?
+Lets go through this code one step at a time:
+
+ #Pizza please
+ import pyaudiogame
+ from pyaudiogame import cash as storage
+ spk = pyaudiogame.speak
+ MyApp = pyaudiogame.App("Pizza Please")
+
+We have our imports like always. We import pyaudiogame, we import pyaudiogame.cash with the title of storage, then we assign spk to the function pyaudiogame.speak. Finally we assign MyApp to pyaudiogame.App with the title "pizza please".
+
+ storage.screen = ["start"]
+ storage.toppings = ["cheese", "olives", "mushrooms", "Pepperoni", "french fries"]
+ storage.your_toppings = ["cheese"]
+ storage.did_run = False
+
+Here we create our variables. We have one constant, storage.toppings, but in order to make everything match, we put it in storage.
+storage.screen is a string inside a list that helps us keep track of where we are in the app. This is how one can figure out what what scene should be running and by making this accessible by all the modules in an app, any function can then change the screen of the program.
+`storage.your_toppings` is the list that we change most, it is the player's list of toppings.
+`storage.did_run` is the most checked variable, it is checked every time the game loop runs. It says if the message that is the instructions for each screen has run or not.
+
+ def is_number(number, topping_list):
+ """Will check that what the user enters is really a number and not a letter, also that it is within our list"""
+ if number in "0123456789":
+ number = int(number)
+ if number <= len(topping_list)-1:
+ return number
+
+We have a lot of new things in this function, so lets go through it line by line:
+
+ def is_number(number, topping_list):
+
+This function is what we call an error checkor. It checks that the program won't crash if the user enters a letter or a number that is out of range.
+
+ """Will check that what the user enters is really a number and not a letter, also that it is within our list"""
+
+This line is what we call a dockstring. It is what should always be placed on the first line of the function block. It describes why we have the function and a little of what it does. Up to this point we haven't been using so many dockstrings, but from now on, they should be in just about every function.
+
+ if number in "0123456789":
+
+This checks if the number we are checking is really a number. The in statement checks in lists and strings. It is much better than writing or statements. So if we wished, we could type something like:
+if number in ["1", "2", "3", "4", "5", "6"]
+This will check in a list rather than a string. But as we are checking one character that is a string, we can just use a larger string.
+
+ number = int(number)
+
+You can convert from one type to another by using the type function. There is an str function, there is a float function, there is an int function, there is a list function and a function for any other type you need. We need to convert to an int so we can access an item in a list.
+
+ if number <= len(topping_list)-1:
+
+One can't do <= with a string very well. Len is a built-in function that will give the amount of items in a list or string. But remember, lists begin from 0 rather than 1, so if we had the len without the 1, we would pass a number that is too high and will raise an error. You can also just say if number < `len(topping_list)`:, but I think this way is clearer.
+
+ return number
+
+The return statement is not something we have done before. Return is a way for a function to become a value. So if a number was passed to the function `is_number` and that number fit all the requirements, it would be returned. You can have a variable equal a function as well. We will see this later.
+Note that a function always returns something, but if nothing is given, it returns None.
+You can only return one value, but a list counts as one value and you can assign 2 or more variables to a list/function that returns a list like:
+name, age = ["Joe", 42]
+
+ def say_message(message):
+ """Will check if the message has been read and if so, passes. Else, it will read the message"""
+ if not storage.did_run:
+ spk(message)
+ storage.did_run = True
+
+This function makes sure that we run a function that says a message only once. This function is run every loop and if we didn't have it, our screen reader would be speaking the message 30 times a second.
+
+ def add_topping(key):
+ """Will add a topping to your pizza"""
+ number = is_number(key, storage.toppings)
+
+We define a function with the argument of the current key. Then we have the dockstring, then we run the function we created above, the `is_number` function. We pass the key and the list that we are going to check the length of.
+
+ if number or number == 0:
+
+We check that there is a number that returned. We have a bug if we just say the first statement though as 0 is considered nothing, so will not be alowd through unless we say it is alowd explicitly.
+
+ storage.your_toppings.append(storage.toppings[number])
+
+Here we append to `your_toppings` the topping from the toppings list.
+
+ spk("You added %s to your pizza. Your pizza currently has %s on top" % (storage.toppings[number], storage.your_toppings))
+
+Here we say the topping that we just added to the `your_toppings` list and the list of `your_toppings.` The reason why we can say the list of `your_toppings` is because we converted it to a string with the `%s` string formatter.
+
+ def remove_topping(key):
+ """Removes toppings from the pizza"""
+ number = is_number(key, storage.your_toppings)
+ if number or number == 0:
+ t = storage.your_toppings.pop(number)
+
+The first half of this function is the same as the `add_topping` function, but this last line brings a new function. The pop function. Pop will remove what ever number you tell it to remove and if there is no argument, it removes the last item. We are giving it the number that the player typed here.
+
+ if t == "cheese":
+ spk("You can't remove cheese, what are you, Italian?")
+
+The pop function will return the item that it popped, so that means that t is the popped item. Here we are checking if the pop item is cheese. If it is cheese, we will send a message saying that you can't remove cheese.
+
+ storage.your_toppings.insert(0, "cheese")
+
+The insert function does exactly what it sounds like. It inserts an item into the list at the location you specify. Here we are inserting an item at the top of the list. The argument order is the location and then the item you wish to insert.
+
+ else:
+ spk("You removed %s from your pizza. Now your pizza has %s on top" % (t, storage.your_toppings))
+
+If t is not equal to cheese, we will keep it removed and send a message that the user removed the item and then say what toppings are left on the pizza.
+
+#assignment
+1. Read the python documentation on lists.
+2. Add another option for changing the sauce to be either pesto, white or red.
+
+#Extra credit
+1. Make it so that you can remove extra cheese, but not the first cheese. \*hint\* check out len.
+2. make it so you can't add more than one of each topping, but double cheese.
+3. This looks almost like a game. Make it into a game somehow.
+4. Use every list operation in some way, either in this program, or in another.
diff --git a/documentation/basic/lesson7.md b/documentation/basic/lesson7.md
new file mode 100644
index 0000000..cbad564
--- /dev/null
+++ b/documentation/basic/lesson7.md
@@ -0,0 +1,13 @@
+#So what does this mean?
+This means that you have enough knowledge to make a simple game!
+You can create stats by assigning numbers to variables, you can put those variables in storage, you can import random to make your game more interesting, you can create functions to run if statements to check if variables are something and you can speak text.
+#How to create a game
+There are two aproaches programmers use to make a game or an app, there is something called "bottom up" and "top down".
+Bottom up is when a programmer has a piece of code they wish to get working and they get that one piece of code working, then create a game around that.
+Top down is where a programmer sits down and writes out everything they would like to have in their app, then makes an outline for their game.
+For new programmers, top down is what works best.
+##first step
+I'm sure you have some ideas of what games to write, and if you don't, just make something that has to do with monkies and or penguins who wish to take over the world. You can't go wrong there.
+Once you have an idea, write a paragraph describing the game.
+
+
diff --git a/examples/basic_games/pie_heavens/game sketch.txt b/examples/basic_games/pie_heavens/game sketch.txt
new file mode 100644
index 0000000..7cbf90f
--- /dev/null
+++ b/examples/basic_games/pie_heavens/game sketch.txt
@@ -0,0 +1,195 @@
+game sketch
+
+Pie Heavens
+
+Summery:
+You are a pie floating through space, fighting Milky Way aliens. You float around stars and asteroids. The Milky Way aliens shoot forks at the pie and the pie shoots a heat ray because he is a hot apple pie. There are 10 or so rooms and one enemy. If possible, the pie will advance a level. The goal is to float to meet the Giant Way and kill it to get the crown for the ruler of the universe.
+
+structure
+Each room will have attributes and will either do nothing, heal, or damage the pie. A room will also have a random chance of having an enimy.
+moving
+You press one of the arrow keys to move. It really doesn't make any difference what one, it is all random.
+You press h to hear health of the pie, g to hear the health of the enimy and x to hear xp.
+combat
+It will be random who is first, but you press space to shoot your pie ray. You also have a special attack that will charge 10% each room. This ray will do a lot of damage. You press ctrl to shoot this ray.
+You hit between 15 and 30 damage on the first level, then each level you get an extra 40% strength. Your deathray hits 40% of the enimy's hp at level 1 and +5% each level after.
+All hits have a 3/4 chance of hitting.
+death
+you start out with 3 lives and when you kill a boss you get a life.
+leveling
+Each hit you will get 1 XP
+You start out with 100 HP and get 10% each level.
+levels cost twice the amount
+As you level, the creatures level and they will get anywhere from 30 hp less to 30 hp above your hp.
+They are also a little weeker than you are.
+navigation
+There will be screens:
+movement
+start
+combat
+death
+
+Always on all the screens there is the key r for repeat text.
+On all screens but start there is the keys
+h, tells health,
+x, tells xp and xp tnl,
+l for lives and
+c for the charge of the death-ray.
+
+movement
+When ever a player hits the "floating along" or move-to-next location button, a random function is called with random.choice and sets the message, sets the read_message to true, adds or removes hp and chooses if a combat or move button will be shown.
+start
+Start just has the start game and goal. It could be the place for adding a save option later.
+combat
+In combat, There will be 3 new keys:
+ctrl, death ray
+space, heat blast and
+g, health of the enimy
+When the combat screen opens, a check will run to see who will hit first, the player or the fo. If the fo, the fo hits and the screen waits, otherwise it says: "You sneek up on the evil chocolate and are able to hit the first blow"
+Right after the player attacks then, the chocolate attacks. The message will be set to the last attack message. It will say something like:
+"You open a small hole in your crust and let out a blast of heat. The chocolate fo is baithed in heat and loses 10 HP. The chocolate spits out some ascidic cream and it lands on your shell. You lose 13 HP."
+There will be a list of attack messages and a list of fo attack messages. Each attack, one of these messages will be chosen for each.
+First a fo is created from the fo variables. Both the custom death message and extra xp and extra life are set if needed, Then a check for who will attack happens, then if the fo, it attacks. then for each turn there is: the player will attack, then a death check and level check will go, then the fo will attack, then another death check will happen. Then the read_message will be set to True.
+death
+Death is different than the other screens as it is really a sub-set of combat. There is all the key commands but space and ctrl. There is one more, return will either go back to start or the traveling screen.
+An argument will be passed to death, either player or fo. If it is player, a message from the player's death messages will show, 1 life will be subtracted from the player's lives and if the lives is less than 0, another message will show that you lost the game. If you do have lives, then it will say that you can return to floating.
+If the fo dies, a message will be shown from the fo's death list or from the second argument of death which is set when combat starts (for bosses). The extra xp and lives are added and a level check is done. The read_message will be set to True.
+level check
+Will check if player_xp >= next_level and if so, will append on to the end of the message text that you advanced a level.
+
+Bosses
+There are 5 bosses and every 2 levels you reach a boss. on the 10th level you reach the giant way.
+
+engine
+The logic function will have:
+list of screen checks
+key checks with extra logic statements checking for each screen, like space only on combat, and g for death and combat
+a check if read_message is true and if so, reads text
+
+constants
+hp_gain = 0.10
+hp_heal = 0.40
+xp_multiplyer_tnl = 2
+missed_number = 4
+xp_per_hit = 1
+
+room_list = [healroom, damageroom, room1, room2, room3, room4, room5, room6]
+player_attacks = ["You open up a small hole in your crust and let a blast of piping hot heat go shooting toward the evil chocolate. You hit it for %s damage.", "You find a piece of filling that is Scalding and you direct it's heat at your chocolate foe. It is melted for %s damage.", "As you feel your filling bubble, you direct a particularly hot bubble to burst right on the evil chocolate's surface, melting a spot causing %s damage."]
+fo_attacks = ["The lump of lascivious candy sends a nut hurling toward you. It smacks onto your shell, causing a crack for %s damage.", "The evil chocolate lobs a lump of acidic cream onto your crust, burning you for %s damage.", "The evil chocolate charges your soft underside and smacks into you causing %s damage."]
+player_misses = ["You catapult a dob of filling at the dreadful chocolate, but aimed too high.", "You search for some heat inside your filling, but can't find any before the evil chocolate attacks you again.", "You fling a piece of apple at the evil chocolate, but it just brushes past it's revolting shell."]
+fo_misses = ["The evil chocolate charges at your underside, but you manage to flip onto your side before it hits you.", "The horrible chocolate picks out a large nut and flings it strait past you.", "You laugh as the disgusting chocolate digs for nuts inside its revolting filling before giving up."]
+deathray_hits = ["You gently coax the massive hot bubble from your center out to where you blast it in all its fury on the deserving chocolate. It melts for %s damage", "You silently send a huge pocket of hot air at the dastardly coco brains, giving a new meaning to the phrase, \"silent but deadly\" and you manage to remove %s damage from the lackluster lunch food", "You work up the courage and like the great pies of old, send a bubble of heat hurling toward your choco foe, delivering %s damage.", "You feel yourself becoming pie a la mode, but then realise that it is that all your heat has gon into a super hot bubble that you blast at the cracked up coco butter ball. It melts the lump of lackluster chocolate for %s damage"]
+deathray_misses = [""You gently coax a huge bubble of hot air out of your center, but right before it reaches your launching spot, it pops and you are left with nothing but some hot filling.", "Trying to get the bubble of hot air as large as possible, you add one too many spurts of hot air and it pops.", "You gently coax your large bubble of hot air to the launching pad and send it hurling at the chocolate, but it decides to drift and join the stars."]
+
+storage variables
+room_number = 0
+screen = "start"
+message = ""
+read_message = True
+current_fo = None
+
+player_level = 1
+player_hp = 100
+player_xp = 0
+player_deathray_charge = 100
+player_hit = 30
+player_deathray_hit = 40
+player_next_level = 50
+player_lives = 3
+
+fo_current_hp = 100
+fo_max_hp = 130
+fo_strength = 20
+fo_death_message = None
+
+extra_lives = 0
+extra_xp = 0
+
+screens
+start:
+Welcome to pie Heavens!
+Press return to blast off into space and escape to exit!
+
+start2:
+Floating between the stars, no end in sight. Hot from the oven, ready for someone to take a bite.
+A Hot Apple Pie gifted with space flight.
+The Milky Way bites swarm all around, but the crown to control still must be found.
+For a lost pie in space is never aloud.
+Forks and knives are used to hurt and you blast heat for a chocolate milting spurt.
+Press the arrow keys to go randomly drift. If you happen to hit a chocolate foe melt it with space or controll.
+
+
+healroom:
+Near a red giant
+
+A bright red glow spreads out from a massive star relatively close by. The heat helps a pie weld itself back together.
+
+damageroom:
+Escaping a black hole
+Yikes! That is a black hole! Sometimes drifting is not all it's cracked up to be... But now you are... All cracked up... Ouch!
+
+room1:
+Closer into the red giant
+This massive red star is nearing the end of its shining life. At this point the star is poofed up like a balloon with a small dense center of helium that is turning into carbon. The red is due to the relatively cool exterior, but one would still want to keep its distance. Soon though, the force in the center of the star will die and the entire outer layer will implode, making a very squozen ball of mass.
+
+room2:
+With the big cheeses
+Chilling chunks of cheese are floating around you. Earth is not the only moon with its satellite made out of cheese and most planets with moons have more than one. This planet has 37 and they are all made out of cheese. Wonder what they call the largest moon? Probably the big cheese.
+
+room3:
+Between the Stars
+Between the countless dots of light, time is inconsequential. Space is all that matters. With light years between each star, drifting turns into something only another drifter can understand.
+
+room4
+By an Asteroid
+A giant hunk of metal and rock is orbiting around the nearest star. Dust from past collisions cover the surface. Talk about being hard headed...
+
+room5
+Overlooking a Planet
+Dull and seemingly lifeless, this massive collection of elements has formed a very dense and massive rock. What make this different from Asteroids are first the size and the fact that this hunk of junk has an atmosphere of gas.
+
+room6:
+Around a Neutron Star
+This corpse is the result of a fairly large star that became a red giant, and then became so dense that all the corks became neutrons. The mass is not enough for a black hole, but it was too much for a white dwarf.
+
+enemy1
+Small Milkey Way
+
+Directly from Mars, this small piece of chocolate and malt is having a bad nutday!
+
+enemy2
+American Milkey Way
+
+450 calories of unadulterated milkey madness with nuts!
+
+UK milkey Way
+Creamy, smoothe and 99 calories inside a thick chocolate shell. Put this guy in milk to see how he floats.
+
+Forever Yours
+The evil twin of an already evil chocolate bar! This time you've got twin vanilla to destroy.
+
+Milky Way Midnight
+Black, small, but more evil than the other bars, this little guy will not give up until someone is dead. Someone better attack before they lose their head.
+
+boss1:
+Giant American Milkey Way
+
+"The sweet you can eat between meals!" This milkey way is a giant version of the little guys you have seen before. It is a little more than 450 calories, you better be careful!
+
+boss2
+America, the Milkey Way
+
+" At work, rest and play, you get three great tastes in a Milky Way." Death, milk and ablivian!
+
+boss 3
+Milkey God
+
+The milkey god says: "Life's Better the Milky Way." Come and join me, don't float away.
+
+boss4
+Milkey Way Magic stars
+Pop Star, Jess Star, Bright Star, Super Star, Happy Star, Sport Star and Baby Star are all looking at you... Sorry, we were just Eating our last victim... Hahahahahahahaha!!! You're next!
+
+The Giant Way
+Shiver and crack my flaky foe! You seem a little tarty today, perhaps you would like some ice cream to come your way?
+
diff --git a/examples/basic_games/save_the_maiden/outline.txt b/examples/basic_games/save_the_maiden/outline.txt
index 7dc5b15..a09b4ab 100644
--- a/examples/basic_games/save_the_maiden/outline.txt
+++ b/examples/basic_games/save_the_maiden/outline.txt
@@ -1,5 +1,8 @@
Save the maiden is a text adventure game.
+summery:
+You go into a village, learn there is a dragon who needs to be killed, kill the dragon and get your reward.
+
story:
A village is under attack by an evil dragon. Up to this point the dragon had just been taking livestock and wild animals, but last night, it snatched a young maiden while she was on her morning walk.
diff --git a/examples/basic_tutorial/ex6.py b/examples/basic_tutorial/ex6.py
new file mode 100644
index 0000000..7c3eede
--- /dev/null
+++ b/examples/basic_tutorial/ex6.py
@@ -0,0 +1,70 @@
+#Pizza please
+import pyaudiogame
+from pyaudiogame import cash as storage
+spk = pyaudiogame.speak
+MyApp = pyaudiogame.App("Pizza Please")
+
+storage.screen = ["start"]
+storage.toppings = ["cheese", "olives", "mushrooms", "Pepperoni", "french fries"]
+storage.your_toppings = ["cheese"]
+storage.did_run = False
+
+def is_number(number, topping_list):
+ """Will check that what the user enters is really a number and not a letter, also that it is within our list"""
+ if number in "0123456789":
+ number = int(number)
+ if number <= len(topping_list)-1:
+ return number
+
+def say_message(message):
+ """Will check if the message has been read and if so, passes. Else, it will read the message"""
+ if not storage.did_run:
+ spk(message)
+ storage.did_run = True
+
+def add_topping(key):
+ """Will add a topping to your pizza"""
+ number = is_number(key, storage.toppings)
+ if number or number == 0:
+ storage.your_toppings.append(storage.toppings[number])
+ spk("You added %s to your pizza. Your pizza currently has %s on top" % (storage.toppings[number], storage.your_toppings))
+
+def remove_topping(key):
+ """Removes toppings from the pizza"""
+ number = is_number(key, storage.your_toppings)
+ if number or number == 0:
+ t = storage.your_toppings.pop(number)
+ if t == "cheese":
+ spk("You can't remove cheese, what are you, Italian?")
+ storage.your_toppings.insert(0, "cheese")
+ else:
+ spk("You removed %s from your pizza. Now your pizza has %s on top" % (t, storage.your_toppings))
+
+def logic(actions):
+ """Press a and d to switch from adding and removing toppings, press 0-9 to deal with the toppings and press space to eat the pizza"""
+ key = actions['key']
+ if key == "d":
+ spk("Press a number to remove a topping from your pizza, press a to add toppings again")
+ storage.screen[0] = "remove"
+ storage.did_run = False
+ elif key == "a":
+ spk("Press a number to add a topping to your pizza. Press d to remove a topping you don't like")
+ storage.screen[0] = "add"
+ storage.did_run = False
+ elif key == "space":
+ spk("You sit down to enjoy a yummy pizza. You eat... eat... eat... eat... and are finally done. That was good! Now it's time for another!")
+ storage.your_toppings = ['cheese']
+ storage.did_run = False
+ elif storage.screen[0] == "start":
+ spk("Welcom to pizza madness! Here you can build your own pizza to eat! Press a to add toppings, press d to remove them and when you are done, press space to eat your yummy pizza!!!")
+ storage.screen.remove("start")
+ storage.screen.append("add")
+ elif storage.screen[0] == "add":
+ say_message("Please choose a number of toppings to add! Press d to start removing toppings. Toppings are %s" % storage.toppings)
+ if key:
+ add_topping(key)
+ elif storage.screen[0] == "remove" and key:
+ remove_topping(key)
+
+MyApp.logic = logic
+MyApp.run()
diff --git a/pyaudiogame/__init__.py b/pyaudiogame/__init__.py
index 246ebbd..aa597ed 100644
--- a/pyaudiogame/__init__.py
+++ b/pyaudiogame/__init__.py
@@ -1,3 +1,4 @@
from app import App
-#import mixer, cash
+from app import event_queue
from speech import speak
+import cash
diff --git a/pyaudiogame/app.py b/pyaudiogame/app.py
index 8544e5c..46f7c82 100644
--- a/pyaudiogame/app.py
+++ b/pyaudiogame/app.py
@@ -5,6 +5,9 @@
#our program spacific modules:
import ticker
+#This is a global event queue
+event_queue = ticker.Scheduler(time_format=0.001)
+
class App(object):
"""This is to subclass for an application."""
@@ -23,7 +26,7 @@ def __init__(self, title="Test app", fps=30):
#If the mouse should be visible or not
self.mouse = False
#Our event queue
- self.event_queue = ticker.Scheduler(time_format=0.001)
+ self.event_queue = event_queue
#A hard-coded exit key, 1 is escape, 2 is alt + f4 and 0 is nothing **WARNING** if there is no exit key you need to go to command prompt window and hit ctrl + c to exit the window!
self.exit_key = 1
@@ -49,7 +52,7 @@ def run(self):
fpsClock = pygame.time.Clock().tick
fps = self.fps
#tick is for events that are scheduled
- tick = self.event_queue.tick
+ tick = event_queue.tick
#The game logic
logic = self.logic
#Returns events like key presses and mouse movement and we use it in our game logic
@@ -86,7 +89,9 @@ def keys(self):
'mousey': 0,
'key': None,
'mouseClicked': False,
- 'mods': []
+ 'mods': [],
+ 'state': None,
+ 'keyUp': None
}
for event in pygame.event.get():
if event.type == MOUSEMOTION:
@@ -95,7 +100,12 @@ def keys(self):
actions['mousex'], actions['mousey'] = event.pos
actions['mouseClicked'] = True
elif event.type == KEYDOWN:
+ actions['state'] = "down"
actions['key'] = pygame.key.name(event.key)
+ actions['mods'] = mod_id.get(pygame.key.get_mods(), [pygame.key.get_mods()])
+ elif event.type == KEYUP:
+ actions['state'] = "up"
+ actions['keyUp'] = pygame.key.name(event.key)
actions['mods'] = mod_id.get(pygame.key.get_mods(), [])
if event.type == QUIT or (actions['key'] == "escape" and exit_key == 1) or ('alt' in actions['mods'] and actions['key'] == 'f4' and exit_key == 2):
return False
@@ -114,13 +124,31 @@ def quit(self):
sys.exit()
mod_id = {
-64: ['ctrl'],
-320: ['ctrl'],
-1: ['shift'],
-257: ['shift'],
-65: ['ctrl', 'shift'],
-256: ['alt'],
-257: ['alt', 'shift'],
-321: ['ctrl', 'alt', 'shift']
+64: ['left ctrl', 'ctrl'],
+320: ['left ctrl', 'ctrl'],
+1: ['left shift', 'shift'],
+257: ['left shift', 'shift'],
+256: ['left alt', 'alt'],
+2: ['right shift', 'shift'],
+128: ['right ctrl', 'ctrl'],
+65: ['left ctrl', 'ctrl', 'left shift', 'shift'],
+66: ['left ctrl', 'ctrl', 'right shift', 'shift'],
+257: ['left alt', 'alt', 'left shift', 'shift'],
+129: ['right ctrl', 'ctrl', 'left shift', 'shift'],
+130: ['right ctrl', 'ctrl', 'right shift', 'shift'],
+321: ['left ctrl', 'ctrl', 'left alt', 'alt', 'left shift', 'shift'],
+322: ['left ctrl', 'ctrl', 'left alt', 'alt', 'right shift', 'shift'],
+258: ['left alt', 'alt', 'right shift', 'shift'],
+384: ['left alt', 'alt', 'right ctrl', 'ctrl'],
+386: ['left alt', 'alt', 'right ctrl', 'ctrl', 'right shift', 'shift'],
}
+if __name__ == '__main__':
+ f = App("Key Test")
+ def logic(actions):
+ mods = actions['mods']
+ if mods:
+ spk(str(mods))
+
+ f.logic = logic
+ f.run()
\ No newline at end of file
diff --git a/pyaudiogame/speech.py b/pyaudiogame/speech.py
index cec7239..bba661d 100644
--- a/pyaudiogame/speech.py
+++ b/pyaudiogame/speech.py
@@ -1,58 +1,137 @@
#Speaks text in the way I wish without hard-coding accessible_output like normal.
-#accessible_output2 has a compiling error and accessible_output2 and accessible_output are not compatible.
#import accessible_output2.outputs.auto
#spk = accessible_output2.outputs.auto.Auto().output
from accessible_output import speech
spk = speech.Speaker().output
-current_text = "Hello to the world"
-position = [0, 0]
speechOn = True
+lexicon = {' ': 'space', '\n': 'carriage return'}
-def speak(text, speech_dict=False):
+def speak(text, sp=True):
"""Is the leading function for speech"""
- global current_text
- position = [0, 0]
if text in lexicon:
text = lexicon.get(text, text)
- if speechOn:
+ if speechOn and sp:
spk(text)
- current_text = text
-
-def navigate(direction):
- """use word_forward/back, letter_forward/back, top, bottom"""
- text = "nothin yet"
- word_list = current_text.split(' ')
- if direction == "letter_forward":
- position[0] = scroll("forward", position[0], len(current_text))
- elif direction == "letter_back":
- position[0] = scroll("back", position[0], len(current_text))
- elif direction == "word_forward":
- position[1] = scroll("forward", position[1], len(word_list))
- elif direction == "word_back":
- position[1] = scroll("back", position[1], len(word_list))
- if direction in ['letter_forward', 'letter_back']:
- text = current_text[position[0]]
- elif direction in ['word_back', 'word_forward']:
- text = word_list[position[1]]
- position[0] = current_text.index(word_list[position[1]])
- print(text)
-
-
-def scroll(direction, current_position, length):
- if direction == "forward":
- current_position += 1
- if direction == "back":
- current_position -= 1
- if current_position > length - 1:
- return length - 1
- elif current_position < 0:
- return current_position + 1
- else:
- return current_position
+ return Text(text)
-lexicon = {' ': 'space', '\n': 'carriage return'}
+class Text(object):
+ """Deals with processing of text"""
+ def __init__(self, text):
+ self.text = text
+ self.word_position = 0
+ self.letter_position = 0
+ self.current_word = None
+ self.current_letter = text[0]
+ self.word_list = text.split(' ')
+ for i in self.word_list:
+ if i != self.word_list[-1]:
+ i = " " + i
+
+ def letter_to_word(self):
+ """Will look at the number of the letter and figure out where in the string it is and return the current word"""
+ number_list = []
+ n = 0
+ for i in self.word_list:
+ number_list.append([n, n + len(i)])
+ n += len(i)
+ for i in number_list:
+ if self.letter_position in range(i[0], i[1]):
+ self.current_word = self.word_list[number_list.index(i)]
+ return self.current_word
+
+ def word_to_letter(self):
+ """Run this and all the current letter and position will be updated"""
+ f = self.text.index(self.current_word)
+ self.letter_position = f
+ self.current_letter = self.text[f]
+ return self.current_letter
+
+ def change_letter(self, number, speak=True):
+ """Add or subtract to this to change the current letter"""
+ f = self.letter_position + number
+ if f < 0:
+ self.letter_position = 0
+ elif f < len(self.text):
+ self.letter_position = f
+ else:
+ self.letter_position = len(self.text)-1
+ self.letter_to_word()
+ self.word_position = self.word_list.index(self.current_word)
+ self.current_letter = self.text[self.letter_position]
+ if speak:
+ self.speak(self.current_letter)
+ return self.current_letter
+
+ def change_word(self, number, speak=True):
+ """Will move word by word"""
+ f = self.word_position + number
+ if f < 0:
+ self.word_position = 0
+ elif f < len(self.word_list):
+ self.word_position = f
+ else:
+ self.word_position = len(self.word_list)-1
+ self.current_word = self.word_list[self.word_position]
+ self.word_to_letter()
+ if speak:
+ self.speak(self.current_word)
+ return self.current_word
+
+ def navigate(self, command, speak=True):
+ """Call this with the commands: start, end, word_forward, word_back, letter_forward, letter_back"""
+ text = self.text
+ if command == "start":
+ self.letter_position = 0
+ self.word_position = 0
+ self.letter_to_word()
+ elif command == "end":
+ self.letter_position = len(text)-1
+ self.word_position = len(self.word_list)-1
+ self.letter_to_word()
+ elif command == "word_back":
+ text = self.change_word(-1, False)
+ elif command == "word_forward":
+ text = self.change_word(1, False)
+ elif command == "letter_back":
+ text = self.change_letter(-1, False)
+ elif command == "letter_forward":
+ text = self.change_letter(1, False)
+ if speak:
+ self.speak(text)
+ return text
+
+ def speak(self, text=None):
+ """Will either speak the current text or the text that it is passed"""
+ if not text:
+ text = self.text
+ if text in lexicon:
+ text = lexicon.get(text, text)
+ spk(text)
+
+ def move(self, actions, speak=True):
+ """Will speak letters and words in a normal windows setting with right and left arrowing through the letters and ctrl+right and left arrow moving through words"""
+ key = actions['key']
+ mods = actions['mods']
+ text = ""
+ if key == "left" and not "ctrl" in mods:
+ text = self.navigate("letter_back", False)
+ elif key == "right" and not "ctrl" in mods:
+ text = self.navigate("letter_forward", False)
+ elif key == "left" and "ctrl" in mods:
+ text = self.navigate("word_back", False)
+ elif key == "right" and "ctrl" in mods:
+ text = self.navigate("word_forward", False)
+ elif key in ["up", "down"]:
+ text = self.text
+ elif key in "end":
+ text = self.navigate("end", False)
+ elif key == "home":
+ text = self.navigate("start", False)
+ if speak and text:
+ self.speak(text)
+ return text
def main():
print(current_text)
@@ -60,3 +139,35 @@ def main():
c = raw_input("< direction?")
navigate(c)
+if __name__ == '__main__':
+ f = Text("I like to dance")
+
+ import pyaudiogame
+ my_app = pyaudiogame.App("Letters and words")
+ storage = pyaudiogame.cash
+ storage.text = Text("I like to dance")
+ def logic(actions):
+ """This is using the more basic change_letter and change_word functions from the word class"""
+ k = actions['key']
+ mods = actions['mods']
+ if k == "right" and not mods:
+ f.change_letter(1)
+ elif k == "left" and not mods:
+ f.change_letter(-1)
+ elif k == "left" and "ctrl" in mods:
+ f.change_word(-1)
+ elif k == "right" and "ctrl" in mods:
+ f.change_word(1)
+ elif k == "up":
+ f.speak()
+
+ def logic(actions):
+ """This is the most simple way of using actions. You need key and mods keys in the actions dict for this to work. built for use with pyaudiogame"""
+ key = actions['key']
+ if key == "space":
+ storage.text.speak()
+ elif key:
+ storage.text.move(actions)
+
+ my_app.logic = logic
+ my_app.run()
diff --git a/pyaudiogame/ticker.py b/pyaudiogame/ticker.py
index e0d2bb2..31bb847 100644
--- a/pyaudiogame/ticker.py
+++ b/pyaudiogame/ticker.py
@@ -40,18 +40,25 @@ def tick(self, elapsed_time):
event.tick(elapsed_time*self.time_format)
[self.events.remove(e) for e in done_events]
- def schedule(self, function, delay=0, repeats=1, before_delay=False, *args, **kwargs):
- """function is the name of the function that will run without the (), delay is the amount of time to wait, repeats is the amount of times the event will run (0) for infinent, and the wrest are arguments for the function"""
- e = EventMaker(function, delay, repeats, before_delay, *args, **kwargs)
+ def schedule(self, function, delay=0, repeats=1, before_delay=False, name=None, *args, **kwargs):
+ """function is the name of the function that will run without the (), delay is the amount of time to wait, repeats is the amount of times the event will run (0) for infinent, before_delay says that the function run before the delay, name is the title of the event, and the wrest are arguments for the function"""
+ e = EventMaker(function, delay, repeats, before_delay, name, *args, **kwargs)
self.events.add(e)
+ def unschedule(self, event_name):
+ """Call this with the event name as a string to remove it from the queue"""
+ for i in self.events:
+ if i.name == event_name:
+ i.done = True
+
class EventMaker:
"""This class is the event. It has all the functions to run the event."""
- def __init__(self, function, delay, repeats, before_delay, *args, **kwargs):
+ def __init__(self, function, delay, repeats, before_delay, name, *args, **kwargs):
self.function = function
self.delay = delay
self.repeats = repeats
self.before_delay = before_delay
+ self.name = name
self.args = args
self.kwargs = kwargs
diff --git a/pyaudiogame/ui/grid.py b/pyaudiogame/ui/grid.py
index fe903b9..bbe699a 100644
--- a/pyaudiogame/ui/grid.py
+++ b/pyaudiogame/ui/grid.py
@@ -23,22 +23,24 @@ def check(self, x, y):
"""Call this to see if there is an object"""
for o in self.objects:
if x >= o.min_x and x <= o.max_x and y >= o.min_y and y <= o.max_y:
+ if o.run:
+ return o.run()
return True
- def add_wall(self, min_x=1, max_x=10, min_y=5, max_y=5):
+ def add_wall(self, min_x, max_x, min_y, max_y, run=None):
"""Adds a Wall object to the object list"""
- new_wall = Wall(min_x, max_x, min_y, max_y)
+ new_wall = Wall(min_x, max_x, min_y, max_y, run)
self.objects.append(new_wall)
return new_wall
-
class Wall(object):
"""This just has the properties for basic Wall objects"""
- def __init__(self, min_x, max_x, min_y, max_y):
+ def __init__(self, min_x, max_x, min_y, max_y, run=None):
self.min_x = min_x
self.max_x = max_x
self.min_y = min_y
self.max_y = max_y
+ self.run = run
def __repr__(self):
"""Call this class to see the below returned"""