-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditor.py
147 lines (89 loc) · 4.74 KB
/
editor.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
import sys
import pygame as p
from scripts.utils import load_images,load_image
from scripts.tilemap import TileMap
from scripts.clouds import Clouds
# from temp import *
class Editor:
def __init__(self) :
p.init()
p.display.set_caption("Levieel Editor")
icon=p.image.load("data/images/rika.jpg")
p.display.set_icon(icon)
self.screen=p.display.set_mode((640,480))
self.clock =p.time.Clock()
self.vertical=[False,False]
self.horizontal=[False,False]
self.assets={
'decor':load_images("tiles/decor"),
'grass': load_images("tiles/grass"),
'large_decor': load_images("tiles/large_decor"),
'stone': load_images("tiles/stone"),
'background': load_image("background.png"),
'clouds': load_images("clouds"),
}
self.tilemap=TileMap(self)
self.display=p.Surface(tuple(i/2 for i in self.screen.get_size() ))
self.scroll=[0,0]
self.clouds=Clouds(self.assets['clouds'])
self.tile_list=list(i for i in list(self.assets.keys())[:4])
self.tile_group=0
self.tile_variant=0
self.shift=False
def run(self):
while True:
self.curr_tile=self.assets[self.tile_list[self.tile_group]][self.tile_variant].copy()
self.curr_tile.set_alpha(100)
self.display.blit(self.assets['background'],(0,0))
self.display.blit(self.curr_tile,(5,5))
render_scroll=list(int(i) for i in self.scroll)
self.clouds.update()
self.clouds.render(self.display,offset=render_scroll)
self.tilemap.render(self.display,offset=render_scroll)
self.screen.blit(p.transform.scale(self.display,self.screen.get_size()),(0,0))
p.display.update()
self.clock.tick(60)
for event in p.event.get():
if event.type==p.QUIT:
p.quit()
sys.exit()
if event.type==p.MOUSEBUTTONDOWN:
if event.button==1:
self.left_click=True
if event.button==2:
self.middle_click=True
if event.button==3:
self.right_click=True
if event.button==4:
if(not self.shift):
self.tile_group=(self.tile_group+1)%len(self.tile_list)
self.tile_variant=0
else:
self.tile_variant=(self.tile_variant+1)%len(self.assets[self.tile_list[self.tile_group]])
if event.button==5:
if(not self.shift):
self.tile_group=(self.tile_group-1)%len(self.tile_list)
self.tile_variant=0
else:
self.tile_variant=(self.tile_variant-1)%len(self.assets[self.tile_list[self.tile_group]])
if event.type==p.KEYDOWN:
if (event.key==p.K_w or event.key==p.K_UP) :
self.vertical[0]=True
if (event.key==p.K_s or event.key==p.K_DOWN) :
self.vertical[1]=True
if event.key==p.K_d or event.key==p.K_RIGHT :
self.horizontal[0]=True
if event.key==p.K_a or event.key==p.K_LEFT :
self.horizontal[1]=True
if event.key==p.K_LSHIFT:
self.shift= not self.shift
if event.type==p.KEYUP:
if event.key==p.K_w or event.key==p.K_UP:
self.vertical[0]=False
if (event.key==p.K_d or event.key==p.K_RIGHT) :
self.horizontal[0]=False
if (event.key==p.K_a or event.key==p.K_LEFT) :
self.horizontal[1]=False
if event.key==p.K_s or event.key==p.K_DOWN:
self.vertical[1]=False
Editor().run()