Professional Documents
Culture Documents
A Mario Game Program In Python simple and clean GUI is provided for easy gameplay.
The gameplay design is so simple that the user won’t find it difficult to use and understand.
Different images are used in the development of this game project, the gaming
environment is just like the Mario game.
Watch the video here to see the full running super mario game in python.
Anyway if you want level up your knowledge in programming especially games in python,
try this new article I’ve made for you Code For Game in Python: Python Game Projects With
Source Code
This Super Mario In Python also includes a downloadable Mario Game In Python source
code for free, just find the downloadable source code below and click to start downloading.
https://itsourcecode.com/free-projects/python-projects/mario-game-in-python-with-source-code/ 1/12
7/2/2021 Mario Game In Python With Source Code | FREE | 2020
To start creating a Mario Game In Python, make sure that you have PyCharm IDE
installed in your computer.
https://itsourcecode.com/free-projects/python-projects/mario-game-in-python-with-source-code/ 2/12
7/2/2021 Mario Game In Python With Source Code | FREE | 2020
https://itsourcecode.com/free-projects/python-projects/mario-game-in-python-with-source-code/ 3/12
7/2/2021 Mario Game In Python With Source Code | FREE | 2020
x
The Code Given Below Is For Importing Modules
1 import pygame
2 import sys
https://itsourcecode.com/free-projects/python-projects/mario-game-in-python-with-source-code/ 4/12
7/2/2021 Mario Game In Python With Source Code | FREE | 2020
15 elif SCORE > 30: x
16 cactus_img_rect.bottom = 200
17 fire_img_rect.top = WINDOW_HEIGHT - 200
18 LEVEL = 4
In this module which is the level of the game if you pass the challenge of the given level.
https://itsourcecode.com/free-projects/python-projects/mario-game-in-python-with-source-code/ 5/12
7/2/2021 Mario Game In Python With Source Code | FREE | 2020
66 mario.update() x
67 for f in flames_list:
68 if f.flames_img_rect.colliderect(mario.mario_img_rect):
69 game_over()
70 if SCORE > mario.mario_score:
71 mario.mario_score = SCORE
72 pygame.display.update()
73 CLOCK.tick(FPS)
74
In This Module which is the main module of the game that consist of boolean and other loop
and conditions.
https://itsourcecode.com/free-projects/python-projects/mario-game-in-python-with-source-code/ 6/12
7/2/2021 Mario Game In Python With Source Code | FREE | 2020
Mario-Game-Program-In-Python-Output-1
https://itsourcecode.com/free-projects/python-projects/mario-game-in-python-with-source-code/ 7/12
7/2/2021 Mario Game In Python With Source Code | FREE | 2020
56
57
if self.up:
x
58 self.dragon_img_rect.top -= self.dragon_velocity
59 elif self.down:
60 self.dragon_img_rect.top += self.dragon_velocity
61
62
63 class Flames:
64 flames_velocity = 20
65
66 def __init__(self):
67 self.flames = pygame.image.load('fireball.png')
68 self.flames_img = pygame.transform.scale(self.flames, (20, 20))
69 self.flames_img_rect = self.flames_img.get_rect()
70 self.flames_img_rect.right = dragon.dragon_img_rect.left
71 self.flames_img_rect.top = dragon.dragon_img_rect.top + 30
72
73
74 def update(self):
75 canvas.blit(self.flames_img, self.flames_img_rect)
76
77 if self.flames_img_rect.left > 0:
78 self.flames_img_rect.left -= self.flames_velocity
79
80
81 class Mario:
82 velocity = 10
83
84 def __init__(self):
85 self.mario_img = pygame.image.load('maryo.png')
86 self.mario_img_rect = self.mario_img.get_rect()
87 self.mario_img_rect.left = 20
88 self.mario_img_rect.top = WINDOW_HEIGHT/2 - 100
89 self.down = True
90 self.up = False
91
92 def update(self):
93 canvas.blit(self.mario_img, self.mario_img_rect)
94 if self.mario_img_rect.top <= cactus_img_rect.bottom:
95 game_over()
96 if SCORE > self.mario_score:
97 self.mario_score = SCORE
98 if self.mario_img_rect.bottom >= fire_img_rect.top:
99 game_over()
100 if SCORE > self.mario_score:
101 self.mario_score = SCORE
102 if self.up:
103 self.mario_img_rect.top -= 10
104 if self.down:
105 self.mario_img_rect.bottom += 10
106
107
108 def game_over():
109 pygame.mixer.music.stop()
110 music = pygame.mixer.Sound('mario_dies.wav')
111 music.play()
112 topscore.top_score(SCORE)
113 game_over_img = pygame.image.load('end.png')
114 game_over_img_rect = game_over_img.get_rect()
115 game_over_img_rect.center = (WINDOW_WIDTH/2, WINDOW_HEIGHT/2)
116 canvas.blit(game_over_img, game_over_img_rect)
117 while True:
118 for event in pygame.event.get():
119 if event.type == pygame.QUIT:
120 pygame.quit()
121 sys.exit()
122 if event.type == pygame.KEYDOWN:
123 if event.key == pygame.K_ESCAPE:
124 pygame.quit()
125 sys.exit()
126 music.stop()
127 game_loop()
128 pygame.display.update()
129
130
131 def start_game():
132 canvas.fill(BLACK)
133 start_img = pygame.image.load('start.png')
134 start_img_rect = start_img.get_rect()
135 start_img_rect.center = (WINDOW_WIDTH/2, WINDOW_HEIGHT/2)
136 canvas.blit(start_img, start_img_rect)
https://itsourcecode.com/free-projects/python-projects/mario-game-in-python-with-source-code/ 8/12
7/2/2021 Mario Game In Python With Source Code | FREE | 2020
137
138
while True:
for event in pygame.event.get():
x
139 if event.type == pygame.QUIT:
140 pygame.quit()
141 sys.exit()
142 if event.type == pygame.KEYDOWN:
143 if event.key == pygame.K_ESCAPE:
144 pygame.quit()
145 sys.exit()
146 game_loop()
147 pygame.display.update()
148
149
150 def check_level(SCORE):
151 global LEVEL
152 if SCORE in range(0, 10):
153 cactus_img_rect.bottom = 50
154 fire_img_rect.top = WINDOW_HEIGHT - 50
155 LEVEL = 1
156 elif SCORE in range(10, 20):
157 cactus_img_rect.bottom = 100
158 fire_img_rect.top = WINDOW_HEIGHT - 100
159 LEVEL = 2
160 elif SCORE in range(20, 30):
161 cactus_img_rect.bottom = 150
162 fire_img_rect.top = WINDOW_HEIGHT - 150
163 LEVEL = 3
164 elif SCORE > 30:
165 cactus_img_rect.bottom = 200
166 fire_img_rect.top = WINDOW_HEIGHT - 200
167 LEVEL = 4
168
169
170
171
172
173 def game_loop():
174 while True:
175 global dragon
176 dragon = Dragon()
177 flames = Flames()
178 mario = Mario()
179 add_new_flame_counter = 0
180 global SCORE
181 SCORE = 0
182 global HIGH_SCORE
183 flames_list = []
184 pygame.mixer.music.load('mario_theme.wav')
185 pygame.mixer.music.play(-1, 0.0)
186 while True:
187 canvas.fill(BLACK)
188 check_level(SCORE)
189 dragon.update()
190 add_new_flame_counter += 1
191
192 if add_new_flame_counter == ADD_NEW_FLAME_RATE:
193 add_new_flame_counter = 0
194 new_flame = Flames()
195 flames_list.append(new_flame)
196 for f in flames_list:
197 if f.flames_img_rect.left <= 0:
198 flames_list.remove(f)
199 SCORE += 1
200 f.update()
201
202 for event in pygame.event.get():
203 if event.type == pygame.QUIT:
204 pygame.quit()
205 sys.exit()
206 if event.type == pygame.KEYDOWN:
207 if event.key == pygame.K_UP:
208 mario.up = True
209 mario.down = False
210 elif event.key == pygame.K_DOWN:
211 mario.down = True
212 mario.up = False
213 if event.type == pygame.KEYUP:
214 if event.key == pygame.K_UP:
215 mario.up = False
216 mario.down = True
217 elif event.key == pygame.K_DOWN:
https://itsourcecode.com/free-projects/python-projects/mario-game-in-python-with-source-code/ 9/12
7/2/2021 Mario Game In Python With Source Code | FREE | 2020
218 mario.down = True x
219 mario.up = False
220
221 score_font = font.render('Score:'+str(SCORE), True, GREEN)
222 score_font_rect = score_font.get_rect()
223 score_font_rect.center = (200, cactus_img_rect.bottom + score_font_rect.height/2
224 canvas.blit(score_font, score_font_rect)
225
226 level_font = font.render('Level:'+str(LEVEL), True, GREEN)
227 level_font_rect = level_font.get_rect()
228 level_font_rect.center = (500, cactus_img_rect.bottom + score_font_rect.height/2
229 canvas.blit(level_font, level_font_rect)
230
231 top_score_font = font.render('Top Score:'+str(topscore.high_score),True,GREEN)
232 top_score_font_rect = top_score_font.get_rect()
233 top_score_font_rect.center = (800, cactus_img_rect.bottom + score_font_rect.heig
234 canvas.blit(top_score_font, top_score_font_rect)
235
236 canvas.blit(cactus_img, cactus_img_rect)
237 canvas.blit(fire_img, fire_img_rect)
238 mario.update()
239 for f in flames_list:
240 if f.flames_img_rect.colliderect(mario.mario_img_rect):
241 game_over()
242 if SCORE > mario.mario_score:
243 mario.mario_score = SCORE
244 pygame.display.update()
245 CLOCK.tick(FPS)
246
247
248 start_game()
249
250
251
DOWNLOAD
I have here the list of Best Python Project with Source code free to download for free, I
hope this can help you a lot.
Summary
The Mario Game In Python is written in python programming language, Python is very
smooth to research the syntax emphasizes readability and it is able to reduces time
ingesting in developing.Also in this tutorial is the simplest way for the beginners or the
student to enhance their logical skills in programming.
Related Articles
https://itsourcecode.com/free-projects/python-projects/mario-game-in-python-with-source-code/ 10/12
7/2/2021 Mario Game In Python With Source Code | FREE | 2020
Inquiries
If you have any questions or suggestions about Mario Game In Python , please feel free
to leave a comment below.
Share this:
Twitter Facebook
Like this:
Loading...
Best Python Projects for Best Python Projects With Code For Game in Python:
Beginners Source Code 2021 Python Game Projects With
June 18, 2020 July 9, 2020 Source Code
In "Python Projects" In "Python Projects" August 13, 2020
In "Python Projects"
https://itsourcecode.com/free-projects/python-projects/mario-game-in-python-with-source-code/ 12/12