Fall 2016 7HRL Game
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

290 lines
8.4 KiB

  1. #!/usr/bin/python
  2. #
  3. # Jared Dunbar
  4. #
  5. # 7 Hour Rogue Like, November 12, 2016
  6. import sys, os, curses, random, threading
  7. # Curses stuff
  8. term = curses.initscr()
  9. curses.noecho()
  10. curses.cbreak()
  11. term.keypad(True)
  12. #curses.start_color()
  13. curses.curs_set(0)
  14. term.nodelay(1)
  15. #sound trigger
  16. triggered = True
  17. FAST = False # disables slow printing (you know, dev)
  18. def slow(string):
  19. slow = not FAST
  20. for char in string:
  21. term.addch(char)
  22. term.refresh()
  23. get = term.getch()
  24. if(get == -1):
  25. pass
  26. else:
  27. slow = False
  28. if slow: curses.napms(100)
  29. def soundOne():
  30. os.system("play 1.ogg 2>/dev/null")
  31. def soundTwo():
  32. '''
  33. os.system("play begin.ogg 2>/dev/null")
  34. os.system("play mid.ogg 2>/dev/null")
  35. os.system("play fin.ogg 2>/dev/null")
  36. '''
  37. os.system("play game.ogg 2>/dev/null")
  38. def shoot():
  39. os.system("play blast.mp3 2>/dev/null")
  40. def rocket():
  41. os.system("play rocket.mp3 2>/dev/null")
  42. def john():
  43. os.system("play and-his-name-is-john-cena.mp3 2>/dev/null")
  44. def intro():
  45. # Clear screen
  46. term.clear()
  47. # intro
  48. slow ("You enter a strange land, the trees are scragly and dark.\n")
  49. slow ("The sky is grey and gringy.\n")
  50. slow ("You walk along a cobblestone path,\n")
  51. slow ("through this dead forest.\n")
  52. term.nodelay(0)
  53. term.addstr(6,6, "Press any key to continue (or space to skip)")
  54. curses.curs_set(1)
  55. term.refresh()
  56. action = term.getch()
  57. if action == 32: FAST = True
  58. term.clear()
  59. term.refresh()
  60. if not FAST: curses.napms(800)
  61. st1.start()
  62. if not FAST: curses.napms(200)#200ms
  63. term.addstr(6,6, "As you walk, you notice a dark motion to the right.")
  64. term.refresh()
  65. if not FAST: curses.napms(2000)#2200ms
  66. term.addstr(8,6, "It is swift and secretive")
  67. term.refresh()
  68. if not FAST: curses.napms(2000)#4200ms
  69. term.addch(".")
  70. term.refresh()
  71. if not FAST: curses.napms(1000)#5200ms
  72. term.addch(".")
  73. term.refresh()
  74. if not FAST: curses.napms(1000)#6200ms
  75. term.addch(".")
  76. term.refresh()
  77. if not FAST: curses.napms(8000)#14200ms
  78. term.addstr(10, 6, "Frightened, you begin running up the path.")
  79. term.refresh()
  80. if not FAST: curses.napms(10000)#24200ms
  81. term.addstr(12, 6, "Suddenly, there's a flash")
  82. term.refresh()
  83. if not FAST: curses.napms(2000)#26200ms
  84. curses.curs_set(0)
  85. term.clear()
  86. term.refresh()
  87. if not FAST: curses.napms(4000)#30200ms
  88. term.addstr(6, 6, ".. and then you see nothing")
  89. curses.curs_set(1)
  90. term.refresh()
  91. if not FAST: curses.napms(5000)#35200ms
  92. term.addstr(8, 10, "It's as though you're in a daze, a dream.")
  93. term.refresh()
  94. if not FAST: curses.napms(18000)#53.2s
  95. term.clear()
  96. term.addstr(6,6, "You slowly move forwards, stumbling up the path")
  97. term.refresh()
  98. if not FAST: curses.napms(2000)#55.2s
  99. term.addstr(8, 6, "objects begin to flow into your vision,")
  100. term.refresh()
  101. if not FAST: curses.napms(3000)#58.2s
  102. term.addstr(10, 6, "abstract thoughts with no bearing or direction")
  103. term.refresh()
  104. if not FAST: curses.napms(12000)#70.2s
  105. term.addstr(12, 6, "A flash comes from the right,")
  106. term.addstr(14, 6, "as an alien enters your vision,")
  107. term.addstr(16, 6, "a purple, slimy, alien.")
  108. term.refresh()
  109. if not FAST: curses.napms(7800)#78s
  110. term.clear()
  111. term.addstr(6,6, "Another alien comes into view.")
  112. term.addstr(8,6, "You are very afraid now.")
  113. term.refresh()
  114. if not FAST: curses.napms(8000)#? doesn't matter
  115. term.clear()
  116. term.addstr(6,10, "Suddenly, the ground appears again!")
  117. term.addstr(10,10, "Controls: Press wasd (or the arrow keys) to move,")
  118. term.addstr(12,20, "and space to attack. TAP the keys")
  119. term.addstr(16,10, "Use the numeric keys 1-3 to select your weapon:")
  120. term.addstr(18,12, "1: gun")
  121. term.addstr(19,12, "2: gernade launcher")
  122. term.addstr(20,12, "3: john cena")
  123. term.addstr(22,12, "Press any key to continue")
  124. term.refresh()
  125. term.getch()
  126. def game():
  127. curses.curs_set(0)
  128. os.system("pkill play 2>/dev/null 1>/dev/null 0>/dev/null")
  129. st2.start()
  130. curses.napms(100)
  131. term.clear()
  132. term.refresh()
  133. # 32space, a97, w119, s115, d100, up259, down258, left260, right261
  134. # 1:49,2:50,3:51,4:52,5:53
  135. cont = True
  136. # Player stats
  137. points = 1
  138. weapon = 1
  139. message = ""
  140. px = 0
  141. py = 0
  142. # Enemy Stats
  143. health = 20
  144. epx = 0
  145. epy = 0
  146. # Enemy Sprite
  147. s1 = " _______"
  148. s2 = " .' '."
  149. s3 = " _.-~===========~-._"
  150. s4 = "(___________________)"
  151. s5 = " \_______/"
  152. while(cont):
  153. # Draw
  154. term.clear()
  155. term.border(0)
  156. term.addstr(0,30,"Destroy the aliens!")
  157. term.addstr(2,23,"Score: " + str(points))
  158. term.addstr(2,35,"Alien Health: " + str(health))
  159. term.addstr(4,28,message)
  160. term.addstr(6 + epy,6 + epx,s1)
  161. term.addstr(7 + epy,6 + epx,s2)
  162. term.addstr(8 + epy,6 + epx,s3)
  163. term.addstr(9 + epy,6 + epx,s4)
  164. term.addstr(10 + epy,6 + epx,s5)
  165. term.addch(18 + py, 6 + px, "#")
  166. term.refresh()
  167. # Act
  168. action = term.getch()
  169. if action != -1:
  170. if action == 32:
  171. if weapon == 1:
  172. if abs((epx+10) - px) < 15:
  173. shoot()
  174. message = "you aimed and shot an alien"
  175. points+=1
  176. health-=1
  177. else:
  178. message = "you were not close enough"
  179. elif weapon == 2:
  180. if abs((epx + 10) - px) < 30:
  181. rocket()
  182. message = "wrecked! a space ship blew up"
  183. points+=5
  184. health-=3
  185. else:
  186. message = "you were not close enough"
  187. else:
  188. john()
  189. message = "you scared an alien child away"
  190. points-=3
  191. health-=1
  192. elif action == 49:
  193. weapon = 1
  194. os.system("espeak \"gun selected\" 2>/dev/null")
  195. elif action == 50:
  196. weapon = 2
  197. os.system("espeak \"gernade launcher selected\" 2>/dev/null")
  198. elif action == 51:
  199. weapon = 3
  200. os.system("espeak \"john cena selected\" 2>/dev/null")
  201. # a97, w119, s115, d100, up259, down258, left260, right261
  202. elif action == 97:
  203. if px > 0: px-=1
  204. elif action == 260:
  205. if px > 0: px-=1
  206. elif action == 100:
  207. if px < 60: px+=1
  208. elif action == 261:
  209. if px < 60: px+=1
  210. elif action == 119:
  211. if py > 0: py-=1
  212. elif action == 259:
  213. if py > 0: py-=1
  214. elif action == 115:
  215. if py < 4: py+=1
  216. elif action == 258:
  217. if py < 4: py+=1
  218. else:
  219. os.system("espeak \"" + str(action) + "\" 2>/dev/null")
  220. pass
  221. movex = random.randint(1,3)
  222. movex-=2
  223. if movex == -1:
  224. if epx > 0: epx+=movex
  225. elif movex == 1:
  226. if epx < 40: epx+=movex
  227. else:
  228. pass
  229. movey = random.randint(1,3)
  230. movey-=2
  231. if movey == -1:
  232. if epy > 0: epy+=movey
  233. elif movey == 1:
  234. if epy < 4: epy+=movey
  235. else:
  236. pass
  237. if points < 0:
  238. cont = False
  239. term.clear()
  240. term.addstr(6,6,"You lost!")
  241. if health < 18:
  242. term.addstr(8,6, "You got shot")
  243. else:
  244. term.addstr(8,6, "You got bass blasted")
  245. term.addstr(10,6,"Your score was " + str(points))
  246. term.refresh()
  247. curses.napms(5000)
  248. if health < 0:
  249. cont = False
  250. term.clear()
  251. term.addstr(6,6,"Your sanity has been returned")
  252. term.addstr(8,6,"Your score was " + str(points))
  253. term.refresh()
  254. curses.napms(5000)
  255. points-=0.1
  256. st1 = threading.Thread(target=soundOne)
  257. st2 = threading.Thread(target=soundTwo)
  258. try:
  259. intro()
  260. game()
  261. except KeyboardInterrupt:
  262. curses.endwin()
  263. except Exception as err:
  264. curses.endwin()
  265. print(err)
  266. curses.endwin()