-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathobjectives.py
100 lines (84 loc) · 4.89 KB
/
objectives.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import pygame
import os
from pygame.math import Vector2
from config import *
class Cabage():
def __init__(self, x, y):
self.position = Vector2(x, y)
self.rect = pygame.Rect(self.position.x, self.position.y, TILE_SIZE * 2, TILE_SIZE * 2)
class Counter():
def __init__(self):
self.value = 0
self.base_font = pygame.font.Font(os.path.join("resources", "fonts", "PixeloidSans-Bold.ttf"), 30)
self.transparent_surface = pygame.Surface((310, TILE_SIZE * 4), pygame.SRCALPHA)
self.transparent_surface.fill((0, 0, 0, 200))
self.transparent_rect = pygame.Rect(TILE_SIZE, WINDOW_HEIGHT - TILE_SIZE * 7, 310, TILE_SIZE * 4)
self.header = self.base_font.render("Access cards:", True, (198, 189, 0))
def draw(self, screen):
screen.blit(self.transparent_surface, self.transparent_rect)
screen.blit(self.header, ((self.transparent_rect.centerx) - (self.header.get_width() / 2), WINDOW_HEIGHT - TILE_SIZE * 6))
number = str(self.value) + "/3"
number_text = self.base_font.render(number, True, (198, 189, 0))
screen.blit(number_text, ((self.transparent_rect.centerx) - (number_text.get_width() / 2), WINDOW_HEIGHT - TILE_SIZE * 5 + 10))
class Instruction():
def __init__(self):
self.base_font = pygame.font.Font(os.path.join("resources", "fonts", "PixeloidSans-Bold.ttf"), 30)
self.instructions = "You're the last hope in the plague world. Your main objective is to find 3 access cards to unlock the cure for the virus."
def draw(self, screen, camera):
collection = [word.split(' ') for word in self.instructions.splitlines()]
space = self.base_font.size(' ')[0]
defaultX = -camera.position.x + 4 * TILE_SIZE
x,y = (defaultX, -camera.position.y - TILE_SIZE * 8)
for lines in collection:
for words in lines:
word_surface = self.base_font.render(words, True, (198, 189, 0))
word_width , word_height = word_surface.get_size()
if x + word_width >= defaultX + 800:
x = defaultX
y += word_height
screen.blit(word_surface, (x - len(lines) * 17, y))
x += word_width + space
x = defaultX
y += word_height
class Potion():
def __init__(self, x, y):
self.position = Vector2(x, y)
self.rect = pygame.Rect(self.position.x, self.position.y, TILE_SIZE * 2, TILE_SIZE * 2)
self.current_animation = "idle"
self.load_animation(self.current_animation)
def load_animation(self, animation_name):
# "animation_name":["path_to_assets", number_of_assets, frame_duration]
animations = {"idle":["resources\health_potion_anim.png", 4, 200]}
image = pygame.image.load(animations[animation_name][0]).convert_alpha()
self.frames_number = animations[animation_name][1]
self.frames = [pygame.transform.scale(image.subsurface((i * TILE_SIZE, 0, TILE_SIZE, TILE_SIZE)), (TILE_SIZE * 2, TILE_SIZE * 2)) for i in range(self.frames_number)]
self.frame_duration = animations[animation_name][2]
self.current_frame = 0
self.last_frame_change = pygame.time.get_ticks()
def draw(self, screen, camera):
now = pygame.time.get_ticks()
if now - self.last_frame_change > self.frame_duration:
self.current_frame = (self.current_frame + 1) % self.frames_number
self.last_frame_change = now
screen.blit(self.frames[self.current_frame], (self.rect.x - camera.position.x, self.rect.y - camera.position.y, TILE_SIZE * 2, TILE_SIZE * 2))
class Card():
def __init__(self, x, y):
self.position = Vector2(x, y)
self.rect = pygame.Rect(self.position.x, self.position.y, TILE_SIZE * 2, TILE_SIZE * 2)
self.current_animation = "idle"
self.load_animation(self.current_animation)
def load_animation(self, animation_name):
# "animation_name":["path_to_assets", number_of_assets, frame_duration]
animations = {"idle":["resources\card_anim.png", 4, 200]}
image = pygame.image.load(animations[animation_name][0]).convert_alpha()
self.frames_number = animations[animation_name][1]
self.frames = [pygame.transform.scale(image.subsurface((i * TILE_SIZE, 0, TILE_SIZE, TILE_SIZE)), (TILE_SIZE * 2, TILE_SIZE * 2)) for i in range(self.frames_number)]
self.frame_duration = animations[animation_name][2]
self.current_frame = 0
self.last_frame_change = pygame.time.get_ticks()
def draw(self, screen, camera):
now = pygame.time.get_ticks()
if now - self.last_frame_change > self.frame_duration:
self.current_frame = (self.current_frame + 1) % self.frames_number
self.last_frame_change = now
screen.blit(self.frames[self.current_frame], (self.rect.x - camera.position.x, self.rect.y - camera.position.y, TILE_SIZE * 2, TILE_SIZE * 2))