forked from Ndymario/Python-MvsL-Old
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
110 lines (86 loc) · 3.21 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
########################################################################
# Author: Nolan Y. / bbomb64 / Christopher D. # #
# Description: My goal is to recreate the New Super Mario Bros. #
# DS gamemode Mario vs Luigi. Even if it's not perfect, #
# it'll be a fun challenge! #
########################################################################
# Enable/Disable DEBUG mode
DEBUG = False
# Enable/Disable Player 2
P2 = True
# Import things I might need
from pygame_functions import *
import sys
from level import *
from player import *
from cmap import *
# Allows us to use another folder than the folder this file is located
sys.path.insert(1, "./Sprites")
#---------------------------------#
##########--BEGIN CLASSES--##########
##########--END CLASSES--##########
#---------------------------------#
##########--BEING FUNCTIONS--######
##########--END FUNCTIONS--########
#---------------------------------#
##########-Begin Main Code-########
# Load Level Data
levelchunk1 = []
level = Level("Levels/1-1.lvl")
cmap = CMap("Cmap/1-1.cmap")
# Define some constants
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
# Setup the screen and other display stuff
# Note: WIDTH & HEIGHT are imported from player.py!
screen = screenSize(WIDTH, HEIGHT, None, None, False)
# Frame handler (used for any sprite animation)
frame = 0
nextFrame = clock()
# Create a player
mario = Player(makeSprite("Sprites/Mario.png",15), -26)
if P2: #Experimental
luigi = Player(makeSprite("Sprites/Luigi.png",15), -31, 0.2, 1, pygame.K_w, pygame.K_s, pygame.K_a, pygame.K_d,50)
players = mario, luigi
else:
players = [mario]
# Load the Player's sprites
for player in players:
showSprite(player.playerSprite)
while True:
events = pygame.event.get()
for event in events:
if event.type == pygame.QUIT: sys.exit()
keys = pygame.key.get_pressed()
# Get player inputs
for player in players:
# Turn inputs into movement
player.RefineInput(keys, cmap, player.playerSprite, frame,level)
# Debug
if (DEBUG):
print(player)
# Calculate and update position
player.calculatePosition()
updated_position = player.check_collision(cmap)
player.x = updated_position[0]
player.y = updated_position[1]
player.x_velocity = updated_position[2]
player.y_velocity = updated_position[3]
# Check for death
player.death()
# Limit the framerate to 60 FPS
tick(60)
#Render the screen
screen.fill(WHITE)
for tile in level.tiles:
for w in range(int(tile.width / 16)):
for h in range(int(tile.height / 16)):
screen.blit(pygame.image.load(tile.tile_image), [tile.x + (w * 16), tile.y - (h * 16)])
# Update the player's sprite location
for player in players:
moveSprite(player.playerSprite, player.x, player.y + player.height)
updateDisplay()
# Limits the frame rate of sprites (60 FPS walk cycle is bad)
if clock() > nextFrame:
frame = (frame+1)%3
nextFrame += 60