/*
Please note, the map file sections *must* be 200 chars in length, or else it won't work. OK?
*/
setscreen ("graphics:600;400")
const Gravity := 2
const runSpeed := 10
const jumpSpeed := 20
const accelSpped := 1
const mapLength := 199
var chars : array char of boolean
var groundHeight : int := 60
var maxJumpHeight : int
var grabLevelFromFile : flexible array 1 .. 1 of string % Each different object group has its own spot in this array, before we parse each obj into individual chars.
var mapPartsArray : array 1 .. mapLength, 1 .. 7 of string % Our array for storing each different object parsed into individual chars.
var numbItemsInObjType : array 1 .. 20 of int % Here we will store how many items are in each object type. This is we don't segfault later.
var curMapObject : string % This is the string of the current type of object we are parsing
var curItemPosition : int % This is counting what individual block we are on.
var lngth : int % Show the length of the
var mapfile : int % this is the pointer turing uses for the I/O stream for the mapfile
var curObjectType : int % This is the type of the object we are parsing. IE: the ground blocks are a "1"
var numbObjectTypesToParse : int
var numbObjectTypesToRender : int
var numbItemsToRender : int
var loopCounter : int % Just a generic loop counter to count, guess what? loops!
var debugFont : int
var xpos : int
var ypos : int
var xvel : int
var yvel : int
var topImg : int
var bgImg : int
var marioImg : int
var marioSprite : int
var groundImg : int
var blockLvl1Img : int
var coinBlockLvl1Img : int
var blockLvl2Img : int
var coinBlockLvl2Img : int
var groundSprite : array 1 .. mapLength of int
var blockLvl1Sprite : array 1 .. mapLength of int
var blockLvl2Sprite : array 1 .. mapLength of int
var coinBlockLvl1Sprite : array 1 .. mapLength of int
var coinBlockLvl2Sprite : array 1 .. mapLength of int
curObjectType := 1
curItemPosition := 1
numbObjectTypesToParse := 0
curObjectType := 1
debugFont := Font.New ("serif:12")
topImg := Pic.FileNew ("images/TopBar.bmp")
bgImg := Pic.FileNew ("images/BG.bmp")
marioImg := Pic.FileNew ("images/Mario.bmp")
groundImg := Pic.FileNew ("images/BottomBrick.bmp")
blockLvl1Img := Pic.FileNew ("images/BrickBox.bmp")
coinBlockLvl1Img := Pic.FileNew ("images/CoinBox.bmp")
blockLvl2Img := Pic.FileNew ("images/BrickBox.bmp")
coinBlockLvl2Img := Pic.FileNew ("images/CoinBox.bmp")
marioSprite := Sprite.New (marioImg)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% This is for parsing the map file
open : mapfile, "levels/1.txt", get % eventually this will be removed and dynamically generate a list of levels for the user to choose
loop % grabbing the data from the level
exit when eof (mapfile) % exit the loop when we've reached the end of the mapfile
get : mapfile, grabLevelFromFile (upper (grabLevelFromFile)) % grabbing the text from the map file
new grabLevelFromFile, upper (grabLevelFromFile) + 1 % on the next loop move onto the next line in the map file
%put "Success! Map object #", curObjectType, " was parsed correctly: " .. % let's see if this succedes after each loop
%put grabLevelFromFile (curObjectType) % put the current ASCII character string into the grablevel array that holds the basic objects, not yet parsed to individual chars.
curObjectType := curObjectType + 1 % every time we parse a new line, we also move onto the next map object.
numbObjectTypesToParse := numbObjectTypesToParse + 1
% add up the total number of different objects in the map. See the def. by the variable 'numbObjects' for a complete description.
%delay (500)
end loop
curObjectType := 1
curItemPosition := 1
loop % Let's loop to parse all the map objects sections into characters in the 'mapPartsArray' array.
numbItemsInObjType (curObjectType) := 0
curMapObject := grabLevelFromFile (curObjectType) % setting the current type of object we are parsing
lngth := length (curMapObject) % grabbing the length of the current map object
%put grabLevelFromFile (curObjectType), " :: curObjectType" % print the current map file section we are parsing
%put curMapObject, " :: curMapObject" % make sure that the current "block" of code was inserted into it's string properly
%put curObjectType, " :: curObjectType" % more debug printing, this one shows what map object type we are parsing currently.
%put " "
%delay (500)
curItemPosition := 1
loop % loop until we parse the whole string into the array
mapPartsArray (curItemPosition, curObjectType) := curMapObject (1)
% ^^^^ make the the location in the array specified by 'curPosition' be equal to the first char of the current object of the map file
%delay (50) % slow so we can see what is going on
%put mapPartsArray (curItemPosition, curObjectType), " " .. % make sure things are being parsed correctly
curItemPosition := curItemPosition + 1 % lets add up how many blocks we've inspected
curMapObject := curMapObject (2 .. lngth) % shave off the first char of curMapObject. It's been stored in an array, we don't need it anymore.
lngth := length (curMapObject) % grab the new length after shaving off the first char
numbItemsInObjType (curObjectType) := numbItemsInObjType (curObjectType) + 1 % mapStats(curObjectType) holds the total number of characters in the current object (total number of "blocks"
exit when lngth = 0 % exit the loop when we've parsed the whole string
end loop
%put " "
curObjectType := curObjectType + 1 % why not move onto the next map object during the next loop iteration?
numbObjectTypesToParse := numbObjectTypesToParse - 1 % We've parsed one object, so remove it's count from the total
exit when numbObjectTypesToParse = 0 % end the loop once we've parsed all the map objects
end loop
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% This is actually the game. Everything above this is for parsing the map file.
curObjectType := 1
curItemPosition := 1
xpos := 285
ypos := 60
xvel := 5
yvel := 0
loopCounter := 1
Sprite.SetFrameRate (33)
Pic.Draw (bgImg, 0, 1, picCopy)
loop % Ugh. Turing only allows 1000 sprites. Shit, what will I do here?
coinBlockLvl2Sprite (curItemPosition) := Sprite.New (coinBlockLvl1Img)
Sprite.Show (coinBlockLvl2Sprite (curItemPosition))
Sprite.SetPosition ((coinBlockLvl2Sprite (curItemPosition)), -30, 120, false)
blockLvl2Sprite (curItemPosition) := Sprite.New (blockLvl2Img)
Sprite.Show (blockLvl2Sprite (curItemPosition))
Sprite.SetPosition ((blockLvl2Sprite (curItemPosition)), -30, 120, false)
coinBlockLvl1Sprite (curItemPosition) := Sprite.New (coinBlockLvl1Img)
Sprite.Show (coinBlockLvl1Sprite (curItemPosition))
Sprite.SetPosition ((coinBlockLvl1Sprite (curItemPosition)), -30, 120, false)
blockLvl1Sprite (curItemPosition) := Sprite.New (blockLvl1Img)
Sprite.Show (blockLvl1Sprite (curItemPosition))
Sprite.SetPosition ((blockLvl1Sprite (curItemPosition)), -30, 120, false)
groundSprite (curItemPosition) := Sprite.New (groundImg)
Sprite.Show (groundSprite (curItemPosition))
Sprite.SetPosition ((groundSprite (curItemPosition)), -30, 0, false)
curItemPosition := curItemPosition + 1
exit when curItemPosition = mapLength
end loop
maxJumpHeight := 1
loop
Pic.Draw (topImg, 0, 370, picMerge)
Font.Draw ("xpos: " + intstr (xpos), 10, 380, debugFont, black)
Font.Draw ("ypos: " + intstr (ypos), 100, 380, debugFont, black)
Font.Draw ("maxJumpHeight: " + intstr (maxJumpHeight), 190, 380, debugFont, black)
if groundHeight not= 60 then
if ypos < 60 then
Font.Draw ("Dead!", 360, 380, debugFont, 40)
end if
end if
Sprite.Show (marioSprite)
Sprite.SetPosition (marioSprite, 285, ypos, false)
Input.KeyDown (chars)
curItemPosition := 1
loop
if mapPartsArray (curItemPosition, 1) = "1" then
Sprite.SetPosition (groundSprite (curItemPosition), (curItemPosition * 30 - xpos), 0, false)
end if
if mapPartsArray (curItemPosition, 1) = "0" then
end if
curItemPosition := curItemPosition + 1
exit when curItemPosition = mapLength
end loop
curItemPosition := 1
loop
if mapPartsArray (curItemPosition, 2) = "1" then
Sprite.SetPosition (blockLvl1Sprite (curItemPosition), (curItemPosition * 30 - xpos), 120, false)
end if
if mapPartsArray (curItemPosition, 2) = "0" then
end if
curItemPosition := curItemPosition + 1
exit when curItemPosition = mapLength
end loop
curItemPosition := 1
loop
if mapPartsArray (curItemPosition, 3) = "1" then
Sprite.SetPosition (coinBlockLvl1Sprite (curItemPosition), (curItemPosition * 30 - xpos), 120, false)
end if
if mapPartsArray (curItemPosition, 3) = "0" then
end if
curItemPosition := curItemPosition + 1
exit when curItemPosition = mapLength
end loop
curItemPosition := 1
loop
if mapPartsArray (curItemPosition, 4) = "1" then
Sprite.SetPosition (blockLvl2Sprite (curItemPosition), (curItemPosition * 30 - xpos), 210, false)
end if
if mapPartsArray (curItemPosition, 4) = "0" then
end if
curItemPosition := curItemPosition + 1
exit when curItemPosition = mapLength
end loop
curItemPosition := 1
loop
if mapPartsArray (curItemPosition, 5) = "1" then
Sprite.SetPosition (coinBlockLvl2Sprite (curItemPosition), (curItemPosition * 30 - xpos), 210, false)
end if
if mapPartsArray (curItemPosition, 5) = "0" then
end if
curItemPosition := curItemPosition + 1
exit when curItemPosition = mapLength
end loop
curItemPosition := 1
loop
curItemPosition := curItemPosition + 1
if ypos < 120 then
if mapPartsArray (curItemPosition, 1) = "0" then
if (curItemPosition * 30 - xpos) > 269 then
if (curItemPosition * 30 - xpos) < 301 then
groundHeight := -50
exit when 1 = 1
else
groundHeight := 60
end if
end if
end if
end if
if curItemPosition = mapLength then
exit when 1 = 1
end if
end loop
if chars (KEY_RIGHT_ARROW) then
%put "r"
xpos := xpos + xvel
end if
if chars (KEY_LEFT_ARROW) then
xpos := xpos - xvel
end if
if chars (KEY_UP_ARROW) and ypos = groundHeight then
yvel := jumpSpeed
end if
ypos := ypos + yvel
yvel := yvel - Gravity
if ypos < groundHeight then
yvel := 0
ypos := groundHeight
end if
if chars ('x') then
put "Program Terminated by User"
exit when 1 = 1
end if
delay (25)
end loop