|
Post by warspyking on Mar 21, 2015 15:37:11 GMT
Alright, in attempt to bring up some activeness, I've created this thread. You have 2 options: 1. Share some of your own clever code 2. Share an idea for someone else to code Or of course you can do both I can't wait to see the results.
|
|
|
Post by Thijs on Mar 21, 2015 17:17:02 GMT
Convert decimal to binary numbers.
function DecToBin(Numb)if(Numb)then Numb=tonumber(Numb)c1=Numb%1==0 c2=Numb>=0 c3=Numb<=8.988e+307 if(not c3)then error'\nconverting failure\n(decimal is higher than\nthe function can handle,\nmax is 8.988e+307)'end if(not c1 and not c2)then error'converting failure\n(negative decimal)\n(non-rounded decimal)'end if(not c1)then error'converting failure\n(non-rounded decimal)'end if(not c2)then error'converting failure\n(negative decimal)'end if(Numb==0)then return'0'end function BinExpRange(Num)if(Num)then if type(Num)=='number'then cRng=1 Done=false while(not Done)do if(Num>cRng)then cRng=cRng*2 else Done=true end end return cRng end end end Rng=BinExpRange(Numb)LeftOver=Numb Done=false b=''while(not Done)do if(LeftOver-Rng>=0)then LeftOver=LeftOver-Rng b=b..'1'Rng=Rng/2 if(LeftOver==0)then b=b..string.rep('0',math.log(Rng*2,2))Done=true end else Rng=Rng/2 b=b..'0'end end return b end end
|
|
|
Post by warspyking on Mar 22, 2015 9:42:08 GMT
Wow, cool
|
|
Atom
Junior Member
Posts: 81
|
Post by Atom on Mar 22, 2015 11:56:43 GMT
And if you want to do the opposite, it is much easier, just use this:
bin = 101010101 dec = tonumber(bin, 2)
|
|
|
Post by Thijs on Mar 22, 2015 13:09:04 GMT
Ty Yea indeed, but there are no build in functions for decimal to binary So I made my own, a year ago or so
|
|
|
Post by Admin on Apr 14, 2015 14:23:07 GMT
Alright, in attempt to bring up some activeness, I've created this thread. You have 2 options: 1. Share some of your own clever code 2. Share an idea for someone else to code Or of course you can do both I can't wait to see the results. how about making Pong and many other Atari/Arcade like games. making LED display where you can shift the display in any of the four directions. making painter that saves/loads images in order to use them in your games. with the ability to zoom in/out. making UI elements other than buttons. making a graphical keyboard module (like NumPad example) to use for input. I can keep going on but these are enough for now
|
|
|
Post by warspyking on Apr 15, 2015 1:48:05 GMT
Alright, in attempt to bring up some activeness, I've created this thread. You have 2 options: 1. Share some of your own clever code 2. Share an idea for someone else to code Or of course you can do both I can't wait to see the results. how about making Pong and many other Atari/Arcade like games. making LED display where you can shift the display in any of the four directions. making painter that saves/loads images in order to use them in your games. with the ability to zoom in/out. making UI elements other than buttons. making a graphical keyboard module (like NumPad example) to use for input. I can keep going on but these are enough for now Wow, nice ideas Admin! I already made the Atari game Centipede. Right now I'm making Simon
|
|
|
Post by Tag365 on Apr 18, 2015 4:26:40 GMT
My animated main menu background for my game involves the use of coroutines. It dynamically updates to load the world you last played. The camera moves around randomly though. Quite good if I say so myself.
Here is the source for the main menu:
-- Main menu. function mainmenu() draw.tracktouches(mbegintouch, mtouch, mendtouch) startx, starty = posx, posy local loadworldco = coroutine.create(loadworldmainmenu) loadworldlistco = coroutine.create(updateworldlist) math.randomseed(sys.gettime()) local movex, movey = math.random()*8 - 4, math.random()*8 - 4 local timeperlocationchange = 30 + (math.random()*20 - 10) local trans = 2 local timestart = gettime() local worldhasloaded = false worldlistloaded = false coroutine.resume(loadworldco) coroutine.resume(loadworldlistco) while true do draw.tracktouches(mbegintouch, mtouch, mendtouch) draw.doevents() coroutine.resume(loadworldlistco) -- Handle the animated main menu. if worldhasloaded then posx, posy = posx + movex, -math.abs(posy - movey) math.randomseed(sys.gettime()) movex, movey = movex + (math.random()*1 - .5), movey + (math.random()*1 - .5) if gettime() - timestart > timeperlocationchange + trans then posx = math.random()*2000000 - 1000000 posy = -math.random()*16000 timestart = gettime() end handlegame() else err, worldhasloaded = coroutine.resume(loadworldco) err, worldlistloaded = coroutine.resume(loadworldlistco) --print(worldhasloaded) timestart = gettime() end savedisabledbygame = true -- Draw the main menu. draw.beginframe() if worldhasloaded then drawbackground() err, msg = pcall(drawterrain) if not err then print("error when drawing animated menu: "..msg) end if gettime() - timestart > timeperlocationchange then draw.clear({0, 0, 0, (gettime() - timestart - timeperlocationchange)/trans}) elseif gettime() - timestart < trans then draw.clear({0, 0, 0, 1 - (gettime() - timestart)/trans}) end else draw.clear(draw.black) draw.setfont("Arial", 48) draw.stringinrect("Touch Lua Builder", 0, 36, scrx, scry*.5, draw.white) draw.setfont("Arial", 16) end drawbutton("Play Game", scrx*.5 - 128, scry - 156, scrx*.5 + 128, scry - 120) drawbutton("Settings", scrx*.5 - 128, scry - 120, scrx*.5 + 128, scry - 84) drawbutton("Exit Game", scrx*.5 - 128, scry - 84, scrx*.5 + 128, scry - 48) drawbutton("Computer Test", scrx*.5 - 128, scry - 48, scrx*.5 + 128, scry - 12) draw.endframe() -- Check which menu we need to go to. if gotomenu then if gotomenu == "settings" then settings() elseif gotomenu == "worlds" then selectworldmenu() elseif gotomenu == "computerTest" then local id = computers.newComputer() computers.startComputer(id) computers.switchToComputer(id) end gotomenu = nil end if returnfrommainmenu then returnfrommainmenu = false return end end end
|
|
|
Post by warspyking on Apr 18, 2015 9:12:14 GMT
My animated main menu background for my game involves the use of coroutines. It dynamically updates to load the world you last played. The camera moves around randomly though. Quite good if I say so myself. Here is the source for the main menu: -- Main menu. function mainmenu() draw.tracktouches(mbegintouch, mtouch, mendtouch) startx, starty = posx, posy local loadworldco = coroutine.create(loadworldmainmenu) loadworldlistco = coroutine.create(updateworldlist) math.randomseed(sys.gettime()) local movex, movey = math.random()*8 - 4, math.random()*8 - 4 local timeperlocationchange = 30 + (math.random()*20 - 10) local trans = 2 local timestart = gettime() local worldhasloaded = false worldlistloaded = false coroutine.resume(loadworldco) coroutine.resume(loadworldlistco) while true do draw.tracktouches(mbegintouch, mtouch, mendtouch) draw.doevents() coroutine.resume(loadworldlistco) -- Handle the animated main menu. if worldhasloaded then posx, posy = posx + movex, -math.abs(posy - movey) math.randomseed(sys.gettime()) movex, movey = movex + (math.random()*1 - .5), movey + (math.random()*1 - .5) if gettime() - timestart > timeperlocationchange + trans then posx = math.random()*2000000 - 1000000 posy = -math.random()*16000 timestart = gettime() end handlegame() else err, worldhasloaded = coroutine.resume(loadworldco) err, worldlistloaded = coroutine.resume(loadworldlistco) --print(worldhasloaded) timestart = gettime() end savedisabledbygame = true -- Draw the main menu. draw.beginframe() if worldhasloaded then drawbackground() err, msg = pcall(drawterrain) if not err then print("error when drawing animated menu: "..msg) end if gettime() - timestart > timeperlocationchange then draw.clear({0, 0, 0, (gettime() - timestart - timeperlocationchange)/trans}) elseif gettime() - timestart < trans then draw.clear({0, 0, 0, 1 - (gettime() - timestart)/trans}) end else draw.clear(draw.black) draw.setfont("Arial", 48) draw.stringinrect("Touch Lua Builder", 0, 36, scrx, scry*.5, draw.white) draw.setfont("Arial", 16) end drawbutton("Play Game", scrx*.5 - 128, scry - 156, scrx*.5 + 128, scry - 120) drawbutton("Settings", scrx*.5 - 128, scry - 120, scrx*.5 + 128, scry - 84) drawbutton("Exit Game", scrx*.5 - 128, scry - 84, scrx*.5 + 128, scry - 48) drawbutton("Computer Test", scrx*.5 - 128, scry - 48, scrx*.5 + 128, scry - 12) draw.endframe() -- Check which menu we need to go to. if gotomenu then if gotomenu == "settings" then settings() elseif gotomenu == "worlds" then selectworldmenu() elseif gotomenu == "computerTest" then local id = computers.newComputer() computers.startComputer(id) computers.switchToComputer(id) end gotomenu = nil end if returnfrommainmenu then returnfrommainmenu = false return end end end [/quote]
|
|
|
Post by lars on Apr 20, 2015 18:29:37 GMT
I am working on a draw UI, which is based on objects (Button = Buttons.create() and then Button.setText("Click Me")), do you understand? At this time the Buttons works and i'm working on a Navbar and Textbox
|
|
|
Post by Thijs on Apr 20, 2015 19:59:50 GMT
how about making Pong and many other Atari/Arcade like games. making LED display where you can shift the display in any of the four directions. making painter that saves/loads images in order to use them in your games. with the ability to zoom in/out. making UI elements other than buttons. making a graphical keyboard module (like NumPad example) to use for input. I can keep going on but these are enough for now Wow, nice ideas Admin! I already made the Atari game Centipede. Right now I'm making Simon Well... Saving images is possible but the files will be VERY big...
|
|
Atom
Junior Member
Posts: 81
|
Post by Atom on Apr 20, 2015 20:44:34 GMT
I am working on a draw UI, which is based on objects (Button = Buttons.create() and then Button.setText("Click Me")), do you understand? At this time the Buttons works and i'm working on a Navbar and Textbox I made something like this too and it included buttons, scrollbars and lists It's really useful I hope you'll share it on the forum!
|
|
|
Post by warspyking on Nov 8, 2015 7:15:11 GMT
Bump. It's been a while, anybody got anything new?
|
|
|
Post by lars on Nov 8, 2015 21:09:16 GMT
Got something.
This function allows you to combine 2 Colors to 1. Examples:
combineColors(draw.green, draw.red, 0) --returns draw.green combineColors(draw.green, draw.red, 1) --returns draw.red combineColors(draw.green, draw.red, 0.35) --returns a mix of: 35% green and 65% red
Here the function, with some extras:
function combineColors(color1, color2, level)
level = level * 100
--red reddiff = -1*(color1["red"] - color2["red"]) redpixel = reddiff / 100 print("Red difference: "..reddiff)
--blue bluediff = -1*(color1["blue"] - color2["blue"]) bluepixel = bluediff / 100 print("Blue difference: "..bluediff)
--green greendiff = -1*(color1["green"] - color2["green"]) greenpixel = greendiff / 100 print("Green difference: "..greendiff)
newred = color1["red"] + level * redpixel newblue = color1["blue"] + level * bluepixel newgreen = color1["green"] + level * greenpixel newcolor = {red=newred, blue=newblue, green=newgreen, alpha=1}
print("Red: "..newcolor["red"]) print("Blue: "..newcolor["blue"]) print("Green: "..newcolor["green"])
print("How to define in script:\nmyColor = {red=\""..newcolor["red"].."\", blue=\""..newcolor["blue"].."\", green=\""..newcolor["green"].."\"}")
return newcolor
end
combined = combineColors(draw.green, draw.blue, 0.3573)
draw.setscreen(1) draw.fillrect(0, 0, 320, 480, newcolor)
sleep(math.huge)
|
|
|
Post by warspyking on Nov 8, 2015 21:14:34 GMT
Got something. This function allows you to combine 2 Colors to 1. Examples: combineColors(draw.green, draw.red, 0) --returns draw.green combineColors(draw.green, draw.red, 1) --returns draw.red combineColors(draw.green, draw.red, 0.35) --returns a mix of: 35% green and 65% red
Here the function, with some extras: function combineColors(color1, color2, level)
level = level * 100
--red reddiff = -1*(color1["red"] - color2["red"]) redpixel = reddiff / 100 print("Red difference: "..reddiff)
--blue bluediff = -1*(color1["blue"] - color2["blue"]) bluepixel = bluediff / 100 print("Blue difference: "..bluediff)
--green greendiff = -1*(color1["green"] - color2["green"]) greenpixel = greendiff / 100 print("Green difference: "..greendiff)
newred = color1["red"] + level * redpixel newblue = color1["blue"] + level * bluepixel newgreen = color1["green"] + level * greenpixel newcolor = {red=newred, blue=newblue, green=newgreen, alpha=1}
print("Red: "..newcolor["red"]) print("Blue: "..newcolor["blue"]) print("Green: "..newcolor["green"])
print("How to define in script:\nmyColor = {red=\""..newcolor["red"].."\", blue=\""..newcolor["blue"].."\", green=\""..newcolor["green"].."\"}")
return newcolor
end
combined = combineColors(draw.green, draw.blue, 0.3573)
draw.setscreen(1) draw.fillrect(0, 0, 320, 480, newcolor)
sleep(math.huge)
LOL I was the one who told you to add the number argument to that! I still have a "Gradient" script saved!
|
|