Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %Project - Name undecided
- %Programming started July 29, 2013
- %More information found in "Game Blueprint.doc"
- %Project.t
- var mapLength, mapHeight : int %Length and height of our map
- var stream : int %Used in extracting map from file
- var map : flexible array 1 .. 1 of string %Holds the map
- var imageText : flexible array 1 .. 1 of string %Holds list of images, shortens code significantly
- var pic : array 1 .. 22 of int %Array holding all our images
- 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")
- %Different things that could be in the map.txt file
- 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
- var charx, chary : int %Character position
- var chars : array char of boolean %Used for keyboard input
- var prevchars : array char of boolean %Used for keyboard input
- var facing : string := "up" %Direction character is facing
- function collision (x, y : int) : boolean %Function checks for collision when walking.
- for i : 1 .. upper (obstructions)
- if map (x) (y) = obstructions (i) then
- result true
- end if
- end for
- result false
- end collision
- function indexArray (s : string) : int %Function finds index of an element in the char array
- for i : 1 .. 21
- if Char (i) = s then
- result i
- end if
- end for
- result 0
- end indexArray
- procedure drawScreen
- for i : 1 .. mapLength
- for ii : 1 .. mapHeight
- Pic.Draw (pic (indexArray (map (ii) (i))), i * 40 + 240 - (40 * charx), mapHeight * 40 - (ii * 40) - (40 * chary) + 280 - ((mapHeight - 15) * 40), picMerge)
- end for
- end for
- end drawScreen
- procedure animatedMotion (dir : string, justTurn : boolean) %Procedure handles animation while moving
- var animatedPic : int
- var a, b, c, d : int
- drawScreen
- a := 0
- b := 0
- c := 0
- d := 0
- animatedPic := Pic.New (0, 0, 600, 600)
- case dir of
- label "up" :
- a := 1
- label "down" :
- b := 1
- label "left" :
- c := 1
- label "right" :
- d := 1
- end case
- for i : 1 .. 40
- Pic.Draw (animatedPic, (c * -40) + (d * 40) + (c * i) + (d * -i), (b * -40) + (a * 40) + (b * i) + (a * -i), picCopy)
- Pic.Draw (pic (indexArray (dir)), 280, 280, picMerge) %Draw the character
- delay (1)
- View.Update
- end for
- end animatedMotion
- procedure justTurn (direction : string)
- drawScreen
- Pic.Draw (pic (indexArray (direction)), 280, 280, picMerge)
- View.Update
- end justTurn
- procedure introFade %Procedure handles the fade effects at beginning
- var fade : int %Used in fade intro
- var fade1 : int %Also used in fade intro
- var font1 : int := Font.New ("Lao UI:16:bold")
- var counter1, counter2 : real := 1
- Draw.FillBox (0, 0, 600, 600, black)
- for i : 1 .. 600
- Draw.FillBox (-600 + i, 100, 0 + i, 500, RGB.AddColour (0.95, 0.95, 0.95))
- delay (1)
- end for
- fade := Pic.New (0, 0, 600, 600)
- delay (250)
- Pic.DrawSpecial (pic (22), 100, 200, picCopy, picFadeIn, 2000)
- delay (2000)
- Pic.DrawSpecial (fade, 0, 0, picCopy, picFadeIn, 2000)
- setscreen ("offscreenonly")
- Font.Draw (chr (169) + " 2013-2013", 145, 300, font1, black)
- Font.Draw (chr (169) + " 1997-2013", 145, 280, font1, black)
- Font.Draw (chr (169) + " 1909-2013", 145, 260, font1, black)
- Font.Draw ("GamesWorld", 300, 300, font1, black)
- Font.Draw ("Nathaniel", 300, 280, font1, black)
- Font.Draw ("Copyright Sign", 300, 260, font1, black)
- fade1 := Pic.New (0, 0, 600, 600)
- Pic.Draw (fade, 0, 0, picCopy)
- setscreen ("nooffscreenonly")
- Pic.DrawSpecial (fade1, 0, 0, picCopy, picFadeIn, 2000)
- delay (2000)
- Pic.DrawSpecial (fade, 0, 0, picCopy, picFadeIn, 2000)
- delay (1000)
- setscreen ("offscreenonly") % Set double buffer
- loop
- Draw.FillBox (0, 0, 600, 600, black)
- Draw.FillBox (round (counter1 + counter2), 100, 601, 500, white)
- delay (4)
- View.Update
- counter2 += 0.03
- counter1 += counter2
- exit when counter1 > 600
- end loop
- delay (1000)
- end introFade
- setscreen ("graphics:600;600") % Set screensize
- open : stream, "Map.txt", get % Open map file and load it into string array
- loop
- exit when eof (stream)
- get : stream, map (upper (map))
- new map, upper (map) + 1
- end loop
- mapLength := length (map (1)) %Determine length/height of map
- mapHeight := upper (map) - 1
- stream := 0
- open : stream, "Images.txt", get % Open Image name file and load it into string array
- loop
- exit when eof (stream)
- get : stream, imageText (upper (imageText))
- new imageText, upper (imageText) + 1
- end loop
- for i : 1 .. upper (imageText) - 1 %Load all the images
- pic (i) := Pic.FileNew ("Images/" + imageText (i) + ".bmp")
- end for
- introFade
- charx := 15 %Characters starting position
- chary := 0
- drawScreen
- Pic.Draw (pic (indexArray ("up")), 280, 280, picMerge) %Draw the character
- View.Update
- cls
- loop
- Input.KeyDown (chars) %Handle keyboard input, Walking stuff below
- if chars (KEY_UP_ARROW) then
- if collision (15 - chary - 1, charx + 1) = false then
- chary += 1
- animatedMotion ("up", false)
- else
- justTurn ("up")
- end if
- end if
- if chars (KEY_DOWN_ARROW) then
- if collision (15 - chary + 1, charx + 1) = false then
- chary -= 1
- animatedMotion ("down", false)
- else
- justTurn ("down")
- end if
- end if
- if chars (KEY_LEFT_ARROW) then
- if collision (15 - chary, charx) = false then
- charx -= 1
- animatedMotion ("left", false)
- else
- justTurn ("left")
- end if
- end if
- if chars (KEY_RIGHT_ARROW) then
- if collision (15 - chary, charx + 2) = false then
- charx += 1
- animatedMotion ("right", false)
- else
- justTurn ("right")
- end if
- end if
- end loop
Advertisement
Add Comment
Please, Sign In to add comment