-
Notifications
You must be signed in to change notification settings - Fork 0
/
color_map.py
31 lines (27 loc) · 1.65 KB
/
color_map.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
#!/bin/python3
import pygame
class ColorMap:
def __init__(self):
self.map_x = 0
self.zoom_scale = 0
self.image = pygame.image.load('assets/color_map.png')
self.image_rect = self.image.get_rect()
self.image = pygame.transform.scale(self.image, (int(self.image_rect.width * 2.5),
int(self.image_rect.height * 2.5)))
def update(self, x_to_move, player):
if player.y >= 10:
# collision between player and objects on its right (width -> 100, height -> 100)
if x_to_move < 0 and (self.image.get_at((-self.map_x + player.x + 40 + player.speed, player.y + 99))[1] > 100 or \
self.image.get_at((-self.map_x + player.x + 40 + player.speed, player.y))[1] > 100 or \
self.image.get_at((-self.map_x + player.x + 40 + player.speed, player.y + 33))[1] > 100 or \
self.image.get_at((-self.map_x + player.x + 40 + player.speed, player.y + 66))[1] > 100):
return
# collision between player and objects on its left (width -> 100, height -> 100)
if x_to_move > 0 and (self.image.get_at((-self.map_x + player.x - player.speed, player.y + 99))[1] > 100 or \
self.image.get_at((-self.map_x + player.x - player.speed, player.y))[1] > 100 or \
self.image.get_at((-self.map_x + player.x - player.speed, player.y + 33))[1] > 100 or \
self.image.get_at((-self.map_x + player.x - player.speed, player.y + 66))[1] > 100):
return
if x_to_move == 0:
return
self.map_x += x_to_move