-
Notifications
You must be signed in to change notification settings - Fork 2
/
game.py
84 lines (66 loc) · 2.63 KB
/
game.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
import pygame
from time import time
from player import coords, Player
from pygame.draw import circle
from vocabulary import *
from scene import Scene
from itertools import chain
from graph import Cube, Vector
from math import sin, cos
from rasterizer import Rasterizer
class Game:
def __init__(self, width, height):
self.FPS = 60
self.gravity = -0.003
pygame.init()
pygame.display.set_caption('Test controlling')
pygame.mouse.set_visible(False)
self.screen = pygame.display.set_mode((width, height), pygame.RESIZABLE)
self.clock = pygame.time.Clock()
self.running = True
self.scene = Scene()
self.scene.test()
self.player = Player(Vector(0, 20, 12), self.gravity)
self.rasterizer = Rasterizer()
self.player_get_camera = None
def loop(self):
while self.running:
self.clock.tick(self.FPS)
for event in pygame.event.get():
self.update(event)
self.player.update(event)
self.player.move()
self.player_get_camera = self.player.get_camera()
self.rasterizer.draw(self.screen, self.scene, self.player_get_camera)
self.log()
self.GUI()
pygame.display.update()
pygame.quit()
def update(self, event):
if event.type == pygame.QUIT:
self.running = False
elif event.type == pygame.KEYUP and event.key == pygame.K_ESCAPE:
self.running = False
def GUI(self):
circle(self.screen, BLACK, (WIDTH / 2, HEIGHT / 2), 4, 1)
def log(self):
circle(self.screen, BLACK,
Vector(10, 21, 10).get_vector(self.player.get_camera()).coords_to_cam(self.player.get_camera()), 10)
circle(self.screen, BLACK, Vector(100, 111, 2000).get_vector(self.player.get_camera()).coords_to_cam(
self.player.get_camera()), 10)
clip = self.screen.get_clip()
center = (clip.w / 2, clip.h / 2, 0)
camera = self.player.get_camera()
circle(self.screen, BLACK, convert_point((camera.x, camera.y, 0), center), 5)
circle(self.screen, BLACK, convert_point((10, 21, 10), center), 5)
circle(self.screen, BLACK, convert_point((100, 111, 0), center), 5)
u = 15
pygame.draw.lines(self.screen, WHITE, True, [
convert_point((camera.x, camera.y, 0), center),
convert_point((
camera.x + u * cos(camera.an_xy),
camera.y + u * sin(camera.an_xy),
0,
), center),
], 2)
coords(self.screen, self.player, self.clock.get_fps())