196 lines
4.9 KiB
Python
196 lines
4.9 KiB
Python
import tkinter as tk
|
|
import datetime as dt
|
|
import color
|
|
import sys
|
|
import pygame
|
|
from game import fall, osu, pong, space
|
|
from PIL import Image, ImageTk
|
|
from time import sleep
|
|
from tkinter import messagebox
|
|
|
|
# Var
|
|
win = None
|
|
canvas_pong = None
|
|
canvas_osu = None
|
|
canvas_space = None
|
|
canvas_fall = None
|
|
|
|
# Res
|
|
image_center = None
|
|
AUDIO_THEME_001 = 'res/Audio/theme_001.ogg'
|
|
|
|
# Time
|
|
time = None
|
|
delta = None
|
|
tick = 0
|
|
score = None
|
|
|
|
# Difficulty
|
|
difficulty = 1.0
|
|
MAX_DIFFICULTY = 3.0
|
|
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'))
|
|
|
|
# Pygame
|
|
pygame.init()
|
|
|
|
# Time
|
|
score = tk.IntVar(win, 0)
|
|
|
|
def loop(deltaTime):
|
|
global time, delta, tick, score, difficulty
|
|
|
|
# Create Canvas
|
|
# Ini
|
|
if tick == 2:
|
|
pong.main(canvas_pong)
|
|
if tick == 400:
|
|
osu.main(canvas_osu)
|
|
if tick == 800:
|
|
fall.main(canvas_fall)
|
|
if tick == 1200:
|
|
space.main(canvas_space)
|
|
|
|
# Check end
|
|
if (_end):
|
|
return
|
|
|
|
# Start
|
|
delta = dt.datetime.now()
|
|
deltatime = (delta - time).microseconds * 1e-6
|
|
|
|
# Loop
|
|
try:
|
|
if tick > 2:
|
|
pong.loop(deltatime, difficulty, end)
|
|
if tick > 400:
|
|
osu.loop(deltatime, difficulty, end)
|
|
if tick > 800:
|
|
fall.loop(deltatime, difficulty, end)
|
|
if tick > 1200:
|
|
space.loop(deltatime, difficulty, end)
|
|
except:
|
|
return
|
|
|
|
# Step tick
|
|
tick += 1
|
|
score.set(int(tick / 5))
|
|
|
|
# Step difficulty
|
|
if difficulty < MAX_DIFFICULTY:
|
|
difficulty += DIFFICULTY_STEP
|
|
elif difficulty > MAX_DIFFICULTY:
|
|
difficulty = MAX_DIFFICULTY
|
|
|
|
# End
|
|
time = delta
|
|
win.after(int(1000 / 60), lambda: loop(deltaTime))
|
|
|
|
def main(master = None, end = None):
|
|
global time, delta, lobbyEnd, canvas_pong, canvas_osu, canvas_fall, canvas_space
|
|
|
|
# Ini
|
|
lobbyEnd = end
|
|
ini(master)
|
|
|
|
# Music
|
|
pygame.mixer.init()
|
|
pygame.mixer.music.load(AUDIO_THEME_001)
|
|
pygame.mixer.music.set_volume(0.2)
|
|
pygame.mixer.music.play()
|
|
|
|
# Logo
|
|
if sys.platform.startswith('win'):
|
|
win.iconbitmap('res/logo/icon.ico')
|
|
else:
|
|
logo = tk.PhotoImage('res/logo/icon.png')
|
|
win.tk.call('wm', 'iconphoto', win._w, logo)
|
|
|
|
# Canvas
|
|
canvas_pong = tk.Canvas(win, width = 400, height = 300, bd = 0, highlightthickness = 0, relief = 'ridge', bg = color.LEVEL_1)
|
|
canvas_pong.place(x = 2, y = 2)
|
|
canvas_osu = tk.Canvas(win, width = 400, height = 300, bd = 0, highlightthickness = 0, relief = 'ridge', bg = color.LEVEL_1)
|
|
canvas_osu.place(x = 404, y = 2)
|
|
canvas_fall = tk.Canvas(win, width = 400, height = 300, bd = 0, highlightthickness = 0, relief = 'ridge', bg = color.LEVEL_1)
|
|
canvas_fall.place(x = 2, y = 304)
|
|
canvas_space = tk.Canvas(win, width = 400, height = 300, bd = 0, highlightthickness = 0, relief = 'ridge', bg = color.LEVEL_1)
|
|
canvas_space.place(x = 404, y = 304)
|
|
|
|
# Center image
|
|
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)
|
|
|
|
# Loop
|
|
delta = dt.datetime.now()
|
|
time = dt.datetime.now()
|
|
loop(1000 / 60)
|
|
|
|
def getMessage(score):
|
|
if score < 200:
|
|
return 'Vous ferez peut être mieux la prochaine fois...'
|
|
elif score < 400:
|
|
return 'Un bon début !'
|
|
elif score < 600:
|
|
return 'Pas mal, mais vous ne pouvez faire quatre choses à la fois???'
|
|
elif score < 800:
|
|
return 'Bien, la maitrise vient avec le temps'
|
|
elif score < 1000:
|
|
return 'Bien joué, vous approchez de la difficulté maximum'
|
|
elif score < 2000:
|
|
return "Splendide, vous n\'avez plus qu'à attendre l'éternité"
|
|
elif score < 4000:
|
|
return "Ce jeu n'a plus aucun secrets pour vous !"
|
|
else:
|
|
return 'La légende raconte que seul 『 』 ont réussit cet exploit'
|
|
|
|
def end():
|
|
global _end
|
|
|
|
_end = True
|
|
tk.Label(
|
|
win,
|
|
text = 'Perdu !',
|
|
bg = color.LEVEL_1,
|
|
fg = color.LEVEL_9,
|
|
font = (None, 48)
|
|
).place(relx = 0.5, rely = 0.5, anchor = tk.CENTER)
|
|
win.update()
|
|
sleep(1)
|
|
messagebox.showinfo('Perdu', f'Votre score est de {score.get()} points\n{getMessage(score.get())}')
|
|
|
|
# Terminate
|
|
win.destroy()
|
|
|
|
if type(win) == tk.Tk:
|
|
sys.exit(0)
|
|
else:
|
|
lobbyEnd(score.get())
|
|
|
|
# Main
|
|
if __name__ == "__main__":
|
|
print('Bienvenue dans le jeu QuadraLudi')
|
|
main()
|
|
win.mainloop() |