Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.89 KB | None | 0 0
  1. RunCount = 0
  2. frames = 60
  3. #frames fixes visual Bugs by creating frame and state delays
  4. check = 2
  5. #Neutral = 0, True = 1, False = 2, EraseForGame = 3
  6. Mude = 0
  7. #Neutral = 0, Peasant = 1, Prince = 2, King = 3, GOD = 4
  8. foodState = 0
  9. #Neutral = 0, Gen Food = 1
  10. MyX = 500
  11. MyY = 500
  12. #Worm's postition
  13. fX = 50
  14. fY = 50
  15. #Food's position
  16. Tail = []
  17. TailLen = 8
  18. #For Size Growth Algorithm
  19. North = True
  20. South = False
  21. East = False
  22. West = False
  23. #Direction of the Worm
  24. Score = 0
  25. Time = 1000
  26. ScoreBoard = []
  27. #Score Board NOT IMPLEMENTED
  28.  
  29. #Game stuf
  30. def setup():
  31. frameRate(frames)
  32. size(1000,1000)
  33. background(0)
  34.  
  35. def draw():
  36. global check, Mude, RunCount, Tail, TailLen
  37. background(0)
  38. if check == 2:
  39. titleDraw()
  40. if mousePressed:
  41. check = 1
  42. if check == 1:
  43. modeDraw()
  44. RunCount = RunCount + 1
  45. if check == 4:
  46. Controls()
  47. if Mude == 0:
  48. pass
  49. elif Mude == 1:
  50. Peasant()
  51. drawFood()
  52. elif Mude == 2:
  53. Prince()
  54. drawFood()
  55. elif Mude == 3:
  56. King()
  57. drawFood()
  58. elif Mude == 4:
  59. GOD()
  60. #println(Mude)
  61. println(check)
  62. #println(RunCount)
  63. #println(fX)
  64. #println(fY)
  65.  
  66.  
  67. def titleDraw():
  68. #Draws the Starting Title
  69. global RunCount, frames
  70. frames = 60
  71. frameRate(frames)
  72. RunCount = 0
  73. fill(255)
  74. textSize(60)
  75. textAlign(CENTER,CENTER)
  76. text("Welcome To The Snake Game",500,200)
  77. textSize(25)
  78. textAlign(CENTER,CENTER)
  79. text("Click Mouse to Start",500, 600)
  80.  
  81. def modeDraw():
  82. #Draws UI and interaction functions for the game
  83. global check, Mude, frames
  84. frames = 60
  85. frameRate(frames)
  86. background(0)
  87. textAlign(CENTER,CENTER)
  88. fill(255)
  89. ellipse(500,1000-200,200,100)
  90. ellipse(500,1000-400,200,100)
  91. ellipse(500,1000-600,200,100)
  92. ellipse(500,1000-800,200,100)
  93. rect(0,0,300,100)
  94. rect(700,0,1000,100)
  95. fill(0)
  96. textSize(30)
  97. text("Return to Title",150,50)
  98. text("Controls & Rules",850,50)
  99. fill(255)
  100. textSize(50)
  101. fill(200)
  102. text("Color of Worm",500,50)
  103. textSize(30)
  104. fill(0)
  105. text("Green",500,200)
  106. text("Yellow",500,400)
  107. text("Red",500,600)
  108. text("Rainbow",500,800)
  109. #draws screen
  110. if mousePressed:
  111. if 700 < mouseX < 1000 and 0 < mouseY < 100:
  112. check = 4
  113. if 0 < mouseX < 300 and 0 < mouseY < 100:
  114. check = 2
  115. if 400 < mouseX < 600 and 150 < mouseY < 250 and RunCount > 60:
  116. Mude = 1
  117. #green
  118. if 400 < mouseX < 600 and 350 < mouseY < 450 and RunCount > 60:
  119. Mude = 2
  120. #yellow
  121. if 400 < mouseX < 600 and 550 < mouseY < 650 and RunCount > 60:
  122. Mude = 3
  123. #red
  124. if 400 < mouseX < 600 and 750 < mouseY < 850 and RunCount > 60:
  125. Mude = 4
  126. #rainbow
  127.  
  128.  
  129. if 400 < mouseX < 600 and 150 < mouseY < 250:
  130. fill(0,255,0)
  131. ellipse(500,1000-800,200,100)
  132. fill(0)
  133. text("Green",500,200)
  134. if 400 < mouseX < 600 and 350 < mouseY < 450:
  135. fill(255,255,0)
  136. ellipse(500,1000-600,200,100)
  137. fill(0)
  138. text("Yellow",500,400)
  139. if 400 < mouseX < 600 and 550 < mouseY < 650:
  140. fill(255,0,0)
  141. ellipse(500,1000-400,200,100)
  142. fill(0)
  143. text("Red",500,600)
  144. if 400 < mouseX < 600 and 750 < mouseY < 850:
  145. fill(random(200)+55,random(200)+55,random(200)+55)
  146. ellipse(500,1000-200,200,100)
  147. fill(0)
  148. text("Rainbow",500,800)
  149.  
  150. def GOD():
  151. #The hardest difficulty
  152. global Mude, check, MyX, MyY,frames,TailLen,Score,Time,Tail,foodState
  153. frames = 10
  154. frameRate(frames)
  155. Zx = 0
  156. Zy = 0
  157. check = 3
  158. background(0)
  159. while Zx < 1000:
  160. stroke(50)
  161. line(Zx,1000,Zx,0)
  162. Zx = Zx + 25
  163. while Zy < 1000:
  164. stroke(50)
  165. line(1000,Zy,0,Zy)
  166. Zy = Zy + 25
  167. drawFood()
  168. if MyY >= 1000:
  169. MyY = 1000
  170. if MyY <= 0:
  171. MyY = 0
  172. if MyX >= 1000:
  173. MyX = 1000
  174. if MyX <= 0:
  175. MyX = 0
  176. textSize(50)
  177. if Time < 250:
  178. fill(random(200)+55,random(200)+55,random(200)+55)
  179. else:
  180. fill(255)
  181. text("TIME",800,50)
  182. text("SCORE",200,50)
  183. textSize(30)
  184. text(Time,800,100)
  185. text(Score, 200,100)
  186. fill(255)
  187. noStroke()
  188. Move()
  189. EatEvent()
  190. fill(random(200)+55,random(200)+55,random(200)+55)
  191. ellipse(MyX,MyY,50,50)
  192. DrawFace()
  193. TailAlgorithum()
  194. if Time <= 0:
  195. foodState = 2
  196. background(0)
  197. Time = 0
  198. textSize(80)
  199. fill(100)
  200. text("GAME OVER",500,300)
  201. textSize(50)
  202. text("SCORE",500,500)
  203. text(Score,500,600)
  204. noLoop()
  205. else:
  206. Time = Time - 4
  207.  
  208. def Peasant():
  209. #The "Green" difficulty
  210. global Mude, check, MyX, MyY, frames, TailLen, Score, Time, Tail, foodState
  211. frames = 10
  212. Time = Time - 1
  213. frameRate(frames)
  214. Zx = 0
  215. Zy = 0
  216. check = 3
  217. background(0)
  218. fill(0,255,0)
  219. noStroke()
  220. while Zx < 1000:
  221. stroke(50)
  222. line(Zx,1000,Zx,0)
  223. Zx = Zx + 25
  224. while Zy < 1000:
  225. stroke(50)
  226. line(1000,Zy,0,Zy)
  227. Zy = Zy + 25
  228. drawFood()
  229. textSize(50)
  230. if Time < 250:
  231. fill(0,random(200)+55,0)
  232. else:
  233. fill(255)
  234. text("TIME",800,50)
  235. text("SCORE",200,50)
  236. textSize(30)
  237. text(Time,800,100)
  238. text(Score, 200,100)
  239. fill(255)
  240. noStroke()
  241. Move()
  242. EatEvent()
  243. fill(0,255,0)
  244. ellipse(MyX,MyY,50,50)
  245. DrawFace()
  246. TailAlgorithum()
  247. if Time <= 0:
  248. foodState = 2
  249. background(0)
  250. Time = 0
  251. textSize(80)
  252. fill(100)
  253. text("GAME OVER",500,300)
  254. textSize(50)
  255. text("SCORE",500,500)
  256. text(Score,500,600)
  257. noLoop()
  258. else:
  259. Time = Time - 4
  260.  
  261.  
  262. #expand this later to be a Pickfork on the sides
  263.  
  264. def King():
  265. #The "Red" difficulty
  266. global Mude, check, MyX, MyY, frames, TailLen, Score, Time, Tail, foodState
  267. frames = 10
  268. Time = Time - 3
  269. frameRate(frames)
  270. Zx = 0
  271. Zy = 0
  272. check = 3
  273. background(0)
  274. fill(255,0,0)
  275. noStroke()
  276. while Zx < 1000:
  277. stroke(50)
  278. line(Zx,1000,Zx,0)
  279. Zx = Zx + 25
  280. while Zy < 1000:
  281. stroke(50)
  282. line(1000,Zy,0,Zy)
  283. Zy = Zy + 25
  284. drawFood()
  285. textSize(50)
  286. if Time < 250:
  287. fill(random(200)+55,0,0)
  288. else:
  289. fill(255)
  290. text("TIME",800,50)
  291. text("SCORE",200,50)
  292. textSize(30)
  293. text(Time,800,100)
  294. text(Score, 200,100)
  295. fill(255)
  296. noStroke()
  297. Move()
  298. EatEvent()
  299. fill(255,0,0)
  300. ellipse(MyX,MyY,50,50)
  301. DrawFace()
  302. TailAlgorithum()
  303. if Time <= 0:
  304. foodState = 2
  305. background(0)
  306. Time = 0
  307. textSize(80)
  308. fill(100)
  309. text("GAME OVER",500,300)
  310. textSize(50)
  311. text("SCORE",500,500)
  312. text(Score,500,600)
  313. noLoop()
  314. else:
  315. Time = Time - 4
  316.  
  317. def Prince():
  318. #The "Yellow" difficulty
  319. global Mude, check, MyX, MyY, frames, TailLen, Time, Score, Tail, foodState
  320. frames = 10
  321. Time = Time - 2
  322. frameRate(frames)
  323. Zx = 0
  324. Zy = 0
  325. check = 3
  326. background(0)
  327. fill(255,255,0)
  328. noStroke()
  329. while Zx < 1000:
  330. stroke(50)
  331. line(Zx,1000,Zx,0)
  332. Zx = Zx + 25
  333. while Zy < 1000:
  334. stroke(50)
  335. line(1000,Zy,0,Zy)
  336. Zy = Zy + 25
  337. drawFood()
  338. textSize(50)
  339. if Time < 250:
  340. fill(random(200)+55,random(200)+55,0)
  341. else:
  342. fill(255)
  343. text("TIME",800,50)
  344. text("SCORE",200,50)
  345. textSize(30)
  346. text(Time,800,100)
  347. text(Score, 200,100)
  348. fill(255)
  349. noStroke()
  350. Move()
  351. EatEvent()
  352. fill(255,255,0)
  353. ellipse(MyX,MyY,50,50)
  354. DrawFace()
  355. TailAlgorithum()
  356. if Time <= 0:
  357. foodState = 2
  358. background(0)
  359. Time = 0
  360. textSize(80)
  361. fill(100)
  362. text("GAME OVER",500,300)
  363. textSize(50)
  364. text("SCORE",500,500)
  365. text(Score,500,600)
  366. noLoop()
  367. else:
  368. Time = Time - 4
  369.  
  370. def drawFood():
  371. #Places the food in-game using pointers
  372. global Mude, fX, fY, foodState
  373. if foodState == 2:
  374. pass
  375. if foodState == 0:
  376. setFood()
  377. foodState = 1
  378. if Mude == 1:
  379. stroke(0,255,0)
  380. elif Mude == 2:
  381. stroke(255,255,0)
  382. elif Mude == 3:
  383. stroke(255,0,0)
  384. elif Mude == 4:
  385. stroke(random(200)+55,random(200)+55,random(200)+55)
  386. strokeWeight(20)
  387. point(fX,fY)
  388. strokeWeight(1)
  389. noStroke()
  390.  
  391. def setFood():
  392. #Sets pointers for the food in-game
  393. if foodState == 1:
  394. pass
  395. elif foodState == 0:
  396. global fX,fY
  397. fX = floor(random(1,19))*50
  398. fY = floor(random(1,19))*50
  399.  
  400. def TailAlgorithum():
  401. #The main algorithum, generates the "tail" of the worm with sudo-memory in an array
  402. global Tail,MyX,MyY,check,TailLen
  403. i = 2
  404. if check == 3 and keyPressed == True:
  405. Tail.insert(0, MyY)
  406. Tail.insert(0, MyX)
  407. if len(Tail) > TailLen:
  408. Tail.pop()
  409. Tail.pop()
  410. if len(Tail) == TailLen:
  411. while len(Tail)/2 > i/2:
  412. if Mude == 1:
  413. fill(0,255,0)
  414. elif Mude == 2:
  415. fill(255,255,0)
  416. elif Mude == 3:
  417. fill(255,0,0)
  418. elif Mude == 4:
  419. fill(random(200)+55,random(200)+55,random(200)+55)
  420. #noStroke()
  421. ellipse(Tail[i],Tail[i+1],50,50)
  422. i = i + 2
  423.  
  424. def EatEvent():
  425. #A Basic Event that effects the game and triggers other things
  426. global TailLen,fX,fY,MyX,MyY,foodState,Score
  427. if MyX == fX and MyY == fY:
  428. Score = Score + 1
  429. TailLen = TailLen + 2
  430. foodState = 0
  431. drawFood()
  432.  
  433. def Move():
  434. #This method takes input from the key board to move the worm
  435. global MyY, MyX, North, South, East, West
  436. if keyPressed:
  437. if key == 'w':
  438. MyY = MyY - 25
  439. North = True
  440. East = False
  441. West = False
  442. South = False
  443. if key == 's':
  444. MyY = MyY + 25
  445. North = False
  446. East = False
  447. West = False
  448. South = True
  449. if key == 'a':
  450. MyX = MyX - 25
  451. North = False
  452. East = False
  453. West = True
  454. South = False
  455. if key == 'd':
  456. MyX = MyX + 25
  457. North = False
  458. East = True
  459. West = False
  460. South = False
  461.  
  462. def Controls():
  463. global check
  464. background(0)
  465. fill(255)
  466. textSize(80)
  467. text("CONTROLS",500,100)
  468. text("RULES",500,400)
  469. text("Upcoming Features",500,700)
  470. textSize(30)
  471. text("W-A-S-D To Move the Worm", 500 ,200)
  472. text("Press 'b' To exit a Screen", 500, 250)
  473. text("Your Goal is to feed your worm by eating the pellets.", 500,500)
  474. text("When the Timer hits zero the game is over.",500,550)
  475. text("-> Image and Terrian backgrounds",500,800)
  476. text("-> A Score Board",500,850)
  477. if keyPressed:
  478. if key == "b":
  479. check = 1
  480.  
  481. def DrawFace():
  482. #This Method Draws the eyes of the worm in the corrisponding direction
  483. global North, South, East, West, MyX, MyY
  484. if North == True:
  485. fill(255)
  486. ellipse(MyX-10,MyY-10,20,20)
  487. ellipse(MyX+10,MyY-10,20,20)
  488. fill(0)
  489. ellipse(MyX-10,MyY-15,10,10)
  490. ellipse(MyX+10,MyY-15,10,10)
  491. if South == True:
  492. fill(255)
  493. ellipse(MyX-10,MyY+10,20,20)
  494. ellipse(MyX+10,MyY+10,20,20)
  495. fill(0)
  496. ellipse(MyX-10,MyY+15,10,10)
  497. ellipse(MyX+10,MyY+15,10,10)
  498. if East == True:
  499. fill(255)
  500. ellipse(MyX+10,MyY-10,20,20)
  501. ellipse(MyX+10,MyY+10,20,20)
  502. fill(0)
  503. ellipse(MyX+15,MyY-10,10,10)
  504. ellipse(MyX+15,MyY+10,10,10)
  505. if West == True:
  506. fill(255)
  507. ellipse(MyX-10,MyY-10,20,20)
  508. ellipse(MyX-10,MyY+10,20,20)
  509. fill(0)
  510. ellipse(MyX-15,MyY-10,10,10)
  511. ellipse(MyX-15,MyY+10,10,10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement