from PIL import Image, ImageTk import tkinter as tk import schedule import sys import os ##-------NOTES:------------------------------------------------ ##Selection, computer/episodes,Intro screen -- stats do not decay #if hunger OR enegy go below 20 then mood goes to 0/ lain=mad. #if mood below 20 then lain = mad #if hunger or energy go to 0 then Game over #FUTURE EDIT: Energy=0 isnt death, some othe function? #--------End NOTES--------------------------------------------- #these 3 variables all need to be 1 to have mood be happy. if energy/hunger below 20 these variables are 0 making lain angry hMood = 1 eMood = 1 mMood = 1 allMood = eMood + hMood + mMood #this is for pyinstaller to include my art files in the bundled up .exe. wrap all my file location calls in it def resource_path(relative_path): """ Get absolute path to resource, works for dev and for PyInstaller """ base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__))) return os.path.join(base_path, relative_path) #schedueled status var updates def hungerUpdate(): global Hunger, Mood, hMood, allMood if Hunger >0: Hunger = Hunger -1 if Hunger < 20: Mood = 0 hMood = 0 allMood = mMood + hMood + eMood elif Hunger >= 20: hMood = 1 allMood = mMood + hMood + eMood else: dead() def MoodUpdate(): global Mood, mMood, hMood, eMood, allMood if Mood >0: Mood = Mood -1 if Mood < 20: mMood = 0 allMood = mMood + hMood + eMood elif Mood >= 20: mMood = 1 allMood = mMood + hMood + eMood def EnergyUpdate(): global Energy, Mood, allMood, eMood if Energy >0: Energy = Energy -1 if Energy < 20: Mood = 0 eMood = 0 allMood = mMood + hMood + eMood if Energy <= 0: dead() if Energy >= 20: eMood = 1 allMood = mMood + hMood + eMood else: dead() schedule.every(1).minutes.do(hungerUpdate) schedule.every(2).minutes.do(MoodUpdate) schedule.every(4).minutes.do(EnergyUpdate) #tkinter gif frame animators // scheduled status decay updaters def update(): global index, image, AFTER index = (index+1) % frames im.seek(index) image = ImageTk.PhotoImage(im) label.configure(image=image) AFTER = root.after(speed, update) schedule.run_pending() #updates status, checks if lain should be mad def updateStatusHappy(): global index, image, AFTER, compFrame, Hunger, Mood, Energy, Status, allMood, lainAwake index = (index+1) % frames im.seek(index) image = ImageTk.PhotoImage(im) label.configure(image=image, text=Status) AFTER = root.after(speed, updateStatusHappy) H = (f"{Hunger:>94}\n") M = (f"{Mood:>92}\n") E = (f"{Energy:>92}\n") Status = [H, M, E] allMood = eMood + hMood + mMood if allMood != 3: Mad() schedule.run_pending() #updates status, checks if lain should be happy def updateStatusMad(): global index, image, AFTER, compFrame, Hunger, Mood, Energy, Status, allMood index = (index+1) % frames im.seek(index) image = ImageTk.PhotoImage(im) label.configure(image=image, text=Status) AFTER = root.after(speed, updateStatusMad) H = (f"{Hunger:>94}\n") M = (f"{Mood:>92}\n") E = (f"{Energy:>92}\n") Status = [H, M, E] allMood = eMood + hMood + mMood if allMood == 3: Happy() schedule.run_pending() #No status decay/ gif Frame counters here too def updateNoDecay(): global index, image, AFTER, compFrame, danceFrame, eatFrame, sleepFrame compFrame = (compFrame+1) index = (index+1) % frames im.seek(index) image = ImageTk.PhotoImage(im) label.configure(image=image) AFTER = root.after(speed, updateNoDecay) if compFrame > 127: Happy() #change up above Happy to episodes when i add in video def updateEat(): global index, image, eatFrame, AFTER eatFrame = (eatFrame+1) index = (index+1) % frames im.seek(index) image = ImageTk.PhotoImage(im) label.configure(image=image) AFTER = root.after(speed, updateEat) if eatFrame > 107: Happy() def updateSleep(): global index, image, sleepFrame, AFTER sleepFrame = (sleepFrame+1) index = (index+1) % frames im.seek(index) image = ImageTk.PhotoImage(im) label.configure(image=image) AFTER = root.after(speed, updateSleep) if sleepFrame > 37: Happy() def updateDance(): global index, image, danceFrame, AFTER danceFrame = (danceFrame+1) index = (index+1) % frames im.seek(index) image = ImageTk.PhotoImage(im) label.configure(image=image) AFTER = root.after(speed, updateDance) if danceFrame > 37: Happy() #gif updater but dont start status decay.// used in: intro,friend select, computer, episodes def updateIntro(): global index, image, AFTER index = (index+1) % frames im.seek(index) image = ImageTk.PhotoImage(im) label.configure(image=image) AFTER = root.after(speed, updateIntro) def dead(): global im, index, frames, label, speed root.unbind('') root.unbind('') root.unbind('') root.unbind('') root.unbind('') root.unbind('') root.bind('' , selection) root.after_cancel(AFTER) label.place_forget() im = Image.open(resource_path("dead.gif")) index, frames = 0, im.n_frames image = ImageTk.PhotoImage(im) label = tk.Label(root, image=image) im.seek(index) label.place(x=-2, y=0) speed = 30 root.after(0, updateIntro) def Mad(): global im, index, frames, label, speed root.after_cancel(AFTER) label.place_forget() if allMood != 3: im = Image.open(resource_path("mad.gif")) index, frames = 0, im.n_frames image = ImageTk.PhotoImage(im) label = tk.Label(root, text=Status, image=image, compound='center') im.seek(index) label.place(x=-3, y=0) speed = 130 root.after(0, updateStatusMad) def Happy(): global im, index, frames, label, speed, Mood, danceFrame, eatFrame danceFrame = 0 H = (f"{Hunger:>94}\n") M = (f"{Mood:>92}\n") E = (f"{Energy:>92}\n") Status = [H, M, E] root.unbind('') root.unbind('') root.unbind('') root.unbind('') root.unbind('') root.unbind('') root.bind('' , Actions) root.after_cancel(AFTER) label.place_forget() root.after_cancel(AFTER) im = Image.open(resource_path("happy.gif")) index, frames = 0, im.n_frames image = ImageTk.PhotoImage(im) label = tk.Label(root, text=Status, image=image, compound='center') im.seek(index) label.place(x=-3, y=0) speed = 100 root.after(0, updateStatusHappy) #does nothing for now, energy at 0 = dead(). might make it do something in the futre idk def Tired(): print("Tired") #tkinter window shit root = tk.Tk() root.geometry('320x240') root.title("Friends 4 worms") #variables that act as frame counters, start at 0. +1 every new frame placed. Used for ending gif after 1 play through compFrame = 0 sleepFrame = 0 eatFrame = 0 danceFrame = 0 #status varbies >:) // Initial value setting in friend selection function for restarting game after death screen Hunger = 15 Mood = 25 Energy = 20 #varbies formatting for when tkinter grabs em//sends them to the right side of screen H = (f"{Hunger:>94}\n") M = (f"{Mood:>92}\n") E = (f"{Energy:>92}\n") #bundled up together for tkinter label text= Status = [H, M, E] #first gif on boot up: intro screen variables im = Image.open(resource_path("Welcome.gif")) index, frames = 0, im.n_frames image = ImageTk.PhotoImage(im) label = tk.Label(root, image=image) speed = 500 #animates 1st gif--called at end of script/after all my functions def introScreen(): root.bind('' , selection) im.seek(index) label.place(x=-2, y=0) root.after(0, updateIntro) #each func below is a full page animated gif/"page" navigated by button/key presses def selection(self): global im, index, frames, label, speed, eMood, hMood, mMood, Hunger, Mood, Energy root.unbind('') root.unbind('') root.unbind('') root.unbind('') root.unbind('') root.unbind('') root.bind('' , lainAwake) #refreshing variables for after lain transcends you can restart hMood = 1 eMood = 1 mMood = 1 Hunger = 25 Mood = 25 Energy = 25 #the after cancel STOPS the gifs from speeding up every button press root.after_cancel(AFTER) label.place_forget() im = Image.open(resource_path("select24.gif")) index, frames = 0, im.n_frames image = ImageTk.PhotoImage(im) label = tk.Label(root, image=image) im.seek(index) label.place(x=-2, y=0) speed = 400 root.after(0, updateIntro) def lainAwake(self): global im, index, frames, label, speed, Mood H = (f"{Hunger:>94}\n") M = (f"{Mood:>92}\n") E = (f"{Energy:>92}\n") Status = [H, M, E] root.unbind('') root.unbind('') root.unbind('') root.unbind('') root.unbind('') root.unbind('') root.bind('' , Actions) root.after_cancel(AFTER) label.place_forget() if allMood == 3: root.after_cancel(AFTER) im = Image.open(resource_path("happy.gif")) index, frames = 0, im.n_frames image = ImageTk.PhotoImage(im) label = tk.Label(root, text=Status, image=image, compound='center') im.seek(index) label.place(x=-3, y=0) speed = 75 if allMood != 3: root.after_cancel(AFTER) Mad() root.after(0, updateStatusHappy) elif allMood != 3: Mad() def sleeping(self): global im, index, frames, label, speed, Energy, sleepFrame sleepFrame = 0 root.unbind('') root.unbind('') root.unbind('') root.unbind('') root.unbind('') root.unbind('') root.bind('' , Actions) root.after_cancel(AFTER) label.place_forget() im = Image.open(resource_path("sleeping.gif")) index, frames = 0, im.n_frames image = ImageTk.PhotoImage(im) label = tk.Label(root, image=image) im.seek(index) label.place(x=-2, y=0) speed = 150 root.after(0, updateSleep) #adds energy but caps it at 100 if Energy <80: Energy = Energy + 20 elif Energy >=80: Energy = 100 def Actions(self): global im, index, frames, label, speed, compFrame, danceFrame, sleepFrame, eatFrame compFrame = 0 danceFrame = 0 sleepFrame = 0 eatFrame = 40 root.bind('' , eat) root.bind('' , lainAwake) root.bind('' , Dance) root.bind('' , selection) root.bind('' , sleeping) root.bind('' , Comp) root.after_cancel(AFTER) label.place_forget() im = Image.open(resource_path("action2.gif")) image = ImageTk.PhotoImage(im) index, frames = 0, im.n_frames label = tk.Label(root, image=image) im.seek(index) label.place(x=-2, y=0) speed = 100 root.after(0, update) def eat(self): global im, index, frames, label, speed, Hunger, eatFrame eatFrame = 40 root.unbind('') root.unbind('') root.unbind('') root.unbind('') root.unbind('') root.unbind('') root.bind('' , Actions) root.after_cancel(AFTER) label.place_forget() im = Image.open(resource_path("eat2.gif")) image = ImageTk.PhotoImage(im) index, frames = 40, im.n_frames label = tk.Label(root, image=image) im.seek(index) label.place(x=-2, y=0) speed = 75 root.after(0, updateEat) if Hunger <80: Hunger = Hunger + 20 elif Hunger >=80: Hunger = 100 def Dance(self): global im, index, frames, label, speed, Mood, danceFrame danceFrame = 0 root.unbind('') root.unbind('') root.unbind('') root.unbind('') root.unbind('') root.unbind('') root.bind('' , Actions) root.after_cancel(AFTER) label.place_forget() im = Image.open(resource_path("danceM.gif")) image = ImageTk.PhotoImage(im) index, frames = 0, im.n_frames label = tk.Label(root, image=image) im.seek(index) label.place(x=-2, y=0) speed = 100 root.after(0, updateDance) if Mood <85: Mood = Mood + 15 elif Mood >=85: Mood = 100 def episodes(): global im, index, frames, label, speed, compFrame compFrame = 0 root.unbind('') root.unbind('') root.unbind('') root.unbind('') root.unbind('') root.unbind('') root.bind('' , lainAwake) root.after_cancel(AFTER) label.place_forget() im = Image.open(resource_path("episodemenu.gif")) image = ImageTk.PhotoImage(im) index, frames = 0, im.n_frames label = tk.Label(root, image=image) im.seek(index) label.place(x=-2, y=0) speed = 100 root.after(0, updateNoDecay) def Comp(self): global im, index, frames, label, speed, compFrame, Mood compFrame = 0 root.unbind('') root.unbind('') root.unbind('') root.unbind('') root.unbind('') root.unbind('') root.bind('' , Actions) root.after_cancel(AFTER) label.place_forget() im = Image.open(resource_path("comp2.gif")) image = ImageTk.PhotoImage(im) index, frames = 0, im.n_frames label = tk.Label(root, image=image) im.seek(index) label.place(x=-2, y=0) speed = 50 root.after(0, updateNoDecay) if Mood <92: Mood = Mood + 8 elif Mood >=92: Mood = 100 #call func to run first animated gif page introScreen() #calls tkinter to run root.mainloop()