%%Tiling Engine For Mario v1.0
setscreen ("graphics:640;640")
setscreen ("offscreenonly")
%%Declare Variables
const td : int := 20 %%TILES DOWN ***
const ta : int := 72 %%TILES ACROSS (THE LENGTH OF THE LEVEL)
const TileWidth : int := 32 %%TILE WIDTH ***
const nt : int := 5 %%NUMBER OF TILES BEING USED
const background : int := Pic.FileNew ("tiles/Back2.bmp")
var loader : array 1 .. 400 of int
var level1 : array 0 .. 5 of int
var Across : array 1 .. ta of string
var rander, tiles, tnum, StartPosition, lchng : int
var Locations : array 1 .. (ta * td) of string
var TileImages : array 1 .. (ta * td) of int
var chars : array char of boolean
var lend : int := (TileWidth * ta - 640) * -1
var jc : int := 14
var mem2, do : int := 1
var cntr : int := 0
var enemy2 : int
open : tiles, "tiles.txt", get
open : enemy2, "enemy.txt", get
var achng : int := 1
var LVS : int := 3
var SCORE : int := 000
var ex, ey, ed : flexible array 1 .. 0 of int
var enemy : flexible array 1 .. 0, 1 .. 0 of int
var echng, echng2 : flexible array 1 .. 0 of int
var ecnt : int := 1
var deaths : flexible array 1 .. 0 of string
var test : string := "f"
%%Mario Parameters
var mx, my, mcount, chng, vchng, mbase : int
var chars1 : array char of boolean
var jumpf : int := 1
var dir : string
mbase := 32
dir := "right"
mx := 1
my := mbase
chng := 8
mcount := 1
var mario : array 1 .. 8 of int
var jumping, jumping2 : string := "false"
var shroom : int
shroom := Pic.FileNew ("Question Block/1up.bmp")
Pic.SetTransparentColor (shroom, white)
var shroomer : string := "f"
var schng : int := 5
%%Loads Mario
for i : 1 .. 8
mario (i) := Pic.FileNew ("mario" + intstr (i) + ".BMP")
end for
Pic.Draw (mario (1), mx, my, picMerge)
%%Load The Background
Pic.Draw (background, 1, 1, picCopy)
%%Load the map into an array
StartPosition := 0
for i : 1 .. td
for ii : 1 .. ta
exit when eof (tiles)
get : tiles, Across (ii)
end for
for ii : 1 .. ta
Locations (ii + StartPosition) := Across (ii)
if strint (Locations (ii + StartPosition)) not= 2 then
cntr := cntr + 1
end if
end for
StartPosition += ta
end for
close : tiles
%%Load up the tiles
for i : 1 .. 8
TileImages (i) := Pic.FileNew ("tiles/" + intstr (i) + ".bmp") %Load every image, in order, from the file folder that holds the tiles.
end for
%%Make White Tiles Transparent
for i : 1 .. (ta * td)
Pic.SetTransparentColor (TileImages (strint (Locations (i))), white)
end for
lchng := 0
var cx, cy, cd : array 1 .. cntr of int
var sx, sy, plh : int := 0
var sx2, sy2 : int := 0
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%COLLISION DETECTION VERTICLE%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function detect (n : string, x : int, y : int) : string
for i : 1 .. cntr
if (x + 32) >= cx (i) and x <= (cx (i) + 32) and (y + 56) >= cy (i) and y <= (cy (i) + 32) then
if y = cy (i) + 32 and x + 56 > cx (i) and n = "u" then
result "u"
elsif y + 56 >= cy (i) and x < cx (i) + 6 and x + 56 > cx (i) + 26 and n = "d" then
if cd (i) = 4 then
shroomer := "t"
plh := i
sx2 := cx (i)
sy2 := cy (i)
end if
result "d"
end if
end if
end for
result "f"
end detect
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%COLLISION DETECTION HORIZONTAL%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function detect2 (n : string, x : int, y : int) : string
for i : 1 .. cntr
if (x + 32) >= cx (i) and x <= (cx (i) + 32) and (y + 56) >= cy (i) and y <= (cy (i) + 32) then
if x + 32 <= cx (i) + 6 and y + 1 < cy (i) + 32 and n = "r" then
result "r"
end if
if x >= cx (i) + 25 and y + 1 < cy (i) + 32 and n = "l" then
result "l"
end if
end if
end for
result "f"
end detect2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% process music
% Music.PlayFile ("music.MID")
% end music
% fork music
%%The Tile Mapper
loop
Input.KeyDown (chars)
if chars (KEY_RIGHT_ARROW) then
if mx >= 320 and lchng >= lend and detect2 ("r", mx, my) not= "r" then
lchng := lchng - 5
end if
end if
if chars (KEY_LEFT_ARROW) then
if lchng < 0 and mx <= 329 and detect2 ("l", mx, my) not= "l" then
lchng := lchng + 5
end if
end if
Pic.Draw (background, 1, 1, picCopy)
var XPositionCounter : int := 0
var YPositionCounter : int := td
for i : 1 .. (ta * td)
if XPositionCounter = ta then
YPositionCounter -= 1
XPositionCounter := 0
end if
if YPositionCounter = 0 then
YPositionCounter := 0
end if
Pic.Draw (TileImages (strint (Locations (i))), (TileWidth * XPositionCounter + lchng), (TileWidth * YPositionCounter - TileWidth), picMerge)
if strint (Locations (i)) not= 2 then
if mem2 > cntr then
mem2 := 1
end if
cx (mem2) := TileWidth * XPositionCounter + lchng
cy (mem2) := TileWidth * YPositionCounter - TileWidth
cd (mem2) := strint (Locations (i))
mem2 := mem2 + 1
end if
XPositionCounter += 1
end for
loop
new ex , achng
new ey , achng
new ed , achng
new enemy, achng, 2
new deaths , achng
new echng , achng
new echng2, achng
get : enemy2, ed (achng)
put ed (achng)
exit when eof (enemy2)
achng := achng + 1
end loop
for i : 1 .. achng
for j : 1 .. 2
enemy (i, j) := Pic.FileNew ("tiles/4" + intstr (j) + ".bmp")
end for
end for
for i : 1 .. achng
echng (i) := 4
echng2 (i) := 7
deaths (i) := "f"
end for
put achng
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%One Up Shroom%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if shroomer = "t" then
Pic.Draw (shroom, cx (plh) + sx, cy (plh) + sy, picMerge)
if sy + cy (plh) < sy2 + 32 then
sy := sy + 1
end if
if sy + cy (plh) > sy2 + 31 then
sx := sx + schng
end if
if detect2 ("r", sx + cx (plh), sy + cy (plh)) = "r" then
schng := schng * -1
end if
if detect2 ("l", sx + cx (plh), sy + cy (plh)) = "l" then
schng := schng * -1
end if
if mx + 56 > sx + cx (plh) and mx < sx + 32 + cx (plh) and my < sy + 32 + cy (plh) and my + 56 > sy + cy (plh) then
shroomer := "f"
LVS := LVS + 1
SCORE := SCORE + 100
end if
end if
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%ENEMY CONTROL%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i : 1 .. achng
if deaths (i) = "f" then
Pic.Draw (enemy (i, ecnt), cx (ed (i)) + ex (i), cy (ed (i)) + 32, picMerge)
ex (i) := ex (i) + echng (i)
if detect2 ("l", ex (i) + cx (ed (i)), ey (i)) = "l" then
echng (i) := echng (i) * -1
end if
if detect2 ("r", ex (i) + cx (ed (i)), ey (i)) = "r" then
echng (i) := echng (i) * -1
end if
if detect ("u", ex (i) + cx (ed (i)), ey (i)) not= "u" then
ey (i) := ey (i) - 7
end if
if mx + 32 > ex (i) + cx (ed (i)) and mx < ex (i) + cx (ed (i)) + 32 and my < ey (i) + 32 and my + 56 > ey (i) then
test := "t"
if my > ey (i) + 24 and jumping2 = "true" then
Pic.Free (enemy (i, ecnt))
deaths (i) := "t"
jumping := "true"
SCORE := SCORE + 200
end if
else
test := "f"
end if
end if
end for
if ecnt < 2 then
ecnt := 2
else
ecnt := 1
end if
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%MARIO%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Walking Right Sequence
Input.KeyDown (chars1)
if chars1 (KEY_RIGHT_ARROW) and jumping = "false" and jumping2 = "false" then %Code for walking right
dir := "right"
if mcount = 2 or mcount > 2 then
mcount := 1
elsif mcount < 2 then
mcount := mcount + 1
end if
if mx < 320 and detect2 ("r", mx, my) not= "r" then
for i : 1 .. chng
mx := mx + 1
exit when detect ("r", mx, my) = "r"
end for
end if
if lchng <= lend and detect2 ("r", mx, my) not= "r" then
for i : 1 .. chng
mx := mx + 1
exit when detect ("r", mx, my) = "r"
end for
end if
Pic.Draw (mario (mcount), mx, my, picMerge)
end if
delay (20)
%Jumping Sequence
if chars (KEY_UP_ARROW) and jumpf = 1 then
if jumping = "false" and jumping2 = "false" then
jumping := "true"
jc := 14
jumpf := 0
end if
end if
if jumping = "true" and jumping2 = "false" then %Code for Jumping
if chars1 (KEY_RIGHT_ARROW) then
if mx < 320 and detect2 ("r", mx, my) not= "r" then
for i : 1 .. chng
mx := mx + 1
exit when detect ("r", mx, my) = "r"
end for
end if
if lchng <= lend and detect2 ("r", mx, my) not= "r" then
for i : 1 .. chng
mx := mx + 1
exit when detect ("r", mx, my) = "r"
end for
end if
dir := "right"
end if
if chars1 (KEY_LEFT_ARROW) then
if mx < 320 and detect2 ("l", mx, my) not= "l" then
for i : 1 .. chng
mx := mx - 1
exit when detect ("l", mx, my) = "l"
end for
end if
if lchng <= lend and detect2 ("l", mx, my) not= "l" then
mx := mx - chng
end if
dir := "left"
end if
if dir = "right" then
mcount := 3
else
mcount := 8
end if
for i : 1 .. jc
my := my + 1
exit when detect ("d", mx, my) = "d"
end for
jc := jc - 1
if detect ("d", mx, my) = "d" or jc = 0 then
jumping2 := "true"
jumping := "false"
end if
Pic.Draw (mario (mcount), mx, my, picMerge)
end if
if jumping2 = "true" then
if chars1 (KEY_RIGHT_ARROW) then
if mx < 320 and detect2 ("r", mx, my) not= "r" then
mx := mx + chng
exit when detect ("r", mx, my) = "r"
end if
if lchng <= lend and detect2 ("r", mx, my) not= "r" then
for i : 1 .. chng
mx := mx + 1
exit when detect ("r", mx, my) = "r"
end for
end if
dir := "right"
end if
if chars1 (KEY_LEFT_ARROW) then
if mx < 320 and detect2 ("l", mx, my) not= "l" then
for i : 1 .. chng
mx := mx - 1
exit when detect ("l", mx, my) = "l"
end for
end if
if lchng <= lend and detect2 ("l", mx, my) not= "l" then
mx := mx - chng
exit when detect ("l", mx, my) = "l"
end if
dir := "left"
end if
if dir = "right" then
mcount := 6
else
mcount := 7
end if
for i : 1 .. jc
my := my - 1
exit when detect ("u", mx, my) = "u"
end for
if detect ("u", mx, my) not= "u" then
jc := jc + 1
end if
Pic.Draw (mario (mcount), mx, my, picMerge)
if detect ("u", mx, my) = "u" then
jumping2 := "false"
if dir = "right" then
mcount := 1
else
mcount := 4
end if
end if
end if
if my > 32 and detect ("u", mx, my) not= "u" and jumping = "false" and jumping2 = "false" then
jumping2 := "true"
end if
if chars (KEY_UP_ARROW) = false then
jumpf := 1
end if
%Walking Left Sequence
if chars1 (KEY_LEFT_ARROW) and jumping = "false" and jumping2 = "false" then %Code for walking left
dir := "left"
if mcount = 5 or mcount < 4 then
mcount := 4
elsif mcount < 5 then
mcount := mcount + 1
end if
if lchng = 0 and detect2 ("l", mx, my) not= "l" then
for i : 1 .. chng
mx := mx - 1
exit when detect ("l", mx, my) = "l"
end for
end if
if lchng <= lend and detect2 ("l", mx, my) = "l" then
for i : 1 .. chng
mx := mx - 1
exit when detect ("l", mx, my) = "l"
end for
end if
Pic.Draw (mario (mcount), mx, my, picMerge)
end if
%Static Sequence
if chars1 (KEY_RIGHT_ARROW) = false and chars1 (KEY_LEFT_ARROW) = false and chars1 (KEY_UP_ARROW) = false and jumping = "false" and jumping2 = "false" then %If Static...
if mcount = 4 or mcount = 5 then
mcount := 4
Pic.Draw (mario (mcount), mx, my, picMerge)
elsif mcount = 1 or mcount = 2 then
mcount := 1
Pic.Draw (mario (mcount), mx, my, picMerge)
end if
end if
put ex (3) + cx (3)
put mx
put "Lives: ", LVS, " Score: ", SCORE
View.Update
cls
end loop
|