This repository has been archived by the owner on Nov 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRun.py
102 lines (66 loc) · 2.73 KB
/
Run.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
"""The main class for the game"""
# # # Imports # # #
# System
import datetime
# Dependancies
import pygame
# Util
import Enum as CEnum
# Management
from Render import Camera
from MainMenu import MainMenu
from MovementController import MovementController
from Registry import Registry
from Scene import Scene
# Data Types
from Resources.TMatrix import TMatrix
# Debug
from Blocks.Block import Block
# # # Main Code # # #
pygame.init()
window = pygame.display.set_mode((1520, 800))
pygame.display.set_caption("Pycraft")
# Set up registry
gameRegistry = Registry()
gameRegistry.currentCamera = Camera(90, TMatrix(), gameRegistry)
gameRegistry.currentController = MovementController(gameRegistry)
gameRegistry.currentMainMenu = MainMenu(gameRegistry)
gameRegistry.currentScene = Scene()
gameRegistry.currentWindow = window
gameRegistry.LastRun = datetime.datetime.now()
gameRegistry.Run = CEnum.GameState.Active
gameRegistry.GameScene = CEnum.GameScene.MainMenu
# Debug generate blocks
Block(TMatrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0), gameRegistry.currentScene)
Block(TMatrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1), gameRegistry.currentScene)
Block(TMatrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), gameRegistry.currentScene)
Block(TMatrix(0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0), gameRegistry.currentScene)
Block(TMatrix(0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -1), gameRegistry.currentScene)
Block(TMatrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), gameRegistry.currentScene)
# # # Main Loop # # #
while gameRegistry.Run == CEnum.GameState.Active:
deltaTime = gameRegistry.LastRun - datetime.datetime.now()
LastRun = datetime.datetime.now()
if gameRegistry.GameScene == CEnum.GameScene.MainMenu:
for event in pygame.event.get():
if event.type == pygame.QUIT:
gameRegistry.Run = CEnum.GameState.Dead
if event.type == pygame.MOUSEBUTTONDOWN:
gameRegistry.currentMainMenu.mouse_clicked(event)
gameRegistry.currentMainMenu.render()
elif gameRegistry.GameScene == CEnum.GameScene.Render3D:
for event in pygame.event.get():
if event.type == pygame.QUIT:
gameRegistry.Run = CEnum.GameState.Dead
gameRegistry.currentCamera.transform *= TMatrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
# Get User Input
gameRegistry.currentController.key_down(pygame.key.get_pressed())
x, y = pygame.mouse.get_rel()
gameRegistry.currentController.on_move(x, y)
changedTransform = gameRegistry.currentController.getMovementSet()
gameRegistry.currentCamera.transform *= changedTransform
# Draw the scene
gameRegistry.currentCamera.render3d()
#pygame.time.delay(1)
pygame.display.update()
pygame.quit()