-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCamera.py
More file actions
60 lines (39 loc) · 1.58 KB
/
Camera.py
File metadata and controls
60 lines (39 loc) · 1.58 KB
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
import Map
import pygame
block_length = 20
screen_width = 20 * block_length
screen_height = 10 * block_length
screen = pygame.display.set_mode((screen_width, screen_height))
class Camera:
# Initialisation
def __init__(self, world, x_y_radii, centre, screen):
self.x_y_radii = x_y_radii
self.centre = centre
self.width = 2*x_y_radii[0] + 1
self.height = 2*x_y_radii[1] + 1
self.world = world
self.init_picture()
self.screen = screen
# ---------------- Create array that will be our pixel values
def init_picture(self):
pic = [0]*self.height
for i in range(self.height):
pic[i] = [0]*self.width
self.set_picture(pic)
# -------------- Getters and setters
def set_picture(self, pic):
self.picture = pic
def get_picture(self):
return self.picture
# ----------------- Drawing
def get_screen_coords(self, block_coords, block_length):
return block_coords[0]*block_length, block_coords[1]*block_length
def draw(self):
for i in range(self.width):
for j in range(self.height):
pygame.draw.rect(self.screen, self.world.get_screen_colour(i, j), (i * block_length, j*block_length, block_length, block_length))
pygame.display.update()
w = Map.Map(200, 100)
w.full_generation()
cam = Camera(w, (10, 5), (50, 25), screen)
w.draw(5)