-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Popup Windows, Music Fix and several other not important change in va…
…riable name
- Loading branch information
Showing
5 changed files
with
97 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |