Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %Platformer
- % Creates a window
- var winID : int := Window.Open ("graphics: 895;575, offscreenonly,nobuttonbar, title: Square²")
- %Score
- var scoreSeconds : int := 0
- %Username
- var username : string
- %Level Change
- var userMap1 : boolean := false
- % Type used for points and vectors to track
- type Vector :
- record
- x : real
- y : real
- end record
- % Holds keyboard data
- var pressedChars : array char of boolean
- var chars : array char of boolean
- Input.KeyDown (chars)
- pressedChars := chars
- % Position and velocity of the player
- var pos : Vector
- pos.x := 150;
- pos.y := 275
- var vel : Vector
- vel.x := 0;
- vel.y := 0
- % Position of the camera
- var cam : Vector
- cam.x := 0;
- cam.y := 0
- % Size of the player
- var size : Vector
- size.x := 20;
- size.y := 20
- %Player shape change
- var square, leaf, star : boolean
- square := true
- leaf := false
- star := false
- % Collision booleans and directions
- var isTouchingGround : boolean := false
- var isTouchingWall : boolean := false
- var wallDir : int := 0
- %Pause Key Variable
- var PauseKey : char
- %Font Varialbes
- var font1 : int := Font.New ("Fixedsys:30")
- var font2 : int := Font.New ("Fixedsys:12")
- %Variables for level changing
- var level1b : boolean := true
- var level2b : boolean := false
- %Wall Jump Enable/Disable
- var wallJumpAbility : boolean := true
- %User Colour
- var userColour : int := blue
- %Variables needed
- var numOfPeople : int := 10
- var names : array 1 .. numOfPeople of string %place to hold the names
- var scorse : array 1 .. numOfPeople of int %place to hold the scorse
- var fileName : string := "hiscores.txt" %name of the file where the top sorces will be placed and read from
- %Load high score file
- var fileIn : int %the file stream
- var i : int := 0 %this is a counter to tell what name we are on
- open : fileIn, fileName, get
- loop
- exit when eof (fileIn) %exit when end of file
- i += 1 %add one to the counter
- get : fileIn, names (i) %gets the name of the person at line i
- get : fileIn, scorse (i) %gets the sorcer of the person at line i
- end loop
- %Sorting Method
- %sort the high score list to put the person
- %with the highest sorce 1st and lowest last
- %bouble sort procedure
- %puts the arrays in order of smallest to biggest
- procedure sort
- for ii : 1 .. numOfPeople
- for iii : 2 .. numOfPeople
- if scorse (iii - 1) > scorse (iii) then
- %switchs the values
- var temp : int := scorse (iii - 1)
- scorse (iii - 1) := scorse (iii)
- scorse (iii) := temp
- %also have to swtich the names so they
- %keep lined up with the scorse
- var temp2 : string := names (iii - 1)
- names (iii - 1) := names (iii)
- names (iii) := temp2
- end if
- end for
- end for
- end sort
- var newIndex : int := 0 %the place to put this new sorce
- proc updateHiscore
- %Update highscore list
- sort
- %now we need to check if the newScore beats any of the old ones
- %NOTE: this could be done throw any searching alrgithem but
- %i am using this one b/c it is easy rather then fast
- %if the newScore is better then all of them
- if scoreSeconds < scorse (1) then
- newIndex := 1
- %else sreach for the spot where the new score fits
- else
- for k : 1 .. (numOfPeople - 1)
- if scoreSeconds < scorse (k) and scoreSeconds > scorse (k + 1) then
- newIndex := (k + 1)
- end if
- %chechtch any of thous pesky entrys with the same score
- if scoreSeconds > scorse (k) then
- newIndex := k
- end if
- end for
- end if
- %if newIndex = 0 then newScore dose not get on the list
- if newIndex not= 0 then
- %now we need to put the newScore and newName in the list in the right place, but 1st we have
- %to shift all the ones below it down.
- for decreasing j : numOfPeople .. (newIndex + 1)
- names (j) := names (j - 1)
- scorse (j) := scorse (j - 1)
- end for
- %now we simply place the new entry in
- names (newIndex) := username
- scorse (newIndex) := scoreSeconds
- end if
- end updateHiscore
- %Display hiscore list
- proc hiscoreWin
- var winID4 : int := Window.Open ("graphics: 500; 400, title: Hiscores")
- var highscoreback : int := Pic.FileNew ("GUI/highscore.jpg")
- %Rewrite highscores
- %Re-write and save new highscore
- open : newIndex, "hiscores.txt", put
- for d : 1 .. 10
- put : newIndex, names (d)
- put : newIndex, scorse (d)
- end for
- close : newIndex
- Pic.Draw (highscoreback, 0, 0, picMerge)
- sort
- %now we need a for loop to go throw each array and put that data on the screen
- var hiy : int := 8
- for d : 1 .. numOfPeople
- locate (hiy + d, 15)
- put d, ". ", names (d), " - ", scorse (d)
- end for
- loop
- if chars ('q') then
- quit
- end if
- end loop
- end hiscoreWin
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %Username Window
- var mapChoice : string
- proc usernameWin
- var winID3 : int := Window.Open ("graphics: 375; 230, title: Username")
- var usernamePicture : int := Pic.FileNew ("GUI/username.jpg")
- Pic.Draw (usernamePicture, 0, 0, picMerge)
- locate (9, 13)
- get username
- Window.Hide (winID3)
- Window.SetActive (winID)
- end usernameWin
- var userMap : int
- %Map Selection
- proc selectMap
- var mapDir : string
- var streamNumber : int
- var fileName : string
- var dir : string
- dir := Dir.Current + "/usermaps"
- streamNumber := Dir.Open (dir)
- assert streamNumber > 0
- var font : int := Font.New ("arial:12")
- var y : int := maxx div 2
- if userMap1 = true then
- var winID5 : int := Window.Open ("graphics: 595; 575, title: Map Selection")
- var mapSelectBack : int := Pic.FileNew ("GUI/mapselect.jpg")
- Pic.Draw (mapSelectBack, 0, 0, picCopy)
- locate (6, 8)
- for i : 1 .. 10
- fileName := Dir.Get (streamNumber)
- %put fileName
- Font.Draw (fileName, 50, y, font, red)
- y -= 15
- end for
- Dir.Close (streamNumber)
- get mapDir
- mapDir := "usermaps/" + mapDir %+ ".bmp"
- if File.Exists (mapDir) then
- locate (6, 40)
- put "File Found"
- delay (1000)
- else
- locate (6, 40)
- put "File Not Found"
- delay (1000)
- quit
- end if
- userMap := Pic.FileNew (mapDir)
- Window.Close (winID5)
- Window.SetActive (winID)
- end if
- end selectMap
- % Picture(s) used for background and collision detection
- var platform1 : int := Pic.FileNew ("GUI/map.jpg")
- %Console Window and Settings(code)
- var console : int := Pic.FileNew ("GUI/console.jpg")
- var consoleText : string
- var x, y, mouse : int
- var consoleTextFont : int := Font.New ("Arial:9")
- var realCommand : boolean := false
- var noclip : boolean := false
- proc consoleWindow
- var winID2 : int := Window.Open ("graphics: 370;340,nobuttonbar, title: Console")
- Mouse.Where (x, y, mouse)
- Pic.Draw (console, 0, 0, picCopy)
- locate (20, 4)
- colorback (26)
- get consoleText
- if consoleText = "cheats" then
- realCommand := true
- Font.Draw ("teleport1", 25, maxy - 105, consoleTextFont, white)
- Font.Draw ("teleport2", 25, maxy - 115, consoleTextFont, white)
- Font.Draw ("homepos", 25, maxy - 125, consoleTextFont, white)
- Font.Draw ("shrink", 25, maxy - 135, consoleTextFont, white)
- Font.Draw ("grow", 25, maxy - 145, consoleTextFont, white)
- Font.Draw ("normal", 25, maxy - 155, consoleTextFont, white)
- Font.Draw ("skip100", 25, maxy - 165, consoleTextFont, white)
- Font.Draw ("high", 25, maxy - 175, consoleTextFont, white)
- Font.Draw ("walljump1", 25, maxy - 185, consoleTextFont, white)
- Font.Draw ("walljump0", 25, maxy - 195, consoleTextFont, white)
- Font.Draw ("green", 25, maxy - 205, consoleTextFont, white)
- Font.Draw ("quit", 25, maxy - 215, consoleTextFont, white)
- Font.Draw ("square", 25, maxy - 225, consoleTextFont, white)
- Font.Draw ("leaf", 25, maxy - 235, consoleTextFont, white)
- Font.Draw ("star", 25, maxy - 245, consoleTextFont, white)
- Font.Draw ("noclip0", 25, maxy - 255, consoleTextFont, white)
- Font.Draw ("noclip1", 25, maxy - 265, consoleTextFont, white)
- end if
- if consoleText = "teleport1" then
- realCommand := true
- pos.x := 1150;
- pos.y := 175
- vel.x := 0;
- vel.y := 0
- end if
- if consoleText = "teleport2" then
- realCommand := true
- pos.x := 650;
- pos.y := 355
- vel.x := 0;
- vel.y := 0
- end if
- if consoleText = "homepos" then
- realCommand := true
- pos.x := 150;
- pos.y := 175
- vel.x := 0;
- vel.y := 0
- end if
- if consoleText = "shrink" then
- realCommand := true
- size.x -= 10;
- size.y -= 10
- end if
- if consoleText = "normal" then
- realCommand := true
- size.x := 20;
- size.y := 20
- end if
- if consoleText = "grow" then
- realCommand := true
- size.x += 10;
- size.y += 10
- end if
- if consoleText = "skip100" then
- realCommand := true
- pos.x += 100
- end if
- if consoleText = "higher" then
- realCommand := true
- vel.y += 250
- end if
- if consoleText = "walljump1" then
- realCommand := true
- wallJumpAbility := true
- end if
- if consoleText = "walljump0" then
- realCommand := true
- wallJumpAbility := false
- end if
- if consoleText = "quit" then
- Window.Hide (winID2)
- Window.SetActive (winID)
- end if
- if consoleText = "green" then
- realCommand := true
- userColour := green
- end if
- if consoleText = "square" then
- realCommand := true
- square := true
- star := false
- leaf := false
- end if
- if consoleText = "star" then
- realCommand := true
- square := false
- star := true
- leaf := false
- end if
- if consoleText = "leaf" then
- realCommand := true
- square := false
- star := false
- leaf := true
- end if
- if consoleText = "noclip1" then
- realCommand := true
- noclip := true
- end if
- if consoleText = "noclip0" then
- realCommand := true
- noclip := false
- end if
- if consoleText = "resettimer" then
- realCommand := true
- scoreSeconds := 0
- end if
- if realCommand = true then
- Font.Draw ("Console: User has implemented the following: ", 25, maxy - 55, consoleTextFont, white)
- Font.Draw (consoleText, 25, maxy - 70, consoleTextFont, white)
- delay (2000)
- else
- Font.Draw ("Invalid Command Line", 25, maxy - 55, consoleTextFont, white)
- end if
- Font.Draw ("You can only apply one command at a time.", 25, maxy - 290, consoleTextFont, white)
- delay (500)
- realCommand := false
- Window.Hide (winID2)
- Window.SetActive (winID)
- end consoleWindow
- % Faster to draw alot of fillboxes
- proc fillbox (x : real, y : real, x2 : real, y2 : real, c : int)
- if square = true then
- Draw.FillBox (round (x + cam.x), round (y + cam.y), round (x2 + cam.x), round (y2 + cam.y), userColour)
- elsif leaf = true then
- Draw.FillMapleLeaf (round (x + cam.x), round (y + cam.y), round (x2 + cam.x), round (y2 + cam.y), userColour)
- elsif star = true then
- Draw.FillStar (round (x + cam.x), round (y + cam.y), round (x2 + cam.x), round (y2 + cam.y), userColour)
- end if
- end fillbox
- proc deadScreen
- cls
- put "dead"
- end deadScreen
- proc levelChange
- % Draws background
- if userMap1 = false then
- Pic.Draw (platform1, round (cam.x), round (cam.y), picCopy)
- elsif userMap1 = true then
- Pic.Draw (userMap, round (cam.x), round (cam.y), picCopy)
- end if
- end levelChange
- proc level
- loop
- %Updates Score
- scoreSeconds := 1 + scoreSeconds
- %Fills non-picture areas with a distracting colour
- drawfill (-100, -100, green, black)
- % Get keyboard state
- Input.KeyDown (chars)
- %Pause button
- if chars (' ') then
- Font.Draw ("Game Paused", maxx div 2, maxy - 50, font1, red)
- Font.Draw ("Press any key to continue", maxx div 2, maxy - 100, font2, 11)
- Font.Draw (username, maxx div 2, maxy - 150, font2, 11)
- Font.Draw (intstr (scoreSeconds), maxx div 2, maxy - 200, font2, 11)
- Draw.FillStar (150, 285, 300, 400, yellow)
- View.Update
- PauseKey := getchar
- end if
- %Cheats button
- if chars ('c') and userMap1 = false then
- consoleWindow
- end if
- %Restart button
- if chars ('r') then
- pos.x := 150;
- pos.y := 155
- vel.x := 0;
- vel.y := 100
- end if
- % Move dependent of collision with level and what keys are down
- if (isTouchingGround) then
- if chars ('w') then
- vel.y += 15
- end if
- if chars ('a') then
- vel.x -= 1
- end if
- if chars ('d') then
- vel.x += 1
- end if
- else
- % Wall Jump
- if (isTouchingWall) and wallJumpAbility = true then
- if chars ('w') then
- vel.y += 15
- vel.x += 5 * wallDir
- end if
- end if
- if chars ('a') then
- vel.x -= 0.1
- end if
- if chars ('d') then
- vel.x += 0.1
- end if
- end if
- % isTouchingGround is by default false and also helps with jump
- isTouchingGround := false
- % If moving left
- if (round (vel.x) < 0) then
- if (whatdotcolour (round (pos.x + vel.x - size.x + cam.x), round (pos.y - size.y + cam.y)) = black or whatdotcolour (round (pos.x + vel.x - size.x + cam.x), round (pos.y + size.y +
- cam.y)) =
- black) and noclip = false then
- isTouchingWall := true
- wallDir := 1
- vel.x := 0
- else
- pos.x += vel.x
- isTouchingWall := false
- end if
- % If moving right
- elsif (round (vel.x) > 0) then
- % Does the player hit a wall?
- if (whatdotcolour (round (pos.x + vel.x + size.x + cam.x), round (pos.y - size.y + cam.y)) = black or whatdotcolour (round (pos.x + vel.x + size.x + cam.x), round (pos.y + size.y +
- cam.y)) =
- black) and noclip = false then
- % Find where the player hit the wall
- isTouchingWall := true
- wallDir := -1
- vel.x := 0
- else
- pos.x += vel.x
- isTouchingWall := false
- end if
- end if
- %If Dead
- if pos.y - size.y < -50 then
- %quit
- end if
- %If Winning Area
- if pos.x - size.x > maxx + 5800 and pos.y - size.y < 50 and userMap1 = false then
- Music.PlayFileStop
- Music.PlayFile ("music/LevelUpSound.wav")
- updateHiscore
- delay (1000)
- hiscoreWin
- exit
- end if
- if pos.x - size.x > 1075 and pos.x - size.x < 1300 and pos.y - size.y > 2750 and pos.y - size.y < 2900 then
- pos.x := 2250;
- pos.y := 550
- vel.x := 0;
- vel.y := 56
- end if
- if (vel.y < 0) then
- % Does the player hit a floor?
- if (whatdotcolour (round (pos.x - size.x + cam.x), round (pos.y + vel.y - size.y + cam.y)) = black or whatdotcolour (round (pos.x + size.x + cam.x), round (pos.y + vel.y - size.y +
- cam.y)) =
- black) then
- % Find where the player hit the floor
- for i : round (vel.y) .. 0
- if (whatdotcolour (round (pos.x - size.x + cam.x), round (pos.y + i - size.y + cam.y)) ~= black and whatdotcolour (round (pos.x + size.x + cam.x), round (pos.y + i -
- size.y +
- cam.y))
- ~= black) then
- % Move the player there
- pos.y := round (pos.y) + i;
- end if
- end for
- isTouchingGround := true
- vel.y := 0
- else
- pos.y += vel.y
- end if
- % If moving up
- elsif (vel.y > 0) then
- % Does the player hit a ceiling?
- if (whatdotcolour (round (pos.x - size.x + cam.x), round (pos.y + vel.y + size.y + cam.y)) = black or whatdotcolour (round (pos.x + size.x + cam.x), round (pos.y + vel.y + size.y +
- cam.y)) =
- black) and noclip = false then
- % Find where the player hit the ceiling
- for decreasing i : round (vel.y) .. 0
- if (whatdotcolour (round (pos.x - size.x + cam.x), round (pos.y + i + size.y + cam.y)) ~= black and whatdotcolour (round (pos.x + size.x + cam.x), round (pos.y + i +
- size.y +
- cam.y))
- ~= black) and noclip = false then
- % Move the player there
- pos.y := round (pos.y) + i;
- end if
- end for
- vel.y := 0
- else
- pos.y += vel.y
- end if
- end if
- % Move camera to center it on the player
- cam.x -= round ((pos.x + cam.x - maxx / 2) / 10)
- cam.y -= round ((pos.y + cam.y - maxy / 2) / 10)
- % Move downward to simulate gravity, less when against a wall
- if (isTouchingWall and vel.y < 0) and noclip = false then
- vel.y -= 9.8 / 30
- else
- vel.y -= 9.8 / 10
- end if
- % Set a maximum speed, less against a wall
- if (isTouchingWall) and (vel.y < -10) then
- vel.y := -10
- end if
- if (vel.y < -15) then
- vel.y := -15
- elsif (vel.y > 15) then
- vel.y := 15
- end if
- if (vel.x < -15) then
- vel.x := -15
- elsif (vel.x > 15) then
- vel.x := 15
- end if
- % Simulates friction
- if (isTouchingGround) then
- vel.x /= 1.2
- end if
- % Sets previous key states to the current key states
- pressedChars := chars
- % Clears
- cls
- levelChange
- % Draws player
- fillbox (pos.x - size.x, pos.y - size.y, pos.x + size.x, pos.y + size.y, blue)
- % Updates window
- Window.Update (winID)
- % Delays
- delay (8)
- end loop
- end level
- var backgroundTitle : int := Pic.FileNew ("GUI/title.jpg")
- var backgroundInstruction : int := Pic.FileNew ("GUI/instructions.jpg")
- var backgroundPassword : int := Pic.FileNew ("GUI/password.jpg")
- var password1 : string
- var backgroundMapCreator : int := Pic.FileNew ("GUI/createmapinstruction.jpg")
- var backgroundCredits : int := Pic.FileNew ("GUI/credits.jpg")
- proc instruction
- loop
- Input.KeyDown (chars)
- cls
- Pic.Draw (backgroundInstruction, 0, 0, picCopy)
- if chars (KEY_ENTER) then
- cls
- level
- end if
- View.Update
- end loop
- end instruction
- proc mapCreator
- loop
- View.Set ("offscreenonly")
- Pic.Draw (backgroundMapCreator, 0, 0, picCopy)
- View.Update
- end loop
- end mapCreator
- proc credits
- loop
- Input.KeyDown (chars)
- cls
- Pic.Draw (backgroundCredits, 0, 0, picCopy)
- if chars (KEY_ENTER) then
- cls
- level
- end if
- View.Update
- end loop
- end credits
- proc titlePage
- %Starts Playing Music
- %Music.PlayFileLoop ("Music.mp3")
- %Music.PlayFileLoop ("gamePlay.mp3")
- Music.PlayFileLoop ("music/derezzed.mp3")
- var x, y, mouse : int
- loop
- View.Set ("offscreenonly")
- Mouse.Where (x, y, mouse)
- Pic.Draw (backgroundTitle, 0, 0, picCopy)
- put x, " ", y
- if x > 458 and x < 698 and y > 405 and y < 464 and mouse = 1 then
- level
- end if
- if x > 509 and x < 747 and y > 322 and y < 381 and mouse = 1 then
- instruction
- View.Update
- end if
- if x > 459 and y > 238 and x < 697 and y < 299 and mouse = 1 then
- mapCreator
- end if
- if x > 459 and y > 72 and x < 699 and y < 132 and mouse = 1 then
- credits
- end if
- View.Update
- end loop
- end titlePage
- usernameWin
- selectMap
- titlePage
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement