-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
228 lines (182 loc) · 6.65 KB
/
main.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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import pygame, sys, time, random
from battle_func import battle
from pygame.locals import *
#creo que esto no es necesario
pygame.mixer.pre_init(44100, -16, 2, 512)
pygame.init()
pygame.mixer.set_num_channels(32)
pygame.display.set_caption('game base')
screen = pygame.display.set_mode((800, 800),0,32)
display = pygame.Surface((300, 300))
grass_img = pygame.image.load('grass.png').convert()
grass_img.set_colorkey((0, 0, 0))
knight_img = pygame.image.load('knight.png').convert()
knight_img.set_colorkey((255, 255, 255))
f = open('map.txt')
map_data = [[int(c) for c in row] for row in f.read().split('\n')]
f.close()
#Texto
def set_text(string, coordx, coordy, fontSize): #Function to set text
font = pygame.font.Font('freesansbold.ttf', fontSize)
#(255, 0, 0) is red, to make black text
text = font.render(string, True, (255, 0, 0))
textRect = text.get_rect()
textRect.center = (coordx, coordy)
totalText = (text, textRect)
return totalText
#Places "Text in Pygame!" with an x,y coord of 500, 250 and 30 font size
#totalText = set_text("You have encountered an enemy", 500, 250, 30)
# setup mixer to avoid
#pygame.mixer.init()
#player_cordinates = [0, 0]
clock = pygame.time.Clock()
encounters = pygame.time.Clock()
#monster_positions = [(4,0)]
class Player():
def __init__(self, x, y) -> None:
self.x = int(x)
self.y = int(y)
self.position = (self.x, self.y)
self.image = grass_img
self.color = (250, 120, 60)
self.velX = 0
self.velY = 0
self.left_pressed = False
self.right_pressed = False
self.up_pressed = False
self.down_pressed = False
self.speed = 4
self.scrollx = 0
self.scrolly = 0
self.death = False
self.hp = 100
self.atk = 3
def draw(self, screen):
display.blit(knight_img, (150-10 , 150-14)) #antes le sumaba y restaba las cordenadas del personaje para hacerlo mover
def update(self):
self.velX = 0
self.velY = 0
if self.left_pressed:
self.velX = -self.speed
player.scrollx += 4
if self.right_pressed:
self.velX = self.speed
self.scrollx -= 4
if self.up_pressed:
self.velY = self.speed
self.scrolly += 4
if self.down_pressed:
self.velY = -self.speed
self.scrolly -=4
self.x += self.velX/3
self.y += self.velY/3
self.position = (self.x, self.y)
self.image = grass_img
player = Player(0, 0)
class Monster():
def __init__(self) -> None:
self.hp = 10
self.atk = 2
def menu():
menu1 = True
player.left_pressed = False
player.right_pressed = False
player.up_pressed = False
player.down_pressed = False
while menu1:
screen.fill((0, 0, 0))
inventario = pygame.image.load('inventario.png')
inventario.set_colorkey((255, 255, 255))
screen.blit(inventario, (0 , 0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
menu1 = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_e:
menu1= False
option1 = pygame.Rect(100, 100, 100, 100)
pygame.draw.rect(screen, (255, 0, 0), option1)
#display.blit()
pygame.display.update()
#clock.tick(60)
print(map_data)
while True:
display.fill((0,0,0))
for y, row in enumerate(map_data):
for x, tile in enumerate(row):
if tile == 1:
#pygame.draw.rect(display, (255, 255, 255), pygame.Rect(x * 10, y * 10, 10, 10), 1)
display.blit(grass_img, (150 + x * 10 - y * 10 + player.scrollx, -390 + x * 5 + y * 5 + player.scrolly))
if player.scrollx > 200:
player.scrollx = -400
elif player.scrollx < -400:
player.scrollx = 200
elif player.scrolly > 300:
player.scrolly = -200
elif player.scrolly < -200:
player.scrolly = 300
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
player.left_pressed = True
if event.key == pygame.K_RIGHT:
player.right_pressed = True
if event.key == pygame.K_UP:
player.up_pressed = True
if event.key == pygame.K_DOWN:
player.down_pressed = True
if event.key == pygame.K_e:
menu()
if event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT:
player.left_pressed = False
if event.key == pygame.K_RIGHT:
player.right_pressed = False
if event.key == pygame.K_UP:
player.up_pressed = False
if event.key == pygame.K_DOWN:
player.down_pressed = False
"""if (player.position) in monster_positions:
monster_positions.pop()
menu()"""
#NO FUNCIONAAAAA
#print((player.position)) #esta no es la pocision real, es relativa a donde partio (150, 100)
#print(player.scrollx, player.scrolly)
x = 0
if x == random.randint(0, 1):
player.left_pressed = False
player.right_pressed = False
player.up_pressed = False
player.down_pressed = False
battle(Monster, screen, player)
if player.death == True:
break
#print(pygame.time.get_ticks())
player.draw(screen)
player.update()
pygame.display.flip() #porque????????????????????????????????????
clock.tick(120) #porque????????????????????????????????????
screen.blit(pygame.transform.scale(display, screen.get_size()), (0, 0)) # esta cosa esta causando problemas pero me da lata arreglarlo
pygame.display.update()
#time.sleep(1)
while player.death == True:
display.fill((0,0,0))
text = set_text(f"You died", 150, 100, 40)
display.blit(text[0], text[1])
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
clock.tick(120)
player.draw(screen)
player.update()
pygame.display.flip()
screen.blit(pygame.transform.scale(display, screen.get_size()), (0, 0)) # esta cosa esta causando problemas pero me da lata arreglarlo
pygame.display.update()