-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
83 lines (55 loc) · 2.25 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
import pygame
import moderngl
import json
import os
from player import *
from entity import *
from pygame.locals import *
pygame.init()
#path
BACKGROUND_PATH = r"C:\Users\nickk\Bip_game\imgs\background"
class Game:
def __init__(self) -> None:
self.load_settings()
self.screen = pygame.display.set_mode(self.screen_params); self.clock = pygame.time.Clock()
self.player = Player([40, 400])
self.ground = Ground(-10000, 740, 100000, 50) # -inf downspot +inf some_nomber = 50 (just not 0)
self.background = pygame.image.load(BACKGROUND_PATH + r"\desert\background.png").convert_alpha()
bakcground_scale = 0.75
self.background = pygame.transform.scale(self.background, (self.background.get_width() * bakcground_scale,
self.background.get_height() * bakcground_scale))
self.background.set_colorkey((0, 0, 0))
self.background_rect = self.background.get_rect()
self.background_rect.center = [i / 2 for i in self.screen_params]
self.run()
def load_settings(self) -> None:
with open('settings.json') as file:
settings = json.loads(file.read())
self.screen_params = (settings["screen"]["width"], settings["screen"]["height"])
self.fps = settings["fps"]
file.close()
def draw(self):
Entity.entitys.update()
self.player.verticasl_collision(self.ground)
self.screen.blit(self.background, self.background_rect)
Entity.entitys.draw(self.screen)
pygame.display.flip()
def check_keys(self):
self.player.check_keys()
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.run = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
self.run = False
if event.type == pygame.KEYUP:
if event.key == K_d or event.key == K_a:
self.player.stop_moving()
def run(self):
self.run = True
while self.run:
self.check_keys()
self.draw()
self.clock.tick(self.fps)
pygame.quit()
Game()