Skip to content

Commit

Permalink
Popup Windows, Music Fix and several other not important change in va…
Browse files Browse the repository at this point in the history
…riable name
  • Loading branch information
Sfever authored Mar 29, 2024
1 parent f53dded commit b4028d8
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 69 deletions.
31 changes: 15 additions & 16 deletions codes/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,34 @@
import time
import sys
import random
from . import popup
#This files is used to intialize only
#No actual function
#typehints
class inital:
config_exist=0
config_path="./settings/config.json"
W_width=0
W_height=0
caption="Pending"
screen=""
start_time=0
def __init__(self):
self.start_time=time.time()
self.popupManager=popup.PopupWindow()
self.configPath="./settings/config.json"
self.configExist=0
self.caption="Just a Title"
pg.init()
if os.path.exists(self.config_path):
if os.access(self.config_path,os.R_OK):
self.config_exist=1
if self.config_exist==0:
if os.path.exists(self.configPath):
if os.access(self.configPath,os.R_OK):
self.configExist=1
if self.configExist==0:
warnings.warn("config.json can not be read,loading defaults...")
self.popupManager.ShowWarning("Config Not found!")
for i in tr.trange(100):
time.sleep(round(random.uniform(0.01,0.2),2))#absolutely weird, this progress bar indicates nothing
self.W_width=720
self.W_height=480
time.sleep(1)
#config detection
#config detection
else:
print("Loading config from config.json...")
config={}
with open(self.config_path,'r') as config_reader:#read configs
with open(self.configPath,'r') as config_reader:#read configs
config=json.load(config_reader)
jump_bar=config["jumpbar"]
if jump_bar!=True:
Expand All @@ -55,7 +54,7 @@ def get_screen_object(self):
return self.screen
#get config exist or not
def get_config_status(self):
return self.config_exist
return self.configExist
#get resolutions
def get_reso_horizontal(self):
return self.W_width
Expand All @@ -74,8 +73,8 @@ def onquit(self):
print("quit success, run time",(end_time-self.start_time),"seconds")
sys.exit()
def get_config(self):
if self.config_exist==1:
with open(self.config_path,'r') as config_reader:
if self.configExist==1:
with open(self.configPath,'r') as config_reader:
config=json.load(config_reader)
return config
else:
Expand Down
23 changes: 11 additions & 12 deletions codes/music.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
import time
import pydub
import pydub.playback
import simpleaudio as sa
import os
import pydub.playback
import threading
from multiprocessing import Process

class MusicPlayer:
def __init__(self):
self.music_type = "mp3"
self.music_path = ""
self.player_thread = None
self.stop_playback = threading.Event()
self.play_obj = None

def set_path(self, path):
self.music_path = path
self.music_type = os.path.splitext(path)[1][1:]

def play_music(self):
music_instance = pydub.AudioSegment.from_file(self.music_path, self.music_type)
pydub.playback.play(music_instance)
def play(self):
def play_music():
music_instance = pydub.AudioSegment.from_file(self.music_path, self.music_type)
while not self.stop_playback.is_set():
pydub.playback._play_with_simpleaudio(music_instance)

self.stop_playback.clear()
self.player_thread = threading.Thread(target=play_music)
self.player_thread = Process(target=self.play_music)
self.player_thread.start()
time.sleep(1)

def stop(self):
if self.player_thread is not None:
self.stop_playback.set()
self.player_thread.join()
self.player_thread.terminate()
self.player_thread = None
9 changes: 9 additions & 0 deletions codes/popup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import tkinter
from tkinter import messagebox
class PopupWindow():
def __init__(self) -> None:
pass
def ShowPopupWindow(self,message):
messagebox.showinfo("Notice",message)
def ShowWarning(self,message):
messagebox.showwarning("Warning",message)
2 changes: 1 addition & 1 deletion codes/startscreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self):
print("Initilization of start screen complete successfully")
#loading texts
def load_title(self,main:init.inital):
if main.config_exist==1:
if main.configExist==1:
config=main.get_config()
#with open(main.config_path,'r') as config_reader:
# config=json.load(config_reader)
Expand Down
101 changes: 61 additions & 40 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,61 @@
from codes import init as base
from codes import startscreen as ss
from codes import button
import pygame as pg
import pygame.locals as pgl
#intialize objects
main=base.inital()
main.init_window()
mainwindow=main.get_screen_object()
start_screen=ss.startscr()
start_screen.load_title(main)
#easter_egg_quit_button=button.button(10,10,100,100)
is_start_screen=1
is_game_screen=0
def hello():
return 0
while True:
for event in pg.event.get():
if event.type == pgl.QUIT:
main.onquit()
if event.type==pgl.MOUSEBUTTONDOWN:
mousepos=pg.mouse.get_pos()
if is_start_screen==1:
button_result=start_screen.onpress_start_screen(mousepos,hello,main.onquit)
if button_result[0]!=None:
is_start_screen=button_result[0]
is_game_screen=button_result[0]+1
#easter_egg_quit_button.onclick(main.onquit(),mousepos)
if is_start_screen==1:
#show background if it's there
start_screen.show_background(mainwindow)
start_screen.show_start_exit_button_text(mainwindow,main)
start_screen.start_exit_button(main)
#show title text
start_screen.show_title(mainwindow,main)
elif is_game_screen==1:
main.init_window()
pass
#Update display
pg.display.update()
def main():
from codes import init as base
from codes import startscreen as ss
from codes import popup
import pygame as pg
import pygame.locals as pgl
import time
#intialize objects
main=base.inital()
main.init_window()
mainwindow=main.get_screen_object()
start_screen=ss.startscr()
start_screen.load_title(main)
#easter_egg_quit_button=button.button(10,10,100,100)
is_start_screen=1
is_game_screen=0
windowManger=popup.PopupWindow()
def Hello():
return 0

clock=pg.time.Clock()
while 1:
clock.tick(60)
#print("4")
for event in pg.event.get():
if event.type == pgl.QUIT:
main.onquit()
if event.type==pgl.MOUSEBUTTONDOWN:
mousepos=pg.mouse.get_pos()
if is_start_screen==2:
button_result=start_screen.onpress_start_screen(mousepos,Hello,main.onquit)
print(button_result)
if button_result[0]!=None:
is_start_screen=button_result[0]
is_game_screen=button_result[0]+1
#easter_egg_quit_button.onclick(main.onquit(),mousepos)
#print("5")
if is_start_screen==1:
#show background if it's there
start_screen.show_background(mainwindow)
start_screen.show_start_exit_button_text(mainwindow,main)
start_screen.start_exit_button(main)
#show title text
start_screen.show_title(mainwindow,main)
music_thread_ss=start_screen.play_music("./res/bgm_start.m4a")
music_player_ss=start_screen.get_player()
is_start_screen=2
elif is_game_screen==1:
music_player_ss.stop()
main.init_window()
is_game_screen=2
#print("3")
elif is_game_screen==2:
#print("7")
pass
#Update display
pg.display.update()
#print("6")

if __name__=="__main__":
main()

0 comments on commit b4028d8

Please sign in to comment.