-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspawnobject.py
82 lines (64 loc) · 2.42 KB
/
spawnobject.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
# date: 28. may 2024
import numpy as np
import random
import pygame
class SpawnObject:
def __init__(self, start_position, color):
self.start_pos = start_position
self.color = color
def matrix_glider(self):
# glider
# 0|1|0
# 0|0|1
# 1|1|1
object_matrix = np.array([[0,1,0],
[0,0,1],
[1,1,1]]).T
object_matrix = np.rot90(object_matrix, random.randint(0,3))
positions_on_grid = self.set_positions(object_matrix)
return positions_on_grid
def matrix_rpentomino(self):
# R-Pentomino
# 0|1|1
# 1|1|0
# 0|1|0
object_matrix = np.array([[0,1,1],
[1,1,0],
[0,1,0]]).T
object_matrix = np.rot90(object_matrix, random.randint(0,3))
positions_on_grid = self.set_positions(object_matrix)
return positions_on_grid
def matrix_table(self):
# Table
# 1|1|1|1
# 1|0|0|1
object_matrix = np.array([[1, 1, 1, 1],
[1, 0, 0, 1]]).T
object_matrix = np.rot90(object_matrix, random.randint(0, 3))
positions_on_grid = self.set_positions(object_matrix)
return positions_on_grid
def matrix_block(self):
# Table
# 1|1
# 1|1
object_matrix = np.array([[1, 1],
[1, 1]]).T
object_matrix = np.rot90(object_matrix, random.randint(0, 3))
positions_on_grid = self.set_positions(object_matrix)
return positions_on_grid
def set_positions(self, object_matrix):
positions_set = set()
for i in range(np.shape(object_matrix)[0]):
for j in range(np.shape(object_matrix)[1]):
if object_matrix[i][j]:
positions_set.add((self.start_pos[0]+i, self.start_pos[1]+j, self.color))
return positions_set
class FPS:
def __init__(self, color):
self.clock = pygame.time.Clock()
self.font = pygame.font.SysFont("Verdana", 8)
self.text = self.font.render(str(self.clock.get_fps()), True, color)
self.color = color
def render(self, display, audio_name):
self.text = self.font.render(audio_name + ' | ' + str(round(self.clock.get_fps(),1)), True, self.color)
display.blit(self.text, (10, 10))