Browse Source

Merge branch 'small-fixes-for-0.3.3'

Conflicts:
	README.html
	saves/default.ini

Published version 0.3.3 to master branch
pull/11/head 0.3.3-alpha.1
Max Lange 7 years ago
parent
commit
c9f058e85c
  1. 7
      .gitignore
  2. 178
      README.html
  3. 89
      README.md
  4. 15
      Run.py
  5. 2
      assets/lang/credits.txt
  6. BIN
      assets/sprites/Button1.tif
  7. BIN
      assets/sprites/Button2.tif
  8. BIN
      assets/sprites/Button3.tif
  9. BIN
      assets/sprites/inputbox2.tif
  10. BIN
      assets/sprites/logo.tif
  11. BIN
      assets/sprites/planet1.tif
  12. BIN
      assets/sprites/star1.tif
  13. BIN
      assets/sprites/star2.bmp
  14. BIN
      assets/sprites/star3.bmp
  15. BIN
      assets/sprites/star4.bmp
  16. BIN
      assets/sprites/star5.bmp
  17. 2
      assets/templates/default.vars
  18. 8
      assets/templates/load.menu
  19. 7
      assets/templates/main.menu
  20. 14
      assets/templates/nr1.design
  21. 1
      assets/templates/pause.menu
  22. 7
      assets/templates/savescreen.menu
  23. 1
      assets/templates/settings.menu
  24. 1
      libs/__init__.py
  25. 2
      libs/menu/IO.py
  26. 119
      libs/menu/creator.py
  27. 141
      libs/menu/disp_elem.py
  28. 99
      libs/tygamusic/tygamusic.py
  29. 11
      saves/Test.ini
  30. 15
      saves/default.ini
  31. 10
      src/__init__.py
  32. 2
      src/chat.py
  33. 69
      src/draw.py
  34. 24
      src/interface.py
  35. 24
      src/main.py
  36. 201
      src/menu.py
  37. 4
      src/midi_in.py
  38. 14
      src/missions.py
  39. 2
      src/movement.py
  40. 43
      src/namings.py
  41. 163
      src/objects.py
  42. 30
      src/player.py
  43. 139
      src/settings.py
  44. 2
      src/sounds.py
  45. 7
      src/specials.py
  46. 98
      src/worlds.py
  47. 2
      todo&notes.txt

7
.gitignore vendored

