-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlatformer1.py
103 lines (79 loc) · 3.46 KB
/
Platformer1.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
"""
Sample Python/Pygame Programs
Simpson College Computer Science
http://programarcadegames.com/
http://simpson.edu/computer-science/
From:
http://programarcadegames.com/python_examples/f.php?file=move_with_walls_example
Explanation video: http://youtu.be/8IRyt7ft7zg
Part of a series:
http://programarcadegames.com/python_examples/f.php?file=move_with_walls_example.py
http://programarcadegames.com/python_examples/f.php?file=maze_runner.py
http://programarcadegames.com/python_examples/f.php?file=platform_jumper.py
http://programarcadegames.com/python_examples/f.php?file=platform_scroller.py
http://programarcadegames.com/python_examples/f.php?file=platform_moving.py
http://programarcadegames.com/python_examples/sprite_sheets/
"""
import pygame
from modules.sprites import *
from modules.events import *
from modules.physics import *
from pygame import *
"""
Global constants
"""
# Colors
BLACK = (0, 0, 0)
PINK = (255, 20, 147)
properties = dict(line.strip().split('=') for line in open('settings.ini'))
resourceFiles = {}
resourceFiles["MAIN_CHARACTER"] = 'resources/spritemaps/BODY_skeleton.png'
HALF_WIDTH = int(int(properties['SCREEN_WIDTH']) / 2)
HALF_HEIGHT = int(int(properties['SCREEN_HEIGHT']) / 2)
def complex_camera(camera, target_rect):
l, t, _, _ = target_rect
_, _, w, h = camera
l, t, _, _ = -l+HALF_WIDTH, -t+HALF_HEIGHT, w, h
l = min(0, l) # stop scrolling at the left edge
l = max(-(camera.width-int(properties['SCREEN_WIDTH'])), l) # stop scrolling at the right edge
t = max(-(camera.height-int(properties['SCREEN_HEIGHT'])), t) # stop scrolling at the bottom
t = min(0, t) # stop scrolling at the top
return Rect(l, t, w, h)
# Call this function so the Pygame library can initialize itself
pygame.init()
screen = pygame.display.set_mode([int(properties['SCREEN_WIDTH']), int(properties['SCREEN_HEIGHT'])])
# Set the title of the window
pygame.display.set_caption('Between the world of Black and Blue')
# Create the player paddle object
playerSpriteSheet = resourceFiles["MAIN_CHARACTER"]
player = Player.Player(playerSpriteSheet)
# Level management initialization
all_sprite_group = pygame.sprite.Group()
wall_group = pygame.sprite.Group()
all_proximity_entities_list = []
background = Background.Background()
level_manager = LevelManager.LevelManager(all_sprite_group, wall_group, all_proximity_entities_list, background, player)
level_manager.load_level(1)
clock = pygame.time.Clock()
done = False
camera = Camera.Camera(complex_camera, int(properties['LEVEL_WIDTH']), int(properties['LEVEL_HEIGHT']))
eventsManager = EventsManager.EventsManager(player)
proximityManager = ProximityManager.ProximityManager((player,))
while not done:
for event in pygame.event.get():
done = eventsManager.determineEvent(event)
PhysicsEngine.PhysicsEngine().applyGravity([player])
all_sprite_group.update()
screen.fill(PINK)
camera.update(player)
proximityManager.checkProximityToPlayers(all_proximity_entities_list)
for y in range(0, int(properties['LEVEL_HEIGHT']), background.iHeight):
for x in range(0, int(properties['LEVEL_WIDTH']), background.iWidth):
background.rect.x = x
background.rect.y = y
screen.blit( background.image,camera.apply(background))
for entity in all_sprite_group:
screen.blit(entity.image, camera.apply(entity))
pygame.display.flip()
clock.tick(60)
pygame.quit()