Guest User

The nameless game

a guest
Sep 15th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.26 KB | None | 0 0
  1. %Project - Name undecided
  2. %Programming started July 29, 2013
  3. %More information found in "Game Blueprint.doc"
  4. %Project.t
  5.  
  6. var mapLength, mapHeight : int %Length and height of our map
  7. var stream : int %Used in extracting map from file
  8. var map : flexible array 1 .. 1 of string %Holds the map
  9. var imageText : flexible array 1 .. 1 of string %Holds list of images, shortens code significantly
  10. var pic : array 1 .. 22 of int %Array holding all our images
  11. const Char : array 1 .. 21 of string := init ("R", "G", "B", "V", "H", "1", "2", "3", "4", "up", "right", "down", "left", "q", "w", "e", "r", "a", "s", "d", "f")
  12. %Different things that could be in the map.txt file
  13. const obstructions : array 1 .. 15 of string := init ("B", "V", "H", "1", "2", "3", "4", "a", "s", "d", "f", "q", "w", "e", "r") %Can't walk through these things
  14. var charx, chary : int %Character position
  15. var chars : array char of boolean %Used for keyboard input
  16. var prevchars : array char of boolean %Used for keyboard input
  17. var facing : string := "up" %Direction character is facing
  18.  
  19. function collision (x, y : int) : boolean %Function checks for collision when walking.
  20. for i : 1 .. upper (obstructions)
  21. if map (x) (y) = obstructions (i) then
  22. result true
  23. end if
  24. end for
  25. result false
  26. end collision
  27.  
  28. function indexArray (s : string) : int %Function finds index of an element in the char array
  29. for i : 1 .. 21
  30. if Char (i) = s then
  31. result i
  32. end if
  33. end for
  34. result 0
  35. end indexArray
  36.  
  37. procedure drawScreen
  38. for i : 1 .. mapLength
  39. for ii : 1 .. mapHeight
  40. Pic.Draw (pic (indexArray (map (ii) (i))), i * 40 + 240 - (40 * charx), mapHeight * 40 - (ii * 40) - (40 * chary) + 280 - ((mapHeight - 15) * 40), picMerge)
  41. end for
  42. end for
  43. end drawScreen
  44.  
  45. procedure animatedMotion (dir : string, justTurn : boolean) %Procedure handles animation while moving
  46. var animatedPic : int
  47. var a, b, c, d : int
  48.  
  49. drawScreen
  50.  
  51. a := 0
  52. b := 0
  53. c := 0
  54. d := 0
  55.  
  56. animatedPic := Pic.New (0, 0, 600, 600)
  57.  
  58. case dir of
  59. label "up" :
  60. a := 1
  61.  
  62. label "down" :
  63. b := 1
  64.  
  65. label "left" :
  66. c := 1
  67.  
  68. label "right" :
  69. d := 1
  70. end case
  71.  
  72. for i : 1 .. 40
  73. Pic.Draw (animatedPic, (c * -40) + (d * 40) + (c * i) + (d * -i), (b * -40) + (a * 40) + (b * i) + (a * -i), picCopy)
  74. Pic.Draw (pic (indexArray (dir)), 280, 280, picMerge) %Draw the character
  75. delay (1)
  76. View.Update
  77. end for
  78. end animatedMotion
  79.  
  80. procedure justTurn (direction : string)
  81. drawScreen
  82.  
  83. Pic.Draw (pic (indexArray (direction)), 280, 280, picMerge)
  84. View.Update
  85. end justTurn
  86.  
  87. procedure introFade %Procedure handles the fade effects at beginning
  88. var fade : int %Used in fade intro
  89. var fade1 : int %Also used in fade intro
  90. var font1 : int := Font.New ("Lao UI:16:bold")
  91. var counter1, counter2 : real := 1
  92. Draw.FillBox (0, 0, 600, 600, black)
  93. for i : 1 .. 600
  94. Draw.FillBox (-600 + i, 100, 0 + i, 500, RGB.AddColour (0.95, 0.95, 0.95))
  95. delay (1)
  96. end for
  97. fade := Pic.New (0, 0, 600, 600)
  98. delay (250)
  99. Pic.DrawSpecial (pic (22), 100, 200, picCopy, picFadeIn, 2000)
  100. delay (2000)
  101. Pic.DrawSpecial (fade, 0, 0, picCopy, picFadeIn, 2000)
  102. setscreen ("offscreenonly")
  103. Font.Draw (chr (169) + " 2013-2013", 145, 300, font1, black)
  104. Font.Draw (chr (169) + " 1997-2013", 145, 280, font1, black)
  105. Font.Draw (chr (169) + " 1909-2013", 145, 260, font1, black)
  106. Font.Draw ("GamesWorld", 300, 300, font1, black)
  107. Font.Draw ("Nathaniel", 300, 280, font1, black)
  108. Font.Draw ("Copyright Sign", 300, 260, font1, black)
  109. fade1 := Pic.New (0, 0, 600, 600)
  110. Pic.Draw (fade, 0, 0, picCopy)
  111. setscreen ("nooffscreenonly")
  112. Pic.DrawSpecial (fade1, 0, 0, picCopy, picFadeIn, 2000)
  113. delay (2000)
  114. Pic.DrawSpecial (fade, 0, 0, picCopy, picFadeIn, 2000)
  115. delay (1000)
  116. setscreen ("offscreenonly") % Set double buffer
  117. loop
  118. Draw.FillBox (0, 0, 600, 600, black)
  119. Draw.FillBox (round (counter1 + counter2), 100, 601, 500, white)
  120. delay (4)
  121. View.Update
  122. counter2 += 0.03
  123. counter1 += counter2
  124. exit when counter1 > 600
  125. end loop
  126. delay (1000)
  127. end introFade
  128.  
  129. setscreen ("graphics:600;600") % Set screensize
  130.  
  131. open : stream, "Map.txt", get % Open map file and load it into string array
  132.  
  133. loop
  134. exit when eof (stream)
  135. get : stream, map (upper (map))
  136. new map, upper (map) + 1
  137. end loop
  138.  
  139. mapLength := length (map (1)) %Determine length/height of map
  140. mapHeight := upper (map) - 1
  141.  
  142. stream := 0
  143.  
  144. open : stream, "Images.txt", get % Open Image name file and load it into string array
  145.  
  146. loop
  147. exit when eof (stream)
  148. get : stream, imageText (upper (imageText))
  149. new imageText, upper (imageText) + 1
  150. end loop
  151.  
  152. for i : 1 .. upper (imageText) - 1 %Load all the images
  153. pic (i) := Pic.FileNew ("Images/" + imageText (i) + ".bmp")
  154. end for
  155.  
  156. introFade
  157.  
  158. charx := 15 %Characters starting position
  159. chary := 0
  160.  
  161. drawScreen
  162.  
  163. Pic.Draw (pic (indexArray ("up")), 280, 280, picMerge) %Draw the character
  164. View.Update
  165. cls
  166.  
  167. loop
  168. Input.KeyDown (chars) %Handle keyboard input, Walking stuff below
  169.  
  170. if chars (KEY_UP_ARROW) then
  171. if collision (15 - chary - 1, charx + 1) = false then
  172. chary += 1
  173. animatedMotion ("up", false)
  174. else
  175. justTurn ("up")
  176. end if
  177. end if
  178.  
  179. if chars (KEY_DOWN_ARROW) then
  180. if collision (15 - chary + 1, charx + 1) = false then
  181. chary -= 1
  182. animatedMotion ("down", false)
  183. else
  184. justTurn ("down")
  185. end if
  186. end if
  187.  
  188. if chars (KEY_LEFT_ARROW) then
  189. if collision (15 - chary, charx) = false then
  190. charx -= 1
  191. animatedMotion ("left", false)
  192. else
  193. justTurn ("left")
  194. end if
  195. end if
  196.  
  197. if chars (KEY_RIGHT_ARROW) then
  198. if collision (15 - chary, charx + 2) = false then
  199. charx += 1
  200. animatedMotion ("right", false)
  201. else
  202. justTurn ("right")
  203. end if
  204. end if
  205. end loop
Advertisement
Add Comment
Please, Sign In to add comment