-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
74 lines (58 loc) · 1.96 KB
/
utils.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
#!/usr/bin/python2
# -*- coding: utf-8 -*-
import os
import pygame
class Arithmetic:
@staticmethod
def lerp(val1, val2, percent):
return round(val1 + (val2 - val1) * percent)
@staticmethod
def lerpf(val1, val2, percent):
return val1 + (val2 - val1) * percent
@staticmethod
def clamp(vmin, vmax, val):
return min(vmax, max(val, vmin))
class Constants:
EXIT_SCREEN = 0
FPS = 60
GAME_SCREEN = 1
GRAVITY = 9.8
GROW_KEY = pygame.K_UP
HEIGHT = 700
MAX_PLAYER_HEIGHT = 250
MAX_PLAYER_WIDTH = 250
MIN_PLAYER_HEIGHT = 10
MIN_PLAYER_WIDTH = 10
SHRINK_KEY = pygame.K_DOWN
SIZE_INTERVAL = 2
TITLE = "Neon Abyss"
WIDTH = 600
class Graphics:
@staticmethod
def hue_shift(color, hueShift):
col = color if isinstance(color, pygame.color.Color) else pygame.color.Color(color)
col.hsva = ((col.hsva[0] + hueShift) % 360, min(col.hsva[1], 100), min(col.hsva[2], 100), min(col.hsva[3], 255))
return col
class Resources:
@staticmethod
def load_image(name, size=None):
image = pygame.image.load(name).convert_alpha()
if size is not None:
image = pygame.transform.scale(image, size).convert_alpha()
return image
@staticmethod
def load_colorized_image(name, hueShift, size=None):
image = Resources.load_image(name, size=size)
try:
from pygame import PixelArray
pxls = pygame.PixelArray(image)
for x, y in ((x, y) for x in xrange(image.get_width()) for y in xrange(image.get_height())):
pxls[x, y] = Graphics.hue_shift(image.unmap_rgb(pxls[x, y]), hueShift)
except ImportError:
col = pygame.color.Color(0)
col.hsva = (hueShift, 50, 50, 255)
image.fill(col, None, pygame.BLEND_RGBA_ADD)
return image
class Settings:
AUDIO = 1 # 1 = audio / 0 = mute
GRAPHICS = 2 # 2 = high / 1 = medium / 0 = low