@ -5,11 +5,8 @@
**.pyo
**.pyc
#custom pattern to make ignored files without addig new rule
**IGNORE*.*
#the Ninja project file
**.nja
#Custom ignored files
**~.*
#empty folders
screenshots/*

178
README.html

@ -16,46 +16,46 @@
</script>
</head>
<body>
<p><img alt="main_picture" src="https://lh3.googleusercontent.com/-ZjA1FSivXNw/VSaOqy8nSRI/AAAAAAAAAB4/_nW122LgHr0/s701-no/all.tiff"></p>
<p><img alt="Logo" src="https://lh3.googleusercontent.com/-ZjA1FSivXNw/VSaOqy8nSRI/AAAAAAAAAB4/_nW122LgHr0/s701-no/all.tiff" title="Logo"></p>
<h2>Project Interstellar is a 2d space-adventure game</h2>
<h4>developed in and with : Python, Pygame, subversion and Ninja-IDE. Currently pre-alpha status.</h4>
<h4>developed in and with : Python, Pygame, Git/Github and Ninja-IDE. Currently pre-alpha status.</h4>
<p>Version 0.3.x</p>
<p>Version 0.3.3</p>
<h2>How to Run the Game</h2>
<p><br>This is just a developement version so you need
the programming language Python version 2.x:</br>
https://www.python.org/downloads/
<br>And the physics and graphics engine pygame:</br>
http://www.pygame.org/download.shtml
the programming language <a href="https://www.python.org/downloads/release/python-2710/">Python version 2.x .</a></br>
<br>And the physics and graphics engine <a href="http://www.pygame.org/download.shtml">Pygame.</a></br>
<br>Both have a good guide how to install them otherwise google is your friend.</br>
<h5>Windows:</h5>
In normal case double clicking Run.py should start it. If this does not work google for "How to start a .py file".
<br></br>
<h5>Debian based systems:</h5>
Double click on Run.sh. If this does not work make sure it has its executable bit set. Do this by opening a treminal in this folder or navigating there with a "normal" terminal and then copy-paste this command: chmod u+x ./Run.sh
Double click on Run.sh. If this does not work make sure it has its executable bit set. Do this by opening a terminal in this folder or navigating there with a "normal" terminal and then copy-paste this command: chmod u+x ./Run.sh
<br></br>
<h5>Other:</h5>
Google for: "how to run python files in" and add you OS
<br></br></p>
<h2>How to play</h2>
<p>To play, simply run the "Run.py" file located in the base directory</p>
<p><br>Use WASD for movement (arrowkeys work too)</br>
<br>F or space will shoot a bullet</br>
<br>When on full power use C to shoot in eight directions</br>
<br>Pressing Y makes you faster while X slower</br>
<br>Use escape to pause the game</br>
<br>Can you get below my 295294ms?</br>
<br></br></p>
<h2>Features</h2>
<p><ul>
<li>wasd or arrowkeys for movement</li>
<li>f12 for screenshot</li>
<li>f6 to change music</li>
<li>esc to exit</li>
<li>f or space to shoot</li>
<li>y to move faster</li>
<li>c when power bar is filled up will shoot in 8 directions</li>
<li>many hidden features</li>
</ul></p>
<h2>Custom music</h2>
<p>Simply paste your music into the ./assets/music folder to be included in the game.
"_" will be replaced with spaces " ". For best support use .ogg but .mp3 will work too.</p>
<h2>File / Code information</h2>
<p>(Codelines ver:0.3.2.7)</p>
<p>(Codelines ver:0.3.3)</p>
<table>
<thead>
<tr>
@ -73,88 +73,118 @@ Google for: "how to run python files in" and add you OS
<td>53</td>
</tr>
<tr>
<td>tygamusic.py</td>
<td>libs/menu/creator.py</td>
<td>351</td>
<td>84</td>
<td>435</td>
</tr>
<tr>
<td>libs/menu/disp_elem.py</td>
<td>324</td>
<td>88</td>
<td>412</td>
</tr>
<tr>
<td>libs/menu/IO.py</td>
<td>30</td>
<td>6</td>
<td>36</td>
</tr>
<tr>
<td>libs/tygamusic/tygamusic.py</td>
<td>218</td>
<td>80</td>
<td>298</td>
</tr>
<tr>
<td>chat.py</td>
<td>src/chat.py</td>
<td>4</td>
<td>5</td>
<td>9</td>
</tr>
<tr>
<td>draw.py</td>
<td>222</td>
<td>55</td>
<td>277</td>
<td>src/draw.py</td>
<td>160</td>
<td>42</td>
<td>202</td>
</tr>
<tr>
<td>interface.py</td>
<td>93</td>
<td>src/interface.py</td>
<td>108</td>
<td>17</td>
<td>110</td>
<td>125</td>
</tr>
<tr>
<td>main.py</td>
<td>44</td>
<td>34</td>
<td>78</td>
<td>src/main.py</td>
<td>46</td>
<td>30</td>
<td>76</td>
</tr>
<tr>
<td>menu.py</td>
<td>287</td>
<td>68</td>
<td>355</td>
<td>src/menu.py</td>
<td>317</td>
<td>116</td>
<td>487</td>
</tr>
<tr>
<td>midi_in.py</td>
<td>57</td>
<td>13</td>
<td>70</td>
<td>src/midi_in.py</td>
<td>71</td>
<td>19</td>
<td>90</td>
</tr>
<tr>
<td>missions.py</td>
<td>52</td>
<td>src/missions.py</td>
<td>55</td>
<td>19</td>
<td>71</td>
<td>74</td>
</tr>
<tr>
<td>src/movement.py</td>
<td>14</td>
<td>9</td>
<td>23</td>
</tr>
<tr>
<td>movement.py</td>
<td>139</td>
<td>29</td>
<td>168</td>
<td>src/namings.py</td>
<td>74</td>
<td>24</td>
<td>98</td>
</tr>
<tr>
<td>namings.py</td>
<td>57</td>
<td>16</td>
<td>73</td>
<td>src/objects.py</td>
<td>214</td>
<td>51</td>
<td>265</td>
</tr>
<tr>
<td>objects.py</td>
<td>287</td>
<td>54</td>
<td>341</td>
<td>src/player.py</td>
<td>153</td>
<td>45</td>
<td>198</td>
</tr>
<tr>
<td>settings.py</td>
<td>381</td>
<td>78</td>
<td>459</td>
<td>src/settings.py</td>
<td>317</td>
<td>17</td>
<td>394</td>
</tr>
<tr>
<td>sounds.py</td>
<td>src/sounds.py</td>
<td>7</td>
<td>4</td>
<td>11</td>
<td>5</td>
<td>12</td>
</tr>
<tr>
<td>src/specials.py</td>
<td>67</td>
<td>14</td>
<td>81</td>
</tr>
<tr>
<td>specials.py</td>
<td>70</td>
<td>15</td>
<td>85</td>
<td>src/worlds.py</td>
<td>101</td>
<td>32</td>
<td>133</td>
</tr>
<tr>
<td></td>
@ -164,26 +194,26 @@ Google for: "how to run python files in" and add you OS
</tr>
<tr>
<td><strong>Total</strong></td>
<td><strong>2220</strong></td>
<td><strong>501</strong></td>
<td><strong>2721</strong></td>
<td><strong>2723</strong></td>
<td><strong>730</strong></td>
<td><strong>3462</strong></td>
</tr>
</tbody>
</table>
<p><strong>Top3 code only:</strong><ul>
<li>settings.py 381</li>
<li>menu.py 287, 68</li>
<li>objects.py 287, 54</li></ul></p>
<li>libs/menu/creator.py 351</li>
<li>libs/menu/disp_elem.py 324</li>
<li>src/menu.py &amp; src/settings.py 317</li></ul></p>
<p><strong>Top3 Commented or empty lines:</strong><ul>
<li>tygamusic 80</li>
<li>settings.py 78</li>
<li>menu.py 68</li></ul></p>
<li>menu.py 116</li>
<li>libs/menu/disp_elem.py 88</li>
<li>libs/menu/creator.py 84</li></ul></p>
<p><strong>Top3 Total:</strong><ul>
<li>settings.py 459</li>
<li>menu.py 355</li>
<li>objects.py 341</li></ul></p>
<li>src/menu.py 487</li>
<li>libs/menu/creator.py 435</li>
<li>libs/menu/disp_elem.py 412</li></ul></p>
<h2>Contact Information</h2>
<p>You can contact me on the homepage: http://www.pygame.org/project-Project+Interstellar-2943-.html
<p>You can contact me on the <a href="http://www.pygame.org/project-Project+Interstellar-2943-.html">homepage</a>
or via email: max12354678910@gmail.com
(subject: Project_interstellar)</p>
<h2>Licences</h2>

89
README.md

@ -1,23 +1,21 @@
![main_picture](https://lh3.googleusercontent.com/-ZjA1FSivXNw/VSaOqy8nSRI/AAAAAAAAAB4/_nW122LgHr0/s701-no/all.tiff)
![Logo](https://lh3.googleusercontent.com/-ZjA1FSivXNw/VSaOqy8nSRI/AAAAAAAAAB4/_nW122LgHr0/s701-no/all.tiff "Logo")
<h2>Project Interstellar is a 2d space-adventure game</h2>
<h4>developed in and with : Python, Pygame, subversion and Ninja-IDE. Currently pre-alpha status.</h4>
<h4>developed in and with : Python, Pygame, Git/Github and Ninja-IDE. Currently pre-alpha status.</h4>
Version 0.3.x
Version 0.3.3
How to Run the Game
-------------------
<br>This is just a developement version so you need
the programming language Python version 2.x:</br>
https://www.python.org/downloads/
<br>And the physics and graphics engine pygame:</br>
http://www.pygame.org/download.shtml
the programming language [Python version 2.x .](https://www.python.org/downloads/release/python-2710/)</br>
<br>And the physics and graphics engine [Pygame.](http://www.pygame.org/download.shtml)</br>
<br>Both have a good guide how to install them otherwise google is your friend.</br>
<h5>Windows:</h5>
In normal case double clicking Run.py should start it. If this does not work google for "How to start a .py file".
<br></br>
<h5>Debian based systems:</h5>
Double click on Run.sh. If this does not work make sure it has its executable bit set. Do this by opening a treminal in this folder or navigating there with a "normal" terminal and then copy-paste this command: chmod u+x ./Run.sh
Double click on Run.sh. If this does not work make sure it has its executable bit set. Do this by opening a terminal in this folder or navigating there with a "normal" terminal and then copy-paste this command: chmod u+x ./Run.sh
<br></br>
<h5>Other:</h5>
Google for: "how to run python files in" and add you OS
@ -25,18 +23,20 @@ Google for: "how to run python files in" and add you OS
How to play
-----------
To play, simply run the "Run.py" file located in the base directory
<br>Use WASD for movement (arrowkeys work too)</br>
<br>F or space will shoot a bullet</br>
<br>When on full power use C to shoot in eight directions</br>
<br>Pressing Y makes you faster while X slower</br>
<br>Use escape to pause the game</br>
<br>Can you get below my 295294ms?</br>
<br></br>
Features
--------
<ul>
<li>wasd or arrowkeys for movement</li>
<li>f12 for screenshot</li>
<li>f6 to change music</li>
<li>esc to exit</li>
<li>f or space to shoot</li>
<li>y to move faster</li>
<li>c when power bar is filled up will shoot in 8 directions</li>
<li>many hidden features</li>
</ul>
@ -47,46 +47,51 @@ Simply paste your music into the ./assets/music folder to be included in the gam
File / Code information
-----------------------
(Codelines ver:0.3.2.7)
(Codelines ver:0.3.3)
| File | Code | Non-code | Total |
| ---: | :--: | :---------------------: | :---: |
| Run.py | 39 | 14 | 53 |
| tygamusic.py | 218 | 80 | 298 |
| chat.py | 4 | 5 | 9 |
| draw.py | 222 | 55 | 277 |
| interface.py | 93 | 17 | 110 |
| main.py | 44 | 34 | 78 |
| menu.py | 287 | 68 | 355 |
| midi_in.py | 57 | 13 | 70 |
| missions.py | 52 | 19 | 71 |
| movement.py | 139 | 29 | 168 |
| namings.py | 57 | 16 | 73 |
| objects.py | 287 | 54 | 341 |
| settings.py | 381 | 78 | 459 |
| sounds.py | 7 | 4 | 11 |
| specials.py | 70 | 15 | 85 |
| File | Code | Non-code | Total |
| --------------------------: | :-: | :-: | :-: |
| Run.py | 39 | 14 | 53 |
| libs/menu/creator.py | 351 | 84 | 435 |
| libs/menu/disp_elem.py | 324 | 88 | 412 |
| libs/menu/IO.py | 30 | 6 | 36 |
| libs/tygamusic/tygamusic.py | 218 | 80 | 298 |
| src/chat.py | 4 | 5 | 9 |
| src/draw.py | 160 | 42 | 202 |
| src/interface.py | 108 | 17 | 125 |
| src/main.py | 46 | 30 | 76 |
| src/menu.py | 317 | 116 | 487 |
| src/midi_in.py | 71 | 19 | 90 |
| src/missions.py | 55 | 19 | 74 |
| src/movement.py | 14 | 9 | 23 |
| src/namings.py | 74 | 24 | 98 |
| src/objects.py | 214 | 51 | 265 |
| src/player.py | 153 | 45 | 198 |
| src/settings.py | 317 | 17 | 394 |
| src/sounds.py | 7 | 5 | 12 |
| src/specials.py | 67 | 14 | 81 |
| src/worlds.py | 101 | 32 | 133 |
| | | |
| <strong>Total</strong> | <strong>2220</strong> | <strong>501</strong> | <strong>2721</strong> |
| <strong>Total</strong> | <strong>2723</strong> | <strong>730</strong> | <strong>3462</strong> |
<strong>Top3 code only:</strong><ul>
<li>settings.py 381</li>
<li>menu.py 287, 68</li>
<li>objects.py 287, 54</li></ul>
<li>libs/menu/creator.py 351</li>
<li>libs/menu/disp_elem.py 324</li>
<li>src/menu.py & src/settings.py 317</li></ul>
<strong>Top3 Commented or empty lines:</strong><ul>
<li>tygamusic 80</li>
<li>settings.py 78</li>
<li>menu.py 68</li></ul>
<li>menu.py 116</li>
<li>libs/menu/disp_elem.py 88</li>
<li>libs/menu/creator.py 84</li></ul>
<strong>Top3 Total:</strong><ul>
<li>settings.py 459</li>
<li>menu.py 355</li>
<li>objects.py 341</li></ul>
<li>src/menu.py 487</li>
<li>libs/menu/creator.py 435</li>
<li>libs/menu/disp_elem.py 412</li></ul>
Contact Information
-------------------
You can contact me on the homepage: http://www.pygame.org/project-Project+Interstellar-2943-.html
You can contact me on the [homepage](http://www.pygame.org/project-Project+Interstellar-2943-.html)
or via email: max12354678910@gmail.com
(subject: Project_interstellar)

15
Run.py

@ -13,8 +13,9 @@ try:
os.environ['SDL_VIDEO_CENTERED'] = '1'
pygame.init()
# checks if font module is availible
pygame.font
#Checks for correct version
# Checks for correct version
if pygame.version.ver < "1.9.1":
raise SystemExit("Old Pygame version: " + pygame.version.ver)
if sys.version[:5] < "2.7.6":
@ -22,20 +23,20 @@ try:
if sys.version[:5] >= "3.0.0":
raise SystemExit("No support for Python3")
#Run the game
# Run the game
from src import main
main.void()
#Handeling errors
# Handeling errors
except ImportError as message:
if str(message)[len(str(message)) - 6:] == "pygame": # pygame not installed
raise SystemExit("Pygame not installed")
else:
#unknown import error
# unknown import error
print (("ERROR IMPORTING MODULES: %s" % message))
raise SystemExit(traceback.format_exc())
except AttributeError as detail:
#excuted if font module is not installed
# excuted if font module is not installed
detail = str(detail)
print(detail)
if detail[len(detail) - 5:][:4] == "font": # Basicly the name of the module
@ -45,7 +46,7 @@ except AttributeError as detail:
print("")
raise SystemExit(traceback.format_exc())
except Exception as detail:
#general errors
# general errors
print(("Unexpected error:", sys.exc_info()[0]))
print("")
raise SystemExit(traceback.format_exc())
raise SystemExit(traceback.format_exc())

2
assets/lang/credits.txt

@ -40,4 +40,4 @@ check the README for further information
I am NCO
I am Pixdigit

BIN
assets/sprites/Button1.tif

Binary file not shown.

BIN
assets/sprites/Button2.tif

Binary file not shown.

BIN
assets/sprites/Button3.tif

Binary file not shown.

BIN
assets/sprites/inputbox2.tif

Binary file not shown.

BIN
assets/sprites/logo.tif

Binary file not shown.

BIN
assets/sprites/planet1.tif

Binary file not shown.

BIN
assets/sprites/star1.tif

Binary file not shown.

BIN
assets/sprites/star2.bmp

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

BIN
assets/sprites/star3.bmp

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

BIN
assets/sprites/star4.bmp

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

BIN
assets/sprites/star5.bmp

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

2
assets/templates/default.vars

@ -1,7 +1,7 @@
<#box1 = (./assets/templates/nr1.design,6)
<#box2 = (./assets/templates/nr1.design,./assets/sprites/knob1.tif,6)
<%ratio = 1100
<~size = 25
<~size = 20
<"typeface = monospace
<*color = (255,255,10)
<%half = 50

8
assets/templates/load.menu

@ -0,0 +1,8 @@
&./assets/templates/default.vars
*|Load saved game|30 |$typeface|$color |$half + 0|%10 + 0|
*|$savename |20 |$typeface|$color |$half + 0|%20 + 0|
@|Return |$size|5|$typeface|$color|$box1|%80 + 0|%30 + 0|
/add project stats here
@|Previous |$size|5|$typeface|$color|$box1|%20 + 0|%90 + 0|
@|Load |$size|5|$typeface|$color|$box1|%50 + 0|%90 + 0|
@|Next |$size|5|$typeface|$color|$box1|%80 + 0|%90 + 0|

7
assets/templates/main.menu

@ -4,6 +4,7 @@
*|Project Interstellar|40 |$typeface|$color |$half + 0|%10 + 0|
*|Main Menu |30 |$typeface|$color |$half + 0|$qrt + 0|
@|Start |$size|$ratio|$typeface|$color|$box1|$half + 0|%40 + 0|
~@|Settings |$size|$ratio|$typeface|$color|$box1|BottomLeft|%0 + 0|%0 + 10|
~~@|Credits |$size|$ratio|$typeface|$color|$box1|BottomLeft|%0 + 0|%0 + 10|
~~~@|Exit |$size|$ratio|$typeface|$color|$box1|BottomLeft|%0 + 0|%0 + 10|
~@|Load Game |$size|$ratio|$typeface|$color|$box1|BottomLeft|%0 + 0|%0 + 10|
~~@|Settings |$size|$ratio|$typeface|$color|$box1|BottomLeft|%0 + 0|%0 + 10|
~~~@|Credits |$size|$ratio|$typeface|$color|$box1|BottomLeft|%0 + 0|%0 + 10|
~~~~@|Exit |$size|$ratio|$typeface|$color|$box1|BottomLeft|%0 + 0|%0 + 10|

14
assets/templates/nr1.design

@ -1,10 +1,6 @@
type = button
#corner = ./assets/sprites/design1.tif
line = ./assets/sprites/design1.tif
#line_orientation = vertical or horiontal
#inner_color = (255,128,128,100)
#Can create templates if line xor corner is missing
#line_orientation determines wether the given template is for the left or the top
# default is for the top
design = ./assets/sprites/design1.tif
#loads a design image
# consisting of stripes with the pattern
inner_color = (0,0,50,20)
#inner_color sets the color inside the button
# default is trancparency
# default is trancparency

1
assets/templates/pause.menu

@ -1,4 +1,5 @@
&./assets/templates/default.vars
<#background = (./assets/sprites/Background1.tif)
*|Pause |35 |$typeface|$color |$half + 0|%12 + 0|
@|Continue |$size|$ratio|$typeface|$color|$box1|$half + 0|%40 + 0|

7
assets/templates/savescreen.menu

@ -1,7 +0,0 @@
&./assets/templates/default.vars
/#TODO halp
*|Load saved game|30 |$typeface|$color |$half + 0|%10 + 0|
*|$savename |20 |$typeface|$color |$half + 0|%20 + 0|
/add project stats here
@|Previous |$size|$ratio|$typeface|$color|$box1|%30 + 0|%90 + 0|
@|Next |$size|$ratio|$typeface|$color|$box1|%70 + 0|%90 + 0|

1
assets/templates/settings.menu

@ -2,6 +2,7 @@
<[sizes = (Very Small, Small, Medium, Big, Very Big)
<#background = (./assets/sprites/Background1.tif)
*|Settings |30 |$typeface|$color |$half + 0|$qrt + 0|
-|Volume |$volume |$size|$ratio|$typeface|$color|$box2 |$half + 0|%40 + 10|
~-|Button Size|$sizes|$button size|$size|$ratio|$typeface|$color|$box2|BottomLeft|%0 + 0|%0 + 10|
~~-|Fullscreen |$offon|$fullscreen |$size|$ratio|$typeface|$color|$box2|BottomLeft|%0 + 0|%0 + 10|

1
libs/__init__.py

@ -0,0 +1 @@
# -*- coding: utf-8 -*-

2
libs/menu/IO.py

@ -32,4 +32,4 @@ def read(filename, variable):
ident = line.index("<")
varname = (line[ident + 2:line.index("=") - 1]).strip()
if varname == variable:
return line[line.index("=") + 1:].strip()
return line[line.index("=") + 1:].strip()

119
libs/menu/creator.py

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
import pygame
import disp_elem
from . import disp_elem
def convert2list(string):
@ -48,6 +48,8 @@ class create_menu():
self.elems = {"buttons": [], "sliders": [], "surfs": {}}
ident = 0
all_elems = {}
elem_id = 1
with open(filename) as conf_file:
for line in conf_file:
@ -55,15 +57,14 @@ class create_menu():
if len(line) < 1 or line[0] == "/":
continue
#This checks for the identation
old_ident = ident
# This checks for the identation
ident = 0
if line[0] == "~":
ident = line[:line.index("|") - 1].count("~") # Counts identation marks
line = line[ident:] # removes identation marks for analysis
#Here are the diferent types of elements
#and comments that can be used
# Here are the diferent types of elements
# and comments that can be used
if line[0] == "&": # An import of existing variables
file2 = line[1:]
self.vars.update(create_menu(file2, {}, pygame.Rect(1, 1, 1, 1)).vars)
@ -76,9 +77,9 @@ class create_menu():
self.vars[var[1:]] = float(elem)
if var[0] == "#": # A desing variable
elems = convert2list(elem)
#this adds non-existing types
#(hoverover and klicked)
#to the desing if they are missing
# this adds non-existing types
# (hoverover and klicked)
# to the desing if they are missing
try:
elems[len(elems) - 1] = int(elems[len(elems) - 1])
if len(elems) == 2:
@ -127,15 +128,11 @@ class create_menu():
self.elems["surfs"][text] = [pygame.image.load(img[0]).convert_alpha(),
pygame.Rect(
(
(ref.w * rel_x) + abs_x,
(ref.h * rel_y) + abs_y,
),
(
0,
0
)
)]
((ref.w * rel_x) + abs_x,
(ref.h * rel_y) + abs_y,),
(0, 0))]
all_elems[elem_id] = self.elems["surfs"][text]
elem_id += 1
if line[0] == "*": # A title is defined in language
line = line[2:]
@ -183,6 +180,8 @@ class create_menu():
pos = pygame.Rect((xpos, ypos), (0, 0))
self.elems["surfs"][text] = [img, pos]
all_elems[elem_id] = self.elems["surfs"][text]
elem_id += 1
if line[0] == "@": # A button is defined in language
line = line[2:]
@ -192,10 +191,10 @@ class create_menu():
text = self.vars[text[1:]]
content = text
#Determines wether relation argument is given
additional_arguments = 1 if ident > 0 else 0
#Through relation argument there might be another "|"
if line.count("|") == 5 + additional_arguments:
# Determines wether relation argument is given
are_additional_arguments = 1 if ident > 0 else 0
# Through relation argument there might be another "|"
if line.count("|") == 5 + are_additional_arguments:
imagemode = True
line = line[line.index("|") + 1:].lstrip()
if line.strip()[0] == "$":
@ -245,8 +244,8 @@ class create_menu():
quit()
if ident > 0:
#Reads the relation point
#(Topleft, Topright, Bottomleft, Bottomright)
# Reads the relation point
# (Topleft, Topright, Bottomleft, Bottomright)
line = line[line.index("|") + 1:].lstrip()
if line[0] == "$":
relation = self.vars[line[1: line.index("|")].strip()]
@ -258,28 +257,30 @@ class create_menu():
rel_x, abs_x = analyse_num(line[0: line.index("|")].strip(), self.vars)
line = line[line.index("|") + 1:-1].lstrip()
rel_y, abs_y = analyse_num(line, self.vars)
#If relative to another button
# If relative to another button
if ident > 0:
#Adds absolute x and y value to current button
#TODO: the referring element to is not always a button
if relation[:3] == "top":
abs_y += self.elems["buttons"][-1 * (ident - old_ident)].pos.top
if relation[:6] == "bottom":
abs_y += self.elems["buttons"][-1 * (ident - old_ident)].pos.bottom
if relation[-4:] == "left":
abs_x += self.elems["buttons"][-1 * (ident - old_ident)].pos.left
if relation[-5:] == "right":
abs_x += self.elems["buttons"][-1 * (ident - old_ident)].pos.right
#Ignores relative placement
rel_x = 0
rel_y = 0
if type(all_elems[elem_id - 1]) != type(pygame.Surface):
# Adds absolute x and y value to current slider
if relation[:3] == "top":
abs_y += all_elems[elem_id - 1].pos.top
if relation[:6] == "bottom":
abs_y += all_elems[elem_id - 1].pos.bottom
if relation[-4:] == "left":
abs_x += all_elems[elem_id - 1].pos.left
if relation[-5:] == "right":
abs_x += all_elems[elem_id - 1].pos.right
# Ignores relative placement
rel_x = 0
rel_y = 0
self.elems["buttons"].append(disp_elem.button(text,
rel_x, abs_x, rel_y, abs_y, ref,
content,
typeface, size, ratio, color, design[:3]))
#Centers non-relative buttons so their center is on the
#given x and y coordiante
all_elems[elem_id] = self.elems["buttons"][-1]
elem_id += 1
# Centers non-relative buttons so their center is on the
# given x and y coordiante
if ident == 0:
self.elems["buttons"][-1].center()
@ -290,9 +291,9 @@ class create_menu():
if text[0] == "$":
text = self.vars[text[1:]]
#Determines wether relation argument is given
# Determines wether relation argument is given
additional_arguments = 1 if ident > 0 else 0
#Through relation argument there might be another "|"
# Through relation argument there might be another "|"
if line.count("|") == 10 + additional_arguments:
line = line[line.index("|") + 1:].lstrip()
if line[0] == "$":
@ -318,7 +319,6 @@ class create_menu():
options = False
line = line[line.index("|") + 1:].lstrip()
if line.strip()[0] == "$":
#print line[1: line.index("|")].strip()
default_value = float(self.vars[line[1: line.index("|")].strip()])
else:
default_value = float(line[: line.index("|")].strip())
@ -357,8 +357,8 @@ class create_menu():
quit()
if ident > 0:
#Reads the relation point
#(Topleft, Topright, Bottomleft, Bottomright)
# Reads the relation point
# (Topleft, Topright, Bottomleft, Bottomright)
line = line[line.index("|") + 1:].lstrip()
if line[0] == "$":
relation = self.vars[line[1: line.index("|")].strip()]
@ -373,22 +373,25 @@ class create_menu():
rel_y, abs_y = analyse_num(line, self.vars)
if ident > 0:
#Adds absolute x and y value to current button
if relation[:3] == "top":
abs_y += self.elems["sliders"][-1 * (ident - old_ident)].pos.top
if relation[:6] == "bottom":
abs_y += self.elems["sliders"][-1 * (ident - old_ident)].pos.bottom
if relation[-4:] == "left":
abs_x += self.elems["sliders"][-1 * (ident - old_ident)].pos.left
if relation[-5:] == "right":
abs_x += self.elems["sliders"][-1 * (ident - old_ident)].pos.right
#Ignores relative placement
rel_x = 0
rel_y = 0
if type(all_elems[elem_id - 1]) != type(pygame.Surface):
# Adds absolute x and y value to current slider
if relation[:3] == "top":
abs_y += all_elems[elem_id - 1].pos.top
if relation[:6] == "bottom":
abs_y += all_elems[elem_id - 1].pos.bottom
if relation[-4:] == "left":
abs_x += all_elems[elem_id - 1].pos.left
if relation[-5:] == "right":
abs_x += all_elems[elem_id - 1].pos.right
# Ignores relative placement
rel_x = 0
rel_y = 0
self.elems["sliders"].append(disp_elem.slider(text, default_value,
size, ratio, typeface, color, img,
rel_x, abs_x, rel_y, abs_y, ref, options))
all_elems[elem_id] = self.elems["sliders"][-1]
elem_id += 1
if ident == 0:
self.elems["sliders"][-1].center()
@ -396,6 +399,8 @@ class create_menu():
self.elems["surfs"]["background"] = [pygame.transform.smoothscale(
pygame.image.load(self.vars["background"][0]).convert(),
ref.size), pygame.Rect(0, 0, 0, 0)]
all_elems[elem_id] = self.elems["surfs"]["background"]
elem_id += 1
def blit(self, screen, events):
try:
@ -426,4 +431,4 @@ class create_menu():
for elem in self.elems:
if type(elem) != pygame.Surface:
if elem.name == name:
return elem
return elem

141
libs/menu/disp_elem.py

@ -6,7 +6,7 @@ import string
def modrender(typeface, size, text, antialias, color, maxsize, borderoff):
#local typeface!
# local typeface!
nofit = True
while nofit:
tmpfont = pygame.font.SysFont(typeface, size)
@ -20,7 +20,7 @@ def modrender(typeface, size, text, antialias, color, maxsize, borderoff):
def getmaxsize(typeface, size, text, antialias, color, maxsize, borderoff):
#local typeface!
# local typeface!
nofit = True
while nofit:
tmpfont = pygame.font.SysFont(typeface, size)
@ -38,46 +38,46 @@ class button():
def __init__(self, name, rel_x, x, rel_y, y, ref, content_in, typeface,
size, ratio, color, button_designs):
"""Initalises with x and y as center point"""
#basic font and then everything should be clear
#three different instances of create_outline!
#this way three images can be generated
# basic font and then everything should be clear
# three different instances of create_outline!
# this way three images can be generated
#This prepares button for either to contain text or an image
# This prepares button for either to contain text or an image
self.isimage = False
if content_in != name: # True = Image
if type(content_in) == pygame.Surface: # Surf already exists
content = content_in
contentpos = content.get_rect()
self.isimage = True
elif type(content_in) == str: # Only string is provided, image needs loading
elif type(content_in) == str: # Only string is provided image needs loading
content = pygame.image.load(content_in).convert_alpha()
contentpos = content.get_rect()
self.isimage = True
else: # False = Font/Text
#Loads the font
# Loads the font
self.font = pygame.font.SysFont(typeface, int(size))
#renders the text and creates a rect
# renders the text and creates a rect
content = self.font.render(name, True, color)
contentpos = content.get_rect()
#creating emtpy surface that is the size of the desired button
# creating emtpy surface that is the size of the desired button
tmp_centertext_image = pygame.Surface((contentpos.h * ratio,
contentpos.h)).convert_alpha()
tmp_centertext_image.fill((0, 0, 0, 0))
tmp_center_pos = tmp_centertext_image.get_rect()
#blitting the text onto the surface
# bliting the text onto the surface
contentpos.center = tmp_center_pos.center
tmp_centertext_image.blit(content, contentpos)
#Adding image to interface
# Adding image to interface
content = tmp_centertext_image
contentpos = content.get_rect()
#saving typeface for later use
# saving typeface for later use
self.typeface = typeface
#creating ouline templates
# creating ouline templates
normal = create_outline(button_designs[0])
hover = create_outline(button_designs[0])
klick = create_outline(button_designs[0])
@ -85,20 +85,20 @@ class button():
self.state = 0
self.name = name
self.klicked = False
#calcualte absolute position
#and define rect
# calcualte absolute position
# and define rect
x = x + rel_x * float(ref.w)
y = y + rel_y * float(ref.h)
self.pos = pygame.Rect((x, y), contentpos.size)
self.move(x, y)
#move buttons and create images
#also adds content inside button
# move buttons and create images
# also adds content inside button
for num in range(len(self.buttons)):
self.buttons[num].create_box(num, self.pos)
#defines position in the middle of button
# defines position in the middle of button
contentpos.centerx = self.buttons[num].pos.centerx - self.buttons[num].pos.x
contentpos.centery = self.buttons[num].pos.centery - self.buttons[num].pos.y
#blits content centered in button
# blits content centered in button
self.buttons[num].box.blit(content, contentpos)
self.pos.size = self.buttons[0].pos.size
@ -109,17 +109,17 @@ class button():
def changetext(self, text, color):
"""Changes the text inside the button"""
#renders the text and creates a rect
# renders the text and creates a rect
content = self.font.render(text, True, color)
contentpos = content.get_rect()
#creating emtpy surface that is the size of the desired button
# creating emtpy surface that is the size of the desired button
tmp_centertext_image = pygame.Surface((contentpos.h * ratio,
contentpos.h)).convert_alpha()
tmp_centertext_image.fill((0, 0, 0, 0))
tmp_center_pos = tmp_centertext_image.get_rect()
#blitting the text onto the surface
# bliting the text onto the surface
contentpos.center = tmp_center_pos.center
tmp_centertext_image.blit(content, contentpos)
content = tmp_centertext_image
@ -134,8 +134,8 @@ class button():
self.pos = self.pos.move(x, y)
def update(self, events):
#changes image when hovered over or being clicked
#also posts a menu event to show that a button has been clicked
# changes image when hovered over or being clicked
# also posts a menu event to show that a button has been clicked
if self.pos.collidepoint(pygame.mouse.get_pos()) and not self.klicked:
self.state = 1
for event in events:
@ -283,8 +283,13 @@ class slider():
self.knob_pos.left = self.pos.left + tmp
if type(self.options_list) == bool:
text = self.name + ": " + str(self.value * 100)[:3] + "%"
text = text.replace("0.0", "0").replace(".", "")
# adding a "." to the end to ensure at least one is included
text = str(self.value * 100)[:3] + "."
# removes "." and everything behind it
text = text[:text.index(".")]
# Adds the description and the % at the end
text = self.name + ": " + text + "%"
# Turns text into a pygame.Surface
self.render_text = self.typeface.render(text, True, self.color)
self.is_defined_list = False
else:
@ -329,16 +334,12 @@ class create_outline():
self.resources[option] = var
def create_template(self, pos):
corner = None
line = None
line_orient = None
from .creator import convert2list
design = self.resources["design"]
design = pygame.image.load(design)
self.color = None
if "corner" in self.resources:
corner = pygame.image.load(self.resources["corner"])
if "line" in self.resources:
line = pygame.image.load(self.resources["line"])
if "line_orientation" in self.resources:
line_orient = pygame.image.load(self.resources["line_orientation"])
# gets selected background color
if "inner_color" in self.resources:
color = convert2list(self.resources["inner_color"])
if len(color) == 3:
@ -347,36 +348,28 @@ class create_outline():
self.color = (int(color[0]), int(color[1]), int(color[2]), int(color[3]))
else:
self.color = (0, 0, 0, 0)
if corner is None:
if line is None:
print("No image given to create design.")
else:
if line_orient == "vertical":
line = pygame.transform.rotate(line, -90)
line_rect = line.get_rect()
size = line_rect.h
#crop the line to the wished string
line_string = pygame.Surface((1, size))
line_string.blit(line, (0, 0), pygame.Rect(pos, 0, 1, size))
line = line_string
line_rect = line.get_rect()
self.pixels = {}
self.pattern = pygame.Surface((1, size))
for a in range(size):
self.pattern.set_at((0, a), line.get_at((0, a)))
corner = pygame.Surface((size, size))
for a in range(size):
for x in range(size):
for y in range(size):
if x >= a and y >= a:
corner.set_at((x, y), self.pattern.get_at((0, a)))
else:
if line is None:
size = corner.get_height()
self.line = pygame.Surface((1, size))
for a in range(size):
self.line.set_at((0, a), corner.get_at((size - 1, a)))
return [line, corner]
design_rect = design.get_rect()
size = design_rect.h
# extract the selected collum
line_string = pygame.Surface((1, size))
line_string.blit(design, (0, 0), pygame.Rect(pos, 0, 1, size))
design = line_string
design_rect = design.get_rect()
self.pixels = {}
# create the final surface to blit pattern to
self.pattern = pygame.Surface((1, size))
# set the pixel colors for the pattern
for a in range(size):
self.pattern.set_at((0, a), design.get_at((0, a)))
# transforms linear pattern into a corner
corner = pygame.Surface((size, size))
for a in range(size):
for x in range(size):
for y in range(size):
if x >= a and y >= a:
corner.set_at((x, y), self.pattern.get_at((0, a)))
return [self.pattern, corner]
def create_box(self, mode, rect):
posx = rect.x
@ -387,24 +380,24 @@ class create_outline():
width += border * 2
height += border * 2
self.top = pygame.Surface((width, border))
#creating top frame line
# creating top frame line
for pos in range(width):
self.top.blit(self.modes[mode][0], pygame.Rect(pos, 0, 0, 0))
#blit left top corner
# blit left top corner
self.top.blit(self.modes[mode][1], pygame.Rect(0, 0, 0, 0))
#blit right top corner
# blit right top corner
self.top.blit(pygame.transform.flip(self.modes[mode][1], True, False),
pygame.Rect(width - border, 0, 0, 0))
#create bottom line
# create bottom line
self.bottom = pygame.transform.flip(self.top, False, True)
#create left frame line
# create left frame line
self.left = pygame.Surface((border, height))
tmp_line = pygame.transform.rotate(self.modes[mode][0], 90)
for pos in range(height):
self.left.blit(tmp_line, pygame.Rect(0, pos, 0, 0))
#create right frame line
# create right frame line
self.right = pygame.transform.flip(self.left, True, False)
#Merge all together
# Merge all together
final = pygame.Surface((width, height), pygame.SRCALPHA)
final.fill(self.color)
final.blit(self.left, pygame.Rect(0, 0, 0, 0))
@ -415,4 +408,4 @@ class create_outline():
self.pos = self.box.get_rect()
self.pos.x = posx - border
self.pos.y = posy - border
return (self.pos, self.box)
return (self.pos, self.box)

99
libs/tygamusic/tygamusic.py

@ -19,7 +19,7 @@ class CreateQueue():
"""Initizalize a new Playlist-like object.
usage:
object = CreateQueue(self, path, exceptbegin, endevent=USEREVENT+100)
object = CreateQueue(path, exceptbegin, endevent=USEREVENT+100)
path (string)
is the path tygamusic should search for availible music.
@ -44,27 +44,23 @@ self.files (list)
A list of all files for possible playback.
self.playlist (list)
A list containing the filenames of the songs.
If self.update() is called without its shouldplaynextsong option
explicitly set to False the next song of this list will be played
if music has ended.
self.volume (float)
A value from 0 to 1 for playback volume.
Volume gets updated if self.update is called.
These are
These are internal values that should not be modified unless
you are 100% sure what you do.
self._endeventnum (int)
An int used for defining the event when music playback has stopped.
Changing this after creating the object has no effect.
self._path (str)
This contains the path to from where music should be loaded
Changing this in an created object may cause errors
except you know what you're doing exactly.
This contains the path to from where music should be loaded.
self._pauselevel (int)
An int representing how many songs have ben paused
An int representing how many songs have been paused
while an other song was already paused.
self._playing (bool)
Determines wether a song currently loaded (aka "playing")
Determines wether a song is currently loaded (aka "playing")
self._timeplayed (dict)
A dictionary with entrys looking like this:
self._timeplayed[filename] = current_playing_pos
@ -91,16 +87,16 @@ self._timeplayed (dict)
def get_music(self):
"""Return all files with given conditions."""
#Look up tygamusic.CreateQueue.__init__.__doc__ for more info
# Look up tygamusic.CreateQueue.__init__.__doc__ for more info
files = []
#Runs through all files and checks for filetype
# Runs through all files and checks for filetype
for filename in os.listdir(self._path):
supportedmusic = [
filename.endswith(".ogg") or filename.endswith(".mp3")
or filename.endswith(".mid") or filename.endswith(".midi")
or filename.endswith(".wav")]
#Adds file if it is supported format
# Adds file if it is supported format
# and doesn't begin with specified beinning
if (supportedmusic[0] and
filename[0:len(self.__exception)] != self.__exception):
@ -124,21 +120,20 @@ shouldplaynextsong (bool)
if music has ended
"""
#print self.volume
#Adjust volume to its own volume.
# Adjust volume to its own volume.
pygame.mixer.music.set_volume(self.volume)
#Adds a random song to playlist
# Adds a random song to playlist
# if it is smaller than the amount of music provided
if len(self.playlist) < len(self.files) - 1 and self.files != [None]:
self.add_random("end")
#If no events are specified pygame.event.get()
# If no events are specified pygame.event.get()
# will be called.
if type(events) == bool:
if events:
events = pygame.event.get()
else:
return
#Playes next song if the last one has ended.
# Playes next song if the previous one has ended.
if self.__endevent in events and shouldplaynextsong:
self.playlist.pop(0)
self._playing = False
@ -150,48 +145,48 @@ shouldplaynextsong (bool)
Usage:
self.play(operation, *options)
Operations:
"play" (needs amount of replays additionally)
"next" (needs amount of replays additionally)
"play" (amount of replays can be defined optionally)
"next" (amount of replays can be defined optionally)
"loop"