-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStageCreator.py
executable file
·134 lines (117 loc) · 4.64 KB
/
StageCreator.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
#!/usr/bin/python
# coding: utf-8
# Author: Rodrigo Contreras Reyes
import pygame, sys
from pygame.locals import *
def start():
'''Generates a map based in the draw on the screen to a file.'''
pygame.init()
cha_cod = ['S','F','W','B']
cha_num = [0,0,0,0]
cha_col = [(175,121,191),(210,228,140),(137,190,228),(212,114,87)]
# This is the structure to save the map
map_struct = [[0 for i in range(30)] for i in range(25)]
for i in range(1,24):
for j in range(1,29):
map_struct[i][j] = 1
cha_num[0] = 30*25 - 28*23
cha_num[1] = 28*23
screen = pygame.display.set_mode((30*20,25*20), DOUBLEBUF | HWSURFACE, 32)
pygame.display.set_caption("StoneHunters [MAP CREATOR] - By RoCR [ To Gab ]")
icon = pygame.image.load("images/icon.png").convert_alpha()
pygame.display.set_icon(icon)
screen.fill((20, 20, 20))
running = True
font = pygame.font.Font("accid.ttf", 14)
x, y = 1, 1
while running:
# Event managing:
events = pygame.event.get()
if events:
for e in events:
if e.type == pygame.QUIT:
running = False
if e.type == pygame.KEYDOWN:
if e.key == pygame.K_ESCAPE:
running = False
if e.key == pygame.K_DOWN:
y += 1
if e.key == pygame.K_UP:
y -= 1
if e.key == pygame.K_LEFT:
x -= 1
if e.key == pygame.K_RIGHT:
x += 1
if e.key == pygame.K_SPACE:
cha_num[map_struct[y][x]] -= 1
if cha_num[3] == 0:
cha_num[3] += 1
map_struct[y][x] = 3
else:
map_struct[y][x] = (map_struct[y][x] + 1) % 4
cha_num[map_struct[y][x]] += 1
if e.key == pygame.K_s:
if cha_num[3] == 0:
cha_num[3] += 1
map_struct[y][x] = 3
else:
cha_num[map_struct[y][x]] -= 1
map_struct[y][x] = 0
cha_num[map_struct[y][x]] += 1
if e.key == pygame.K_f:
if cha_num[3] == 0:
cha_num[3] += 1
map_struct[y][x] = 3
else:
cha_num[map_struct[y][x]] -= 1
map_struct[y][x] = 1
cha_num[map_struct[y][x]] += 1
if e.key == pygame.K_w:
if cha_num[3] == 0:
cha_num[3] += 1
map_struct[y][x] = 3
else:
cha_num[map_struct[y][x]] -= 1
map_struct[y][x] = 2
cha_num[map_struct[y][x]] += 1
if e.key == pygame.K_b:
cha_num[map_struct[y][x]] -= 1
map_struct[y][x] = 3
cha_num[map_struct[y][x]] += 1
if x < 1:
x = 28
if x > 28:
x = 1
if y < 1:
y = 23
if y > 23:
y = 1
for i in range(25):
for j in range(30):
pygame.draw.rect(screen, cha_col[map_struct[i][j]], (j*20,i*20,20,20))
text = cha_cod[map_struct[i][j]]
ren = font.render(text, 1, (20,20,20))
screen.blit(ren,(j*20+8,i*20+2))
for i in range(1,30):
pygame.draw.line(screen, (20,20,20), (i*20, 0), (i*20, 500))
for i in range(1,25):
pygame.draw.line(screen,(20,20,20), (0,i*20), (600, i*20))
draw_cursor(screen, x*20, y*20)
pygame.display.flip()
# Save the map info in to the file
my_file = "generated_stage.stg"
f = open(my_file, 'w')
for i in range(25):
for j in range(30):
f.write(cha_cod[map_struct[i][j]])
f.write('\n')
f.close()
sys.exit()
def draw_cursor(screen,x,y):
'''Draws a red non-filled square to represent the cursor.'''
pygame.draw.line(screen, (255, 0, 0), (x, y), (x+20, y))
pygame.draw.line(screen, (255, 0, 0), (x, y), (x, y+20))
pygame.draw.line(screen, (255, 0, 0), (x+20, y), (x+20, y+20))
pygame.draw.line(screen, (255, 0, 0), (x, y+20), (x+20, y+20))
if __name__ == "__main__":
start()