forked from Tardimgg/poem_renpy_game
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.py
More file actions
133 lines (118 loc) · 5.07 KB
/
start.py
File metadata and controls
133 lines (118 loc) · 5.07 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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import pygame, os
class TextView(pygame.sprite.Sprite):
def __init__(self, text, x, y, right_finish_position, finish_callback, group):
super(TextView, self).__init__(group)
self._text = text
self._in_start = True
self._x = x * 1.0
self._y = y * 1.0
self._current_x = x
self._current_y = y
self._right_finish_position = right_finish_position
self._finish_callback = finish_callback
self._font_text = pygame.font.Font(None, 50)
self.image = self._font_text.render(text, 1, WHITE)
self.rect = self.image.get_rect(center=(x, y))
self._last_coordinates = None
self._k_x = 1 * 1.0
self._k_y = 1 * 1.0
self._speed = 8
def update(self, *args):
if len(args) > 0 and (self.rect[0] + self.rect[2]) > args[0][0] > self.rect[0] and (
self.rect[1] + self.rect[3]) > args[0][1] > self.rect[1]:
if len(args) == 2 and self._in_start:
if (self.rect[0] + self.rect[2]) > args[0][0] > self.rect[0] and (self.rect[1] + self.rect[3]) > \
args[0][1] > self.rect[1]:
self._last_coordinates = (args[1][0], args[1][1])
self._in_start = False
delta_x = abs(self._x - self._last_coordinates[0])
delta_y = abs(self._y - self._last_coordinates[1])
if delta_x > delta_y:
self._k_x = 1
self._k_y = abs(self._y - self._last_coordinates[1]) / abs(self._x - self._last_coordinates[0])
elif delta_x < delta_y:
self._k_x = abs(self._x - self._last_coordinates[0]) / abs(self._y - self._last_coordinates[1])
self._k_y = 1
self._k_x *= 1 if self._x < self._last_coordinates[0] else -1
self._k_y *= 1 if self._y < self._last_coordinates[1] else -1
self._k_x *= self._speed
self._k_y *= self._speed
self._move()
target_position.pop(0)
self._finish_callback()
else:
global target_positiona
print(target_position)
target_position.insert(0, self._last_coordinates)
print(target_position)
self._last_coordinates = None
self._k_x *= -1
self._k_y *= -1
self._move()
elif self._y == self._current_y:
self._in_start = True
self._k_x *= -1
self._k_y *= -1
elif not self._in_start and self._last_coordinates is not None and abs(
self.rect.y - self._last_coordinates[1]) > self._speed:
self._move()
elif self._last_coordinates is None and abs(
self.rect.y - self._y) > self._speed:
self._move()
elif abs(self.rect.y - self._y) <= self._speed:
self._in_start = True
def _move(self):
self._current_x += self._k_x
self._current_y += self._k_y
self.rect.x = self._current_x
self.rect.y = self._current_y
GREEN = (0, 255, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
RANDOM_COLOR = (234, 165, 43)
target_position = [(400, 77), (700, 77), (320, 277), (670, 277)]
FPS = 60
pygame.init()
display = pygame.display.set_mode((1281, 720))
display.fill((255, 255, 255))
clock = pygame.time.Clock()
font = pygame.font.Font(None, 50)
text = font.render("Слово слово_________слово_________слово слово", 1, WHITE)
place = text.get_rect(center=(600, 100))
font1 = pygame.font.Font(None, 50)
text1 = font1.render("Слово_________слово_________слово слово", 1, WHITE)
place1 = text1.get_rect(center=(600, 300))
surf_down = pygame.Surface((1200, 100))
surf_down.fill(RANDOM_COLOR)
rect_surf_down = pygame.Rect((40, 560, 0, 0))
pygame.display.update()
count = 0
def inc_count():
global count
count += 1
text_group = pygame.sprite.Group()
for value in [["qwe", 100, target_position[0]], ["werfui", 300, target_position[1]], ["earhb", 500, target_position[2]],
["it7j", 700, target_position[3]]]:
TextView(value[0], value[1], 600, value[2], inc_count, text_group)
def renderView():
display.blit(image_surf, image_rect)
display.blit(text, place)
display.blit(text1, place1)
display.blit(surf_down, rect_surf_down)
text_group.draw(display)
text_group.draw(display)
pygame.display.update()
image_surf = pygame.image.load("/home/oop/Документы/program/game/game/game_photo1.jpg")
image_rect = image_surf.get_rect()
while True:
for i in pygame.event.get():
if i.type == pygame.QUIT:
exit()
if i.type == pygame.MOUSEBUTTONDOWN and i.button == 1 and len(target_position) > 0:
text_group.update((i.pos[0], i.pos[1]), target_position[0])
elif i.type == pygame.MOUSEBUTTONDOWN and i.button == 1:
text_group.update((i.pos[0], i.pos[1]))
text_group.update()
renderView()
pygame.display.update()
clock.tick(FPS)