-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpyclimber.py
54 lines (41 loc) · 2.02 KB
/
pyclimber.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
"""This module is the main entry for the Py-Climber game"""
import src.game_functions as gf
from src.image_resources import ImageResources
from src.settings import Settings
from src.tilemap import Tilemap
import random
import pygame
def run_game():
"""Main entry point for Py-Climber"""
# Startup pygame object
pygame.init()
random.seed()
# Load our settings object and image resources, disk I/O that can be done in advance
settings = Settings()
image_res = ImageResources(settings)
# Add to the cache so it's accessible where needed
settings.image_res = image_res
# Create the main screen to render to based on settings
screen = pygame.display.set_mode((settings.screen_width, settings.screen_height))
pygame.display.set_caption(settings.caption)
# Create a 2D tilemap - this takes a list of indices and an image list to produce a tiled surface
tile_map = Tilemap(settings, screen, settings.map_indicies, image_res.tile_images,
image_res.block_image, image_res.blob_exit_images, image_res.player_sprite_images, image_res.enemy_blob_images)
# Overwrite default indices with generated map
tile_map.generate_basic_map(settings.map_number_floors , settings.map_number_subfloors)
# Reset the game
gf.reset_game(tile_map)
# Use pygame's simple loop management for a fixed 30 FPS
clock = pygame.time.Clock()
while True:
# Should make sure each frame spends at least 1/30 seconds in this loop
# downside is wasted sleep on fast hardware and slow hardware will lag
# but slow hardware will always lag and implementing a time-delta based
# loop for this simple game is IMHO overkill.
clock.tick(30)
# Process system events (key-presses, joystick, etc)
gf.check_events(settings, screen, tile_map)
# Update the game (this will update all sub-object and render them to the screen)
gf.update_screen(settings, screen, tile_map)
# Invokes the function above when the script is run
run_game()