diff --git a/GameDisplay.py b/GameDisplay.py index 9e396af5e6957ea257f1ad0a5d9250c946bf6317..1b90ae45029c54a909d098ba150437491ad785d3 100644 --- a/GameDisplay.py +++ b/GameDisplay.py @@ -3,70 +3,5 @@ import Settings pygame.init() -DayMenu_font = pygame.font.Font(None, 50) - -DayMenuBackground = pygame.Surface((Settings.Width, Settings.Height)) -DayMenuBackground.fill('Green') - -VarTextBackground = pygame.Surface((200, 50)) -VarTextBackground.fill('Grey') - -DayNumText = DayMenu_font.render('Day: ', False, 'Black') -MoneyText = DayMenu_font.render('Money: ', False, 'Black') -InfamyText = DayMenu_font.render('Infamy: ', False, 'Black') - -ButtonBackground = pygame.Surface((200, 50)) -ButtonBackground.fill('Grey') - -GoEatText = DayMenu_font.render('Mene syömään', False, 'Black') -DontEatText = DayMenu_font.render('Jätä syömättä', False, 'Black') -ExitText = DayMenu_font.render('Exit', False, 'Black') -NextDayText = DayMenu_font.render('Seuraava Päivä', False, 'Black') - -def LoadDayData(Day, Money, Infamy): - global DayNumText, MoneyText, InfamyText - Day = str(Day) - Money = str(Money) - Infamy = str(Infamy) - DayNumText = DayMenu_font.render('Day: ' + Day, False, 'Black') - MoneyText = DayMenu_font.render('Money: ' + Money, False, 'Black') - InfamyText = DayMenu_font.render('Infamy: ' + Infamy, False, 'Black') - def ShowGame(Screen): pass - -def NewDay(Screen): - Screen.blit(DayMenuBackground, (0,0)) - #Show data - Screen.blit(VarTextBackground, (Settings.Width/2-325, 100)) - Screen.blit(DayNumText, (Settings.Width/2-225-pygame.Surface.get_width(DayNumText)/2, 100)) - Screen.blit(VarTextBackground, (Settings.Width/2-100, 100)) - Screen.blit(MoneyText, (Settings.Width/2-pygame.Surface.get_width(MoneyText)/2, 100)) - Screen.blit(VarTextBackground, (Settings.Width/2+125, 100)) - Screen.blit(InfamyText, (Settings.Width/2+225-pygame.Surface.get_width(InfamyText)/2, 100)) - #Buttons - Screen.blit(ButtonBackground, (Settings.Width/2-325, 300)) - Screen.blit(GoEatText, (Settings.Width/2-225-pygame.Surface.get_width(GoEatText)/2, 300)) - Screen.blit(ButtonBackground, (Settings.Width/2-100, 300)) - Screen.blit(DontEatText, (Settings.Width/2-pygame.Surface.get_width(DontEatText)/2, 300)) - Screen.blit(ButtonBackground, (Settings.Width/2+125, 300)) - Screen.blit(ExitText, (Settings.Width/2+225-pygame.Surface.get_width(ExitText)/2, 300)) - - -def IntraDay(Screen): - Screen.blit(DayMenuBackground, (0,0)) - #Show data - Screen.blit(VarTextBackground, (Settings.Width/2-325, 100)) - Screen.blit(DayNumText, (Settings.Width/2-225-pygame.Surface.get_width(DayNumText)/2, 100)) - Screen.blit(VarTextBackground, (Settings.Width/2-100, 100)) - Screen.blit(MoneyText, (Settings.Width/2-pygame.Surface.get_width(MoneyText)/2, 100)) - Screen.blit(VarTextBackground, (Settings.Width/2+125, 100)) - Screen.blit(InfamyText, (Settings.Width/2+225-pygame.Surface.get_width(InfamyText)/2, 100)) - #Buttons - Screen.blit(ButtonBackground, (Settings.Width/2-325, 300)) - Screen.blit(GoEatText, (Settings.Width/2-225-pygame.Surface.get_width(GoEatText)/2, 300)) - #Could add gambling option here - #Screen.blit(ButtonBackground, (Settings.Width/2-100, 300)) - #Screen.blit(GamblingText, (Settings.Width/2-pygame.Surface.get_width(GamblingText)/2, 300)) - Screen.blit(ButtonBackground, (Settings.Width/2+125, 300)) - Screen.blit(NextDayText, (Settings.Width/2+225-pygame.Surface.get_width(NextDayText)/2, 300)) diff --git a/MainMenu.py b/MainMenu.py deleted file mode 100644 index 12c9ec4f9b459c50af4004ca1e2e65332943a423..0000000000000000000000000000000000000000 --- a/MainMenu.py +++ /dev/null @@ -1,113 +0,0 @@ -import pygame -import Settings - -pygame.init() - -#to do: change fonts -Menu_font = pygame.font.Font(None, 50) - -#to do: change to scaling size -ButtonWidth = 200 -ButtonHeight = 50 - -#to do: add border to button background -ButtonBackground = pygame.Surface((ButtonWidth, ButtonHeight)) -ButtonBackground.fill('Grey') - -#Main menu button texts -NewGameButtonText = Menu_font.render('New game', False, 'Black') -LoadGameButtonText = Menu_font.render('Load Game', False, 'Black') -SettingsButtonText = Menu_font.render('Settings', False, 'Black') -ExitButtonText = Menu_font.render('Exit', False, 'Black') - -MenuBackground = pygame.Surface((Settings.Width, Settings.Height)) -MenuBackground.fill('Green') - -#Settings menu texts -ResolutionText = Menu_font.render('Resolution: ' + str(Settings.Width) + ' x ' + str(Settings.Height), False, 'Black') -AudioVolumeText = Menu_font.render('Volume: ' + str(Settings.AudioVolume), False, 'Black') -SaveChangesText = Menu_font.render('Save Changes', False, 'Black') -BackText = Menu_font.render('Back to Main Menu', False, 'Black') - -#Load menu texts to do: show which save slots are in use -Save1Text = Menu_font.render('Game 1', False, 'Black') -Save2Text = Menu_font.render('Game 2', False, 'Black') -Save3Text = Menu_font.render('Game 3', False, 'Black') - -#Render Menu -def ShowMenu(Screen): - Screen.blit(MenuBackground, (0,0)) - #Start Game Button - Screen.blit(ButtonBackground, (Settings.Width/2-ButtonWidth/2,100)) - Screen.blit(NewGameButtonText, (Settings.Width/2 - pygame.Surface.get_width(NewGameButtonText) / 2,100)) - #Settings button - Screen.blit(ButtonBackground, (Settings.Width/2-ButtonWidth/2,200)) - Screen.blit(SettingsButtonText, (Settings.Width/2 - pygame.Surface.get_width(SettingsButtonText) / 2,200)) - #Exit button - Screen.blit(ButtonBackground, (Settings.Width/2-ButtonWidth/2,300)) - Screen.blit(ExitButtonText, (Settings.Width/2 - pygame.Surface.get_width(ExitButtonText) / 2,300)) - -#Render Settings -def ShowSettings(Screen): - Screen.blit(MenuBackground, (0,0)) - #resolution - Screen.blit(ButtonBackground, (Settings.Width/2-ButtonWidth/2, 100)) - Screen.blit(ResolutionText, (Settings.Width/2 - pygame.Surface.get_width(ResolutionText) / 2, 100)) - #AudioVolume - Screen.blit(ButtonBackground, (Settings.Width/2-ButtonWidth/2, 200)) - Screen.blit(AudioVolumeText, (Settings.Width/2 - pygame.Surface.get_width(AudioVolumeText) / 2, 200)) - #Save Changes - Screen.blit(ButtonBackground, (Settings.Width/2-ButtonWidth/2, 300)) - Screen.blit(SaveChangesText, (Settings.Width/2 - pygame.Surface.get_width(SaveChangesText) / 2, 300)) - #Back to main menu - Screen.blit(ButtonBackground, (Settings.Width/2-ButtonWidth/2, 400)) - Screen.blit(BackText, (Settings.Width/2 - pygame.Surface.get_width(BackText) / 2, 400)) - -def UpdateResolution(Width, Height): - pass - -def UpdateVolume(Volume): - pass - -def SaveChanges(): - Settings.AudioVolume = Settings.TAudioVolume - Settings.Width = Settings.TWidth - Settings.Height = Settings.THeight - Settings.SaveSettings() - -def LoadSaveGameTexts(): - global Save1Text, Save2Text, Save3Text - Settings.RefreshSaves() - if Settings.Save1[0] == 0: - Save1Text = Menu_font.render('Slot 1: New game', False, 'Black') - else: - D = str(Settings.Save1[0]) - M = str(Settings.Save1[1]) - I = str(Settings.Save1[2]) - Save1Text = Menu_font.render('Slot 1: Day: ' + D + ' Money: ' + M + ' Infamy: ' + I, False, 'Black') - if Settings.Save2[0] == 0: - Save2Text = Menu_font.render('Slot 2: New game', False, 'Black') - else: - D = str(Settings.Save2[0]) - M = str(Settings.Save2[1]) - I = str(Settings.Save2[2]) - Save2Text = Menu_font.render('Slot 2: Day: ' + D + ' Money: ' + M + ' Infamy: ' + I, False, 'Black') - if Settings.Save3[0] == 0: - Save3Text = Menu_font.render('Slot 3: New game', False, 'Black') - else: - D = str(Settings.Save3[0]) - M = str(Settings.Save3[1]) - I = str(Settings.Save3[2]) - Save3Text = Menu_font.render('Slot 3: Day: ' + D + ' Money: ' + M + ' Infamy: ' + I, False, 'Black') - -def StartGameMenu(Screen): - Screen.blit(MenuBackground, (0,0)) - Screen.blit(ButtonBackground, (Settings.Width/2 - ButtonWidth/2, 100)) - Screen.blit(Save1Text, (Settings.Width/2 - pygame.Surface.get_width(Save1Text)/2, 100)) - Screen.blit(ButtonBackground, (Settings.Width/2 - ButtonWidth/2, 200)) - Screen.blit(Save2Text, (Settings.Width/2 - pygame.Surface.get_width(Save2Text)/2, 200)) - Screen.blit(ButtonBackground, (Settings.Width/2 - ButtonWidth/2, 300)) - Screen.blit(Save3Text, (Settings.Width/2 - pygame.Surface.get_width(Save3Text)/2, 300)) - Screen.blit(ButtonBackground, (Settings.Width/2 - ButtonWidth/2, 400)) - Screen.blit(BackText, (Settings.Width/2 - pygame.Surface.get_width(BackText)/2, 400)) - \ No newline at end of file diff --git a/Menu.py b/Menu.py new file mode 100644 index 0000000000000000000000000000000000000000..0905ea6ddabc505832b8f0cbfd802bb1cbc09ae0 --- /dev/null +++ b/Menu.py @@ -0,0 +1,310 @@ +import pygame +import Settings + +Settings.LoadSettings() + +pygame.init() + +def UpdateGraphics(): + global ButtonWidth, ButtonHeight, ButtonGap, TopMargin, CenterX, Row3, HungerBarWidth, Scale, VarWidth + Scale = Settings.Width / 1080 + VarWidth = int(250*Scale) + ButtonWidth = int(400 * Scale) + ButtonHeight = int(50 * Scale) + ButtonGap = int(30 * Scale) + TopMargin = int(100 * Scale) + CenterX = int(Settings.Width/2) + Row3 = TopMargin + 2 * ButtonHeight + 2 * ButtonGap + HungerBarWidth = int(VarWidth * 3 + ButtonGap * 2) + + #Resize backgrounds + global MenuBackground, Menu_font, ButtonBackground#, SavesBackground + MenuBackground = pygame.Surface((Settings.Width, Settings.Height)) + MenuBackground.fill('Green') + Menu_font = pygame.font.Font(None, int(44*Scale)) + ButtonBackground = pygame.Surface((ButtonWidth, ButtonHeight)) + ButtonBackground.fill('Grey') + #SavesBackground = pygame.Surface((ButtonWidth*2, ButtonHeight)) + #SavesBackground.fill('Grey') + global DayMenu_font, DayMenuBackground, VarTextBackground + DayMenu_font = pygame.font.Font(None, int(44*Scale)) + DayMenuBackground = pygame.Surface((Settings.Width, Settings.Height)) + DayMenuBackground.fill('Green') + VarTextBackground = pygame.Surface((VarWidth, ButtonHeight)) + VarTextBackground.fill('Grey') + global HungerBackground, HungerBar, HungerSlider + HungerBackground = pygame.Surface((HungerBarWidth, ButtonHeight)) + HungerBackground.fill('Grey') + HungerBar = pygame.Surface((2, 2)) + pygame.draw.line(HungerBar, (255,0,0), (0, 0), (0, 1)) + pygame.draw.line(HungerBar, (0,255,0), (1, 0), (1, 1)) + HungerBar = pygame.transform.smoothscale(HungerBar, (int(HungerBarWidth-24*Scale), int(ButtonHeight-16*Scale))) + HungerSlider = pygame.Surface((int(20*Scale), int(ButtonHeight-8*Scale))) + HungerSlider.fill('Blue') + + #Rewrite texts + global NewGameButtonText, LoadGameButtonText, SettingsButtonText, ExitButtonText + global ResolutionText, AudioVolumeText, SaveChangesText, BackText + NewGameButtonText = Menu_font.render('New game', False, 'Black') + LoadGameButtonText = Menu_font.render('Load Game', False, 'Black') + SettingsButtonText = Menu_font.render('Settings', False, 'Black') + ExitButtonText = Menu_font.render('Exit', False, 'Black') + ResolutionText = Menu_font.render('Resolution: ' + str(Settings.Width) + ' x ' + str(Settings.Height), False, 'Black') + AudioVolumeText = Menu_font.render('Volume: ' + str(Settings.AudioVolume), False, 'Black') + SaveChangesText = Menu_font.render('Save Changes', False, 'Black') + BackText = Menu_font.render('Back to Main Menu', False, 'Black') + global GoEatText, DontEatText, ExitText, NextDayText + GoEatText = DayMenu_font.render('Mene syömään', False, 'Black') + DontEatText = DayMenu_font.render('Jätä syömättä', False, 'Black') + ExitText = DayMenu_font.render('Exit', False, 'Black') + NextDayText = DayMenu_font.render('Seuraava Päivä', False, 'Black') + + #Delete buttons + global DelBackground + DelBackground = pygame.Surface((ButtonHeight, ButtonHeight)) + DelBackground.fill('Red') + + #For centering text vertically + global TextTopMargin + TextTopMargin = int((ButtonHeight - pygame.Surface.get_height(ExitText))/2) + +UpdateGraphics() + +#Render Menu +def ShowMenu(Screen): + BtnLeft = CenterX - int(ButtonWidth/2) + Screen.blit(MenuBackground, (0,0)) + #Start Game Button + Screen.blit(ButtonBackground, (BtnLeft,TopMargin)) + Screen.blit(NewGameButtonText, (CenterX - pygame.Surface.get_width(NewGameButtonText) / 2, TopMargin + TextTopMargin)) + #Settings button + Screen.blit(ButtonBackground, (BtnLeft, TopMargin + ButtonHeight + ButtonGap)) + Screen.blit(SettingsButtonText, (CenterX - pygame.Surface.get_width(SettingsButtonText) / 2, TopMargin + TextTopMargin + ButtonHeight + ButtonGap)) + #Exit button + Screen.blit(ButtonBackground, (BtnLeft, TopMargin + 2 * (ButtonHeight + ButtonGap))) + Screen.blit(ExitButtonText, (CenterX - pygame.Surface.get_width(ExitButtonText) / 2, TopMargin + TextTopMargin + 2 * (ButtonHeight + ButtonGap))) + +#Render Settings +def ShowSettings(Screen): + BtnLeft = CenterX - int(ButtonWidth/2) + Screen.blit(MenuBackground, (0,0)) + #resolution + Screen.blit(ButtonBackground, (BtnLeft, TopMargin)) + Screen.blit(ResolutionText, (CenterX - pygame.Surface.get_width(ResolutionText) / 2, TopMargin + TextTopMargin)) + #AudioVolume + Screen.blit(ButtonBackground, (BtnLeft, TopMargin + ButtonHeight + ButtonGap)) + Screen.blit(AudioVolumeText, (CenterX - pygame.Surface.get_width(AudioVolumeText) / 2, TopMargin + TextTopMargin + ButtonHeight + ButtonGap)) + #Save Changes + Screen.blit(ButtonBackground, (BtnLeft, TopMargin + 2 * (ButtonHeight + ButtonGap))) + Screen.blit(SaveChangesText, (CenterX - pygame.Surface.get_width(SaveChangesText) / 2, TopMargin + TextTopMargin + 2 * (ButtonHeight + ButtonGap))) + #Back to main menu + Screen.blit(ButtonBackground, (BtnLeft, TopMargin + 3 * (ButtonHeight + ButtonGap))) + Screen.blit(BackText, (CenterX - pygame.Surface.get_width(BackText) / 2, TopMargin + TextTopMargin + 3 * (ButtonHeight + ButtonGap))) + +def StartGameMenu(Screen): + BtnLeft = CenterX - int(ButtonWidth/2) + Screen.blit(MenuBackground, (0,0)) + #Saves + Screen.blit(ButtonBackground, (BtnLeft, TopMargin)) + Screen.blit(Save1Text, (CenterX - pygame.Surface.get_width(Save1Text)/2, TopMargin + TextTopMargin)) + Screen.blit(ButtonBackground, (BtnLeft, TopMargin + ButtonHeight + ButtonGap)) + Screen.blit(Save2Text, (CenterX - pygame.Surface.get_width(Save2Text)/2, TopMargin + TextTopMargin + ButtonHeight + ButtonGap)) + Screen.blit(ButtonBackground, (BtnLeft, TopMargin + 2 * (ButtonHeight + ButtonGap))) + Screen.blit(Save3Text, (CenterX - pygame.Surface.get_width(Save3Text)/2, TopMargin + TextTopMargin + 2 * (ButtonHeight + ButtonGap))) + #Back to menu + Screen.blit(ButtonBackground, (BtnLeft, TopMargin + 3 * (ButtonHeight + ButtonGap))) + Screen.blit(BackText, (CenterX - pygame.Surface.get_width(BackText)/2, TopMargin + TextTopMargin + 3 * (ButtonHeight + ButtonGap))) + #Delete save buttons + DelBtnLeft = CenterX + int(ButtonWidth/2) + ButtonGap + Screen.blit(DelBackground, (DelBtnLeft, TopMargin)) + Screen.blit(DelBackground, (DelBtnLeft, TopMargin + ButtonHeight + ButtonGap)) + Screen.blit(DelBackground, (DelBtnLeft, TopMargin + 2 * (ButtonHeight + ButtonGap))) + +def NewDay(Screen): + Screen.blit(DayMenuBackground, (0,0)) + #Show data + Screen.blit(VarTextBackground, (CenterX - VarWidth * 1.5 - ButtonGap, TopMargin)) + Screen.blit(DayNumText, (CenterX - VarWidth - ButtonGap - pygame.Surface.get_width(DayNumText)/2, TopMargin + TextTopMargin)) + Screen.blit(VarTextBackground, (CenterX - VarWidth * 0.5, TopMargin)) + Screen.blit(MoneyText, (CenterX-pygame.Surface.get_width(MoneyText)/2, TopMargin + TextTopMargin)) + Screen.blit(VarTextBackground, (CenterX + VarWidth * 0.5 + ButtonGap, TopMargin)) + Screen.blit(InfamyText, (CenterX + VarWidth + ButtonGap - pygame.Surface.get_width(InfamyText)/2, TopMargin + TextTopMargin)) + #Hunger bar + Screen.blit(HungerBackground, (CenterX - int(HungerBarWidth * 0.5), TopMargin+ButtonHeight+ButtonGap)) + Screen.blit(HungerBar, (CenterX - HungerBarWidth * 0.5+int(12*Scale), TopMargin+ButtonHeight+ButtonGap+int(8*Scale))) + Screen.blit(HungerSlider, (HungerPos, TopMargin+ButtonHeight+ButtonGap+int(4*Scale))) + #Buttons + Screen.blit(VarTextBackground, (CenterX - VarWidth * 1.5 - ButtonGap, Row3)) + Screen.blit(GoEatText, (CenterX - VarWidth - ButtonGap - pygame.Surface.get_width(GoEatText)/2, Row3 + TextTopMargin)) + Screen.blit(VarTextBackground, (CenterX - VarWidth * 0.5, Row3)) + Screen.blit(DontEatText, (CenterX-pygame.Surface.get_width(DontEatText)/2, Row3 + TextTopMargin)) + Screen.blit(VarTextBackground, (CenterX + VarWidth * 0.5 + ButtonGap, Row3)) + Screen.blit(ExitText, (CenterX + VarWidth + ButtonGap - pygame.Surface.get_width(ExitText)/2, Row3 + TextTopMargin)) + +def IntraDay(Screen): + Screen.blit(DayMenuBackground, (0,0)) + #Show data + Screen.blit(VarTextBackground, (CenterX - VarWidth * 1.5 - ButtonGap, TopMargin)) + Screen.blit(DayNumText, (CenterX - VarWidth - ButtonGap - pygame.Surface.get_width(DayNumText)/2, TopMargin + TextTopMargin)) + Screen.blit(VarTextBackground, (CenterX - VarWidth * 0.5, TopMargin)) + Screen.blit(MoneyText, (CenterX-pygame.Surface.get_width(MoneyText)/2, TopMargin + TextTopMargin)) + Screen.blit(VarTextBackground, (CenterX + VarWidth * 0.5 + ButtonGap, TopMargin)) + Screen.blit(InfamyText, (CenterX + VarWidth + ButtonGap - pygame.Surface.get_width(InfamyText)/2, TopMargin + TextTopMargin)) + #Hunger bar + Screen.blit(HungerBackground, (CenterX - int(HungerBarWidth * 0.5), TopMargin+ButtonHeight+ButtonGap)) + Screen.blit(HungerBar, (CenterX - HungerBarWidth * 0.5+int(12*Scale), TopMargin+ButtonHeight+ButtonGap+int(8*Scale))) + Screen.blit(HungerSlider, (HungerPos, TopMargin+ButtonHeight+ButtonGap+int(4*Scale))) + #Buttons + Screen.blit(VarTextBackground, (CenterX - VarWidth * 1.5 - ButtonGap, Row3)) + Screen.blit(GoEatText, (CenterX - VarWidth - ButtonGap - pygame.Surface.get_width(GoEatText)/2, Row3 + TextTopMargin)) + Screen.blit(VarTextBackground, (CenterX + VarWidth * 0.5 + ButtonGap, Row3)) + Screen.blit(NextDayText, (CenterX + VarWidth + ButtonGap - pygame.Surface.get_width(NextDayText)/2, Row3 + TextTopMargin)) + +def UpdateVolume(Volume): + pass + +def SaveChanges(): + Settings.AudioVolume = Settings.TAudioVolume + Settings.Width = Settings.TWidth + Settings.Height = Settings.THeight + Settings.SaveSettings() + UpdateGraphics() + +def LoadSaveGameTexts(): + global Save1Text, Save2Text, Save3Text + Settings.RefreshSaves() + if Settings.Saves[0][0] == 0: + Save1Text = Menu_font.render('Slot 1: New game', False, 'Black') + else: + D = str(Settings.Saves[0][0]) + M = str(Settings.Saves[0][1]) + Save1Text = Menu_font.render('Slot 1: Day: ' + D + ' Money: ' + M, False, 'Black') + if Settings.Saves[1][0] == 0: + Save2Text = Menu_font.render('Slot 2: New game', False, 'Black') + else: + D = str(Settings.Saves[1][0]) + M = str(Settings.Saves[1][1]) + Save2Text = Menu_font.render('Slot 2: Day: ' + D + ' Money: ' + M, False, 'Black') + if Settings.Saves[2][0] == 0: + Save3Text = Menu_font.render('Slot 3: New game', False, 'Black') + else: + D = str(Settings.Saves[2][0]) + M = str(Settings.Saves[2][1]) + Save3Text = Menu_font.render('Slot 3: Day: ' + D + ' Money: ' + M, False, 'Black') + +def MouseOverMain(Button, Pos): + if CenterX - ButtonWidth/2 > Pos[0] or Pos[0] > CenterX + ButtonWidth/2: + return False + if Button == 1: + if TopMargin <= Pos[1] <= TopMargin + ButtonHeight: + return True + elif Button == 2: + if TopMargin + ButtonHeight + ButtonGap <= Pos[1] <= TopMargin + 2 * ButtonHeight + ButtonGap: + return True + elif Button == 3: + if TopMargin + 2 * ButtonHeight + 2 * ButtonGap <= Pos[1] <= TopMargin + 3 * ButtonHeight + 2 * ButtonGap: + return True + elif Button == 4: + if TopMargin + 3 * ButtonHeight + 3 * ButtonGap <= Pos[1] <= TopMargin + 4 * ButtonHeight + 3 * ButtonGap: + return True + return False + +def MouseOverDay(Button, Pos): + if TopMargin + 2 * ButtonHeight + 2 * ButtonGap > Pos[1] or Pos[1] > TopMargin + 3 * ButtonHeight + 2 * ButtonGap: + return False + if Button == 1: + if CenterX - VarWidth * 1.5 - ButtonGap <= Pos[0] <= CenterX - VarWidth * 0.5 - ButtonGap: + return True + elif Button == 2: + if CenterX - VarWidth * 0.5 <= Pos[0] <= CenterX + VarWidth * 0.5: + return True + elif Button == 3: + if CenterX + VarWidth * 0.5 + ButtonGap <= Pos[0] <= CenterX + VarWidth * 1.5 + ButtonGap: + return True + +def LoadDayData(Day, Money, Infamy, Hunger): + #global CenterX, HungerBarWidth, Scale + global DayNumText, MoneyText, InfamyText, HungerPos + Day = str(Day) + Money = str(Money) + Infamy = str(int(Infamy)) + DayNumText = DayMenu_font.render('Day: ' + Day, False, 'Black') + MoneyText = DayMenu_font.render('Money: ' + Money, False, 'Black') + InfamyText = DayMenu_font.render('Infamy: ' + Infamy, False, 'Black') + HungerPos = CenterX - int((HungerBarWidth-24 * Scale)/2) + int((Hunger / 100) * HungerBarWidth-24 * Scale) + +def ClickMain(Mouse): + if MouseOverMain(1, Mouse): + #go to start game menu + LoadSaveGameTexts() + return 1 + elif MouseOverMain(2, Mouse): + #go to settings + return 3 + elif MouseOverMain(3, Mouse): + #exit game + pygame.quit() + exit() + return 0 + +def ClickSettings(Mouse): + global ResolutionText, AudioVolumeText + #to do: probably add more resolution options + if MouseOverMain(1, Mouse): + Settings.RotateResolution() + ResolutionText = Menu_font.render('Resolution: ' + str(Settings.TWidth) + ' x ' + str(Settings.THeight), False, 'Black') + elif MouseOverMain(2, Mouse): + #Change Audio + Settings.RotateVolume() + AudioVolumeText = Menu_font.render('Volume: ' + str(Settings.TAudioVolume), False, 'Black') + elif MouseOverMain(3, Mouse): + #Save Changes + SaveChanges() + #Screen = pygame.display.set_mode((Settings.Width, Settings.Height)) + elif MouseOverMain(4, Mouse): + #Reset Temporary setting variables + Settings.ResetTVar() + #Go back to main menu + return 0 + return 3 + +def MouseOverDelete(Button, Pos): + if Pos[0] < CenterX + ButtonWidth/2 + ButtonGap or Pos[0] > CenterX + ButtonWidth/2 + ButtonGap + ButtonHeight: + return False + if Button == 1: + if TopMargin <= Pos[1] <= TopMargin + ButtonHeight: + return True + elif Button == 2: + if TopMargin + ButtonHeight + ButtonGap <= Pos[1] <= TopMargin + 2 * ButtonHeight + ButtonGap: + return True + elif Button == 3: + if TopMargin + 2 * ButtonHeight + 2 * ButtonGap <= Pos[1] <= TopMargin + 3 * ButtonHeight + 2 * ButtonGap: + return True + return False + +def ClickStart(Mouse): + if MouseOverMain(1, Mouse): + Settings.SaveNum = 1 + return 4 + elif MouseOverMain(2, Mouse): + Settings.SaveNum = 2 + return 4 + elif MouseOverMain(3, Mouse): + Settings.SaveNum = 3 + return 4 + elif MouseOverMain(4, Mouse): + #Go back to main menu + return 0 + elif MouseOverDelete(1, Mouse): + #Delete save 1 + Settings.DeleteSave(1) + LoadSaveGameTexts() + elif MouseOverDelete(2, Mouse): + #Delete save 2 + Settings.DeleteSave(2) + LoadSaveGameTexts() + elif MouseOverDelete(3, Mouse): + #Delete save 3 + Settings.DeleteSave(3) + LoadSaveGameTexts() + return 1 \ No newline at end of file diff --git a/OpiskelijaRavintolaPeli.py b/OpiskelijaRavintolaPeli.py index ff8147d3edaa4b67194784b63d78494c4e7cd5eb..02b42bb9e7a3671f639056e5cb4841c01db706ca 100644 --- a/OpiskelijaRavintolaPeli.py +++ b/OpiskelijaRavintolaPeli.py @@ -1,14 +1,9 @@ import pygame from sys import exit import Settings -import MainMenu +import Menu import GameDisplay -#load settings -Settings.LoadSettings() -MainMenu.ResolutionText = MainMenu.Menu_font.render('Resolution: ' + str(Settings.Width) + ' x ' + str(Settings.Height), False, 'Black') -MainMenu.AudioVolumeText = MainMenu.Menu_font.render('Volume: ' + str(Settings.AudioVolume), False, 'Black') - pygame.init() #Width and height user modifiable through settings menu. on first start 1280x720 then based on user selected setting Screen = pygame.display.set_mode((Settings.Width, Settings.Height)) @@ -19,8 +14,37 @@ clock = pygame.time.Clock() Money = 0 Infamy = 0 Day = 0 +Hunger = 0 GameState = 0 -SaveNum = 0 + +def EndDay(): + global Day, Money, Infamy, Hunger + Day += 1 + if((Day - 1) % 30 == 0): + Money += 273 + Infamy *= 0.95 + Infamy -= 1 + if Infamy < 0: + Infamy = 0 + Hunger -= 5 + #update graphics + Menu.LoadDayData(Day, Money, Infamy, Hunger) + #save + Settings.Save(Settings.SaveNum, Day, Money, Infamy, Hunger) + +def StartGame(SaveNum): + SaveNum -= 1 + global Money, Day, Infamy, Hunger + if Settings.Saves[SaveNum][0] == 0: + Money = 273 + Day = 1 + Infamy = 0 + Hunger = 100 + else: + Day = Settings.Saves[SaveNum][0] + Money = Settings.Saves[SaveNum][1] + Infamy = Settings.Saves[SaveNum][2] + Hunger = Settings.Saves[SaveNum][3] while True: for event in pygame.event.get(): @@ -28,158 +52,49 @@ while True: pygame.quit() exit() if event.type == pygame.MOUSEBUTTONDOWN: - if GameState == 0: - if Settings.Width/2-MainMenu.ButtonWidth/2 <= mouse[0] <= Settings.Width/2+MainMenu.ButtonWidth/2: - if 100 <= mouse[1] <= 100+MainMenu.ButtonHeight: - #go to start game menu - MainMenu.LoadSaveGameTexts() - GameState = 1 - elif 200 <= mouse[1] <= 200+MainMenu.ButtonHeight: - #go to settings - GameState = 3 - elif 300 <= mouse[1] <= 300+MainMenu.ButtonHeight: - #exit game - pygame.quit() - exit() + if GameState == 0: + GameState = Menu.ClickMain(mouse) elif GameState == 1: - if Settings.Width/2-MainMenu.ButtonWidth/2 <= mouse[0] <= Settings.Width/2+MainMenu.ButtonWidth/2: - if 100 <= mouse[1] <= 100+MainMenu.ButtonHeight: - SaveNum = 1 - GameState = 4 - if Settings.Save1[0] == 0: - #Create new game at slot 1 - Day = 1 - Money = 273 - Infamy = 0 - else: - #Load game at slot 3 - Day = Settings.Save1[0] - Money = Settings.Save1[1] - Infamy = Settings.Save1[2] - GameDisplay.LoadDayData(Day, Money, Infamy) - elif 200 <= mouse[1] <= 200+MainMenu.ButtonHeight: - SaveNum = 2 - GameState = 4 - if Settings.Save2[0] == 0: - #Create new game at slot 2 - Day = 1 - Money = 273 - Infamy = 0 - else: - #Load game at slot 2 - Day = Settings.Save2[0] - Money = Settings.Save2[1] - Infamy = Settings.Save2[2] - GameDisplay.LoadDayData(Day, Money, Infamy) - elif 300 <= mouse[1] <= 300+MainMenu.ButtonHeight: - SaveNum = 3 - GameState = 4 - if Settings.Save3[0] == 0: - #Create new game at slot 3 - Day = 1 - Money = 273 - Infamy = 0 - else: - #Load game at slot 3 - Day = Settings.Save3[0] - Money = Settings.Save3[1] - Infamy = Settings.Save3[2] - GameDisplay.LoadDayData(Day, Money, Infamy) - elif 400 <= mouse[1] <= 400+MainMenu.ButtonHeight: - #Go back to main menu - GameState = 0 + GameState = Menu.ClickStart(mouse) + if GameState == 4: + StartGame(Settings.SaveNum) + Menu.LoadDayData(Day, Money, Infamy, Hunger) elif GameState == 3: - if Settings.Width/2-MainMenu.ButtonWidth/2 <= mouse[0] <= Settings.Width/2+MainMenu.ButtonWidth/2: - #to do: probably add more resolution options - if 100-MainMenu.ButtonHeight/2 <= mouse[1] <= 100+MainMenu.ButtonHeight/2: - if Settings.TWidth == 1920: - Settings.TWidth = 1280 - Settings.THeight = 720 - else: - Settings.TWidth = 1920 - Settings.THeight = 1080 - MainMenu.ResolutionText = MainMenu.Menu_font.render('Resolution: ' + str(Settings.TWidth) + ' x ' + str(Settings.THeight), False, 'Black') - elif 200-MainMenu.ButtonHeight/2 <= mouse[1] <= 200+MainMenu.ButtonHeight/2: - #Change Audio - if Settings.TAudioVolume == 100: - Settings.TAudioVolume = 0 - elif Settings.TAudioVolume == 0: - Settings.TAudioVolume = 25 - elif Settings.TAudioVolume == 25: - Settings.TAudioVolume = 50 - elif Settings.TAudioVolume == 50: - Settings.TAudioVolume = 75 - else: - Settings.TAudioVolume = 100 - MainMenu.AudioVolumeText = MainMenu.Menu_font.render('Volume: ' + str(Settings.TAudioVolume), False, 'Black') - elif 300-MainMenu.ButtonHeight/2 <= mouse[1] <= 300+MainMenu.ButtonHeight/2: - #Save Changes to do: function to refresh all graphics elements to correct size if resolution changed - MainMenu.SaveChanges() - Screen = pygame.display.set_mode((Settings.Width, Settings.Height)) - pass - elif 400-MainMenu.ButtonHeight/2 <= mouse[1] <= 400+MainMenu.ButtonHeight/2: - #Go back to main menu - GameState = 0 - #Reset Temporary setting variables - Settings.TAudioVolume = Settings.AudioVolume - Settings.TWidth = Settings.Width - Settings.THeight = Settings.Height + GameState = Menu.ClickSettings(mouse) + Screen = pygame.display.set_mode((Settings.Width, Settings.Height)) elif GameState == 4: - if 300 <= mouse[1] <= 350: - if Settings.Width/2-325 <= mouse[0] <= Settings.Width/2 - 125: - #go eat - Money -= 2.95 - GameState = 6 - elif Settings.Width/2-100 <= mouse[0] <= Settings.Width/2 + 100: - #dont go eat so go to next day - Day += 1 - #if new month add money - if (Day-1) % 30 == 0: - Money += 273 - #infamy decay - Infamy *= 0.95 - #update graphics - GameDisplay.LoadDayData(Day, Money, Infamy) - #save - Settings.Save(SaveNum, Day, Money, Infamy) - elif Settings.Width/2+125 <= mouse[0] <= Settings.Width/2 + 325: - #exit to main menu - GameState = 0 + if Menu.MouseOverDay(1, mouse): + #go eat + Money -= 2.95 + GameState = 6 + elif Menu.MouseOverDay(2, mouse): + #dont go eat so go to next day + EndDay() + elif Menu.MouseOverDay(3, mouse): + #exit to main menu + GameState = 0 elif GameState == 5: - if 300 <= mouse[1] <= 350: - if Settings.Width/2-325 <= mouse[0] <= Settings.Width/2 - 125: - #go eat - Money -= 2.95 - #elif Settings.Width/2-50 <= mouse[0] <= Settings.Width/2 + 50: - #Gambling not in use for now... - #pass - elif Settings.Width/2+125 <= mouse[0] <= Settings.Width/2 + 325: - #go to next day - GameState = 4 - Day += 1 - #if new month add money - if (Day-1) % 30 == 0: - Money += 273 - #infamy decay - Infamy *= 0.95 - #update graphics - GameDisplay.LoadDayData(Day, Money, Infamy) - #save - Settings.Save(SaveNum, Day, Money, Infamy) + if Menu.MouseOverDay(1, mouse): + #go eat + Money -= 2.95 + elif Menu.MouseOverDay(3, mouse): + #go to next day + GameState = 4 + EndDay() elif GameState == 6: pass #render screen based on gamestate if GameState == 0: - MainMenu.ShowMenu(Screen) + Menu.ShowMenu(Screen) elif GameState == 1: - MainMenu.StartGameMenu(Screen) + Menu.StartGameMenu(Screen) elif GameState == 3: - MainMenu.ShowSettings(Screen) + Menu.ShowSettings(Screen) elif GameState == 4: - GameDisplay.NewDay(Screen) + Menu.NewDay(Screen) elif GameState == 5: - GameDisplay.IntraDay(Screen) + Menu.IntraDay(Screen) elif GameState == 6: GameDisplay.ShowGame(Screen) diff --git a/Settings.py b/Settings.py index 67168e5c5e8466735dbad80f6f0bc5e9ff2be98c..394a02c0cdb1c78dd703f0a1bbfc17a60c57a44a 100644 --- a/Settings.py +++ b/Settings.py @@ -1,17 +1,16 @@ -#main settings variables -Width = 1280 -Height = 720 -AudioVolume = 100 - def LoadSettings(): try: - global Width, Height, AudioVolume + global Width, Height, AudioVolume, TWidth, THeight, TAudioVolume file = open("SavedSettings.txt", "r") Width = int(file.readline().strip()) Height = int(file.readline().strip()) AudioVolume = int(file.readline().strip()) file.close() + TWidth = Width + THeight = Height + TAudioVolume = AudioVolume + except FileNotFoundError: #file doesn't exist create file and use default settings file = open("SavedSettings.txt", "w") @@ -20,11 +19,6 @@ def LoadSettings(): file.write("100\n") file.close() -#Temporary settings variables for unsaved settings -TWidth = Width -THeight = Height -TAudioVolume = AudioVolume - def SaveSettings(): file = open("SavedSettings.txt", "w") file.write(str(Width) + "\n") @@ -39,26 +33,52 @@ def Load(SaveNum): D = int(file.readline().strip()) M = int(file.readline().strip()) I = float(file.readline().strip()) + H = int(file.readline().strip()) file.close() - return [D, M, I] + return [D, M, I, H] except FileNotFoundError: - return [0, 0, 0] + return [0, 0, 0, 0] -def Save(SaveNum, D, M, I): +def Save(SaveNum, D, M, I, H): save = "Save" + str(SaveNum) + ".txt" file = open(save, "w") file.write(str(D) + "\n") file.write(str(M) + "\n") file.write(str(I) + "\n") + file.write(str(H) + "\n") file.close() #Saves -Save1 = Load(1) -Save2 = Load(2) -Save3 = Load(3) +Saves = [Load(1), Load(2), Load(3)] +SaveNum = 0 def RefreshSaves(): - global Save1, Save2, Save3 - Save1 = Load(1) - Save2 = Load(2) - Save3 = Load(3) \ No newline at end of file + global Saves + Saves = [Load(1), Load(2), Load(3)] + +def RotateVolume(): + global TAudioVolume + TAudioVolume += 25 + if TAudioVolume > 100: + TAudioVolume = 0 + +def RotateResolution(): + global TWidth, THeight + if TWidth == 1920: + TWidth = 1280 + THeight = 720 + else: + TWidth = 1920 + THeight = 1080 + +def ResetTVar(): + global AudioVolume, Width, Height, TAudioVolume, TWidth, THeight + TAudioVolume = AudioVolume + TWidth = Width + THeight = Height + +def DeleteSave(SaveNum): + save = "Save" + str(SaveNum) + ".txt" + file = open(save, "w") + file.write("0\n0\n0\n0\n") + file.close() \ No newline at end of file