Skip to content

Commit 08c96d9

Browse files
Add files via upload
1 parent 64e8457 commit 08c96d9

File tree

11 files changed

+264
-0
lines changed

11 files changed

+264
-0
lines changed

Super_mario-main/README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Super Mario Game
2+
3+
## Overview
4+
This is a 2D Super Mario-inspired platformer game built using Python and the Pygame library. The game features multiple levels, platforms, and a menu system, along with player movement, collision detection, and scrolling backgrounds.
5+
6+
---
7+
8+
## Features
9+
- **Player Movement**: Mario can move left, right, and jump.
10+
- **Platform Collision**: Mario can stand on platforms and interact with them.
11+
- **Scrolling Levels**: The game features large levels with camera scrolling.
12+
- **Multiple Levels**: Players can select from different levels in the menu.
13+
- **Start Menu**: Includes options to start the game and choose levels.
14+
15+
---
16+
17+
## Project Structure
18+
```
19+
/Super_mario
20+
/assets
21+
/backgrounds
22+
level1_bg.png
23+
level2_bg.png
24+
/platforms
25+
platform.png
26+
/sprites
27+
mario.png
28+
/levels
29+
__init__.py
30+
level_base.py
31+
level1.py
32+
level2.py
33+
game.py
34+
player.py
35+
main.py
36+
```
37+
38+
### Key Files
39+
- **`main.py`**: Entry point for the game. Handles the start menu and level selection.
40+
- **`game.py`**: Manages the game loop and level switching.
41+
- **`player.py`**: Defines the Player class and its behavior (movement, gravity, etc.).
42+
- **`levels/level_base.py`**: Base class for all levels, including platform and background management.
43+
- **`levels/level1.py` & `levels/level2.py`**: Specific configurations for Level 1 and Level 2.
44+
45+
---
46+
47+
## How to Run the Game
48+
1. Clone this repository:
49+
```bash
50+
git clone <repository_url>
51+
```
52+
53+
2. Navigate to the project directory:
54+
```bash
55+
cd Super_mario
56+
```
57+
58+
3. Install the required dependencies:
59+
```bash
60+
pip install pygame
61+
```
62+
63+
4. Run the game:
64+
```bash
65+
python main.py
66+
```
67+
68+
---
69+
70+
## Controls
71+
- **Left Arrow**: Move left
72+
- **Right Arrow**: Move right
73+
- **Space**: Jump
74+
- **Escape**: Return to the menu
75+
76+
---
77+
78+
## Future Enhancements
79+
- Add enemies (e.g., Goombas, Koopas) with AI behavior.
80+
- Implement power-ups (e.g., mushrooms, fire flowers).
81+
- Add checkpoints and save progress.
82+
- Include parallax scrolling for a better visual experience.
83+
- Improve graphics and animations.
84+
85+
---
86+
87+
## License
88+
This project is licensed under the MIT License. Feel free to use, modify, and distribute the code as needed.
89+
90+
---
91+
92+
## Acknowledgments
93+
- Built using the [Pygame](https://www.pygame.org/) library.
94+
- Inspired by Nintendo's Super Mario series.
Loading
Loading
Loading
Loading

Super_mario-main/Super_mario/game.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import pygame
2+
from player import Player
3+
from levels.level1 import Level1
4+
from levels.level2 import Level2
5+
6+
def game_loop(level):
7+
clock = pygame.time.Clock()
8+
FPS = 120
9+
player = Player(100, 540)
10+
running = True
11+
camera_x = 0
12+
13+
while running:
14+
screen = pygame.display.set_mode((800, 600))
15+
keys = pygame.key.get_pressed()
16+
17+
for event in pygame.event.get():
18+
if event.type == pygame.QUIT:
19+
return
20+
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
21+
return # Return to menu
22+
23+
player.move(keys)
24+
player.update(level.platforms)
25+
26+
camera_x = max(0, min(player.rect.x - 400, level.width - 800))
27+
28+
level.draw(screen, camera_x)
29+
player.draw(screen, camera_x)
30+
31+
pygame.display.update()
32+
clock.tick(FPS)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from levels.level_base import Level
2+
3+
class Level1(Level):
4+
def __init__(self, player):
5+
super().__init__(player)
6+
self.load_background("level1_bg.png")
7+
self.create_platforms([
8+
(300, self.height - 100, 100, 20),
9+
(600, self.height - 150, 150, 20),
10+
(1000, self.height - 100, 100, 20),
11+
(1300, self.height - 200, 150, 20),
12+
(1800, self.height - 250, 200, 20),
13+
])
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from levels.level_base import Level
2+
3+
class Level2(Level):
4+
def __init__(self, player):
5+
super().__init__(player)
6+
self.load_background("level2_bg.png")
7+
self.create_platforms([
8+
(400, self.height - 150, 120, 20),
9+
(800, self.height - 180, 160, 20),
10+
(1200, self.height - 220, 180, 20),
11+
(1600, self.height - 250, 200, 20),
12+
(2100, self.height - 300, 250, 20),
13+
])
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import pygame
2+
import os
3+
4+
class Level:
5+
def __init__(self, player):
6+
self.width = 2400 # Level width
7+
self.height = 600 # Level height
8+
self.background = None
9+
self.platforms = []
10+
self.player = player
11+
12+
def load_background(self, image_path):
13+
"""Load background image for the level."""
14+
self.background = pygame.image.load(os.path.join("assets", "backgrounds", image_path))
15+
self.background = pygame.transform.scale(self.background, (self.width, self.height))
16+
17+
def create_platforms(self, platform_list):
18+
"""Create platforms for the level."""
19+
self.platforms = [pygame.Rect(x, y, w, h) for (x, y, w, h) in platform_list]
20+
21+
def draw(self, screen, camera_x):
22+
"""Draw the level background and platforms."""
23+
screen.blit(self.background, (-camera_x, 0))
24+
for platform in self.platforms:
25+
pygame.draw.rect(screen, (150, 75, 0), (platform.x - camera_x, platform.y, platform.width, platform.height))
26+
27+
def update(self):
28+
"""Update level elements (e.g., moving platforms, enemies in future)."""
29+
pass # Placeholder for future logic

Super_mario-main/Super_mario/main.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import pygame
2+
from game import game_loop
3+
from levels.level1 import Level1
4+
from levels.level2 import Level2
5+
from player import Player
6+
7+
pygame.init()
8+
screen = pygame.display.set_mode((800, 600))
9+
font = pygame.font.Font(None, 50)
10+
11+
def start_menu():
12+
while True:
13+
screen.fill((255, 255, 255))
14+
title_text = font.render("Super Mario", True, (0, 0, 0))
15+
level1_text = font.render("Press 1 for Level 1", True, (0, 0, 0))
16+
level2_text = font.render("Press 2 for Level 2", True, (0, 0, 0))
17+
screen.blit(title_text, (300, 200))
18+
screen.blit(level1_text, (250, 300))
19+
screen.blit(level2_text, (250, 350))
20+
pygame.display.update()
21+
22+
for event in pygame.event.get():
23+
if event.type == pygame.QUIT:
24+
return
25+
if event.type == pygame.KEYDOWN:
26+
if event.key == pygame.K_1:
27+
game_loop(Level1(Player(100, 540)))
28+
if event.key == pygame.K_2:
29+
game_loop(Level2(Player(100, 540)))
30+
31+
start_menu()

0 commit comments

Comments
 (0)