menu.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-"
  3. """
  4. NoINIW 2051 - by psy (epsylon@riseup.net)
  5. """
  6. import os, sys, time
  7. os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "hide"
  8. os.environ['SDL_VIDEO_CENTERED'] = '1'
  9. import pygame
  10. import pygameMenu
  11. from data.levels.level0.level0 import login as level0
  12. FPS=60.0
  13. VERSION = "V:0.1(beta)_25072020"
  14. CAPTION = "cYpher.PunK! { //Shell_Based//m-RPG// }: [ NoINIW_2051 ]"
  15. TITLE = "[NoINIW-2051]"
  16. WINDOW_SIZE = (1024, 768)
  17. COLOR_WHITE = (255, 255, 255)
  18. COLOR_BLACK = (0, 0, 0)
  19. COLOR_GRAY = (50, 50, 50)
  20. COLOR_GREEN = (0, 160, 0)
  21. COLOR_BLUE = (0, 0, 228)
  22. COLOR_YELLOW = (255, 255, 0)
  23. COLOR_ORANGE = (242, 91, 37)
  24. logo_path = "data/images/logo.png"
  25. icon_path = "data/images/icon.png"
  26. play_path = "data/images/play.png"
  27. options_path = "data/images/options.png"
  28. exit_path = "data/images/exit.png"
  29. cheats_path = "data/images/cheats.png"
  30. howto_path = "data/images/howto.png"
  31. forum_path= "data/images/forum.png"
  32. update_path= "data/images/update.png"
  33. author_path = "data/images/author.png"
  34. music_path = "data/sounds/menu.ogg"
  35. menu_cfg = "data/menu.cfg"
  36. ####### start of: translations section ########
  37. translations_menu = "data/translations/menu.txt"
  38. tutorial_EN_path = "data/translations/tutorial_EN.txt"
  39. tutorial_ES_path = "data/translations/tutorial_ES.txt"
  40. updates_EN_path = "data/translations/updates_EN.txt"
  41. updates_ES_path = "data/translations/updates_ES.txt"
  42. forum_EN_path = "data/translations/forum_EN.txt"
  43. forum_ES_path = "data/translations/forum_ES.txt"
  44. credits_EN_path = "data/translations/credits_EN.txt"
  45. credits_ES_path = "data/translations/credits_ES.txt"
  46. translations_cheats_path = "data/translations/cheats.txt"
  47. ####### end of: translations section ########
  48. pygame.init() # pygame lib init
  49. pygame.font.init()
  50. font_type = "data/fonts/Vera.ttf"
  51. font_type_bold = "data/fonts/VeraBold.ttf"
  52. font_type_logo = "data/fonts/DejaVuSerif-BoldItalic.ttf"
  53. font_size = 18
  54. font_REA_size = 15
  55. font_version_size = 16
  56. font_counter_size = 52
  57. fontObj = pygame.font.Font(font_type, font_size) # create font object for menu
  58. fontObjBold = pygame.font.Font(font_type_bold, font_size) # create font bold object for menu
  59. fontVerObj = pygame.font.Font(font_type, font_version_size) # create font object for version
  60. fontCounterObj = pygame.font.Font(font_type_bold, font_counter_size) # create font object for counter
  61. fontREAObj = pygame.font.Font(font_type, font_REA_size) # create font object for REA
  62. sound = pygameMenu.sound.Sound() # load game menu sounds
  63. sound.load_example_sounds() # load menu sounds
  64. music = pygame.mixer.music.load(music_path) # load game menu music
  65. logo = pygame.image.load(logo_path) # load game logo image
  66. icon = pygame.image.load(icon_path) # load game icon image
  67. surface = pygame.display.set_icon(icon) # set icon on window
  68. surface = pygame.display.set_mode(WINDOW_SIZE) # set display mode
  69. def load_menu_translations(set_language):
  70. if set_language == "0": # English
  71. language_translation = "ENGLISH"
  72. else: # Spanish
  73. language_translation = "SPANISH"
  74. f = open(translations_menu, "r")
  75. translations = f.readlines()
  76. f.close()
  77. for lost in translations:
  78. lost = lost.replace("\n", "")
  79. if language_translation in str(lost):
  80. if "MENU_GAME_HOWTO" in lost:
  81. MENU_GAME_TUTORIAL = str(lost.split(":")[1])
  82. elif "MENU_GAME_START" in lost:
  83. MENU_GAME_PLAY = str(lost.split(":")[1])
  84. elif "MENU_GAME_SETTINGS" in lost:
  85. MENU_GAME_OPTIONS = str(lost.split(":")[1])
  86. elif "MENU_GAME_UPGRADE" in lost:
  87. MENU_GAME_UPDATE = str(lost.split(":")[1])
  88. elif "MENU_GAME_PUBLIC" in lost:
  89. MENU_GAME_FORUM = str(lost.split(":")[1])
  90. elif "MENU_GAME_AUTHOR" in lost:
  91. MENU_GAME_AUTHOR = str(lost.split(":")[1])
  92. elif "MENU_GAME_CHEATS" in lost:
  93. MENU_GAME_CHEATS = str(lost.split(":")[1])
  94. elif "MENU_GAME_END" in lost:
  95. MENU_GAME_EXIT = str(lost.split(":")[1])
  96. elif "MENU_GAME_LANG" in lost:
  97. MENU_GAME_LANG = str(lost.split(":")[1])
  98. elif "MENU_GAME_L-EN" in lost:
  99. MENU_GAME_LANG_EN = str(lost.split(":")[1])
  100. elif "MENU_GAME_L-ES" in lost:
  101. MENU_GAME_LANG_ES = str(lost.split(":")[1])
  102. elif "MENU_GAME_FULLSCREEN" in lost:
  103. MENU_GAME_FULLSCREEN = str(lost.split(":")[1])
  104. elif "MENU_GAME_MUSIC" in lost:
  105. MENU_GAME_MUSIC = str(lost.split(":")[1])
  106. elif "MENU_GAME_RETURN_SETTINGS" in lost:
  107. MENU_GAME_RETURN_SETTINGS = str(lost.split(":")[1])
  108. return MENU_GAME_TUTORIAL, MENU_GAME_PLAY, MENU_GAME_OPTIONS, MENU_GAME_UPDATE, MENU_GAME_FORUM, MENU_GAME_AUTHOR, MENU_GAME_CHEATS, MENU_GAME_EXIT, MENU_GAME_LANG, MENU_GAME_LANG_EN, MENU_GAME_LANG_ES, MENU_GAME_FULLSCREEN, MENU_GAME_MUSIC, MENU_GAME_RETURN_SETTINGS
  109. def load_stored_settings():
  110. f = open(menu_cfg, "r")
  111. stored_config = f.readlines()
  112. f.close()
  113. for conf in stored_config:
  114. if "LANGUAGE" in conf: # language
  115. set_language = conf.replace("\n","").split(":")[1]
  116. elif "FULLSCREEN" in conf: # screen size
  117. set_fullscreen = conf.replace("\n","").split(":")[1]
  118. if set_fullscreen == "0": # window mode
  119. surface = pygame.display.set_mode(WINDOW_SIZE)
  120. else: # fullscreen
  121. surface = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
  122. else: # music
  123. set_music = conf.replace("\n","").split(":")[1]
  124. if set_music == "0": # music disabled
  125. music = pygame.mixer.music.stop()
  126. else: # music enabled
  127. music = pygame.mixer.music.play(-1)
  128. return set_language, set_fullscreen, set_music
  129. def button(img, coords, surface):
  130. image = pygame.image.load(img)
  131. imagerect = image.get_rect()
  132. imagerect.topright = coords
  133. surface.blit(image, imagerect)
  134. return (image, imagerect)
  135. def main_background():
  136. surface.fill(COLOR_BLACK) # main menu background color
  137. MENU_GAME_TUTORIAL, MENU_GAME_PLAY, MENU_GAME_OPTIONS, MENU_GAME_UPDATE, MENU_GAME_FORUM, MENU_GAME_AUTHOR, MENU_GAME_CHEATS, MENU_GAME_EXIT, MENU_GAME_LANG, MENU_GAME_LANG_EN, MENU_GAME_LANG_ES, MENU_GAME_FULLSCREEN, MENU_GAME_MUSIC, MENU_GAME_RETURN_SETTINGS = load_menu_translations(set_language)
  138. pygame.draw.rect(surface,COLOR_WHITE,(0,260,WINDOW_SIZE[0],475))
  139. surface.blit(logo, (WINDOW_SIZE[0]/4+25, WINDOW_SIZE[1]/2-85)) # load logo
  140. text_surface = fontVerObj.render(VERSION, True, COLOR_WHITE) # load version text with antialiasing
  141. surface.blit(text_surface, dest=(WINDOW_SIZE[0]/2-500, WINDOW_SIZE[1]/2+360)) # set version number
  142. pygame.draw.rect(surface,COLOR_WHITE,(0,70,WINDOW_SIZE[0],160))
  143. howto_rect = pygame.draw.rect(surface,COLOR_WHITE,(160,85,180,60))
  144. button_howto = button(howto_path,(WINDOW_SIZE[0]/10+120, WINDOW_SIZE[1]/3-170), surface)
  145. howto_surface = fontObjBold.render(str(MENU_GAME_TUTORIAL), True, COLOR_BLACK)
  146. surface.blit(howto_surface, dest=(WINDOW_SIZE[0]/10+125, WINDOW_SIZE[1]/3-150))
  147. play_rect = pygame.draw.rect(surface,COLOR_WHITE,(160,155,180,60))
  148. button_play = button(play_path,(WINDOW_SIZE[0]/10+120, WINDOW_SIZE[1]/3-100), surface)
  149. play_surface = fontObjBold.render(str(MENU_GAME_PLAY)+"!", True, COLOR_BLACK)
  150. surface.blit(play_surface, dest=(WINDOW_SIZE[0]/10+125, WINDOW_SIZE[1]/3-80))
  151. options_rect = pygame.draw.rect(surface,COLOR_WHITE,(340,85,180,60))
  152. button_options = button(options_path,(WINDOW_SIZE[0]/10+300, WINDOW_SIZE[1]/3-170), surface)
  153. options_surface = fontObjBold.render(str(MENU_GAME_OPTIONS), True, COLOR_BLACK)
  154. surface.blit(options_surface, dest=(WINDOW_SIZE[0]/10+305, WINDOW_SIZE[1]/3-150))
  155. update_rect = pygame.draw.rect(surface,COLOR_WHITE,(340,155,180,60))
  156. button_update = button(update_path,(WINDOW_SIZE[0]/10+300, WINDOW_SIZE[1]/3-100), surface)
  157. update_surface = fontObjBold.render(str(MENU_GAME_UPDATE), True, COLOR_BLACK)
  158. surface.blit(update_surface, dest=(WINDOW_SIZE[0]/10+305, WINDOW_SIZE[1]/3-80))
  159. forum_rect = pygame.draw.rect(surface,COLOR_WHITE,(520,85,180,60))
  160. button_forum = button(forum_path,(WINDOW_SIZE[0]/10+480, WINDOW_SIZE[1]/3-170), surface)
  161. forum_surface = fontObjBold.render(str(MENU_GAME_FORUM), True, COLOR_BLACK)
  162. surface.blit(forum_surface, dest=(WINDOW_SIZE[0]/10+485, WINDOW_SIZE[1]/3-150))
  163. author_rect = pygame.draw.rect(surface,COLOR_WHITE,(520,155,180,60))
  164. button_author = button(author_path,(WINDOW_SIZE[0]/10+480, WINDOW_SIZE[1]/3-100), surface)
  165. author_surface = fontObjBold.render(str(MENU_GAME_AUTHOR), True, COLOR_BLACK)
  166. surface.blit(author_surface, dest=(WINDOW_SIZE[0]/10+485, WINDOW_SIZE[1]/3-80))
  167. cheats_rect = pygame.draw.rect(surface,COLOR_WHITE,(700,85,200,60))
  168. button_cheats = button(cheats_path,(760, WINDOW_SIZE[1]/3-170), surface)
  169. cheats_surface = fontObjBold.render(str(MENU_GAME_CHEATS)+"!", True, COLOR_BLACK)
  170. surface.blit(cheats_surface, dest=(765, WINDOW_SIZE[1]/3-150))
  171. exit_rect = pygame.draw.rect(surface,COLOR_WHITE,(700,155,200,60))
  172. button_exit = button(exit_path,(760, WINDOW_SIZE[1]/3-100), surface)
  173. exit_surface = fontObjBold.render(str(MENU_GAME_EXIT), True, COLOR_BLACK)
  174. surface.blit(exit_surface, dest=(765, WINDOW_SIZE[1]/3-80))
  175. check_menu_events(howto_rect, play_rect, options_rect, update_rect, forum_rect, author_rect, cheats_rect, exit_rect, MENU_GAME_OPTIONS, MENU_GAME_LANG, MENU_GAME_LANG_EN, MENU_GAME_LANG_ES, MENU_GAME_FULLSCREEN, MENU_GAME_MUSIC, MENU_GAME_RETURN_SETTINGS)
  176. def settings_background():
  177. pygame.draw.rect(surface,COLOR_WHITE,(0,0,0,0))
  178. def display_text_animation(rect, string, l):
  179. text = ''
  180. for i in range(len(string)):
  181. text += string[i]
  182. text_surface = fontREAObj.render(text, True, COLOR_ORANGE)
  183. text_rect = rect
  184. text_rect.center = (WINDOW_SIZE[0]/2+10, WINDOW_SIZE[0]/2-10+l)
  185. surface.blit(text_surface, text_rect)
  186. pygame.display.update()
  187. pygame.time.wait(100)
  188. def show_tutorial():
  189. tutorial_menu = pygameMenu.Menu(surface, # main menu menu
  190. bgfun=settings_background,
  191. color_selected=COLOR_YELLOW,
  192. font=font_type_bold,
  193. font_color=COLOR_WHITE,
  194. font_size=16,
  195. font_size_title=28,
  196. menu_alpha=100,
  197. menu_color=COLOR_BLACK,
  198. menu_height=40,
  199. menu_width=int(WINDOW_SIZE[0]),
  200. onclose=pygameMenu.events.EXIT,
  201. option_shadow=False,
  202. title="",
  203. menu_color_title=COLOR_ORANGE,
  204. widget_alignment=pygameMenu.locals.ALIGN_LEFT,
  205. window_height=40,
  206. window_width=WINDOW_SIZE[0]
  207. )
  208. topA = "data/images/topA.png"
  209. topB = "data/images/topB.png"
  210. top_menu_A = pygame.image.load(topA) # load game top front A
  211. top_menu_B = pygame.image.load(topB) # load game top front B (exit)
  212. surface.blit(top_menu_A, (WINDOW_SIZE[0]-1025, WINDOW_SIZE[1]-770)) # load top main image
  213. surface.blit(top_menu_B, (WINDOW_SIZE[0]-25, WINDOW_SIZE[1]-769)) # load top exit image
  214. tutorial_rect = pygame.draw.rect(surface,COLOR_BLACK,(WINDOW_SIZE[0]/9+95,WINDOW_SIZE[1]/2-100,600,400)) # tutorial back box
  215. if set_language == "0": # English
  216. f = open(tutorial_EN_path, "r")
  217. else: # Spanish
  218. f = open(tutorial_ES_path, "r")
  219. tutorial = f.readlines()
  220. f.close()
  221. l = 0
  222. for line in tutorial:
  223. l = l+20 # used to create spaces between lines
  224. line = line.replace("\n", "")
  225. display_text_animation(tutorial_rect, line, l)
  226. for event in pygame.event.get():
  227. if event.type == 5: # "5" = click DOWN event
  228. main() # whatever click goes to main menu
  229. create_counter(10) # create visual ETA counter for return to main menu
  230. def update_menu():
  231. update_m = pygameMenu.Menu(surface, # main menu menu
  232. bgfun=settings_background,
  233. color_selected=COLOR_YELLOW,
  234. font=font_type_bold,
  235. font_color=COLOR_WHITE,
  236. font_size=16,
  237. font_size_title=28,
  238. menu_alpha=100,
  239. menu_color=COLOR_BLACK,
  240. menu_height=40,
  241. menu_width=int(WINDOW_SIZE[0]),
  242. onclose=pygameMenu.events.EXIT,
  243. option_shadow=False,
  244. title="",
  245. menu_color_title=COLOR_ORANGE,
  246. widget_alignment=pygameMenu.locals.ALIGN_LEFT,
  247. window_height=40,
  248. window_width=WINDOW_SIZE[0]
  249. )
  250. topA = "data/images/topA.png"
  251. topB = "data/images/topB.png"
  252. top_menu_A = pygame.image.load(topA) # load game top front A
  253. top_menu_B = pygame.image.load(topB) # load game top front B (exit)
  254. surface.blit(top_menu_A, (WINDOW_SIZE[0]-1025, WINDOW_SIZE[1]-770)) # load top main image
  255. surface.blit(top_menu_B, (WINDOW_SIZE[0]-25, WINDOW_SIZE[1]-769)) # load top exit image
  256. update_rect = pygame.draw.rect(surface,COLOR_BLACK,(WINDOW_SIZE[0]/9+95,WINDOW_SIZE[1]/2-100,600,400)) # update back box
  257. if set_language == "0": # English
  258. f = open(updates_EN_path, "r")
  259. else: # Spanish
  260. f = open(updates_ES_path, "r")
  261. updates = f.readlines()
  262. f.close()
  263. l = 0
  264. for line in updates:
  265. l = l+35 # used to create spaces between lines
  266. line = line.replace("\n", "")
  267. display_text_animation(update_rect, line, l)
  268. for event in pygame.event.get():
  269. if event.type == 5: # "5" = click DOWN event
  270. main() # whatever click goes to main menu
  271. l = 150
  272. r = 9
  273. create_counter(10) # create visual ETA counter for return to main menu
  274. def forum_menu():
  275. forum_m = pygameMenu.Menu(surface, # main menu menu
  276. bgfun=settings_background,
  277. color_selected=COLOR_YELLOW,
  278. font=font_type_bold,
  279. font_color=COLOR_WHITE,
  280. font_size=16,
  281. font_size_title=28,
  282. menu_alpha=100,
  283. menu_color=COLOR_BLACK,
  284. menu_height=40,
  285. menu_width=int(WINDOW_SIZE[0]),
  286. onclose=pygameMenu.events.EXIT,
  287. option_shadow=False,
  288. title="",
  289. menu_color_title=COLOR_ORANGE,
  290. widget_alignment=pygameMenu.locals.ALIGN_LEFT,
  291. window_height=40,
  292. window_width=WINDOW_SIZE[0]
  293. )
  294. topA = "data/images/topA.png"
  295. topB = "data/images/topB.png"
  296. top_menu_A = pygame.image.load(topA) # load game top front A
  297. top_menu_B = pygame.image.load(topB) # load game top front B (exit)
  298. surface.blit(top_menu_A, (WINDOW_SIZE[0]-1025, WINDOW_SIZE[1]-770)) # load top main image
  299. surface.blit(top_menu_B, (WINDOW_SIZE[0]-25, WINDOW_SIZE[1]-769)) # load top exit image
  300. forum_rect = pygame.draw.rect(surface,COLOR_BLACK,(WINDOW_SIZE[0]/9+95,WINDOW_SIZE[1]/2-100,600,400)) # update back box
  301. if set_language == "0": # English
  302. f = open(forum_EN_path, "r")
  303. else: # Spanish
  304. f = open(forum_ES_path, "r")
  305. forums = f.readlines()
  306. f.close()
  307. l = 0
  308. for line in forums:
  309. l = l+35 # used to create spaces between lines
  310. line = line.replace("\n", "")
  311. display_text_animation(forum_rect, line, l)
  312. for event in pygame.event.get():
  313. if event.type == 5: # "5" = click DOWN event
  314. main() # whatever click goes to main menu
  315. create_counter(10) # create visual ETA counter for return to main menu
  316. def author_menu():
  317. credits_m = pygameMenu.Menu(surface, # main menu menu
  318. bgfun=settings_background,
  319. color_selected=COLOR_YELLOW,
  320. font=font_type_bold,
  321. font_color=COLOR_WHITE,
  322. font_size=16,
  323. font_size_title=28,
  324. menu_alpha=100,
  325. menu_color=COLOR_BLACK,
  326. menu_height=40,
  327. menu_width=int(WINDOW_SIZE[0]),
  328. onclose=pygameMenu.events.EXIT,
  329. option_shadow=False,
  330. title="",
  331. menu_color_title=COLOR_ORANGE,
  332. widget_alignment=pygameMenu.locals.ALIGN_LEFT,
  333. window_height=40,
  334. window_width=WINDOW_SIZE[0]
  335. )
  336. topA = "data/images/topA.png"
  337. topB = "data/images/topB.png"
  338. top_menu_A = pygame.image.load(topA) # load game top front A
  339. top_menu_B = pygame.image.load(topB) # load game top front B (exit)
  340. surface.blit(top_menu_A, (WINDOW_SIZE[0]-1025, WINDOW_SIZE[1]-770)) # load top main image
  341. surface.blit(top_menu_B, (WINDOW_SIZE[0]-25, WINDOW_SIZE[1]-769)) # load top exit image
  342. author_rect = pygame.draw.rect(surface,COLOR_BLACK,(WINDOW_SIZE[0]/9+95,WINDOW_SIZE[1]/2-100,600,400)) # update back box
  343. if set_language == "0": # English
  344. f = open(credits_EN_path, "r")
  345. else: # Spanish
  346. f = open(credits_ES_path, "r")
  347. credits = f.readlines()
  348. f.close()
  349. l = 0
  350. for line in credits:
  351. l = l+35 # used to create spaces between lines
  352. line = line.replace("\n", "")
  353. display_text_animation(author_rect, line, l)
  354. for event in pygame.event.get():
  355. if event.type == 5: # "5" = click DOWN event
  356. main() # whatever click goes to main menu
  357. create_counter(10) # create visual ETA counter for return to main menu
  358. def cheats_menu():
  359. cheats_m = pygameMenu.Menu(surface, # cheats menu menu
  360. bgfun=settings_background,
  361. color_selected=COLOR_YELLOW,
  362. font=font_type_bold,
  363. font_color=COLOR_WHITE,
  364. font_size=16,
  365. font_size_title=28,
  366. menu_alpha=100,
  367. menu_color=COLOR_BLACK,
  368. menu_height=40,
  369. menu_width=int(WINDOW_SIZE[0]),
  370. onclose=pygameMenu.events.EXIT,
  371. option_shadow=False,
  372. title="",
  373. menu_color_title=COLOR_ORANGE,
  374. widget_alignment=pygameMenu.locals.ALIGN_LEFT,
  375. window_height=40,
  376. window_width=WINDOW_SIZE[0]
  377. )
  378. topA = "data/images/topA.png"
  379. topB = "data/images/topB.png"
  380. top_menu_A = pygame.image.load(topA) # load game top front A
  381. top_menu_B = pygame.image.load(topB) # load game top front B (exit)
  382. surface.blit(top_menu_A, (WINDOW_SIZE[0]-1025, WINDOW_SIZE[1]-770)) # load top main image
  383. surface.blit(top_menu_B, (WINDOW_SIZE[0]-25, WINDOW_SIZE[1]-769)) # load top exit image
  384. if set_language == "0": # English
  385. language_translation = "ENGLISH"
  386. else: # Spanish
  387. language_translation = "SPANISH"
  388. f = open(translations_cheats_path, "r")
  389. translations_cheats = f.readlines()
  390. f.close()
  391. for lost in translations_cheats:
  392. lost = lost.replace("\n", "")
  393. if language_translation in str(lost):
  394. if "MENU_CHEATS_ENTER" in lost:
  395. MENU_CHEATS_ENTER = str(lost.split(":")[1])
  396. elif "MENU_CHEATS_TRY" in lost:
  397. MENU_CHEATS_TRY = str(lost.split(":")[1])
  398. cheats_menu = pygameMenu.Menu(surface, # cheats menu
  399. bgfun=settings_background,
  400. color_selected=COLOR_YELLOW,
  401. font=font_type_bold,
  402. font_color=COLOR_WHITE,
  403. font_size=14,
  404. font_size_title=35,
  405. menu_alpha=100,
  406. menu_color=COLOR_BLACK,
  407. menu_height=220,
  408. menu_width=int(WINDOW_SIZE[0]),
  409. onclose=main,
  410. option_shadow=False,
  411. title="",
  412. menu_color_title=COLOR_ORANGE,
  413. widget_alignment=pygameMenu.locals.ALIGN_LEFT,
  414. window_height=220,
  415. window_width=WINDOW_SIZE[0]
  416. )
  417. cheats_menu.add_text_input("* "+str(MENU_CHEATS_ENTER)+": ",
  418. default='',
  419. maxchar=16,
  420. textinput_id='cheat_code',
  421. input_underline='')
  422. def try_cheat(): # add some code cheats: free shell upgrade, etc. (leaked during videogame unboxing!)
  423. #data = cheats_menu.get_input_data()
  424. main() # (btm) returning to main menu
  425. cheats_menu.add_option("-> "+str(MENU_CHEATS_TRY)+" <-", try_cheat)
  426. while True:
  427. cheats_menu.mainloop()
  428. def create_counter(counter):
  429. l = 150
  430. r = counter
  431. for i in range(0,counter): # create counter for reset
  432. text = str(r)
  433. text_surface = fontCounterObj.render(text, True, COLOR_BLACK)
  434. text_rect = pygame.draw.rect(surface,COLOR_WHITE,(WINDOW_SIZE[0]/2-480,WINDOW_SIZE[1]/2-170,100,100)) # counter back box
  435. text_rect.center = (WINDOW_SIZE[0]/2-420, WINDOW_SIZE[0]/2-250)
  436. surface.blit(text_surface, text_rect)
  437. r = r - 1
  438. time.sleep(1)
  439. pygame.display.flip()
  440. if r < 0:
  441. main()
  442. def check_menu_events(howto_rect, play_rect, options_rect, update_rect, forum_rect, author_rect, cheats_rect, exit_rect, MENU_GAME_OPTIONS, MENU_GAME_LANG, MENU_GAME_LANG_EN, MENU_GAME_LANG_ES, MENU_GAME_FULLSCREEN, MENU_GAME_MUSIC, MENU_GAME_RETURN_SETTINGS):
  443. for event in pygame.event.get():
  444. if event.type == 5: # "5" = click DOWN event
  445. mouse = pygame.mouse.get_pos()
  446. m1 = mouse[0]
  447. m2 = mouse[1]
  448. mouse_rect = pygame.draw.rect(surface,COLOR_ORANGE,(m1,m2,1,1)) # locate cursor position!
  449. howto_event_zone = pygame.Rect.colliderect(howto_rect, mouse_rect) # tutorial
  450. play_event_zone = pygame.Rect.colliderect(play_rect, mouse_rect) # play
  451. options_event_zone = pygame.Rect.colliderect(options_rect, mouse_rect) # options
  452. update_event_zone = pygame.Rect.colliderect(update_rect, mouse_rect) # update
  453. forum_event_zone = pygame.Rect.colliderect(forum_rect, mouse_rect) # forum
  454. author_event_zone = pygame.Rect.colliderect(author_rect, mouse_rect) # credits
  455. cheats_event_zone = pygame.Rect.colliderect(cheats_rect, mouse_rect) # cheats
  456. exit_event_zone = pygame.Rect.colliderect(exit_rect, mouse_rect) # exit
  457. if howto_event_zone == 1:
  458. show_tutorial()
  459. elif play_event_zone == 1:
  460. start_game()
  461. elif options_event_zone == 1:
  462. config_menu(MENU_GAME_OPTIONS, MENU_GAME_LANG, MENU_GAME_LANG_EN, MENU_GAME_LANG_ES, MENU_GAME_FULLSCREEN, MENU_GAME_MUSIC, MENU_GAME_RETURN_SETTINGS)
  463. elif update_event_zone == 1:
  464. update_menu()
  465. elif forum_event_zone == 1:
  466. forum_menu()
  467. elif author_event_zone == 1:
  468. author_menu()
  469. elif cheats_event_zone == 1:
  470. cheats_menu()
  471. elif exit_event_zone == 1:
  472. sys.exit()
  473. def config_menu(MENU_GAME_OPTIONS, MENU_GAME_LANG, MENU_GAME_LANG_EN, MENU_GAME_LANG_ES, MENU_GAME_FULLSCREEN, MENU_GAME_MUSIC, MENU_GAME_RETURN_SETTINGS):
  474. global settings_menu
  475. settings_menu = pygameMenu.Menu(surface, # settings menu
  476. bgfun=settings_background,
  477. color_selected=COLOR_YELLOW,
  478. font=font_type_bold,
  479. font_color=COLOR_WHITE,
  480. font_size=14,
  481. font_size_title=35,
  482. menu_alpha=100,
  483. menu_color=COLOR_BLACK,
  484. menu_height=220,
  485. menu_width=int(WINDOW_SIZE[0]),
  486. onclose=main,
  487. option_shadow=False,
  488. title="",
  489. menu_color_title=COLOR_ORANGE,
  490. widget_alignment=pygameMenu.locals.ALIGN_LEFT,
  491. window_height=220,
  492. window_width=WINDOW_SIZE[0]
  493. )
  494. settings_menu.add_selector(MENU_GAME_LANG+":",
  495. [(MENU_GAME_LANG_EN, 'EN'),
  496. (MENU_GAME_LANG_ES, 'ES')],
  497. selector_id='language',
  498. default=int(set_language))
  499. settings_menu.add_selector(MENU_GAME_FULLSCREEN+":",
  500. [('OFF', 'OFF'),
  501. ('ON', 'ON')],
  502. selector_id='fullscreen',
  503. default=int(set_fullscreen))
  504. settings_menu.add_selector(MENU_GAME_MUSIC+":",
  505. [('OFF', 'OFF'),
  506. ('ON', 'ON')],
  507. selector_id='music',
  508. default=int(set_music))
  509. settings_menu.add_option(MENU_GAME_RETURN_SETTINGS, check_form_settings, align=pygameMenu.locals.ALIGN_CENTER)
  510. while True:
  511. settings_menu.mainloop()
  512. def check_form_settings():
  513. data = settings_menu.get_input_data()
  514. for k in data.keys():
  515. if k == "language": # set language
  516. set_language = data[k][1]
  517. elif k == "fullscreen": # set fullscreen
  518. set_fullscreen = data[k][1]
  519. else: # set music
  520. set_music = data[k][1]
  521. save_stored_settings(set_language, set_fullscreen, set_music) # store settings to menu.cfg
  522. main() # return back to main menu
  523. def save_stored_settings(set_language, set_fullscreen, set_music):
  524. f = open(menu_cfg, "r")
  525. menu_config = f.readlines()
  526. f.close()
  527. menuc = open(menu_cfg, "w")
  528. for conf in menu_config:
  529. if "LANGUAGE" in conf: # language
  530. menuc.write("LANGUAGE:"+str(set_language)+os.linesep)
  531. elif "FULLSCREEN" in conf: # screen size
  532. menuc.write("FULLSCREEN:"+str(set_fullscreen)+os.linesep)
  533. else: # music
  534. menuc.write("MUSIC:"+str(set_music))
  535. menuc.close()
  536. def main(test=False):
  537. global set_fullscreen
  538. global set_language
  539. global set_music
  540. global main_menu
  541. pygame.display.set_caption(CAPTION)
  542. clock = pygame.time.Clock()
  543. set_language, set_fullscreen, set_music = load_stored_settings()
  544. main_menu = pygameMenu.Menu(surface, # main menu
  545. bgfun=main_background,
  546. color_selected=COLOR_YELLOW,
  547. font=font_type,
  548. font_color=COLOR_BLACK,
  549. font_size=14,
  550. font_size_title=35,
  551. menu_alpha=100,
  552. menu_color=COLOR_GRAY,
  553. menu_height=1,
  554. menu_width=int(WINDOW_SIZE[0]),
  555. onclose=pygameMenu.events.EXIT,
  556. option_shadow=False,
  557. title=TITLE+":",
  558. menu_color_title=COLOR_ORANGE,
  559. window_height=1,
  560. window_width=WINDOW_SIZE[0]
  561. )
  562. main_menu.set_sound(sound, recursive=True) # set menu sounds
  563. while True:
  564. clock.tick(FPS)
  565. main_menu.mainloop(disable_loop=test)
  566. pygame.display.flip()
  567. if test == True:
  568. break
  569. def start_game():
  570. level0(surface, COLOR_WHITE, COLOR_BLACK, COLOR_BLUE, COLOR_GRAY, COLOR_YELLOW, COLOR_ORANGE, WINDOW_SIZE, set_language)
  571. def level0_login_background():
  572. None
  573. if __name__ == '__main__':
  574. main()