Skip to content

Commit

Permalink
Deleting Meaningless function, tidy up codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sfever authored Apr 1, 2024
1 parent cdbe232 commit d63b20a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
21 changes: 12 additions & 9 deletions codes/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,32 @@ def __init__(self):
end_time=time.time()
print("Intialize suceess with time",(end_time-self.start_time),"seconds")
#get screen object for other files to draw
def get_screen_object(self):
'''
def GetScreenObject(self):
return self.screen
#get config exist or not
def get_config_status(self):
def GetConfigStatus(self):
return self.configExist
#get resolutions
def get_reso_horizontal(self):
def GetResolutionH(self):
return self.W_width
def get_reso_vertical(self):
def GetResolutionV(self):
return self.W_height
def get_window_size(self):
return [self.get_reso_horizontal(),self.get_reso_vertical()]
def init_window(self):
You can always access with .
'''
def GetWindowSize (self):
return [self.W_width,self.W_height]
def InitializeWindow(self):
self.screen=pg.display.set_mode([self.W_width,self.W_height],pg.RESIZABLE)
#print(type(self.screen))
pg.display.set_caption(self.caption)#initializing window
print("Init Success")
def onquit(self):
def OnQuit(self):
pg.quit()
end_time=time.time()
print("quit success, run time",(end_time-self.start_time),"seconds")
sys.exit()
def get_config(self)->list:
def GetConfig(self)->list:
if self.configExist==1:
with open(self.configPath,'r') as config_reader:
config=json.load(config_reader)
Expand Down
14 changes: 6 additions & 8 deletions codes/startscreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self):
#loading texts
def LoadTitle(self,main:init.inital):
if main.configExist==1:
config:list=main.get_config()
config:list=main.GetConfig()
#with open(main.config_path,'r') as config_reader:
# config=json.load(config_reader)
#load title text properties from config.json
Expand All @@ -39,7 +39,7 @@ def ShowTitle(self,window:pg.surface.Surface,main:init.inital):
self.textview.textList[self.textList[self.title_text]].SetText()
self.textview.textList[self.textList[self.title_text]].RenderSurface()
F_width,F_height=self.textview.textList[self.textList[self.title_text]].GetDimensions()
window.blit(self.textview.textList[self.textList[self.title_text]].GetSurface(),((main.get_reso_horizontal()-F_width)/2,100))
window.blit(self.textview.textList[self.textList[self.title_text]].GetSurface(),((main.W_width-F_width)/2,100))
pg.display.update()
def ShowBackground(self,window:pg.surface.Surface):
if self.bgexist==1:
Expand All @@ -63,13 +63,13 @@ def ShowStartExitButtonText(self,window:pg.surface.Surface,main:init.inital):
self.textview.textList[self.textList[self.quit_button_text]].RenderSurface()
S_width,S_height=self.textview.textList[self.textList[self.start_button_text]].GetDimensions()
Q_width,Q_height=self.textview.textList[self.textList[self.quit_button_text]].GetDimensions()
window.blit(self.textview.textList[self.textList[self.start_button_text]].GetSurface(),((main.get_reso_horizontal()-S_width)/2,(main.get_reso_vertical()-S_height)/2))
window.blit(self.textview.textList[self.textList[self.quit_button_text]].GetSurface(),((main.get_reso_horizontal()-Q_width)/2,(main.get_reso_vertical()-S_height)/2+100))
window.blit(self.textview.textList[self.textList[self.start_button_text]].GetSurface(),((main.W_width-S_width)/2,(main.W_height-S_height)/2))
window.blit(self.textview.textList[self.textList[self.quit_button_text]].GetSurface(),((main.W_width-Q_width)/2,(main.W_height-S_height)/2+100))
def StartExitButton(self,main:init.inital):
S_width,S_height=self.textview.textList[self.textList[self.start_button_text]].GetDimensions()
Q_width,Q_height=self.textview.textList[self.textList[self.quit_button_text]].GetDimensions()
start_button=self.buttons.NewButton((main.get_reso_horizontal()-S_width)/2,(main.get_reso_vertical()-S_height)/2,S_width,S_height)
quit_button=self.buttons.NewButton((main.get_reso_horizontal()-Q_width)/2,(main.get_reso_vertical()-S_height)/2+100,Q_width,Q_height)
start_button=self.buttons.NewButton((main.W_width-S_width)/2,(main.W_height-S_height)/2,S_width,S_height)
quit_button=self.buttons.NewButton((main.W_width-Q_width)/2,(main.W_height-S_height)/2+100,Q_width,Q_height)
self.buttonslist.append(start_button)
self.start_button=len(self.buttonslist)-1
self.buttonslist.append(quit_button)
Expand All @@ -78,8 +78,6 @@ def PlayMusic(self,music_path):
self.musicplayer=music.MusicPlayer()
self.musicplayer.SetPath(music_path)
self.musicplayer.Play()
def GetPlayer(self):
return self.musicplayer
def OnPress(self,mousepos,startaction,quitaction):
return [self.buttons.buttonList[self.buttonslist[self.start_button]].OnClick(startaction,mousepos), self.buttons.buttonList[self.buttonslist[self.quit_button]].OnClick(quitaction,mousepos)]

Expand Down
26 changes: 13 additions & 13 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ def main():
import time
#intialize objects
main=base.inital()
main.init_window()
mainwindow=main.get_screen_object()
start_screen=ss.startscr()
start_screen.load_title(main)
main.InitializeWindow()
mainwindow=main.screen
start_screen=ss.StartScreen()
start_screen.LoadTitle(main)
#easter_egg_quit_button=button.button(10,10,100,100)
is_start_screen=1
is_game_screen=0
Expand All @@ -24,11 +24,11 @@ def Hello():
#print("4")
for event in pg.event.get():
if event.type == pgl.QUIT:
main.onquit()
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)
button_result=start_screen.OnPress(mousepos,Hello,main.OnQuit)
print(button_result)
if button_result[0]!=None:
is_start_screen=button_result[0]
Expand All @@ -37,17 +37,17 @@ def Hello():
#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)
start_screen.ShowBackground(mainwindow)
start_screen.ShowStartExitButtonText(mainwindow,main)
start_screen.StartExitButton(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()
start_screen.ShowTitle(mainwindow,main)
start_screen.PlayMusic("./res/bgm_start.m4a")
music_player_ss=start_screen.musicplayer
is_start_screen=2
elif is_game_screen==1:
music_player_ss.Stop()
main.init_window()
main.InitializeWindow()
is_game_screen=2
#print("3")
elif is_game_screen==2:
Expand Down

0 comments on commit d63b20a

Please sign in to comment.