-
Notifications
You must be signed in to change notification settings - Fork 0
/
textcraft.py
6846 lines (6128 loc) · 227 KB
/
textcraft.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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import copy
import math
import random
import time
from functools import partial
from os.path import join
from kivy.app import App
from kivy.clock import Clock
from kivy.config import Config, ConfigParser
from kivy.core.window import Window
from kivy.lang import Builder
from kivy.properties import BooleanProperty
from kivy.storage.jsonstore import JsonStore
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.uix.image import Image
from kivy.uix.label import Label
from kivy.uix.popup import Popup
from kivy.uix.relativelayout import RelativeLayout
from kivy.uix.screenmanager import NoTransition, Screen, ScreenManager
from kivy.uix.scrollview import ScrollView
from kivy.uix.dropdown import DropDown
from kivy.uix.settings import Settings, SettingsWithSidebar
from kivy.uix.textinput import TextInput
from kivy.uix.progressbar import ProgressBar
from kivy.graphics import Color, Ellipse, Rectangle, RoundedRectangle
from kivy.core.text import Label as CoreLabel
from kivy.base import runTouchApp
from jsonsettings import json_settings
testing = False
splash = """
TEXTCRAFT Alpha 0.1
Sam Stoltenberg
"""
sm = ScreenManager(transition=NoTransition())
main_text = ''
# Bugs
# future error, lol burning enchanted wooden tools,
# won't be able to select which wood tool to burn
def alert(msg):
"""Takes a message and displays a popup for it"""
_var_msg = msg
if 'pickaxe' in msg:
_var_msg = str('Your %s\nhas broken!' % current_pickaxe[0])
_var_msg = _var_msg.replace('_', ' ')
elif 'axe' in msg:
_var_msg = str('Your %s\nhas broken!' % current_axe[0])
_var_msg = _var_msg.replace('_', ' ')
elif 'shovel' in msg:
_var_msg = str('Your %s\nhas broken!' % current_shovel[0])
_var_msg = _var_msg.replace('_', ' ')
elif 'sword' in msg:
_var_msg = str('Your %s\nhas broken!' % current_sword[0])
_var_msg = _var_msg.replace('_', ' ')
elif 'helmet' in msg:
_var_msg = str('Your %s\nhas broken!' % current_helmet[0])
_var_msg = _var_msg.replace('_', ' ')
elif 'chestplate' in msg:
_var_msg = str('Your %s\nhas broken!' % current_chestplate[0])
_var_msg = _var_msg.replace('_', ' ')
elif 'leggings' in msg:
_var_msg = str('Your %s\nhas broken!' % current_leggings[0])
_var_msg = _var_msg.replace('_', ' ')
elif 'boots' in msg:
_var_msg = str('Your %s\nhas broken!' % current_boots[0])
_var_msg = _var_msg.replace('_', ' ')
global alertx_label
alertx_label = AlertWindow()
alertx_label.text = str(_var_msg)
Window.add_widget(alertx_label)
def alertf(msg):
_var_msg = msg
global alertx_label
alertx_label = AlertWindow()
alertx_label.text = str(_var_msg)
Window.add_widget(alertx_label)
def testbtn_callback(self):
sm.switch_to(Testing())
# statcheck use with sc('tree', 'logs')
def sc(family, stat):
x = 0
for i in stats:
if i[0] == family:
for j in i[1]:
if j == stat:
return(i[1][x+1])
x += 1
return 0
class Engine(object):
def __init__(self):
pass
# Stores x, y times
def store(self, x, y):
print(x, y)
global equipment
if y > 0:
stat.item(x, y)
y = int(y)
# ['stick', 'wood_plank', 2, 4]
# ['fishing_rod', 'stick', 3, 'string', 2, 1]]
# x is the item to add
# y is the quanity
# This is how all items are stored into the inventory
added = False
in_tools = False
item_deleted = False
z = 0
remove = 0
tools2 = copy.deepcopy(tools)
for i in tools2:
if x == i[0]:
if y > 0:
while y > 0:
equipment.append(i)
in_tools = True
y -= 1
elif not in_tools:
for i in equipment:
if i[0] == x and not item_deleted:
item_deleted = True
equipment.remove(i)
in_tools = True
if not in_tools:
for i in inventory:
if i[0] == x:
i[1] = i[1] + y
added = True
if not added:
inventory.append([x, y])
# Checking the clock or moving time forward
def tick(self, x):
# tick(0) checks the clock
# tick(x) checks clock and moves time forward by x
global clock
global night
print('time', clock)
if x == 0:
if clock < 50:
night = False
return (" Birds are singing in the sunlight...\n")
else:
night = True
return (" Crickets are chirping in the moonlight...\n")
# For sleeping
elif x == 100:
clock = 0
night = False
msg = ''
msg += ("=========================\n")
msg += ("=========================\n")
msg += ("The sun has RISEN!\n")
msg += ("=========================\n")
msg += ("=========================\n")
alertf(msg)
else:
clock += x
if clock >= 50 and night == False:
night = True
msg = ''
msg += ("=========================\n")
msg += ("=========================\n")
msg += ("The sun has FALLEN!\n")
msg += ("=========================\n")
msg += ("=========================\n")
alertf(msg)
if clock >= 100:
night = False
msg = ''
msg += ("=========================\n")
msg += ("=========================\n")
msg += ("The sun has RISEN!\n")
msg += ("=========================\n")
msg += ("=========================\n")
clock = 0
alertf(msg)
def money_add(self, x):
# add achievement here for negatives
# spending money :)
global money
money += x
def save(object):
global night
global furnace_have
global health
global wolves
global clock
global money
global current_pickaxe
global user_id
global current_shovel
global current_axe
global current_helmet
global current_chestplace
global current_leggings
global current_boots
global current_sword
global current_time
global furnace_level
global time_left_cooking
global is_cooking
global farming_started
global time_passed_storm
global cooking_chart
global stats
current_time = math.floor(time.time())
base = []
base.append(night)
base.append(furnace_have)
base.append(health)
base.append(wolves)
base.append(clock)
base.append(money)
base.append(current_pickaxe)
base.append(user_id)
base.append(current_shovel)
base.append(current_axe)
base.append(current_helmet)
base.append(current_chestplate)
base.append(current_leggings)
base.append(current_boots)
base.append(current_sword)
base.append(current_time)
base.append(furnace_level)
base.append(time_left_cooking)
base.append(is_cooking)
base.append(farming_started)
base.append(time_passed_storm)
base.append(cooking_chart)
store_file.put('inventory', content=inventory)
store_file.put('all_farms', content=all_farms)
store_file.put('equipment', content=equipment)
store_file.put('achievements_list', content=achievements_list)
store_file.put('base', content=base)
store_file.put('stats', content=stats)
def version(object):
pass
def dead(self):
global death_message
global night
global furnace_have
global health
global wolves
global clock
global money
global equipment
global current_pickaxe
global user_id
global current_shovel
global current_axe
global current_helmet
global current_chestplate
global current_leggings
global current_boots
global current_sword
global current_time
global furnace_level
global time_left_cooking
global is_cooking
global farming_started
global time_passed_storm
global cooking_chart
global achievements_list
global inventory
global all_farms
global base
Clock.unschedule(FarmEngine.interval)
Clock.unschedule(engine.count_down)
# [variable ,Don't have have 0 or 1 ,goal ,
# "achievement",reason for achievement]
achievements_list = [
[0, 0, 'Dirt Miner', 100, 'mining 100 dirt'], # 0
[0, 0, 'Dirty Diamonds', 2, 'mining 2 diamonds'], # 1
[0, 0, 'Tree Hugger(not)', 50, 'killing 50 trees'], # 2
[0, 0, 'Cover Me Feet', 1, 'pouring water on lava (not dying)'],
[0, 0, 'Sorry, Mom', 1, 'killing a cow'], # 4
[0, 0, 'Jill', 20, 'filling your bucket 20 times'], # 5
[0, 0, 'Good morning, ladies', 10, 'catching 10 fish'], # 6
[0, 0, 'Bitch Tamer', 5, 'taming 5 wolves'], # 7
[0, 0, 'Dar3 D3vil', 10, 'killing 10 creepers'], # 8
[0, 0, 'Worrisome', 100, 'opening inventory 100 times'], # 9
[0, 0, 'Oink, Oink', 100, 'eat 100 items'] # 10
# 11 millionaire
]
current_time = (math.floor(time.time()))
inventory = [['torch', 1]]
all_farms = []
base = [0, 0, 100, 0, 0, 0,
['fist',-1, 0, -1, .5], 'user_id',
['fist', -1, 0, -1, .5],
['fist', -1, 0, -1, .5],
['skin', -1, 0, -1, 1],
['skin', -1, 0, -1, 1],
['skin', -1, 0, -1, 1],
['skin', -1, 0, -1, 1],
['fist', -1, 0, -1, .5],
current_time, 1, 0, False, False, 0, []]
equipment = []
height = 64
night = base[0]
furnace_have = base[1]
health = base[2]
wolves = base[3]
clock = base[4]
money = base[5]
current_pickaxe = base[6]
user_id = base[7]
current_shovel = base[8]
current_axe = base[9]
current_helmet = base[10]
current_chestplate = base[11]
current_leggings = base[12]
current_boots = base[13]
current_sword = base[14]
current_time = base[15]
furnace_level = base[16]
time_left_cooking = base[17]
is_cooking = base[18]
farming_started = base[19]
time_passed_storm = base[20]
cooking_chart = base[21]
engine.save()
sm.add_widget(Death(name='dead'))
sm.switch_to(Death())
def count_down(self, dt):
global cooking_chart
global time_left_cooking
global is_cooking
global furnace_level
a = cooking_chart
material = a[0]
material_quantity = a[1]
fuel = a[2]
fq = a[3]
if not is_cooking: # first time cooking defines time
is_cooking = True
time_left_cooking = int(3 * (1/float(furnace_level)) * material_quantity)
# 3 * 1 / furnace_level * material
if time_left_cooking == 0:
_double = 1
if random.randint(0, 100) < (furnace_level * 2):
_double = 2
for i in cook_output:
if material == i[0]:
gained_material = i[1]
engine.store(gained_material, material_quantity)
stat.cook(gained_material, material_quantity)
is_cooking = False
Clock.unschedule(engine.count_down)
# add images, if x material, put x image comment line
# comment line in engine.count_down
tmaterial = gained_material.replace("_", " ")
# done_cooking_button.text =
alertf(str(('Your %s %s\n' +
'has cooked\n' +
'using %s %s.') % (
material_quantity,
tmaterial,
fq, fuel.replace('_', ' '))))
#done_cooking_popup.open()
else:
time_left_cooking -= 1
def close_popup(self, popup):
popup.dismiss()
# When unequipping something, ...
# if it's not a fist or skin, puts back in inventory
def old_equipment(self, x):
if x[0] == 'fist' or x[0] == 'skin':
pass
else:
equipment.append(x)
# command example stat.ore('obsidian', 20)
class Stat(object):
# add to adventure
def animal(self, material, quantity):
if material == 'cow':
achievements_list[4][0] += 1
elif material == 'creeper':
achievements_list[8][0] += 1
stat.add(material, quantity, 'animal')
def ore(self, material, quantity):
if material == 'diamond':
achievements_list[1][0] += 1
elif material == 'dirt':
achievements_list[0][0] += 1
stat.add(material, quantity, 'ore')
def tree(self, material, quantity):
if material == 'tree':
achievements_list[2][0] += 1
stat.add(material, quantity, 'tree')
def craft(self, material, quantity):
stat.add(material, quantity, 'craft')
def cook(self, material, quantity):
stat.add(material, quantity, 'cook')
def harvest(self, material, quantity):
stat.add(material, quantity, 'harvest')
def item(self, material, quantity):
stat.add(material, quantity, 'item')
def misc(self, material, quantity):
if material == 'open_inv':
achievements_list[9][0] += 1
elif material == 'eat':
achievements_list[10][0] += 1
elif material == 'fish_caught':
achievements_list[6][0] += 1
elif material == 'wolf_tamed':
achievements_list[7][0] += 1
elif material == 'bucket_filled':
achievements_list[5][0] += 1
elif material == 'lava_blocked':
achievements_list[3][0] += 1
stat.add(material, quantity, 'misc')
def add(self, material, quantity, family):
global stats
z = 0
added = False
for i in stats:
if i[0] == family:
for j in i[1]:
z += 1
if material == j:
added = True
i[1][z] = int(i[1][z]) + quantity
if not added:
i[1].append(material)
i[1].append(quantity)
self.check_achieve()
engine.save()
def check_achieve(self):
for i in achievements_list:
if i[0] >= i[3] and i[1] == 0:
i[1] = 1
alert("You gained %s achievement" % i[2])
class HealthBar(ProgressBar):
def __init__(self, **kwargs):
super(HealthBar, self).__init__(**kwargs)
global health
self.value = health
self.label = CoreLabel(
text='Health',
font_size=Window.height/16)
self.texture_size = None
self.refresh_text()
self.draw()
def draw(self):
with self.canvas:
self.canvas.clear()
# Draw no progress bar
Color(.188, .209, .148)
RoundedRectangle(
pos=self.pos,
size=self.size)
Color(.5, 0, 0)
if self.value > 0:
var = 100.0/self.value
# Draw progress bar
RoundedRectangle(
pos=self.pos,
size=(self.width/var, self.height))
# Center and draw the text
Color(1, 1, 1, 1)
RoundedRectangle(texture=self.label.texture, size=self.texture_size,
pos=(self.size[0]/2 - self.texture_size[0]/2, self.size[1]/2 - self.texture_size[1]/2))
def refresh_text(self):
# Render the label
self.label.refresh()
# Set the texture size each refresh
self.texture_size = list(self.label.texture.size)
def set_value(self, value):
self.value = value
self.refresh_text()
self.draw()
class EquipmentBar(ProgressBar):
def __init__(self, **kwargs):
super(EquipmentBar, self).__init__(**kwargs)
self.label = CoreLabel(
text=self.text,
font_size=Window.height/16)
self.texture_size = None
self.refresh_text()
self.draw()
def draw(self):
with self.canvas:
self.canvas.clear()
# Draw no progress bar
Color(.5, 0, 0)
RoundedRectangle(
pos=self.pos,
size=self.size)
Color(0, .65, 0)
if self.value > 0:
var = 100.0/self.value
# Draw progress bar
RoundedRectangle(
pos=self.pos,
size=(self.width/var, self.height))
# Center and draw the text
Color(1, 1, 1, 1)
RoundedRectangle(texture=self.label.texture, size=self.texture_size,
pos=(self.size[0]/2 - self.texture_size[0]/2, self.size[1]/2 - self.texture_size[1]/2))
def refresh_text(self):
# Render the label
self.label.refresh()
# Set the texture size each refresh
self.texture_size = list(self.label.texture.size)
def set_value(self, value):
self.value = value
self.refresh_text()
self.draw()
class AlertWindow(Label):
def __init__(self, **kwargs):
super(AlertWindow, self).__init__(**kwargs)
self.font_size = '45dp'
self.pos = [0, -300]
self.color = ([.42, .77, .92, 1])
Clock.schedule_interval(self.move, .01)
def move(self, dt):
self.pos[1] += 2.5
if self.pos[1] >= 350:
Clock.unschedule(self.move)
Window.remove_widget(alertx_label)
class InvBtn(Button):
def __init__(self, **kwargs):
super(InvBtn, self).__init__(**kwargs)
self.font_size = '40dp'
self.size_hint=(.4, .4)
class Inv(Screen):
def __init__(self, **kwargs):
super(Inv, self).__init__(**kwargs)
inventory.sort()
global health
global equipment
self.selected_event = None
self.selected_item = None
self.selected_quantity = None
self.added = 0
self.bind(on_enter=self.build)
self.scroll = ScrollView(
scroll_type=['bars'],
bar_width='80dp',
size=(Window.width, Window.height),
pos_hint={'center_x': .5},
bar_color=([.81, .55, .55, 1]), #
bar_inactive_color=([.55, .17, .17, 1])) #
self.grid = GridLayout(
size_hint=(None, 2),
cols=2
)
self.btn1 = Button(
text='Trash',
font_size='50dp',
color=(0, 0, 0, 1),
background_normal="btnimg/trash.jpg",
size_hint=(None, None),
height=int(Window.height)/6,
width=int(Window.width)/4,
pos_hint={'center_x': .1}
)
self.btn1.bind(on_press=self.trash)
self.btn2 = Button(
text='Equip',
font_size='50dp',
color=(0, 0, 0, 1),
size_hint=(None, None),
height=int(Window.height)/6,
width=int(Window.width)/2,
pos_hint={'center_x': .492}
)
self.btn2.bind(on_press=self.equip)
self.btn4 = Button(
text='Exit',
font_size='45dp',
size_hint=(None, None),
width=int(Window.width)/4,
height=int(Window.height)/6,
background_color=(0.77, 0.52, 1.24, 1),
pos_hint={'center_x': .9, 'center_y': .1}
)
self.btn4.bind(on_press=self.main)
self.eatbtn = Button(
text='',
font_size='50dp',
color=(0, 0, 0, 1),
size_hint=(None, None),
height=int(Window.height)/6,
width=int(Window.width)/2,
pos_hint={'center_x': .492}
)
self.eatbtn.bind(on_press=self.eat)
self.label = Label(
text='Equipment',
font_size='40dp',
size_hint_x=None,
# height=self.minimum_height,
width=Window.width/2.22,
#background_color=(0, 0, 0, 1)
)
self.label2 = Label(
text='Equipment bar image',
font_size='40dp',
size_hint_x=None,
# Equipment bar image!!
# height=self.minimum_height,
width=Window.width/2.22,
#background_color=(0, 0, 0, 1)
)
self.scroll.scroll_y = Inv.scroll_pos
for i in inventory:
if i[1] <= 0:
inventory.remove(i)
else:
self.added += 1
bstext = str('%s %s' % (i[1], i[0]))
bstext = bstext.replace("_", " ")
self.btn = InvBtn()
self.btn.text = bstext
self.btn.bind(on_press=self.callback)
self.btn.item = i[0]
self.btn.quantity = i[1]
self.grid.add_widget(self.btn)
if self.added % 2 == 1:
self.btn = Button(
text='',
size_hint=(.4, .4),
background_color=(0, 0, 0, 1)
)
self.grid.add_widget(self.btn)
self.grid.add_widget(self.label)
self.grid.add_widget(self.label2)
for i in equipment:
self.added += 1
bstext = str('%s' % i[0])
bstext = bstext.replace("_", " ")
self.btn = InvBtn()
self.btn.text = bstext
self.btn.bind(on_press=self.equip_callback)
self.btn.item = i
self.btn.quantity = 1
# THIS IS WHERE YOU ADD THE DURABILITY % BAR in inv screen
self.grid.add_widget(self.btn)
for i in range(6):
self.btn = Button(
text='',
size_hint=(.4, .4),
background_color=(0, 0, 0, 1)
)
self.grid.add_widget(self.btn)
self.scroll.add_widget(self.grid)
self.add_widget(self.scroll)
self.add_widget(self.btn1)
self.add_widget(self.btn4)
def build(self, event):
stat.misc("open_inv", 1)
def equip_callback(self, event):
self.remove_widget(self.btn2)
self.add_widget(self.btn2)
self.selected_item = event.item
self.selected_quantity = event.quantity
try:
self.selected_event.background_color = (1, 1, 1, 1)
except AttributeError:
pass
self.selected_event = event
event.background_color = (1, 0, 1, 1)
def callback(self, event):
global health
self.selected_item = event.item
self.selected_quantity = event.quantity
try:
self.selected_event.background_color = (1, 1, 1, 1)
except AttributeError:
pass
self.edible = False
self.remove_widget(self.eatbtn)
for i in edible:
if self.selected_item == i[0]:
try:
self.remove_widget(self.btn2)
self.add_widget(self.eatbtn)
self.eatbtn.bind(on_press=self.eat)
if health == 100:
self.eatbtn.text = 'Health Full'
else:
self.eatbtn.text = 'Eat'
except Exception:
pass
self.edible = True
if self.selected_item in tools:
self.remove_widget(self.btn2)
self.add_widget(self.btn2)
self.selected_event = event
event.background_color = (1, 0, 1, 1)
def eat(self, event):
global health
global death_message
stat.misc("eat", 1)
engine.store(self.selected_item, -1)
self.selected_quantity -= 1
if self.selected_quantity == 0:
Inv.scroll_pos = self.scroll.scroll_y
sm.switch_to(Inv())
# need more code here
else:
self.eatbtn.bind(on_press=self.eat)
for i in inventory:
if i[0] == self.selected_item:
eattext = str('%s %s' % (i[1], i[0]))
eattext = eattext.replace("_", " ")
self.selected_event.text = eattext
if self.selected_item in semi_edible:
if random.randint(0, 100) < 70:
self.eatbtn.text = 'Ehh...'
self.eat_item()
else:
self.eatbtn.text = 'Yuck...'
health -= 10
if health <= 0:
death_message = 'You die of a\nmysterious sickness'
engine.dead()
else:
self.eatbtn.text = 'Yum!'
self.eat_item()
def eat_item(self):
global health
for i in edible:
if i[0] == self.selected_item:
health += i[1]
if health > 100:
health = 100
if health == 100:
self.eatbtn.text = 'Health Full'
def passed(self, event):
pass
def trash(self, event):
if self.selected_item != None and self.selected_item not in tools:
#self.remove_widget(self.selected_event)
engine.store(self.selected_item, -self.selected_quantity)
Inv.scroll_pos = self.scroll.scroll_y
sm.switch_to(Inv())
elif self.selected_item != None:
#self.remove_widget(self.selected_event)
engine.store(self.selected_item[0], -self.selected_quantity)
Inv.scroll_pos = self.scroll.scroll_y
sm.switch_to(Inv())
def equip(self, event):
global picks
global shovels
global axes
global swords
global helmets
global chestplates
global leggings
global boots
global current_pickaxe
global current_shovel
global current_axe
global current_sword
global current_helmet
global current_chestplate
global current_leggings
global current_boots
_item = self.selected_item
_item[0] = _item[0].replace(" ", "_")
if 'pickaxe' in _item[0]:
engine.store(_item[0], -1)
engine.old_equipment(current_pickaxe)
current_pickaxe = _item
elif 'axe' in _item[0]:
engine.store(_item[0], -1)
engine.old_equipment(current_axe)
current_axe = _item
elif 'shovel' in _item[0]:
engine.store(_item[0], -1)
engine.old_equipment(current_shovel)
current_shovel = _item
elif 'sword' in _item[0]:
engine.store(_item[0], -1)
engine.old_equipment(current_sword)
current_sword = _item
elif 'helmet' in _item[0]:
engine.store(_item[0], -1)
engine.old_equipment(current_helmet)
current_helmet = _item
elif 'chestplate' in _item[0]:
engine.store(_item[0], -1)
engine.old_equipment(current_chestplate)
current_chestplate = _item
elif 'leggings' in _item[0]:
engine.store(_item[0], -1)
engine.old_equipment(current_leggings)
current_leggings = _item
elif 'boots' in _item[0]:
engine.store(_item[0], -1)
engine.old_equipment(current_boots)
current_boots = _item
Inv.scroll_pos = self.scroll.scroll_y
sm.switch_to(Inv())
def main(self, event):
Inv.scroll_pos = 1
sm.switch_to(MainScreen())
class Equip(Screen):
def __init__(self, **kwargs):
super(Equip, self).__init__(**kwargs)
_current = []
_current.append(current_helmet)
_current.append(current_chestplate)
_current.append(current_leggings)
_current.append(current_boots)
_current.append(current_sword)
_current.append(current_shovel)
_current.append(current_pickaxe)
_current.append(current_axe)
# to fix the buttons, add scrollview to relative
# and add the buttons to relative
# or just remove scrollview, since it can all fit on
# the screen
self.exitbtn = Button(
text='Exit',
font_size='45dp',
size_hint=(None, None),
width=int(Window.width)/4,
height=int(Window.height)/6,
background_color=(0.77, 0.52, 1.24, 1),
pos_hint={'center_x': .9, 'center_y': .1}
)
self.exitbtn.bind(on_press=self.exit_screen)
self.add_widget(self.exitbtn)
scrollview = ScrollView()
self.grid = GridLayout(cols=1)
for i in _current:
if i[0] != 'fist' and i[0] != 'skin':
relate = GridLayout(cols=1, size_hint=(None, None), size=(Window.width, Window.height/11))
relate2 = RelativeLayout()
bstext = i[0].replace('_', ' ')
EquipmentBar.text='%s' % bstext
percentage = math.ceil(100 * (i[1]) / i[3])
label = EquipmentBar(
size_hint=(None, None),
max=100,
height=Window.height/12.0,
width=Window.width
)
label.set_value(percentage)
relate2.add_widget(label)
label2 = Label(
size_hint=(None,None),
height=5)
self.grid.add_widget(label2)
self.btn = Button(
text='Unequip',
font_size='25dp',
size_hint=(None, None),
height=Window.height/20.0,
width=Window.width/6.0,
pos_hint={'center_y': .4, 'center_x': .1})
self.btn.item = i
self.btn.bind(on_press=self.unequip)
relate2.add_widget(self.btn)
relate.add_widget(relate2)
self.grid.add_widget(relate)
label3 = Label(
size_hint=(None,None),
height=5)
self.grid.add_widget(label3)
gridz = GridLayout(cols=2)
gridz.add_widget(Label(size_hint_x=None,
width=int(Window.width/4.0)))
self.btn3 = Button(
text='Equip Best',
font_size='50dp',
color=(0, 0, 0, 1),
size_hint=(None, None),
pos_hint={'center_x': .5},
height=int(Window.height)/5.0,
width=int(Window.width)/2.0
)
gridz.add_widget(self.btn3)
self.btn3.bind(on_press=self.equip_best)
self.maingrid = GridLayout(cols=1)
self.maingrid.add_widget(self.grid)
self.maingrid.add_widget(gridz)
self.add_widget(self.maingrid)
def unequip(self, event):
global picks
global shovels
global axes
global swords
global helmets
global chestplates
global leggings
global boots
global current_pickaxe
global current_shovel
global current_axe
global current_sword
global current_helmet
global current_chestplate
global current_leggings
global current_boots
global equipment
_item = event.item
if 'pickaxe' in _item[0]:
engine.old_equipment(current_pickaxe)
current_pickaxe = ['fist', -1, 0, -1, .5]
elif 'axe' in _item[0]:
engine.old_equipment(current_axe)
current_axe = ['fist', -1, 0, -1, .5]