Add lobby

This commit is contained in:
2019-05-02 20:57:19 +02:00
parent d48b63b9d5
commit efb364720e
2 changed files with 206 additions and 16 deletions

62
main.py
View File

@@ -7,20 +7,17 @@ from PIL import Image, ImageTk
from time import sleep
from tkinter import messagebox
win = tk.Tk()
win['bg'] = color.LEVEL_9
win.title('Quadraludi')
win.geometry('806x606')
win.resizable(False, False)
# Var
win = None
# Res
image_center = ImageTk.PhotoImage(Image.open('res/logo/main.png'))
image_center = None
# Time
time = None
delta = None
tick = 0
score = tk.IntVar(win, 0)
score = None
# Difficulty
difficulty = 1.0
@@ -29,6 +26,28 @@ DIFFICULTY_STEP = (MAX_DIFFICULTY - difficulty) / 5000
# End
_end = False
lobbyEnd = None
def ini(master):
global win, image_center, score
# if run from lobby
if (master != None):
win = tk.Toplevel(master)
else:
win = tk.Tk()
win['bg'] = color.LEVEL_9
win.title('Quadraludi')
win.geometry('806x606')
win.resizable(False, False)
win.focus_force()
# Res
image_center = ImageTk.PhotoImage(Image.open('res/logo/main.png'))
# Time
score = tk.IntVar(win, 0)
def loop(deltaTime):
global time, delta, tick, score, difficulty
@@ -42,11 +61,14 @@ def loop(deltaTime):
deltatime = (delta - time).microseconds * 1e-6
# Loop
if tick > 2:
fall.loop(deltatime, difficulty, end)
osu.loop(deltatime, difficulty, end)
pong.loop(deltatime, difficulty, end)
space.loop(deltatime, difficulty, end)
try:
if tick > 2:
fall.loop(deltatime, difficulty, end)
osu.loop(deltatime, difficulty, end)
pong.loop(deltatime, difficulty, end)
space.loop(deltatime, difficulty, end)
except:
return
# Step tick
tick += 1
@@ -62,8 +84,12 @@ def loop(deltaTime):
time = delta
win.after(int(1000 / 60), lambda: loop(deltaTime))
def main():
global time, delta
def main(master = None, end = None):
global time, delta, lobbyEnd
# Ini
lobbyEnd = end
ini(master)
# Create Canvas
canvas_pong = tk.Canvas(win, width = 400, height = 300, bd = 0, highlightthickness = 0, relief = 'ridge', bg = color.LEVEL_1)
@@ -82,7 +108,7 @@ def main():
logo = tk.PhotoImage('res/logo/icon.png')
win.tk.call('wm', 'iconphoto', win._w, logo)
tk.Label(win, image = image_center, bg = color.LEVEL_1).place(x = 401 - 32, y = 301 - 32)
# tk.Label(win, image = image_center, bg = color.LEVEL_1).place(x = 401 - 32, y = 301 - 32)
# Score
tk.Label(win, textvariable = score, bg = color.LEVEL_1, fg = color.BROWN, font = (None, 12)).place(x = 2, y = 2)
@@ -124,7 +150,11 @@ def end():
# Terminate
win.destroy()
sys.exit(0)
if type(win) == tk.Tk:
sys.exit(0)
else:
lobbyEnd(score.get())
# Main
if __name__ == "__main__":