Mesaif

v1.1

May 26th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.93 KB | None | 0 0
  1. %Snake (ogodno)
  2.  
  3. %VERSION 1.0
  4. % - Ready to play!
  5. %to do:
  6. % - read/write to file for high scores
  7. % - fix help button
  8. % - many more features
  9. %VERSION 1.1
  10. % - Added save data
  11. % - Bug fixes
  12. % - Added poise
  13. % - Fixed help button
  14. %to do:
  15. % -change method of snake drawing
  16. % -add item that resets snake length
  17.  
  18.  
  19. %NOTES%
  20. %Save file format:
  21. % high score
  22. % name
  23. % high score difficulty
  24. %NOTES
  25.  
  26.  
  27. %Setup
  28. setscreen ("graphics")
  29. View.Set ("graphics:800;800")
  30.  
  31. %Variables
  32. var x1, y1, x2, y2 : int
  33. var Pc : int := 12 %Color of the point
  34. var chars : array char of boolean
  35.  
  36. var direction : string := "none" %Tells what direction the snake is moving
  37.  
  38. var Sx, Sy : int := 395
  39. var speed : int := 6
  40.  
  41. var Ex, Ey : int
  42. var L, W : int
  43.  
  44. var Ex2, Ey2 : int
  45.  
  46. var Ec : int := 9
  47. var score : int := 0 %Stores score
  48.  
  49. var font1 : int
  50.  
  51. var difficulty : int
  52. var enemyW : int
  53.  
  54. var titleF : int %Font var
  55.  
  56. var mx, my, b : int %Mouse input vars
  57.  
  58. var highscore : int := 0 %high score var
  59. var highscoreDIF : int := 0
  60. var name : string := "noJUAN"
  61.  
  62. var stream : int
  63.  
  64.  
  65. var HS : int
  66. var NM : string
  67. var DF : int
  68.  
  69. var savedataINT : array 1..2 of string
  70.  
  71.  
  72. %Fonts
  73. titleF := Font.New ("serif:20")
  74.  
  75. %Procedures
  76.  
  77. procedure restart
  78. cls
  79. drawfillbox (0, 0, 800, 800, black)
  80. locate (13, 40)
  81. color (12)
  82. colorback (black)
  83. put "YOU DIED"
  84. delay (2000)
  85.  
  86. %if statements for high scores
  87. if score > highscore then
  88. highscoreDIF := difficulty
  89. cls
  90. locate (13, 40)
  91. colorback (black)
  92. put "HIGH SCORE! What is your name?: " ..
  93. color (white)
  94. get name
  95. delay (500)
  96. cls
  97. locate (13, 20)
  98.  
  99.  
  100. %Congrats message
  101. color (12)
  102. put "Congratulations " ..
  103. color (white)
  104. put name ..
  105. color (12)
  106. put ", you acheived a high score of " ..
  107. color (white)
  108. put score ..
  109. color (12)
  110. put "!" ..
  111. locate (14, 20)
  112. put "You beat the previous high score by " ..
  113. color (white)
  114. put (score - highscore) ..
  115. color (12)
  116. put "!"
  117. %End of congrats
  118.  
  119.  
  120. highscore := score
  121.  
  122. open : stream, "save.txt", put
  123. put : stream, highscore
  124. put : stream, name
  125. put : stream, highscoreDIF
  126. close : stream
  127.  
  128.  
  129. elsif score = highscore then
  130. cls
  131. locate (20, 30)
  132. colorback (black)
  133. color (12)
  134. put "You matched the previous high score of ", score, " by ", name, " at ", highscoreDIF, "..."
  135. else
  136. cls
  137. locate (20, 30)
  138. colorback (black)
  139.  
  140. %Put so close
  141. put "You were off of the high score " ..
  142. color (white)
  143. put highscore ..
  144. color (12)
  145. put " by " ..
  146. color (white)
  147. put highscore - score ..
  148. color (12)
  149. put " points!"
  150.  
  151. delay (1000)
  152. locate (21, 30)
  153. put "Better luck next time!"
  154. delay (3000)
  155. end if
  156. %end of high scores if statements
  157.  
  158.  
  159. delay (6000)
  160. Sx := 395
  161. Sy := 395
  162. cls
  163. end restart
  164.  
  165.  
  166.  
  167. procedure point
  168.  
  169. %Make a random placement that doesnt go over the screen
  170. randint (x1, 0, 790)
  171. randint (y1, 0, 790)
  172.  
  173. %Set the other x/y value to 8 units larger
  174. x2 := x1 + 8
  175. y2 := y1 + 8
  176.  
  177. if whatdotcolor (x1, y1) = white then
  178. randint (x1, 0, 790)
  179. randint (y1, 0, 790)
  180. x2 := x1 + 8
  181. y2 := y1 + 8
  182. end if
  183.  
  184. %Draw the point
  185. drawfillbox (x1, y1, x2, y2, Pc)
  186.  
  187. end point
  188.  
  189. process enemy () %Draws the enemy
  190.  
  191. loop
  192. %Randomize size and pos of the enemy
  193. randint (Ex, 0, 790)
  194. randint (Ey, 0, 790)
  195. randint (L, 2, 15)
  196. randint (W, 1, 15)
  197.  
  198. %Set the other point of the box
  199. Ex2 := Ex + W
  200. Ey2 := Ey + L
  201.  
  202. drawfillbox (Ex, Ey, Ex2, Ey2, Ec)
  203. delay (enemyW)
  204. end loop
  205.  
  206. end enemy
  207.  
  208. procedure SCORE
  209. locate (1, 1)
  210. color (39)
  211. colorback (black)
  212. put "Score: ", score ..
  213. end SCORE
  214.  
  215. procedure snek
  216.  
  217.  
  218. loop
  219. Input.KeyDown (chars)
  220. drawfillbox (Sx, Sy, Sx + 10, Sy + 10, white)
  221.  
  222.  
  223. %If statement for keyboard input
  224. if chars (KEY_UP_ARROW) then
  225. Sy := Sy + speed %Speed is a variable that can be changed earlier on in the code
  226. direction := "UP"
  227. score += 10
  228. SCORE
  229. elsif chars (KEY_LEFT_ARROW) then
  230. Sx := Sx - speed
  231. direction := "LEFT"
  232. score += 10
  233. SCORE
  234. elsif chars (KEY_RIGHT_ARROW) then
  235. Sx := Sx + speed
  236. direction := "RIGHT"
  237. score += 10
  238. SCORE
  239. elsif chars (KEY_DOWN_ARROW) then
  240. Sy := Sy - speed
  241. direction := "DOWN"
  242. score += 10
  243. SCORE
  244. end if
  245. %End of if statement
  246.  
  247.  
  248. %Collision detection
  249. if direction = "UP" then
  250. if whatdotcolor (Sx + 5, Sy + 11) = white or whatdotcolor (Sx + 5, Sy + 11) = 9 then
  251. restart
  252. exit
  253. end if
  254. elsif direction = "LEFT" then
  255. if whatdotcolor (Sx - 1, Sy + 5) = white or whatdotcolor (Sx - 1, Sy + 5) = 9 then
  256. restart
  257. exit
  258. end if
  259. elsif direction = "RIGHT" then
  260. if whatdotcolor (Sx + 11, Sy + 5) = white or whatdotcolor (Sx + 11, Sy + 5) = 9 then
  261. restart
  262. exit
  263. end if
  264.  
  265. elsif direction = "DOWN" then
  266. if whatdotcolor (Sx + 5, Sy - 1) = white or whatdotcolor (Sx + 5, Sy - 1) = white then
  267. restart
  268. exit
  269. end if
  270. end if
  271. %End of collision detection
  272.  
  273.  
  274. %POINT DETECTION
  275. for i : 1 .. 10 %Checks for the point nearby
  276.  
  277. if direction = "UP" then
  278. if whatdotcolor (Sx + i, Sy + 11) = 12 then
  279. drawfillbox (x1, y1, x2, y2, black)
  280. point
  281. score += 500
  282. SCORE
  283. elsif whatdotcolor (Sx - 1, Sy + i) = 9 then
  284. end if
  285.  
  286. elsif direction = "LEFT" then
  287. if whatdotcolor (Sx - 1, Sy + i) = 12 then
  288. drawfillbox (x1, y1, x2, y2, black)
  289. point
  290. score += 500
  291. SCORE
  292. elsif whatdotcolor (Sx - 1, Sy + i) = 9 then
  293. end if
  294.  
  295. elsif direction = "RIGHT" then
  296. if whatdotcolor (Sx + 11, Sy + i) = 12 then
  297. drawfillbox (x1, y1, x2, y2, black)
  298. point
  299. score += 500
  300. SCORE
  301. elsif whatdotcolor (Sx - 1, Sy + i) = 9 then
  302. end if
  303.  
  304. elsif direction = "DOWN" then
  305. if whatdotcolor (Sx + i, Sy - 1) = 12 then
  306. drawfillbox (x1, y1, x2, y2, black)
  307. point
  308. score += 500
  309. SCORE
  310. elsif whatdotcolor (Sx - 1, Sy + i) = 9 then
  311. end if
  312. end if
  313.  
  314. end for
  315. %END OF POINT DETECTION
  316.  
  317. delay (50) %Delay so that it doesn't move crazy fast
  318. end loop
  319.  
  320. end snek
  321.  
  322. procedure LOAD
  323.  
  324. open : stream, "save.txt", get
  325. get : stream, HS
  326. get : stream, NM
  327. get : stream, DF
  328. delay (50)
  329. close : stream
  330.  
  331. highscore := HS
  332. name := NM
  333. highscoreDIF := DF
  334. end LOAD
  335.  
  336. procedure Main
  337.  
  338. score := 0
  339.  
  340. %choose difficulty
  341. cls
  342. drawfillbox (0, 0, 800, 800, 50)
  343. colorback (50)
  344. color (black)
  345. put "Difficulty (1-5): " ..
  346. get difficulty
  347. cls
  348. locate (1, 1)
  349. color (black)
  350. %difficulty chosen
  351.  
  352.  
  353. %puts prev high score stats
  354. LOAD
  355. put "PREVIOUS HIGH SCORE: " ..
  356. color (12)
  357. put highscore ..
  358. color (black)
  359. put " BY " ..
  360. color (12)
  361. put name ..
  362. color (black)
  363. put " AT DIFFICULTY: " ..
  364. color (12)
  365. put highscoreDIF
  366. color (black)
  367. %previous high score stats
  368.  
  369.  
  370.  
  371. %wait
  372. put "3..."
  373. delay (1000)
  374. put "2..."
  375. delay (1000)
  376. put "1..."
  377. delay (1000)
  378. %wait
  379.  
  380. %CHANGE DIFFICULTY
  381. if difficulty = 1 then
  382. enemyW := 5000
  383. elsif difficulty = 2 then
  384. enemyW := 4000
  385. elsif difficulty = 3 then
  386. enemyW := 3000
  387. elsif difficulty = 4 then
  388. enemyW := 2000
  389. elsif difficulty = 5 then
  390. enemyW := 1000
  391. else
  392. enemyW := 3000
  393. end if
  394.  
  395. drawfillbox (0, 0, 800, 800, black)
  396. point
  397.  
  398. if difficulty >= 4 then %Enemies with difficulty of greater than 4
  399. fork enemy
  400. end if
  401.  
  402. snek
  403.  
  404. end Main
  405.  
  406.  
  407.  
  408. %Main loop
  409. loop
  410. loop
  411. drawfillbox (0, 0, 800, 800, 50)
  412. Font.Draw ("By Saif K.", 0, 0, titleF, black)
  413. Font.Draw ("START", 380, 380, titleF, black)
  414. Font.Draw ("HELP", 380, 350, titleF, black)
  415. Mouse.Where (mx, my, b)
  416. if mx >= 380 and mx <= 463 and my >= 380 and my <= 397 and b = 1 then
  417. exit
  418. end if
  419. if mx >= 360 and mx <= 443 and my >= 360 and my <= 379 and b = 1 then
  420. drawfillbox (0, 0, 800, 800, 50)
  421. colorback (50)
  422. delay (200)
  423. cls
  424. locate (1, 1)
  425. %RULES/HOWTOPLAY
  426. put "HOW TO PLAY: "
  427.  
  428. put " "
  429.  
  430. put "1.Use arrow keys to move"
  431.  
  432. put "2.500 points for red boxes"
  433.  
  434. put "3.10 points while moving"
  435.  
  436. put "4.At difficulty 4 or 5 avoid blue boxes!"
  437.  
  438. put "5.Dont move backwards!"
  439. %RULES/HOWTOPLAY
  440. delay (5000)
  441.  
  442. end if
  443. delay (50)
  444. cls
  445. end loop
  446.  
  447. Main
  448. end loop
Advertisement
Add Comment
Please, Sign In to add comment