-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
224 lines (169 loc) · 8.06 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
from kivy.uix.button import Button
from kivy.uix.label import Label
import Map
from kivy.core.window import Window
from kivy.uix.relativelayout import RelativeLayout
from kivy.app import App
from kivy.clock import Clock
from kivy.uix.image import Image
from kivy.config import Config
import kivy
import Player
import Tile
import Event
import business_logic
kivy.require('2.0.0')
Window.size = (1920, 1080)
Window.clearcolor = (78 / 255, 173 / 255, 245 / 255, 1)
Window.fullscreen = True
Config.set('graphics', 'width', '1920')
Config.set('graphics', 'height', '1080')
Config.set('graphics', 'window_state', 'maximized')
Config.set('graphics', 'resizable', False)
class MyApp(App):
def __init__(self):
super().__init__()
self.generate_thief_layout = None
self.btn2 = None
self.btn1 = None
self.thief_info = None
self.thief_layout = None
self.clicker_display = None
self.clicker_buy_button = None
self.counter_button = None
self.drone_buy_button = None
self.main_loop = None
self.event_clock = None
self.autoclicker_clock = None
self.drone_movement = None
self.my_events = None
self.player = None
self.main_layout = None
self.event_layout = None
self.drone_layout = None
self.map_layout = None
self.wealth_display = None
self.drone_display = None
self.map = None
self.tile_map = None
def build(self):
self.generate_thief_layout = False
self.map = Map.load_map("map.txt")
self.tile_map = Map.map_organise(self.map)
self.main_layout = RelativeLayout()
self.drone_layout = RelativeLayout()
self.event_layout = RelativeLayout()
self.map_layout = RelativeLayout()
desk = Image(source='desk.png', pos=(-130, -471), allow_stretch=False,
nocache=True)
self.map_layout.add_widget(desk)
Map.build_map(self.tile_map, self.map_layout)
Tile.find_neighbours(self.tile_map)
drone_spawn = Tile.find_tile(self.tile_map, "DRONEX")
drone_spawn = drone_spawn.neighbours["up"]
self.player = Player.Player(drone_spawn)
screen = Image(source='screen.png', pos=(-130, 14), allow_stretch=False,
nocache=True)
self.map_layout.add_widget(screen)
self.clicker_buy_button = Button(background_normal='autoclicker.png', background_down='autoclicker_down.png',
pos=(1010, 10), size_hint=(None, None), size=(262, 172))
self.clicker_buy_button.bind(on_press=lambda instance: self.IncreaseAutoclicker())
self.map_layout.add_widget(self.clicker_buy_button)
self.drone_buy_button = Button(background_normal='drone_buy.png', background_down='drone_buy_down.png', pos=(1245, 10),
size_hint=(None, None), size=(262, 172))
self.drone_buy_button.bind(on_press=lambda instance: self.player.purchaseDrone())
self.map_layout.add_widget(self.drone_buy_button)
self.counter_button = Button(background_normal='counter.png', background_down='counter.png', pos=(100, 10),
size_hint=(None, None), size=(532, 130))
self.map_layout.add_widget(self.counter_button)
self.wealth_display = Label(text=str(self.player.wealth),
pos=(-715, -457), font_size=40, )
self.map_layout.add_widget(self.wealth_display)
self.drone_display = Label(text=str(self.player.drone_count),
pos=(-545, -457), font_size=40)
self.map_layout.add_widget(self.drone_display)
self.clicker_display = Label(text=str(self.player.autoclicker),
pos=(-427, -457), font_size=40)
self.map_layout.add_widget(self.clicker_display)
lama = Image(source='lama_basista.png', pos=(830, 300),
allow_stretch=False, nocache=True)
lama2 = Image(source='lama_chlopak.png', pos=(830, 50),
allow_stretch=False, nocache=True)
lama3 = Image(source='lama_zaklin.png', pos=(830, -200),
allow_stretch=False, nocache=True)
self.map_layout.add_widget(lama)
self.map_layout.add_widget(lama2)
self.map_layout.add_widget(lama3)
self.my_events = business_logic.EventSpawner(self.tile_map)
self.main_loop = Clock.schedule_interval(
lambda instance: self.refresh(), 0.5)
self.event_clock = Clock.schedule_interval(
lambda instance: self.my_events.spawn_event(), 4)
self.drone_movement = Clock.schedule_interval(
lambda instance: self.move_drones(), 1)
self.thief_layout = RelativeLayout()
self.btn2 = Button(background_normal='gray.png', background_down='gray.png', pos=(100, 100), size_hint=(None, None), size=(400, 200))
self.thief_layout.add_widget(self.btn2)
self.thief_info = Label(text="Your drone has been stolen during the mission.",
pos=(-665, -327), font_size=18)
self.thief_layout.add_widget(self.thief_info)
self.btn1 = Button(text='OK :(', pos=(350, 120), size_hint=(None, None), size=(100, 40))
self.btn1.bind(on_press=lambda instance: self.close_thief_layout())
self.thief_layout.add_widget(self.btn1)
self.refresh()
return self.main_layout
def IncreaseAutoclicker(self):
if self.player.purchaseAutoclicker():
if self.autoclicker_clock is not None:
self.autoclicker_clock.cancel()
self.autoclicker_clock = Clock.schedule_interval(
lambda instance: self.autoclick(), 10 / self.player.autoclicker)
def autoclick(self):
filtered = list(filter(lambda x: not x.is_added_to_destinations, self.my_events.eventList))
if len(filtered) != 0:
Event.add_destination(filtered[0])
def refresh(self):
self.main_layout.clear_widgets()
self.main_layout.add_widget(self.map_layout)
self.drone_layout.clear_widgets()
self.wealth_display.text = str(self.player.wealth)
self.drone_display.text = str(self.player.drone_count)
self.clicker_display.text = str(self.player.autoclicker)
for drone in self.player.drones:
if drone is not None:
if len(drone.movePath) != 0:
drone.draw_drone(self.drone_layout)
else:
if business_logic.thief:
self.player.drones.pop(self.player.drones.index(drone))
self.player.drone_count -= 1
self.drone_display.text = str(self.player.drone_count)
business_logic.thief = False
self.generate_thief_layout = True
self.main_layout.add_widget(self.drone_layout)
self.event_layout.clear_widgets()
for event in self.my_events.eventList:
if event is not None:
event.draw_event(self.event_layout)
self.main_layout.add_widget(self.event_layout)
if self.generate_thief_layout:
self.main_layout.add_widget(self.thief_layout)
return self.main_layout
def move_drones(self):
for event in self.my_events.eventList:
if event.obsolete:
self.my_events.eventList.pop(self.my_events.eventList.index(event))
self.player.increaseWealth(50)
for drone in self.player.drones:
if len(drone.movePath) == 0 and len(Event.destinations) != 0:
event = Event.destinations.pop()
drone.add_target(event)
drone.create_path(event.tile, event.target)
event.image.source = "green_alert.zip"
event.image.reload()
event.remove_button()
for drone in self.player.drones:
drone.move_to(drone.pop_move())
def close_thief_layout(self):
self.generate_thief_layout = False
MyApp().run()