├── .gitignore
├── LICENSE
├── README.md
├── docs
├── assets
│ ├── bg.png
│ ├── discord.png
│ ├── github.png
│ ├── twitter.png
│ └── youtube.png
├── contact.html
├── css
│ ├── docs.css
│ ├── nav.css
│ └── style.css
├── docs.html
└── index.html
├── install.bat
├── mandaw
├── __init__.py
├── animation.py
├── assets
│ └── mandaw.png
├── audio.py
├── examples
│ ├── assets
│ │ ├── adventurer.png
│ │ ├── bird.jpeg
│ │ ├── circle.png
│ │ ├── idle1
│ │ │ ├── adventurer-idle-00.png
│ │ │ ├── adventurer-idle-01.png
│ │ │ ├── adventurer-idle-02.png
│ │ │ └── adventurer-idle-03.png
│ │ ├── mountains.png
│ │ └── normal-run
│ │ │ ├── adventurer-run-00.png
│ │ │ ├── adventurer-run-01.png
│ │ │ ├── adventurer-run-02.png
│ │ │ ├── adventurer-run-03.png
│ │ │ ├── adventurer-run-04.png
│ │ │ └── adventurer-run-05.png
│ ├── background.py
│ ├── collision.py
│ ├── particle.py
│ ├── physics
│ │ ├── ball.py
│ │ ├── cloth.py
│ │ └── physics.py
│ ├── platformer.py
│ ├── pong.py
│ └── sprite-animation.py
├── gameobject.py
├── input.py
├── light.py
├── line.py
├── main.py
├── particle.py
├── prefabs
│ ├── __init__.py
│ └── platformer_controller.py
├── sprite.py
└── text.py
└── setup.py
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | build/
12 | develop-eggs/
13 | dist/
14 | downloads/
15 | eggs/
16 | .eggs/
17 | lib/
18 | lib64/
19 | parts/
20 | sdist/
21 | var/
22 | wheels/
23 | pip-wheel-metadata/
24 | share/python-wheels/
25 | *.egg-info/
26 | .installed.cfg
27 | *.egg
28 | MANIFEST
29 |
30 | # PyInstaller
31 | # Usually these files are written by a python script from a template
32 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
33 | *.manifest
34 | *.spec
35 |
36 | # Installer logs
37 | pip-log.txt
38 | pip-delete-this-directory.txt
39 |
40 | # Unit test / coverage reports
41 | htmlcov/
42 | .tox/
43 | .nox/
44 | .coverage
45 | .coverage.*
46 | .cache
47 | nosetests.xml
48 | coverage.xml
49 | *.cover
50 | *.py,cover
51 | .hypothesis/
52 | .pytest_cache/
53 |
54 | # Translations
55 | *.mo
56 | *.pot
57 |
58 | # Django stuff:
59 | *.log
60 | local_settings.py
61 | db.sqlite3
62 | db.sqlite3-journal
63 |
64 | # Flask stuff:
65 | instance/
66 | .webassets-cache
67 |
68 | # Scrapy stuff:
69 | .scrapy
70 |
71 | # Sphinx documentation
72 | docs/_build/
73 |
74 | # PyBuilder
75 | target/
76 |
77 | # Jupyter Notebook
78 | .ipynb_checkpoints
79 |
80 | # IPython
81 | profile_default/
82 | ipython_config.py
83 |
84 | # pyenv
85 | .python-version
86 |
87 | # pipenv
88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies
90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not
91 | # install all needed dependencies.
92 | #Pipfile.lock
93 |
94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow
95 | __pypackages__/
96 |
97 | # Celery stuff
98 | celerybeat-schedule
99 | celerybeat.pid
100 |
101 | # SageMath parsed files
102 | *.sage.py
103 |
104 | # Environments
105 | .env
106 | .venv
107 | env/
108 | venv/
109 | ENV/
110 | env.bak/
111 | venv.bak/
112 |
113 | # Spyder project settings
114 | .spyderproject
115 | .spyproject
116 |
117 | # Rope project settings
118 | .ropeproject
119 |
120 | # mkdocs documentation
121 | /site
122 |
123 | # mypy
124 | .mypy_cache/
125 | .dmypy.json
126 | dmypy.json
127 |
128 | # Pyre type checker
129 | .pyre/
130 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Mandaw
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # MandawEngine
2 | A Game Engine Made in Python with the Pygame Module
3 |
4 | Discord: https://discord.gg/MPPqj9PNt3
5 |
6 | # Installation
7 | To Get The Latest Version of MandawEngine:
8 | On Windows:
9 | ```
10 | pip install https://github.com/mandaw2014/mandawengine/archive/master.zip
11 | ```
12 | On Mac and Linux
13 | ```
14 | pip3 install https://github.com/mandaw2014/mandawengine/archive/master.zip
15 | ```
16 |
17 | # Getting Started
18 | import Mandaw
19 | ```py
20 | from mandaw import *
21 | ```
22 |
23 | Make a window
24 | ```py
25 | from mandaw import *
26 |
27 | mandaw = Mandaw()
28 |
29 | mandaw.loop()
30 | ```
31 | Make a simple square
32 | ```py
33 | square = GameObject(window = mandaw, shape = "rect", x = 0, y = 0, color = "red", width = 20, height = 20)
34 | ```
35 | Center it with
36 | ```py
37 | square.center()
38 | ```
39 | Draw it
40 | ```py
41 | @mandaw.draw
42 | def draw():
43 | square.draw()
44 | ```
45 | # Full Code
46 | ```py
47 | from mandaw import *
48 |
49 | mandaw = Mandaw("First Mandaw Window!")
50 |
51 | square = GameObject(window = mandaw, shape = "rect", x = 0, y = 0, color = "red", width = 20, height = 20)
52 | square.center()
53 |
54 | @mandaw.draw
55 | def draw():
56 | square.draw()
57 |
58 | mandaw.loop()
59 | ```
60 | # Collisions Between GameObjects
61 | What we have so far
62 | ```py
63 | from mandaw import *
64 |
65 | mandaw = Mandaw("Collisions!", bg_color = "cyan")
66 |
67 | square = GameObject(window = mandaw, shape = "rect", x = 0, y = 0, color = "orange", width = 20, height = 30)
68 | square.center()
69 |
70 | ground = GameObject(window = mandaw, shape = "rect", x = 0, y = 0, color = "gray", width = 5000, height = 100)
71 | ground.center()
72 | ground.y = 500
73 |
74 | @mandaw.draw
75 | def draw():
76 | square.draw()
77 | ground.draw()
78 |
79 | mandaw.loop()
80 | ```
81 | Here We Can Use The `collide()` Function along with the built in `update()` function. For example, We're Going To Make Gravity Here
82 | ```py
83 | from mandaw import *
84 |
85 | mandaw = Mandaw("Collisions!", bg_color = "cyan")
86 |
87 | square = GameObject(window = mandaw, shape = "rect", x = 0, y = 0, color = "orange", width = 20, height = 30)
88 | square.center()
89 |
90 | ground = GameObject(window = mandaw, shape = "rect", x = 0, y = 0, color = "gray", width = 5000, height = 100)
91 | ground.center()
92 | ground.y = 500
93 |
94 | @mandaw.draw
95 | def draw():
96 | square.draw()
97 | ground.draw()
98 |
99 | @mandaw.update
100 | def update(dt):
101 | # Collision code here
102 | if not square.collide(ground):
103 | # Square's y position += 1 x deltaTime
104 | square.y += 1 * dt
105 |
106 | mandaw.loop()
107 | ```
108 |
109 | # Platformer Controller Prefab
110 | What we have so far
111 | ```py
112 | from mandaw import *
113 |
114 | mandaw = Mandaw("Platformer Example", bg_color = "cyan")
115 |
116 | mandaw.loop()
117 | ```
118 | Import the PlatformerController2D with
119 | ```py
120 | from mandaw.prefabs.platformer_controller import PlatformerController2D
121 | ```
122 | Then call it
123 | ```py
124 | player = PlatformerController2D(mandaw, x = 0, y = 0, centered = True)
125 | ```
126 | Then in the ```def update(dt)``` function, call
127 | ```py
128 | @mandaw.update
129 | def update(dt)
130 | player.movement(dt)
131 | ```
132 |
--------------------------------------------------------------------------------
/docs/assets/bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mandaw2014/MandawEngine/cd360c341c757c883f6ceefd5fd3eac03dd86004/docs/assets/bg.png
--------------------------------------------------------------------------------
/docs/assets/discord.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mandaw2014/MandawEngine/cd360c341c757c883f6ceefd5fd3eac03dd86004/docs/assets/discord.png
--------------------------------------------------------------------------------
/docs/assets/github.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mandaw2014/MandawEngine/cd360c341c757c883f6ceefd5fd3eac03dd86004/docs/assets/github.png
--------------------------------------------------------------------------------
/docs/assets/twitter.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mandaw2014/MandawEngine/cd360c341c757c883f6ceefd5fd3eac03dd86004/docs/assets/twitter.png
--------------------------------------------------------------------------------
/docs/assets/youtube.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mandaw2014/MandawEngine/cd360c341c757c883f6ceefd5fd3eac03dd86004/docs/assets/youtube.png
--------------------------------------------------------------------------------
/docs/contact.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Contact
8 |
9 |
10 |
11 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/docs/css/docs.css:
--------------------------------------------------------------------------------
1 | *{
2 | padding: 0;
3 | margin: 0;
4 | font-family: 'Roboto Mono', monospace;
5 | text-decoration: none;
6 | }
7 |
8 | .docs {
9 | text-align: center;
10 | position: relative;
11 | font-size: 20px;
12 | }
13 |
14 | h1 {
15 | text-align: center;
16 | position: relative;
17 | font-size: 50px;
18 | }
19 |
20 | .code_block {
21 | text-align: center;
22 | position: relative;
23 | }
24 |
25 | purple {
26 | color: hsl(289.0, 50%, 50%);
27 | }
28 |
29 | gray {
30 | color: rgb(119, 119, 119);
31 | }
32 |
33 | lightgray {
34 | color: rgb(177, 177, 177);
35 | }
36 |
37 | orange {
38 | color: rgba(255, 115, 0, 0.699);
39 | }
40 |
41 | green {
42 | color: rgb(152, 255, 56);
43 | }
44 |
45 | darkgreen {
46 | color: rgb(128, 182, 1);
47 | }
48 |
49 | blue {
50 | color: rgb(3, 61, 253);
51 | }
52 |
53 | yellow {
54 | color: rgb(219, 186, 0);
55 | }
56 |
--------------------------------------------------------------------------------
/docs/css/nav.css:
--------------------------------------------------------------------------------
1 | header {
2 | background-color: #404040;
3 | }
4 |
5 | .main-nav {
6 | height: 90px;
7 | }
8 |
9 | .logo {
10 | color: white;
11 | line-height: 90px;
12 | font-size: 30px;
13 | font-weight: bold;
14 | text-decoration: none;
15 | margin-left: 30px;
16 | }
17 |
18 | .navlinks {
19 | list-style: none;
20 | float: right;
21 | line-height: 90px;
22 | margin: 0;
23 | padding: 0;
24 | }
25 |
26 | .navlinks li {
27 | display: inline-block;
28 | margin: 0px 20px;
29 | }
30 |
31 | .navlinks li a {
32 | color: white;
33 | text-decoration: none;
34 | transition: all 0.3s linear 0s;
35 | text-transform: uppercase;
36 | }
37 |
38 | .navlinks li a:hover {
39 | color: #7ebcb9;
40 | padding-bottom: 7px;
41 | border-bottom: 2px solid #7ebcb9;
42 | }
43 |
44 | li a.contact {
45 | background-color: #00adb5;
46 | padding: 9px 20px;
47 | border-radius: 50px;
48 | transition: all 0.3s ease 0s;
49 | border-bottom: none;
50 | }
51 |
52 | li a.contact:hover {
53 | background-color: #047e85;
54 | color: white;
55 | border-bottom: none;
56 | }
57 |
58 | #check {
59 | display: none;
60 | }
61 |
62 | .menu-btn {
63 | font-size: 25px;
64 | color: white;
65 | float: right;
66 | line-height: 90px;
67 | margin-right: 40px;
68 | display: none;
69 | cursor: pointer;
70 | }
71 |
72 | @media (max-width: 800px) {
73 | .navlinks {
74 | position: fixed;
75 | width: 100%;
76 | height: 100vh;
77 | text-align: center;
78 | transition: all 0.5s;
79 | right: -100%;
80 | background: #222831;
81 | }
82 | .navlinks li {
83 | display: block;
84 | }
85 | .navlinks li a {
86 | font-size: 20px;
87 | }
88 | .navlinks li a:hover {
89 | border-bottom: none;
90 | }
91 | .menu-btn {
92 | display: block;
93 | }
94 | #check:checked ~ .navlinks {
95 | right: 0;
96 | }
97 | }
98 |
99 | @media (max-width: 360px) {
100 | .logo {
101 | margin-left: 10px;
102 | font-size: 25px;
103 | }
104 | .menu-btn {
105 | margin-right: 10px;
106 | font-size: 25px;
107 | }
108 | .menu-btn:focus {
109 | color: blue;
110 | }
111 | }
--------------------------------------------------------------------------------
/docs/css/style.css:
--------------------------------------------------------------------------------
1 | *{
2 | padding: 0;
3 | margin: 0;
4 | font-family: 'Roboto Mono', monospace;
5 | }
6 |
7 | #slogan {
8 | position: relative;
9 | text-align: center;
10 | z-index: -4;
11 | font-size: 50px;
12 | top: 200px;
13 | }
14 |
15 | #bg {
16 | width: 100%;
17 | display: block;
18 | margin-left: auto;
19 | margin-right: auto;
20 | position: relative;
21 | top: -70px;
22 | z-index: -5;
23 | }
24 |
25 | #install {
26 | text-align: center;
27 | position: relative;
28 | top: 50px;
29 | }
30 |
31 | .code_block {
32 | text-align: center;
33 | position: relative;
34 | }
35 |
36 | purple {
37 | color: hsl(289.0, 50%, 50%);
38 | }
39 |
40 | gray {
41 | color: rgb(119, 119, 119);
42 | }
43 |
44 | orange {
45 | color: rgba(255, 115, 0, 0.699);
46 | }
47 |
48 | green {
49 | color: rgb(152, 255, 56);
50 | }
51 |
52 | blue {
53 | color: rgb(3, 61, 253);
54 | }
55 |
56 | yellow {
57 | color: rgb(219, 186, 0);
58 | }
59 |
60 | @media screen and (max-width: 630px) {
61 | #bg {
62 | top: -130px;
63 | }
64 | #slogan {
65 | top: 60px;
66 | }
67 | }
--------------------------------------------------------------------------------
/docs/docs.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Documentation
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
32 |
33 | Mandaw
34 |
35 |
38 |
39 |
40 |
title =
"Mandaw"
41 |
width =
800
42 |
height =
600
43 |
bg_color =
"black"
44 |
# Background sprite
45 |
background =
type :
FileType
46 |
fps =
60
47 |
keys = []
48 |
input =
Input ()
49 |
run (
self )
50 |
51 |
52 | Mandaw (title , width , height , bg_color )
53 |
54 |
55 |
56 | GameObject
57 |
58 |
61 |
62 |
63 |
window =
type :
Mandaw
64 |
shape =
"rect"
65 |
size = (
20 ,
20 )
66 |
x =
0
67 |
y =
0
68 |
color =
"white"
69 |
draw (
self )
70 |
center (
self )
71 |
center_x (
self )
72 |
center_y (
self )
73 |
74 |
# Can be a GameObject or a List of GameObjects
75 |
collide (
self ,
rect )
76 |
77 |
78 | GameObject (window , shape , size , x , y , color )
79 |
80 |
81 |
82 | Input
83 |
84 |
87 |
88 | Input
89 |
90 |
91 |
pressed =
pygame .
key .
get_pressed ()
92 |
mouse =
pygame .
mouse .
get_pressed ()
93 |
94 |
update (
self )
95 |
get_key_pressed (
self ,
key )
96 |
get_mouse_button (
self ,
button )
97 |
98 |
99 | Input ()
100 |
101 |
102 |
103 | Sprite
104 |
105 |
108 |
109 |
110 |
window =
type :
Mandaw
111 |
image =
type :
FileType
112 |
x =
0
113 |
y =
0
114 |
size = (
200 ,
200 )
115 |
animations = {}
116 |
rect =
pygame .
Rect (
x ,
y ,
size [
0 ],
size [
1 ])
117 |
118 |
draw (
self )
119 |
get_width (
self )
120 |
get_height (
self )
121 |
center (
self )
122 |
center_x (
self )
123 |
center_y (
self )
124 |
collide (
self ,
rect )
125 |
resize (
self ,
size )
126 |
add_animation (
self ,
animation ,
name )
127 |
play_animation (
self ,
name ,
mirror =
None )
128 |
129 |
130 | Sprite (window , image , x , y , size )
131 |
132 |
133 |
134 | Animation
135 |
136 |
139 |
140 |
141 |
anim_folder =
type :
FileType
142 |
anim_time =
type :
Int
143 |
frames = []
144 |
count =
len (
frames )
145 |
146 |
147 | Animation (anim_folder , anim_time )
148 |
149 |
150 |
151 | Color
152 |
153 |
156 |
157 |
158 |
color =
type :
String
159 |
160 |
161 | Color (color )
162 |
163 |
164 |
165 | Text
166 |
167 |
170 |
171 |
172 |
window =
type :
Mandaw
173 |
text =
type :
String
174 |
font_size =
24
175 |
style =
type :
String
176 |
color =
"white"
177 |
x =
0
178 |
y =
0
179 |
font =
pygame .
font .
SysFont (
style ,
font_size )
180 |
text =
font .
render (
text ,
True ,
color )
181 |
draw (
self )
182 |
center (
self )
183 |
184 |
185 | Text (window , text , font_size , style , color x , y )
186 |
187 |
188 |
189 | Audio
190 |
191 |
194 |
195 |
196 |
file =
type :
String
197 |
volume =
type :
Int
198 |
play (
self )
199 |
pause (
self )
200 |
resume (
self )
201 |
stop (
self )
202 |
203 |
204 | Audio (file , volume )
205 |
206 |
207 |
208 | Line
209 |
210 |
213 |
214 |
215 |
window =
type :
Mandaw
216 |
color =
type :
String
217 |
start_pos =
type :
Int
218 |
end_pos =
type :
Int
219 |
220 |
221 | Line (window , color , start_pos , end_pos )
222 |
223 |
224 |
225 | Light
226 |
227 |
230 |
231 |
232 |
window =
type :
Mandaw
233 |
mask_img =
type :
FileType
234 |
235 |
light_init (
self ,
pos )
236 |
draw (
self )
237 |
238 |
239 | Light (window , mask_img )
240 |
241 |
242 |
243 | .
244 |
245 |
246 |
--------------------------------------------------------------------------------
/docs/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | MandawEngine
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
33 |
34 | 2D at its simplest.
35 |
36 |
37 |
38 | Getting Started
39 | Installation
40 |
41 |
pip install mandaw
42 |
43 |
44 | Or To Install The Latest Version
45 | Download The Zip In The Github On Windows: Run The install.bat On Mac and Linux:
46 |
47 |
48 |
python3 setup.py install
49 |
50 |
51 | Making a Window
52 | First, Import Mandaw
53 |
54 |
55 |
from mandaw
import *
56 |
57 |
58 | Then Call Mandaw
59 |
60 |
61 | mandaw = Mandaw(title = "Mandaw" , width = 800 , height = 600 , bg_color = "cyan" )
62 |
63 |
64 | And then Run Mandaw with
65 |
66 |
67 |
while True : mandaw.
run ()
68 |
69 |
70 | Making A Square
71 | Declare the Square With GameObject
72 |
73 |
74 | square = GameObject(window = mandaw, shape = "rect" , size = (20 ,20 ), x = 0 , y = 0 , color = "white" )
75 |
76 |
77 | Then to Center it, write
78 |
79 |
80 | square.center ()
81 |
82 |
83 | Then in the while True : loop, write
84 |
85 |
86 | square.draw ()
87 |
88 |
89 | Collisions Between GameObjects
90 | Make A Ground
91 |
92 |
93 | ground = GameObject(window = mandaw, shape = "rect" , size = (5000 , 100 ), x = 0 , y = 500 , color = "gray" )
94 |
95 |
96 | Center It's X
97 |
98 |
99 | ground.center_x ()
100 |
101 |
102 | Draw it in the while True : loop
103 |
104 |
105 | ground.draw ()
106 |
107 |
108 | Here we can use the collide () function
109 |
110 |
111 |
# Square's y position += 1 x deltaTime
112 |
if not square.
collide (ground):
square.
y +=
1 * mandaw.
dt
113 |
114 |
115 |
118 |
119 | Input in Mandaw
120 |
121 |
122 |
if mandaw.
input .
get_key_pressed (mandaw.
keys [
"A" ]):
print (
"A was pressed!" )
123 |
if mandaw.
input .
get_key_pressed (mandaw.
keys [
"D" ]):
print (
"D was pressed!" )
124 |
if mandaw.
input .
get_mouse_button (
mandaw.
mouse_buttons [
"LEFT" ]):
print (
"Left mouse button was pressed! )
125 |
126 |
127 | .
128 |
129 |
130 |
--------------------------------------------------------------------------------
/install.bat:
--------------------------------------------------------------------------------
1 | python setup.py install
2 | pause
--------------------------------------------------------------------------------
/mandaw/__init__.py:
--------------------------------------------------------------------------------
1 | import os
2 | os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
3 |
4 | from mandaw.main import Mandaw
5 | from mandaw.gameobject import GameObject
6 | from mandaw.line import Line
7 | from mandaw.sprite import Sprite
8 | from mandaw.text import Text
9 | from mandaw.input import Input
10 | from mandaw.audio import Audio
11 | from mandaw.animation import Animation
12 | from mandaw.light import Light
13 | from mandaw.particle import ParticleSpawner
14 |
--------------------------------------------------------------------------------
/mandaw/animation.py:
--------------------------------------------------------------------------------
1 | import os
2 |
3 | class Animation:
4 | def __init__(self, anim_folder, anim_time):
5 | self.frames = []
6 | self.anim_time = anim_time
7 | self.folder = anim_folder
8 |
9 | for f in os.listdir(anim_folder):
10 | if os.path.splitext(f)[1] == ".png":
11 | self.frames.append(f)
12 |
13 | self.frames = sorted(self.frames)
14 | self.count = len(self.frames)
15 |
--------------------------------------------------------------------------------
/mandaw/assets/mandaw.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mandaw2014/MandawEngine/cd360c341c757c883f6ceefd5fd3eac03dd86004/mandaw/assets/mandaw.png
--------------------------------------------------------------------------------
/mandaw/audio.py:
--------------------------------------------------------------------------------
1 | from pygame import mixer
2 |
3 | class Audio:
4 | def __init__(self, file, volume):
5 | self.volume = volume
6 |
7 | self.audio = mixer.Sound(file)
8 | self.audio.set_volume(self.volume)
9 |
10 | def play(self):
11 | self.audio.play()
12 |
13 | def stop(self):
14 | self.audio.stop()
15 |
--------------------------------------------------------------------------------
/mandaw/examples/assets/adventurer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mandaw2014/MandawEngine/cd360c341c757c883f6ceefd5fd3eac03dd86004/mandaw/examples/assets/adventurer.png
--------------------------------------------------------------------------------
/mandaw/examples/assets/bird.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mandaw2014/MandawEngine/cd360c341c757c883f6ceefd5fd3eac03dd86004/mandaw/examples/assets/bird.jpeg
--------------------------------------------------------------------------------
/mandaw/examples/assets/circle.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mandaw2014/MandawEngine/cd360c341c757c883f6ceefd5fd3eac03dd86004/mandaw/examples/assets/circle.png
--------------------------------------------------------------------------------
/mandaw/examples/assets/idle1/adventurer-idle-00.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mandaw2014/MandawEngine/cd360c341c757c883f6ceefd5fd3eac03dd86004/mandaw/examples/assets/idle1/adventurer-idle-00.png
--------------------------------------------------------------------------------
/mandaw/examples/assets/idle1/adventurer-idle-01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mandaw2014/MandawEngine/cd360c341c757c883f6ceefd5fd3eac03dd86004/mandaw/examples/assets/idle1/adventurer-idle-01.png
--------------------------------------------------------------------------------
/mandaw/examples/assets/idle1/adventurer-idle-02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mandaw2014/MandawEngine/cd360c341c757c883f6ceefd5fd3eac03dd86004/mandaw/examples/assets/idle1/adventurer-idle-02.png
--------------------------------------------------------------------------------
/mandaw/examples/assets/idle1/adventurer-idle-03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mandaw2014/MandawEngine/cd360c341c757c883f6ceefd5fd3eac03dd86004/mandaw/examples/assets/idle1/adventurer-idle-03.png
--------------------------------------------------------------------------------
/mandaw/examples/assets/mountains.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mandaw2014/MandawEngine/cd360c341c757c883f6ceefd5fd3eac03dd86004/mandaw/examples/assets/mountains.png
--------------------------------------------------------------------------------
/mandaw/examples/assets/normal-run/adventurer-run-00.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mandaw2014/MandawEngine/cd360c341c757c883f6ceefd5fd3eac03dd86004/mandaw/examples/assets/normal-run/adventurer-run-00.png
--------------------------------------------------------------------------------
/mandaw/examples/assets/normal-run/adventurer-run-01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mandaw2014/MandawEngine/cd360c341c757c883f6ceefd5fd3eac03dd86004/mandaw/examples/assets/normal-run/adventurer-run-01.png
--------------------------------------------------------------------------------
/mandaw/examples/assets/normal-run/adventurer-run-02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mandaw2014/MandawEngine/cd360c341c757c883f6ceefd5fd3eac03dd86004/mandaw/examples/assets/normal-run/adventurer-run-02.png
--------------------------------------------------------------------------------
/mandaw/examples/assets/normal-run/adventurer-run-03.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mandaw2014/MandawEngine/cd360c341c757c883f6ceefd5fd3eac03dd86004/mandaw/examples/assets/normal-run/adventurer-run-03.png
--------------------------------------------------------------------------------
/mandaw/examples/assets/normal-run/adventurer-run-04.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mandaw2014/MandawEngine/cd360c341c757c883f6ceefd5fd3eac03dd86004/mandaw/examples/assets/normal-run/adventurer-run-04.png
--------------------------------------------------------------------------------
/mandaw/examples/assets/normal-run/adventurer-run-05.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mandaw2014/MandawEngine/cd360c341c757c883f6ceefd5fd3eac03dd86004/mandaw/examples/assets/normal-run/adventurer-run-05.png
--------------------------------------------------------------------------------
/mandaw/examples/background.py:
--------------------------------------------------------------------------------
1 | from mandaw import *
2 |
3 | mandaw = Mandaw("Mountain Background", 800, 600, "white")
4 |
5 | mandaw.background = Sprite(mandaw, "./assets/mountains.png", 0, 0, width = mandaw.width, height = mandaw.height)
6 |
7 | mandaw.loop()
--------------------------------------------------------------------------------
/mandaw/examples/collision.py:
--------------------------------------------------------------------------------
1 | from mandaw import *
2 |
3 | mandaw = Mandaw(title = "Mandaw", width = 800, height = 600, bg_color = "cyan")
4 |
5 | square = GameObject(window = mandaw, shape = "rect", width = 20, height = 30, x = 0, y = 0, color = "orange")
6 | square.center()
7 |
8 | ground = GameObject(window = mandaw, shape = "rect", width = 5000, height = 100, x = 0, y = 0, color = "gray")
9 | ground.center()
10 | ground.y = 500
11 |
12 | sprite = Sprite(mandaw, "assets/adventurer.png", 10, 10, 100, 100)
13 |
14 | @mandaw.draw
15 | def draw():
16 | square.draw()
17 | ground.draw()
18 | sprite.draw()
19 |
20 | @mandaw.update
21 | def update(dt):
22 | if not square.collide(ground):
23 | square.y += 150 * dt
24 | if not sprite.collide(ground):
25 | sprite.y += 150 * dt
26 |
27 | mandaw.loop()
--------------------------------------------------------------------------------
/mandaw/examples/particle.py:
--------------------------------------------------------------------------------
1 | from mandaw import *
2 |
3 | mandaw = Mandaw("Particles")
4 | particle = ParticleSpawner(mandaw, 10, (100, 100), 20, (-2, 2), (-2, 2), 0.1, "white", True, 0, [])
5 |
6 | # Args: window, particle count, position, size, velocityx, velocityy, shrink per frame, color, collide, gravity,
7 | # collide_rects
8 |
9 | # Randomizing:
10 | # You can use randomize with particlespawner. You need to create list or tuple (eg. (min_value, max_value))
11 | # You can use this feature only with particle count, size, velocityx, velocityy
12 |
13 | # Collide: You can give collide to particles. You need give True value to collide arg.
14 | # And you need to give GameObjects or Sprite.rect to collide_rects
15 |
16 | @mandaw.draw
17 | def draw():
18 | particle.draw()
19 |
20 | mandaw.loop()
--------------------------------------------------------------------------------
/mandaw/examples/physics/ball.py:
--------------------------------------------------------------------------------
1 | '''
2 | Original code:
3 | https://github.com/idgmatrix/pygame-physics/blob/master/pygame_bouncing_ball.py
4 | @author: kaswan
5 |
6 | Modified:
7 | @author: mandaw2014
8 | '''
9 |
10 | from mandaw import *
11 |
12 | mandaw = Mandaw("Bouncing Ball!")
13 |
14 | ball = GameObject(mandaw, "ellipse")
15 | ball.center()
16 |
17 | ball.ballx, ball.bally = mandaw.width / 2, mandaw.height / 2
18 | ball.vx, ball.vy = 300, 300
19 |
20 | @mandaw.draw
21 | def draw():
22 | ball.draw()
23 |
24 | @mandaw.update
25 | def update(dt):
26 | ball.ballx += ball.vx * dt
27 | ball.bally += ball.vy * dt
28 |
29 | if ball.ballx < 0 or ball.ballx > mandaw.width - 20:
30 | ball.vx = -ball.vx
31 | if ball.bally < 0 or ball.bally > mandaw.height - 20:
32 | ball.vy = -ball.vy
33 |
34 | ball.x = ball.ballx
35 | ball.y = ball.bally
36 |
37 | mandaw.loop()
--------------------------------------------------------------------------------
/mandaw/examples/physics/cloth.py:
--------------------------------------------------------------------------------
1 | '''
2 | Original code:
3 | https://github.com/idgmatrix/pygame-physics/blob/master/verlet_cloth_system_mouse2.py
4 | @author: kaswan
5 |
6 | Modified:
7 | @author: mandaw2014
8 | '''
9 |
10 | from mandaw import *
11 | import pygame, math
12 |
13 | mandaw = Mandaw("Cloth!", 400, 300)
14 |
15 | WIDTH = 400
16 | HEIGHT = 300
17 |
18 | BLACK = (0, 0, 0)
19 | WHITE = (255, 255, 255)
20 | RED = (255, 0, 0)
21 |
22 | class Particle:
23 | def __init__(self, x, y, m = 1.0):
24 | self.m = m
25 | self.x = x
26 | self.y = y
27 | self.oldx = x
28 | self.oldy = y
29 | self.newx = x
30 | self.newy = y
31 | self.ax = 0
32 | self.ay = 9.8
33 |
34 | self.fixed = False
35 | self.selected = False
36 |
37 | def update(self, delta_t):
38 | if self.fixed == False:
39 | self.newx = 2.0 * self.x - self.oldx + self.ax * delta_t * delta_t
40 | self.newy = 2.0 * self.y - self.oldy + self.ay * delta_t * delta_t
41 | self.oldx = self.x
42 | self.oldy = self.y
43 | self.x = self.newx
44 | self.y = self.newy
45 |
46 | if self.x < 0 or self.x > WIDTH:
47 | self.x, self.oldx = self.oldx, self.x
48 | if self.y < 0 or self.y > HEIGHT:
49 | self.y, self.oldy = self.oldy, self.y
50 |
51 | if mouse == False:
52 | self.selected = False
53 |
54 | if self.selected == True:
55 | self.x, self.y = mandaw.input.get_mouse_pos()
56 |
57 | def set_pos(self, pos):
58 | self.x, self.y = pos
59 |
60 | def draw(self, surf, size):
61 | if self.selected == True:
62 | color = RED
63 | else:
64 | color = WHITE
65 |
66 | GameObject(mandaw, "ellipse", width = 3, height = 3, x = int(self.x), y = int(self.y), color = color).draw()
67 |
68 | class Constraint:
69 | def __init__(self, index0, index1):
70 | self.index0 = index0
71 | self.index1 = index1
72 | delta_x = particles[index0].x - particles[index1].x
73 | delta_y = particles[index0].y - particles[index1].y
74 | self.restLength = math.sqrt(delta_x * delta_x + delta_y * delta_y)
75 |
76 | def update(self):
77 | delta_x = particles[self.index1].x - particles[self.index0].x
78 | delta_y = particles[self.index1].y - particles[self.index0].y
79 | deltaLength = math.sqrt(delta_x * delta_x + delta_y * delta_y)
80 | diff = (deltaLength - self.restLength)/(deltaLength+ 0.001)
81 |
82 | if particles[self.index0].fixed == False:
83 | particles[self.index0].x += 0.5 * diff * delta_x
84 | particles[self.index0].y += 0.5 * diff * delta_y
85 | if particles[self.index1].fixed == False:
86 | particles[self.index1].x -= 0.5 * diff * delta_x
87 | particles[self.index1].y -= 0.5 * diff * delta_y
88 |
89 | def draw(self, surf, size):
90 | x0 = particles[self.index0].x
91 | y0 = particles[self.index0].y
92 | x1 = particles[self.index1].x
93 | y1 = particles[self.index1].y
94 |
95 | Line(mandaw, WHITE, (int(x0), int(y0)), (int(x1), int(y1)))
96 |
97 |
98 | def find_particle(pos):
99 | for i in range(len(particles)):
100 | dx = particles[i].x - pos[0]
101 | dy = particles[i].y - pos[1]
102 | if (dx*dx + dy*dy) < 300:
103 | particles[i].selected = True
104 | particles[i].set_pos(pos)
105 | break
106 |
107 | delta_t = 0.1
108 | NUM_ITER = 3
109 | mouse = False
110 | mouse_pos = (0, 0)
111 |
112 | # create particles
113 | NUM_X = 10
114 | NUM_Y = 10
115 | particles = []
116 | for j in range(NUM_Y):
117 | for i in range(NUM_X):
118 | x = 100 + i * 20.0
119 | y = 50 + j * 20.0
120 | p = Particle(x, y)
121 | particles.append(p)
122 |
123 | particles[0].fixed = True
124 | particles[NUM_X-1].fixed = True
125 | particles[(NUM_Y-1) * NUM_X].fixed = True
126 | particles[(NUM_Y) * NUM_X - 1].fixed = True
127 |
128 | constraints = []
129 | for j in range(NUM_Y):
130 | for i in range(NUM_X):
131 | if i < (NUM_X - 1):
132 | index0 = i + j * NUM_X
133 | index1 = (i + 1) + j * NUM_X
134 | c = Constraint(index0, index1)
135 | constraints.append(c)
136 | if j < (NUM_Y - 1):
137 | index0 = i + j * NUM_X
138 | index1 = i + (j + 1) * NUM_X
139 | c = Constraint(index0, index1)
140 | constraints.append(c)
141 |
142 | for j in range(NUM_Y - 1):
143 | for i in range(NUM_X - 1):
144 | index0 = i + j * NUM_X
145 | index1 = (i + 1) + (j + 1) * NUM_X
146 | c = Constraint(index0, index1)
147 | constraints.append(c)
148 | for i in range(1, NUM_X):
149 | index0 = i + j * NUM_X
150 | index1 = (i - 1) + (j + 1) * NUM_X
151 | c = Constraint(index0, index1)
152 | constraints.append(c)
153 |
154 | while True:
155 | for i in range(len(particles)):
156 | particles[i].update(delta_t)
157 |
158 | # constraints update
159 | for i in range(NUM_ITER):
160 | for ii in range(len(constraints)):
161 | constraints[ii].update()
162 |
163 | # particles draw
164 | for i in range(len(particles)):
165 | particles[i].draw(mandaw.window, 3)
166 |
167 | # constraints draw
168 | for i in range(len(constraints)):
169 | constraints[i].draw(mandaw.window, 1)
170 |
171 | for event in pygame.event.get():
172 | if event.type == pygame.MOUSEMOTION and mouse == True:
173 | find_particle(mandaw.input.get_mouse_pos())
174 |
175 | if mandaw.input.get_key_pressed(mandaw.input.keys["E"]):
176 | mouse = True
177 | if mandaw.input.get_key_pressed(mandaw.input.keys["Q"]):
178 | mouse = False
179 |
180 | mandaw.loop()
--------------------------------------------------------------------------------
/mandaw/examples/physics/physics.py:
--------------------------------------------------------------------------------
1 | from mandaw import *
2 | from pygame.math import Vector2
3 |
4 | mandaw = Mandaw("Physics!")
5 |
6 | player = GameObject(mandaw, "rect", 20, 20, 0, 0, "white")
7 | player.center()
8 |
9 | GRAVITY = 1.62
10 |
11 | x = mandaw.width * 0.5
12 | y = mandaw.height * 0.5
13 |
14 | acceleration = Vector2(0, 0)
15 | velocity = Vector2(0, 0)
16 | position = Vector2(x, y)
17 | gravity = Vector2(0, GRAVITY)
18 |
19 | @mandaw.update
20 | def update(dt):
21 | global acceleration, velocity, position
22 | move_left = mandaw.input.get_key_pressed(mandaw.input.keys["A"])
23 | move_right = mandaw.input.get_key_pressed(mandaw.input.keys["D"])
24 | move_up = mandaw.input.get_key_pressed(mandaw.input.keys["W"])
25 | move_down = mandaw.input.get_key_pressed(mandaw.input.keys["S"])
26 |
27 | acceleration.x = (move_right - move_left) * 30 * dt
28 | acceleration.y -= move_up * 30 * dt
29 | acceleration.y += move_down * 30 * dt
30 |
31 | velocity += acceleration * 30 * dt
32 | velocity += gravity * 30 * dt
33 | position += velocity + 30 * acceleration * dt
34 |
35 | acceleration *= 0
36 |
37 | position.x = max(0, min(position.x, mandaw.width - player.width))
38 | position.y = max(0, min(position.y, mandaw.height - player.height))
39 |
40 | if position.y == mandaw.height - player.height:
41 | velocity.x *= 0.95
42 |
43 | player.x = position.x
44 | player.y = position.y
45 |
46 | @mandaw.draw
47 | def draw():
48 | player.draw()
49 |
50 | mandaw.loop()
--------------------------------------------------------------------------------
/mandaw/examples/platformer.py:
--------------------------------------------------------------------------------
1 | from mandaw import *
2 | from mandaw.prefabs.platformer_controller import PlatformerController2D
3 |
4 | # Window
5 | mandaw = Mandaw("Platformer!", bg_color = "cyan")
6 |
7 | # Ground
8 | ground = GameObject(mandaw, shape = "rect", width = 5000, height = 100, x = mandaw.width / 2 - 500, y = 500, color = "gray")
9 |
10 | class Platform(GameObject):
11 | def __init__(self, x, y):
12 | super().__init__(
13 | window = mandaw,
14 | shape = "rect",
15 | width = 50,
16 | height = 10,
17 | x = x,
18 | y = y,
19 | color = "green"
20 | )
21 |
22 | class JumpPlatform(GameObject):
23 | def __init__(self, x, y):
24 | super().__init__(
25 | window = mandaw,
26 | shape = "rect",
27 | width = 50,
28 | height = 10,
29 | x = x,
30 | y = y,
31 | color = "orange"
32 | )
33 |
34 | class SpeedPlatform(GameObject):
35 | def __init__(self, x, y):
36 | super().__init__(
37 | window = mandaw,
38 | shape = "rect",
39 | width = 100,
40 | height = 10,
41 | x = x,
42 | y = y,
43 | color = "blue"
44 | )
45 |
46 | class FinishBlock(GameObject):
47 | def __init__(self, x, y):
48 | super().__init__(
49 | mandaw,
50 | shape = "rect",
51 | width = 50,
52 | height = 10,
53 | x = x,
54 | y = y,
55 | color = "yellow"
56 | )
57 |
58 | # Call the player
59 | player = PlatformerController2D(mandaw, 0, 0, True)
60 | player.y = 400
61 |
62 | center_x = mandaw.width / 2
63 | center_y = mandaw.height / 2
64 |
65 | # Platforms
66 | platform = Platform(center_x - 200, center_y + 170)
67 | platform1 = Platform(center_x - 280, center_y + 140)
68 | platform2 = Platform(center_x - 360, center_y + 110)
69 | platform3 = Platform(center_x - 280, center_y + 80)
70 | platform4 = Platform(center_x - 200, center_y + 50)
71 | platform5 = Platform(center_x - 120, center_y + 20)
72 |
73 | platform6 = Platform(center_x - 40, center_y - 10)
74 | platform7 = JumpPlatform(center_x + 40, center_y + 100)
75 | platform8 = Platform(center_x + 120, center_y - 40)
76 | platform9 = Platform(center_x + 220, center_y - 40)
77 | platform10 = JumpPlatform(center_x + 320, center_y - 40)
78 |
79 | platform11 = Platform(center_x + 220, center_y - 220)
80 | platform12 = SpeedPlatform(center_x + 80, center_y - 220)
81 | platform13 = SpeedPlatform(center_x + -120, center_y - 220)
82 | platform14 = SpeedPlatform(center_x + -320, center_y - 220)
83 |
84 | finishBlock = FinishBlock(center_x + -400, center_y - 220)
85 |
86 | # Add platforms to the object list
87 | player.collision_objects.append(ground)
88 | player.collision_objects.append(platform)
89 | player.collision_objects.append(platform1)
90 | player.collision_objects.append(platform2)
91 | player.collision_objects.append(platform3)
92 | player.collision_objects.append(platform4)
93 | player.collision_objects.append(platform5)
94 | player.collision_objects.append(platform6)
95 | player.collision_objects.append(platform7)
96 | player.collision_objects.append(platform8)
97 | player.collision_objects.append(platform9)
98 | player.collision_objects.append(platform10)
99 | player.collision_objects.append(platform11)
100 | player.collision_objects.append(platform12)
101 | player.collision_objects.append(platform13)
102 | player.collision_objects.append(platform14)
103 | player.collision_objects.append(finishBlock)
104 |
105 | @mandaw.draw
106 | def draw():
107 | # Draw the ground and player
108 | player.draw()
109 | ground.draw()
110 |
111 | platform.draw()
112 | platform1.draw()
113 | platform2.draw()
114 | platform3.draw()
115 | platform4.draw()
116 | platform5.draw()
117 | platform6.draw()
118 | platform7.draw()
119 | platform8.draw()
120 | platform9.draw()
121 | platform10.draw()
122 | platform11.draw()
123 | platform12.draw()
124 | platform13.draw()
125 | platform14.draw()
126 |
127 | finishBlock.draw()
128 |
129 | # Main Game Loop
130 | @mandaw.update
131 | def update(dt):
132 | player.movement(dt)
133 |
134 | if player.collide(platform7):
135 | player.jump_y = 20
136 | if player.collide(platform10):
137 | player.jump_y = 20
138 | if player.collide(platform12):
139 | player.maxspeed = 5
140 | if player.collide(platform13):
141 | player.maxspeed = 5
142 | if player.collide(platform14):
143 | player.maxspeed = 5
144 |
145 | # Run the program
146 | mandaw.loop()
147 |
--------------------------------------------------------------------------------
/mandaw/examples/pong.py:
--------------------------------------------------------------------------------
1 | from mandaw import *
2 | import random
3 |
4 | # General Setup
5 | mandaw = Mandaw("Pong")
6 |
7 | bg_color = (0, 0, 0)
8 | light_gray = (200, 200, 200)
9 |
10 | score1 = 0
11 | score2 = 0
12 |
13 | class Paddle(GameObject):
14 | def __init__(self, x, y):
15 | super().__init__(
16 | window = mandaw,
17 | shape = "rect",
18 | width = 10,
19 | height = 140,
20 | x = x,
21 | y = y,
22 | color = light_gray
23 | )
24 |
25 | self.player_pos = mandaw.height / 2 - 70
26 | self.opponent_speed = 7
27 |
28 | def player_movement(self):
29 | self.y = self.player_pos
30 |
31 | if self.top <= 0:
32 | self.top = 0
33 | if self.bottom >= mandaw.height:
34 | self.bottom = mandaw.height
35 |
36 | def opponent_movement(self):
37 | if self.top < ball.y:
38 | self.top += self.opponent_speed
39 | if self.bottom > ball.y:
40 | self.bottom -= self.opponent_speed
41 |
42 | if self.top <= 0:
43 | self.top = 0
44 | if self.bottom >= mandaw.height:
45 | self.bottom = mandaw.height
46 |
47 | class Ball(GameObject):
48 | def __init__(self):
49 | super().__init__(
50 | window = mandaw,
51 | shape = "ellipse",
52 | width = 20,
53 | height = 20,
54 | x = mandaw.width / 2 - 15,
55 | y = mandaw.height / 2 - 15,
56 | color = light_gray
57 | )
58 |
59 | self.ball_speed_x = 7 * random.choice((1, -1))
60 | self.ball_speed_y = 7 * random.choice((1, -1))
61 |
62 | def ball_movement(self, dt):
63 | global score1
64 | global score2
65 | # Animate the ball
66 | self.x += 50 * self.ball_speed_x * dt
67 | self.y += 50 * self.ball_speed_y * dt
68 |
69 | # Collisions
70 | if self.top <= 0 or self.bottom >= mandaw.height:
71 | self.ball_speed_y *= -1
72 | if self.left <= 0:
73 | self.ball_reset()
74 | score2 += 1
75 | elif self.right >= mandaw.width:
76 | self.ball_reset()
77 | score1 += 1
78 |
79 | if self.colliderect(player) or self.colliderect(opponent):
80 | self.ball_speed_x *= -1
81 |
82 | def ball_reset(self):
83 | self.center()
84 | self.ball_speed_y *= random.choice((1, -1))
85 | self.ball_speed_x *= random.choice((1, -1))
86 |
87 | ball = Ball()
88 | player = Paddle(mandaw.width - 20, mandaw.height / 2 - 70)
89 | opponent = Paddle(10, mandaw.height / 2 - 70)
90 |
91 | speed = 7
92 |
93 | @mandaw.draw
94 | def draw():
95 | # Visuals
96 | mandaw.window.fill(bg_color)
97 | player.draw()
98 | opponent.draw()
99 | ball.draw()
100 | score1_text = Text(mandaw, str(score1), 24, None, "white", 10)
101 | score2_text = Text(mandaw, str(score2), 24, None, "white", mandaw.width - 20)
102 | score1_text.draw()
103 | score2_text.draw()
104 | line = Line(mandaw, light_gray, (mandaw.width / 2, 0), (mandaw.width / 2, mandaw.height))
105 |
106 | @mandaw.update
107 | def update(dt):
108 | # Handling inputs
109 | if mandaw.input.get_key_pressed(mandaw.input.keys["UP"]):
110 | player.player_pos -= 50 * speed * dt
111 |
112 | if mandaw.input.get_key_pressed(mandaw.input.keys["DOWN"]):
113 | player.player_pos += 50 * speed * dt
114 |
115 | # Ball movement
116 | ball.ball_movement(dt)
117 |
118 | # Player movement
119 | player.player_movement()
120 |
121 | # Opponent movement
122 | opponent.opponent_movement()
123 |
124 | mandaw.loop()
125 |
--------------------------------------------------------------------------------
/mandaw/examples/sprite-animation.py:
--------------------------------------------------------------------------------
1 | from mandaw import *
2 |
3 | mandaw = Mandaw("Sprite Animation")
4 |
5 | character = Sprite(window = mandaw, image = "assets/adventurer.png", x = 0, y = 0, width = 200, height = 200)
6 | character.center()
7 |
8 | animation = Animation("assets/idle1", 0.14)
9 | run_anim = Animation("assets/normal-run", 0.14)
10 |
11 | character.add_animation(animation, "idle")
12 | character.add_animation(run_anim, "run")
13 |
14 | speed = 5
15 |
16 | @mandaw.draw
17 | def draw():
18 | character.draw()
19 |
20 | @mandaw.update
21 | def update(dt):
22 | if mandaw.input.get_key_pressed(mandaw.input.keys["D"]):
23 | character.play_animation("run")
24 | character.x += 60 * speed * dt
25 |
26 | elif mandaw.input.get_key_pressed(mandaw.input.keys["A"]):
27 | character.play_animation("run", "x")
28 | character.x -= 60 * speed * dt
29 |
30 | else:
31 | character.play_animation("idle")
32 |
33 | mandaw.loop()
34 |
--------------------------------------------------------------------------------
/mandaw/gameobject.py:
--------------------------------------------------------------------------------
1 | import pygame
2 |
3 | class GameObject(pygame.Rect):
4 | def __init__(self, window, shape = "rect", width = 20, height = 20, x = 0, y = 0, color = "white"):
5 | self.shape = shape
6 | self.width = width
7 | self.height = height
8 |
9 | self.window = window
10 | self.color = color
11 |
12 | self.x = x
13 | self.y = y
14 |
15 | self.collider = "box"
16 |
17 | def draw(self):
18 | if self.shape == "rect" or self.shape == "rectangle" or self.shape == "square":
19 | pygame.draw.rect(self.window.window, self.color, self)
20 |
21 | elif self.shape == "ellipse" or self.shape == "circle":
22 | pygame.draw.ellipse(self.window.window, self.color, self)
23 |
24 | def center(self):
25 | self.x = self.window.width / 2 - self.width / 2
26 | self.y = self.window.height / 2 - self.height / 2
27 |
28 | def center_x(self):
29 | self.x = self.window.width / 2 - self.width / 2
30 |
31 | def center_y(self):
32 | self.y = self.window.height / 2 - self.height / 2
33 |
34 | def collide(self, rect):
35 | try:
36 | if type(rect) != list:
37 | return self.colliderect(rect)
38 | elif type(rect) == list:
39 | return self.collidelistall(rect)
40 | except:
41 | raise AttributeError("MandawError: sorry but when you typed collide(object), the object wasnt a GameObject or a list of GameObjects. see you soon :)")
42 |
43 | if __name__ == "__main__":
44 | from mandaw import *
45 |
46 | mandaw = Mandaw()
47 |
48 | demo = GameObject(mandaw, shape = "ellipse", width = 20, height = 20, x = 0, y = 0, color = "red")
49 | demo.center()
50 |
51 | @mandaw.draw
52 | def draw():
53 | demo.draw()
54 |
55 | mandaw.loop()
56 |
--------------------------------------------------------------------------------
/mandaw/input.py:
--------------------------------------------------------------------------------
1 | import pygame
2 |
3 | class Input:
4 | def __init__(self):
5 | self.pressed = pygame.key.get_pressed()
6 | self.mouse = pygame.mouse.get_pressed()
7 |
8 | self.keys = {
9 | "UP":pygame.K_UP, "DOWN":pygame.K_DOWN,
10 | "LEFT":pygame.K_LEFT, "RIGHT":pygame.K_RIGHT,
11 |
12 | "A":pygame.K_a, "B":pygame.K_b, "C":pygame.K_c,
13 | "D":pygame.K_d, "E":pygame.K_e, "F":pygame.K_f,
14 | "G":pygame.K_g, "H":pygame.K_h, "I":pygame.K_i,
15 | "J":pygame.K_j, "K":pygame.K_k, "L":pygame.K_l,
16 | "M":pygame.K_m, "N":pygame.K_n, "O":pygame.K_o,
17 | "P":pygame.K_p, "Q":pygame.K_q, "R":pygame.K_r,
18 | "S":pygame.K_s, "T":pygame.K_t, "U":pygame.K_u,
19 | "V":pygame.K_v, "W":pygame.K_w, "X":pygame.K_x,
20 | "Y":pygame.K_y, "Z":pygame.K_z,
21 |
22 | "0":pygame.K_0, "1":pygame.K_1,"2":pygame.K_2,
23 | "3":pygame.K_3, "4":pygame.K_4, "5":pygame.K_5,
24 | "6":pygame.K_6, "7":pygame.K_7, "8":pygame.K_8,
25 | "9":pygame.K_9,
26 |
27 | "F1":pygame.K_F1, "F2":pygame.K_F2, "F3":pygame.K_F3,
28 | "F4":pygame.K_F4, "F5":pygame.K_F5, "F6":pygame.K_F6,
29 | "F7":pygame.K_F7, "F8":pygame.K_F8, "F9":pygame.K_F9,
30 | "F10":pygame.K_F10, "F11":pygame.K_F11, "F12":pygame.K_F12,
31 | "F13":pygame.K_F13, "F14":pygame.K_F14, "F15":pygame.K_F15,
32 |
33 | "SCAN_F1":pygame.KSCAN_F1, "SCAN_F2":pygame.KSCAN_F2,
34 | "SCAN_F3":pygame.KSCAN_F3, "SCAN_F4":pygame.KSCAN_F4,
35 | "SCAN_F5":pygame.KSCAN_F5, "SCAN_F6":pygame.KSCAN_F6,
36 | "SCAN_F7":pygame.KSCAN_F7, "SCAN_F8":pygame.KSCAN_F8,
37 | "SCAN_F9":pygame.KSCAN_F9, "SCAN_F10":pygame.KSCAN_F10,
38 | "SCAN_F11":pygame.KSCAN_F11, "SCAN_F12":pygame.KSCAN_F12,
39 | "SCAN_F13":pygame.KSCAN_F13, "SCAN_F14":pygame.KSCAN_F14,
40 | "SCAN_F15":pygame.KSCAN_F15,
41 |
42 | "LCTRL":pygame.K_LCTRL, "RCTRL":pygame.K_RCTRL,
43 | "LSHIFT":pygame.K_LSHIFT, "RSHIFT":pygame.K_RSHIFT,
44 | "LALT":pygame.K_LALT, "RALT":pygame.K_RALT,
45 | "LSUPER":pygame.K_LSUPER, "RSUPER":pygame.K_RSUPER,
46 |
47 | "MOD_CTRL":pygame.KMOD_CTRL, "MOD_ALT":pygame.KMOD_ALT,
48 | "MOD_CAPS":pygame.KMOD_CAPS, "MOD_GUI":pygame.KMOD_GUI,
49 | "MOD_LALT":pygame.KMOD_LALT, "MOD_LCTRL":pygame.KMOD_LCTRL,
50 | "MOD_LGUI":pygame.KMOD_LGUI, "MOD_LMETA":pygame.KMOD_LMETA,
51 | "MOD_LSHIFT":pygame.KMOD_LSHIFT, "MOD_META":pygame.KMOD_META,
52 | "MOD_NONE":pygame.KMOD_NONE, "MOD_MODE":pygame.KMOD_MODE,
53 | "MOD_NUM":pygame.KMOD_NUM, "MOD_RALT":pygame.KMOD_RALT,
54 | "MOD_RSHIFT":pygame.KMOD_RSHIFT, "MOD_RCTRL":pygame.KMOD_RCTRL,
55 | "MOD_RMETA":pygame.KMOD_RMETA, "MOD_RGUI":pygame.KMOD_RGUI,
56 | "MOD_SHIFT":pygame.KMOD_SHIFT, "MODE":pygame.K_MODE,
57 | "SCAN_MODE":pygame.KSCAN_MODE,
58 |
59 | "HOME":pygame.K_HOME, "INSERT":pygame.K_INSERT,
60 | "DELETE":pygame.K_DELETE, "RETURN":pygame.K_RETURN,
61 | "SPACE":pygame.K_SPACE, "PLUS":pygame.K_PLUS,
62 | }
63 |
64 | self.mouse_buttons = {
65 | "LEFT":0, "MIDDLE":1, "RIGHT":2,
66 | }
67 |
68 | def update(self):
69 | self.pressed = pygame.key.get_pressed()
70 | self.mouse = pygame.mouse.get_pressed()
71 |
72 | def get_key_pressed(self, key):
73 | return self.pressed[key]
74 |
75 | def get_mouse_button(self, button):
76 | return self.mouse[button]
77 |
78 | def get_mouse_pos(self):
79 | return pygame.mouse.get_pos()
--------------------------------------------------------------------------------
/mandaw/light.py:
--------------------------------------------------------------------------------
1 | from typing import Union
2 |
3 | import pygame
4 | from pygame.surface import Surface, SurfaceType
5 |
6 | from mandaw import *
7 |
8 | class Light:
9 | light_mask: Union[Surface, SurfaceType]
10 | light_filter: Surface
11 |
12 | def __init__(self, window: Mandaw, mask_img):
13 | self.window = window
14 | self.mask = mask_img
15 |
16 | def light_init(self, pos):
17 | self.pos = pos
18 | self.light_mask = pygame.image.load(self.mask)
19 | self.light_filter = pygame.surface.Surface((self.window.width, self.window.height))
20 | self.light_filter.fill(pygame.color.Color("Gray"))
21 | self.light_filter.blit(self.light_mask, pos)
22 |
23 | def draw(self):
24 | self.window.window.blit(self.light_filter, (0, 0), special_flags=pygame.BLEND_RGBA_SUB)
25 |
26 | if __name__ == '__main__':
27 | from mandaw import *
28 |
29 | mandaw = Mandaw(bg_color="red")
30 |
31 | light = Light(mandaw, "assets/circle.png")
32 | light.light_init((100, 100))
33 |
34 | @mandaw.draw
35 | def draw():
36 | light.draw()
37 |
38 | mandaw.loop()
--------------------------------------------------------------------------------
/mandaw/line.py:
--------------------------------------------------------------------------------
1 | import pygame
2 |
3 | class Line:
4 | def __init__(self, window, color, start_pos, end_pos):
5 | self.window = window
6 | self.color = color
7 | self.start_pos = start_pos
8 | self.end_pos = end_pos
9 |
10 | pygame.draw.aaline(self.window.window, self.color, self.start_pos, self.end_pos)
11 |
--------------------------------------------------------------------------------
/mandaw/main.py:
--------------------------------------------------------------------------------
1 | from mandaw.input import Input
2 | import os, sys, pygame
3 |
4 | class Mandaw:
5 | def __init__(self, title = "Mandaw", width = 800, height = 600, bg_color = (0, 0, 0)):
6 | self.width = width
7 | self.height = height
8 | self.title = title
9 | self.bg_color = bg_color
10 | self.background = None
11 |
12 | self.running = True
13 |
14 | pygame.init()
15 | self.clock = pygame.time.Clock()
16 |
17 | self.window = pygame.display.set_mode((self.width, self.height))
18 | pygame.display.set_caption(self.title)
19 | path = os.path.dirname(os.path.abspath(__file__))
20 | self.icon = os.path.join(path, "./assets/mandaw.png")
21 | image = pygame.image.load(self.icon)
22 | pygame.display.set_icon(image)
23 | self.window.fill(self.bg_color)
24 |
25 | self.last = 0
26 | self.t = pygame.time.get_ticks()
27 | self.dt = (self.t - self.last) / 1000.0
28 | self.last = self.t
29 |
30 | self.delta = 1.0 / 60.0
31 |
32 | self.update_dt = 0
33 | self.update_handlers = []
34 | self.draw_handlers = []
35 |
36 | self.input = Input()
37 |
38 | def _update(self, dt):
39 | self.update_dt += dt
40 | while self.update_dt > self.delta:
41 | for update in self.update_handlers:
42 | update(self.delta)
43 | self.update_dt -= self.delta
44 |
45 | def _draw(self):
46 | for draw in self.draw_handlers:
47 | draw()
48 |
49 | def loop(self):
50 | while self.running:
51 | pygame.display.flip()
52 | self.clock.tick(60)
53 |
54 | pygame.display.update()
55 |
56 | self.input.update()
57 |
58 | self.t = pygame.time.get_ticks()
59 | self.dt = (self.t - self.last) / 1000.0
60 | self.last = self.t
61 |
62 | self.window.fill(self.bg_color)
63 |
64 | self._update(self.dt)
65 |
66 | for event in pygame.event.get():
67 | if event.type == pygame.QUIT:
68 | self.running = False
69 |
70 | if self.input.get_key_pressed(self.input.keys["F5"]):
71 | os.execl(sys.executable, sys.executable, *sys.argv)
72 |
73 | self._draw()
74 |
75 | if self.background != None:
76 | self.background.draw()
77 |
78 | pygame.quit()
79 | quit()
80 |
81 | def quit(self):
82 | self.running = False
83 |
84 | def draw(self, fn):
85 | self.draw_handlers.append(fn)
86 | return fn
87 |
88 | def update(self, fn):
89 | self.update_handlers.append(fn)
90 | return fn
91 |
92 | if __name__ == "__main__":
93 | from mandaw import Mandaw
94 |
95 | mandaw = Mandaw("Mandaw!", width = 800, height = 600, bg_color = (0, 0, 0))
96 |
97 | mandaw.loop()
--------------------------------------------------------------------------------
/mandaw/particle.py:
--------------------------------------------------------------------------------
1 | from typing import List, Union
2 | from typing import Tuple
3 |
4 | import pygame
5 | import random
6 |
7 | import mandaw
8 |
9 | class Particle:
10 |
11 | def __init__(self, WIN: pygame.surface.Surface, x: int, y: int, vel_x: float, vel_y: float, shrink_amount: float,
12 | size: float = 7, color: Tuple[int, int, int] = (255, 255, 255), collision_tolerance: float = 10,
13 | gravity: float = 0.1):
14 | self.WIN: pygame.surface.Surface = WIN
15 | self.x: int = x
16 | self.y: int = y
17 | self.vel_x: float = vel_x
18 | self.vel_y: float = vel_y
19 | self.shrink_amount: float = shrink_amount
20 | self.size: float = size
21 | self.color: Tuple[int, int, int] = color
22 | self.collision_tolerance: float = collision_tolerance
23 | self.gravity: float = gravity
24 | self.rect: pygame.Rect = None
25 | self.update_rect()
26 |
27 | def draw(self) -> None:
28 | pygame.draw.circle(self.WIN, self.color, (self.x, self.y), self.size)
29 |
30 | def shrink(self, dt: float = 1) -> None:
31 | self.size -= self.shrink_amount * dt
32 | self.update_rect()
33 |
34 | def activate_gravity(self, dt: float):
35 | self.vel_y += self.gravity * dt
36 | self.update_rect()
37 |
38 | def move(self, dt: float):
39 | self.x += self.vel_x * dt
40 | self.y += self.vel_y * dt
41 |
42 | def update_rect(self):
43 | self.rect: pygame.Rect = pygame.Rect(self.x - self.size / 2, self.y - self.size / 2, self.size, self.size)
44 |
45 | def randomize_vel(self, limit_x: Tuple[float, float], limit_y: Tuple[float, float]) -> None:
46 | self.vel_x = random.uniform(*limit_x)
47 | self.vel_y = random.uniform(*limit_y)
48 |
49 | def collide_with_rects(self, rects: List[pygame.Rect], dt: float = 1) -> None:
50 | for rect in rects:
51 | rect = rect.copy()
52 | rect.x -= self.collision_tolerance
53 | rect.y -= self.collision_tolerance
54 | rect.w += self.collision_tolerance * 2
55 | rect.h += self.collision_tolerance * 2
56 | if rect.colliderect(self.rect):
57 | if abs(rect.top - self.rect.bottom) < self.collision_tolerance and self.vel_y > 0:
58 | self.vel_y *= (-0.75) * dt
59 | self.y += (self.vel_y * 2) * dt
60 | self.update_rect()
61 | if abs(rect.bottom - self.rect.top) < self.collision_tolerance and self.vel_y < 0:
62 | self.vel_y *= (-0.75) * dt
63 | self.y += (self.vel_y * 2) * dt
64 | self.update_rect()
65 | if abs(rect.right - self.rect.left) < self.collision_tolerance and self.vel_x < 0:
66 | self.vel_x *= (-0.75) * dt
67 | self.x += (self.vel_x * 2) * dt
68 | self.update_rect()
69 | if abs(rect.left - self.rect.right) < self.collision_tolerance and self.vel_x > 0:
70 | self.vel_x *= (-0.75) * dt
71 | self.x += (self.vel_x * 2) * dt
72 | self.update_rect()
73 |
74 | class ParticleSpawner:
75 | def __init__(self, window: mandaw.Mandaw, part_count: Union[int, list, tuple] = 1,
76 | pos: Union[list, tuple] = (0, 0), size: Union[list, tuple, int] = 20,
77 | velocityx: Union[float, list, tuple] = 1, velocityy: Union[float, list, tuple] = 1,
78 | shrink: Union[float, int, list, tuple] = 0.1, color: Union[str, tuple, list] = "white",
79 | collide: bool = False, gravity=0, collide_rects=None):
80 | if collide_rects is None:
81 | collide_rects = []
82 | self.window = window
83 | self.part_count = part_count
84 | self.pos = pos
85 | self.size = size
86 | self.shrink = shrink
87 | self.color = color
88 | self.collide = collide
89 | self.particles = []
90 | self.velocityx = velocityx
91 | self.velocityy = velocityy
92 | self.collide_rects = collide_rects
93 | self.gravity = gravity
94 | if type(part_count) != int:
95 | part_count = random.randint(*part_count)
96 |
97 | for i in range(part_count):
98 | if type(size) != int:
99 | self.size = random.randint(*size)
100 | if type(velocityx) != int:
101 | self.velocityx = random.uniform(*velocityx)
102 | if type(velocityy) != int:
103 | self.velocityy = random.uniform(*velocityy)
104 | self.particles.append(Particle(self.window.window, self.pos[0], self.pos[1], self.velocityx, self.velocityy,
105 | self.shrink,
106 | self.size, gravity=self.gravity, collision_tolerance=10, color=self.color))
107 |
108 | def draw(self):
109 | if len(self.particles) > 0:
110 | for i in self.particles:
111 | i.draw()
112 | i.move(self.window.dt)
113 | i.activate_gravity(self.window.dt)
114 | i.shrink(self.window.dt)
115 | if self.collide:
116 | i.collide_with_rects(self.collide_rects, self.window.dt)
117 | if i.size < 0:
118 | self.particles.remove(i)
--------------------------------------------------------------------------------
/mandaw/prefabs/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mandaw2014/MandawEngine/cd360c341c757c883f6ceefd5fd3eac03dd86004/mandaw/prefabs/__init__.py
--------------------------------------------------------------------------------
/mandaw/prefabs/platformer_controller.py:
--------------------------------------------------------------------------------
1 | from mandaw import *
2 |
3 | class PlatformerController2D(GameObject):
4 | def __init__(self, window, x = 0, y = 0, centered = True):
5 | super().__init__(
6 | window,
7 | shape = "rect",
8 | width = 15,
9 | height = 30,
10 | x = x,
11 | y = y,
12 | color = "orange"
13 | )
14 |
15 | if centered == True:
16 | self.center()
17 | else:
18 | pass
19 |
20 | # Player's X Position
21 | self.pos_x = 0
22 |
23 | # Set the position as a variable
24 | self.pos = self.window.width / 2 - self.width
25 |
26 | self.is_jumping = False
27 | self.jump_y = 10
28 |
29 | self.direction = None
30 |
31 | self.velocity_y = 1
32 |
33 | # Player's speed and maxspeed
34 | self.speed = 15
35 | self.maxspeed = 3
36 |
37 | self.collision_objects = []
38 | self.ignore_speed = []
39 |
40 | self.window = window
41 |
42 | def movement(self, dt):
43 | # Player movement
44 | if self.window.input.get_key_pressed(self.window.input.keys["A"]):
45 | self.pos_x -= self.speed * dt
46 | self.direction = 0
47 |
48 | if self.window.input.get_key_pressed(self.window.input.keys["D"]):
49 | self.pos_x += self.speed * dt
50 | self.direction = 1
51 |
52 | # Momentum
53 | if self.pos_x >= self.maxspeed:
54 | self.pos_x = self.maxspeed
55 | if self.pos_x <= -self.maxspeed:
56 | self.pos_x = -self.maxspeed
57 |
58 | self.pos += self.pos_x
59 |
60 | # Gravity
61 | if not self.collide(self.collision_objects) and self.is_jumping == False:
62 | self.y += 3 * self.velocity_y
63 | self.velocity_y += 0.1
64 |
65 | if self.collide(self.collision_objects):
66 | self.velocity_y = 1
67 |
68 | if not self.collide(self.ignore_speed):
69 | self.maxspeed = 3
70 |
71 | if self.direction == 0 and not self.window.input.get_key_pressed(self.window.input.keys["A"]):
72 | self.pos_x += 10 * dt
73 |
74 | if self.pos_x >= 0:
75 | self.pos_x = 0
76 |
77 | if self.direction == 1 and not self.window.input.get_key_pressed(self.window.input.keys["D"]):
78 | self.pos_x -= 10 * dt
79 |
80 | if self.pos_x <= 0:
81 | self.pos_x = 0
82 |
83 | if not self.collide(self.collision_objects):
84 | if self.direction == 0 and not self.window.input.get_key_pressed(self.window.input.keys["A"]):
85 | self.pos_x += 0.1
86 |
87 | if self.pos_x >= 0:
88 | self.pos_x = 0
89 |
90 | if self.direction == 1 and not self.window.input.get_key_pressed(self.window.input.keys["D"]):
91 | self.pos_x -= 0.1
92 |
93 | if self.pos_x <= 0:
94 | self.pos_x = 0
95 |
96 | # Set the x position as the x variable
97 | self.x = self.pos
98 |
99 | self.jump()
100 |
101 | def jump(self):
102 | # Jumping
103 | if self.is_jumping == False and self.window.input.get_key_pressed(self.window.input.keys["SPACE"]):
104 | self.is_jumping = True
105 | if not self.collide(self.collision_objects):
106 | self.is_jumping = False
107 |
108 | if self.is_jumping == True:
109 | self.y -= self.jump_y
110 | self.jump_y -= 1
111 |
112 | if self.jump_y < -5:
113 | self.is_jumping = False
114 | self.jump_y = 10
115 |
116 | if __name__ == "__main__":
117 | mandaw = Mandaw("PlatformerController2D", bg_color = "cyan")
118 |
119 | player = PlatformerController2D(mandaw, x = 0, y = 0, centered = True)
120 |
121 | ground = GameObject(mandaw, "rect", width = 5000, height = 100, x = 0, y = 500, color = "gray")
122 | ground.center_x()
123 |
124 | player.collision_objects.append(ground)
125 |
126 | @mandaw.draw
127 | def draw():
128 | player.draw()
129 | ground.draw()
130 |
131 | @mandaw.update
132 | def update(dt):
133 | player.movement(dt)
134 |
135 | mandaw.loop()
--------------------------------------------------------------------------------
/mandaw/sprite.py:
--------------------------------------------------------------------------------
1 | import pygame
2 |
3 | class Sprite:
4 | def __init__(self, window, image, x, y, width = 200, height = 200):
5 | self.animations = {}
6 | self.image = pygame.image.load(image)
7 |
8 | if width and height is not None:
9 | self.image = pygame.transform.scale(self.image, (width, height))
10 |
11 | self.window = window
12 | self.x = x
13 | self.y = y
14 | self.width = width
15 | self.height = height
16 | self.rect = pygame.Rect(0, 0, 0, 0)
17 |
18 | def draw(self):
19 | self.rect = pygame.Rect(self.x, self.y, self.width, self.height)
20 | self.window.window.blit(self.image, (self.x, self.y))
21 |
22 | def get_width(self):
23 | return self.image.get_width()
24 |
25 | def get_height(self):
26 | return self.image.get_height()
27 |
28 | def center(self):
29 | self.x = self.window.width / 2 - self.width
30 | self.y = self.window.height / 2 - self.height
31 |
32 | def center_x(self):
33 | self.x = self.window.width / 2 - self.width
34 |
35 | def center_y(self):
36 | self.y = self.window.height / 2 - self.height
37 |
38 | def collide(self, rect):
39 | if type(rect) != list:
40 | return self.rect.colliderect(rect)
41 | elif type(rect) == list:
42 | return self.rect.collidelistall(rect)
43 | else:
44 | print("MandawError: sorry but when you typed collide(object), the object wasnt a string or a list. see "
45 | "you soon :)")
46 |
47 | def resize(self, width, height):
48 | self.image = pygame.transform.scale(self.image, (width, height))
49 |
50 | def add_animation(self, animation, name):
51 | self.animations[name] = {"frames": animation.frames, "length": animation.count, "cooldown": animation.anim_time,
52 | "count": 0, "folder": animation.folder}
53 |
54 | def play_animation(self, name, mirror=None):
55 | for i in self.animations:
56 | if i != name:
57 | self.animations[i]["count"] = 0
58 | else:
59 | self.animations[i]["count"] += self.animations[i]["cooldown"]
60 | if self.animations[i]["count"] >= self.animations[i]["length"]:
61 | self.animations[i]["count"] = 0
62 |
63 | if self.width and self.height is None:
64 | if mirror is None:
65 | self.image = pygame.image.load(self.animations[i]["folder"] + "/" +
66 | self.animations[i]["frames"][int(self.animations[i]["count"])])
67 | elif mirror == "x":
68 | self.image = pygame.transform.flip(pygame.image.load(self.animations[i]["folder"] + "/" +
69 | self.animations[i]["frames"][
70 | int(self.animations[i]["count"])]),
71 | True, False)
72 | elif mirror == "y":
73 | self.image = pygame.transform.flip(pygame.image.load(self.animations[i]["folder"] + "/" +
74 | self.animations[i]["frames"][
75 | int(self.animations[i]["count"])]),
76 | True, False)
77 | else:
78 | if mirror is None:
79 | self.image = pygame.transform.scale(pygame.image.load(self.animations[i]["folder"] + "/" +
80 | self.animations[i]["frames"][
81 | int(self.animations[i]["count"])]),
82 | (self.width, self.height))
83 | elif mirror == "x":
84 | self.image = pygame.transform.flip(
85 | pygame.transform.scale(pygame.image.load(self.animations[i]["folder"] + "/" +
86 | self.animations[i]["frames"][
87 | int(self.animations[i]["count"])]),
88 | (self.width, self.height)), True, False)
89 | elif mirror == "y":
90 | self.image = pygame.transform.flip(
91 | pygame.transform.scale(pygame.image.load(self.animations[i]["folder"] + "/" +
92 | self.animations[i]["frames"][
93 | int(self.animations[i]["count"])]),
94 | (self.width, self.height)),
95 | True, False)
96 |
97 | self.draw()
98 |
99 | if __name__ == '__main__':
100 | from mandaw import *
101 | import os
102 |
103 | mandaw = Mandaw()
104 |
105 | path = os.path.dirname(os.path.abspath(__file__))
106 | bird = os.path.join(path, "./assets/bird.jpeg")
107 |
108 | image = Sprite(mandaw, bird, 0, 0)
109 |
110 | @mandaw.draw
111 | def draw():
112 | image.draw()
113 |
114 | mandaw.loop()
--------------------------------------------------------------------------------
/mandaw/text.py:
--------------------------------------------------------------------------------
1 | import pygame
2 | from sys import platform
3 |
4 | class Text:
5 | def __init__(self, window, text, font_size = 24, file = None, color = "white", x = 0, y = 0):
6 | self.window = window
7 | self.font_size = font_size
8 | self.file = file
9 |
10 | if platform == "linux" or platform == "linux2":
11 | self.font = pygame.font.SysFont(self.file, self.font_size)
12 | if platform == "darwin":
13 | self.font = pygame.font.Font(self.file, self.font_size)
14 | if platform == "win32":
15 | self.font = pygame.font.SysFont(self.file, self.font_size)
16 |
17 | self.color = color
18 | self.x = x
19 | self.y = y
20 |
21 | self.text = self.font.render(text, True, self.color)
22 |
23 | def draw(self):
24 | self.window.window.blit(self.text, (self.x, self.y))
25 |
26 | def center(self):
27 | self.x = self.window.width / 2 - self.font_size / 2
28 | self.y = self.window.height / 2 - self.font_size / 2
29 |
30 | if __name__ == '__main__':
31 | from mandaw import *
32 |
33 | mandaw = Mandaw("Mandaw", bg_color="cyan")
34 |
35 | text = Text(mandaw, "Mandaw", 50)
36 | text.center()
37 |
38 | @mandaw.draw
39 | def draw():
40 | text.draw()
41 |
42 | mandaw.loop()
43 |
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | from distutils.core import setup
2 |
3 | setup(name='Mandaw',
4 | version='1.2.0',
5 | description='A Game Engine Made In Python',
6 | author='mandaw2014',
7 | keywords="python 2d game development",
8 | author_email='mandawbuisness@gmail.com',
9 | url='https://github.com/mandaw2014/MandawEngine',
10 | packages=['mandaw'],
11 | package_dir={'mandaw': 'mandaw'},
12 | install_requires=["pygame"]
13 | )
14 |
--------------------------------------------------------------------------------