-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderer.py
68 lines (31 loc) · 1.13 KB
/
renderer.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
import math
import pygame as pg
class Renderer:
def __init__(self, game, scale) -> None:
self.cols = 64
self.rows = 32
self.scale = scale
self.game = game
self.display_buffer = [0] * (self.cols * self.rows)
def setPixel(self,x,y):
if (x >= self.cols):
x -= self.cols
elif (x <= 0):
x += self.cols
if (y >= self.rows):
x -= self.rows
elif (y <= 0):
y += self.rows
pixel_loc = x + (y * self.cols)
print("Pixel loc: ", pixel_loc)
if pixel_loc < 2048:
self.display_buffer[pixel_loc] ^= 1
return not(self.display_buffer[pixel_loc])
def clear(self):
self.display_buffer = [0] * (self.cols * self.rows)
def render(self):
for i in range(len(self.display_buffer)):
x = ( i % self.cols ) * self.scale
y = math.floor(i / self.cols) * self.scale
if (self.display_buffer[i]):
pg.draw.rect(self.game.display, "black", (x,y, self.scale, self.scale))