Posted 21 April 2012 - 07:16 AM
I'm making a game like super mario brothers but for NeXuS (a programming team i made with a few others)
This is the current code:
We currently have:
How to add a new level:
Now, after "end –After here" add:
Congratulations! You just made a new level.
Join this level by making a teleporter or chaning local level = 1; in line 6 to local level = levelid;
Ex)
Coming soon:
This is the current code:
local scroll = 0;
local jump = 0;
local char = ">";
local coins = 0;
local x,y = term.getSize()
local level = 1;
function newCoin(posX, posY)
term.setCursorPos(posX - scroll, posY + jump)
coin = "O";
if posX - scroll ~= x-1 then --
if(posX - scroll == x/2 and posY + jump == y-10)then
coins = coins+1
coin = ""
else
write(coin)
end
end
end
function floor(param1)
for i=1,x-1 do
term.setCursorPos(i, y-9 + jump)
write(param1)
end
end
function newTeleporter(posX, posY, levelid, title)
term.setCursorPos(posX - scroll, posY + jump)
if posX - scroll ~= x-1 then --
if(posX - scroll == x/2 and posY + jump == y-10)then
level = levelid
else
write(title)
end
end
end
function world()
if(level == 1)then
floor("A")
for i = 1,5 do
newCoin(x/2-i, y-14)
end
newTeleporter(x/2-3, y-10, 999, "X")
elseif(level == 999)then
floor("O")
for i = 1,x-1 do
newCoin(x/2-i, y-14)
end
end
end
function redraw()
term.clear()
term.setCursorPos(1,1)
write("Coins: " ..coins.. " World: 0-" ..level)
term.setCursorPos(x/2, y-10)
write(char)
world()
end
while true do
redraw()
local event, a, b = os.pullEvent();
if(event == "char" and a == "a")then
scroll = scroll-1
char = "<"
elseif(event == "char" and a == "d")then
scroll = scroll+1
char = ">"
elseif(event == "key" and a == 57)then
jump = 1
for i=1,4 do
sleep(0.1)
jump = i
redraw()
end
for i=1,4 do
sleep(0.1)
jump = jump-i
redraw()
end
jump = 0
end
end
(Formatted: http://pastebin.com/3Wah0Grp)We currently have:
floor(String) = Will repeat String across the screen 1 block below your character.
newCoin(x, y) = Will make a Coin ("O") in the x, y with scrolling
newTeleporter(x, y, levelid, String) = Will print "String" at the x, y. Touching it will teleport your player to the level "levelid"
How to add a new level:
Spoiler
We gave you some examples, at world() it shows this:
function world()
if(level == 1)then
floor("A")
for i = 1,5 do
newCoin(x/2-i, y-14)
end
newTeleporter(x/2-3, y-10, 999, "X")
elseif(level == 999)then
floor("O")
for i = 1,x-1 do
newCoin(x/2-i, y-14)
end --After here
end
end
Now, after "end –After here" add:
elseif(level == levelid)then
--level code
Congratulations! You just made a new level.
Join this level by making a teleporter or chaning local level = 1; in line 6 to local level = levelid;
Ex)
function world()
if(level == 1)then
floor("A")
for i = 1,5 do
newCoin(x/2-i, y-14)
end
newTeleporter(x/2-3, y-10, 999, "X")
elseif(level == 999)then
floor("O")
for i = 1,x-1 do
newCoin(x/2-i, y-14)
end --After here
elseif(level == 2)then
floor("A")
newCoin(x/2-3, y-14)
end
end
Coming soon:
- newLevel(levelid)
- Making coins disappear on touch
- newBlock(x, y, String)