Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. import pygame, random
  2.  
  3. #button state variable, order: axes, A(z) B(x) START(enter) SELECT(shift)
  4. #SELECT and START cannot be held
  5. global buttons
  6. buttons = [[0, 0], 0, 0, 0, 0]
  7. pygame.init()
  8. pygame.font.init()
  9. text = pygame.font.Font('PressStart2p.ttf', 8)
  10.  
  11. debugmode = 1
  12.  
  13. #read config file
  14. config = open("config.ini")
  15.  
  16. cfg_resx = int(config.readline())
  17. cfg_resy = int(config.readline())
  18. cfg_res = [cfg_resx, cfg_resy]
  19.  
  20. cfg_fscreen = config.readline()
  21.  
  22. if cfg_fscreen == 1:
  23. cfg_fscreen = pygame.FULLSCREEN
  24.  
  25. global screen
  26. screen = pygame.display.set_mode(cfg_res)
  27. config.close()
  28.  
  29.  
  30. logo = pygame.image.load('titletext.bmp')
  31.  
  32. pygame.event.get()
  33. global output
  34. output = pygame.Surface([255, 240])
  35.  
  36. def update():
  37. pygame.transform.scale(output, cfg_res, screen)
  38. pygame.display.flip()
  39. screen.fill([0, 0, 0])
  40.  
  41. for event in pygame.event.get():
  42. print event
  43. if event.type == pygame.QUIT:
  44. state = 0
  45. elif event.type == pygame.MOUSEMOTION:
  46. continue
  47. elif event.type == pygame.KEYDOWN:
  48. if event.key == pygame.K_UP:
  49. buttons[0][1] += 1
  50. elif event.key == pygame.K_DOWN:
  51. buttons[0][1] -= 1
  52. elif event.key == pygame.K_RIGHT:
  53. buttons[0][0] += 1
  54. elif event.key == pygame.K_LEFT:
  55. buttons[0][0] -= 1
  56. elif event.key == pygame.K_z:
  57. buttons[1] = 1
  58. elif event.key == pygame.K_x:
  59. buttons[2] = 1
  60. elif event.key == pygame.K_RETURN:
  61. buttons[3] = 1
  62. elif event.key == pygame.K_RSHIFT:
  63. buttons[4] = 1
  64. elif event.type -- pygame.KEYUP:
  65. if event.key == pygame.K_UP:
  66. buttons[0][1] -= 1
  67. elif event.key == pygame.K_DOWN:
  68. buttons[0][1] += 1
  69. elif event.key == pygame.K_RIGHT:
  70. buttons[0][0] -= 1
  71. elif event.key == pygame.K_LEFT:
  72. buttons[0][0] += 1
  73. elif event.key == pygame.K_z:
  74. buttons[1] = 0
  75. elif event.key == pygame.K_x:
  76. buttons[2] = 0
  77.  
  78. global state
  79. state = 1
  80. while state != 0:
  81. if state == 1:
  82. option = 2
  83. while state == 1: #main menu
  84. #display logo
  85. output.blit(logo, [25, 20])
  86.  
  87. #display menu text options in correct color
  88. if option == 2:
  89. output.blit(text.render('Start', 0, [250, 250, 250]), [100, 100])
  90. else:
  91. output.blit(text.render('Start', 0, [200, 200, 200]), [100, 100])
  92. if option == 3:
  93. output.blit(text.render('Highscores', 0, [250, 250, 250]), [100, 115])
  94. else:
  95. output.blit(text.render('Highscores', 0, [200, 200, 200]), [100, 115])
  96. if option == 4:
  97. output.blit(text.render('Quit', 0, [250, 250, 250]), [100, 130])
  98. else:
  99. output.blit(text.render('Quit', 0, [200, 200, 200]), [100, 130])
  100. if buttons[4] == 1:
  101. option += 1
  102. buttons[4] = 0
  103. if option >= 5:
  104. option = 2
  105.  
  106. #change state when "start" is pressed
  107. if buttons[3] == 1:
  108. if option == 4:
  109. state = 0
  110. else:
  111. state = option
  112.  
  113. update()
  114. pygame.quit()
  115.  
  116. Traceback (most recent call last):
  117. File "H:GUNFORCEmain.py", line 113, in <module>
  118. update()
  119. File "H:GUNFORCEmain.py", line 65, in update
  120. if event.key == pygame.K_UP:
  121. AttributeError: event member not defined
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement