-->*/ addGame = function(title,engine,itemtype,gameiconurl, gameurl, isMicroStudioGame) games += object title = title iconurl = gameiconurl engine = engine isMicroStudioGame = isMicroStudioGame itemtype = itemtype url = gameurl end end addGames = function() games = [] //microstudio stuff addGame("Fire","MicroStudio", "Effect", "https://joyrider3774.github.io/my_browser_games/fire_microstudio/icon32.png","https://joyrider3774.github.io/my_browser_games/fire_microstudio", true) addGame("Plasma","MicroStudio", "Effect", "https://joyrider3774.github.io/my_browser_games/plasma_microstudio/icon32.png","https://joyrider3774.github.io/my_browser_games/plasma_microstudio", true) addGame("Fire + Plasma","MicroStudio", "Effect", "https://joyrider3774.github.io/my_browser_games/fireplasma_microstudio/icon32.png","https://joyrider3774.github.io/my_browser_games/fireplasma_microstudio", true) addGame("Blockdude","MicroStudio", "Game", "https://joyrider3774.github.io/my_browser_games/blockdude_microstudio/icon32.png","https://joyrider3774.github.io/my_browser_games/blockdude_microstudio", true) addGame("Maze Thingie","MicroStudio", "Game", "https://joyrider3774.github.io/my_browser_games/mazethingie_microstudio/icon32.png","https://joyrider3774.github.io/my_browser_games/mazethingie_microstudio", true) addGame("Znax","MicroStudio", "Game", "https://joyrider3774.github.io/my_browser_games/znax_microstudio/icon32.png","https://joyrider3774.github.io/my_browser_games/znax_microstudio", true) //playdate stuff addGame("Blockdude","Playdate", "Game", "https://joyrider3774.github.io/my_browser_games/blockdude_playdate/icon.png","https://joyrider3774.github.io/my_browser_games/blockdude_playdate", false) addGame("Dynamate","Playdate", "Game", "https://joyrider3774.github.io/my_browser_games/dynamate_playdate/icon.png","https://joyrider3774.github.io/my_browser_games/dynamate_playdate", false) addGame("Formula 1","Playdate", "Game", "https://joyrider3774.github.io/my_browser_games/f1_playdate/icon.png","https://joyrider3774.github.io/my_browser_games/f1_playdate", false) addGame("Puztrix","Playdate", "Game", "https://joyrider3774.github.io/my_browser_games/puztrix_playdate/icon.png","https://joyrider3774.github.io/my_browser_games/puztrix_playdate", false) addGame("Puzzleland","Playdate", "Game", "https://joyrider3774.github.io/my_browser_games/puzzleland_playdate/icon.png","https://joyrider3774.github.io/my_browser_games/puzzleland_playdate", false) addGame("Retrotime","Playdate", "Game", "https://joyrider3774.github.io/my_browser_games/retrotime_playdate/icon.png","https://joyrider3774.github.io/my_browser_games/retrotime_playdate", false) addGame("Rubdio","Playdate", "Game", "https://joyrider3774.github.io/my_browser_games/rubido_playdate/icon.png","https://joyrider3774.github.io/my_browser_games/rubido_playdate", false) addGame("Waternet","Playdate", "Game", "https://joyrider3774.github.io/my_browser_games/waternet_playdate/icon.png","https://joyrider3774.github.io/my_browser_games/waternet_playdate", false) //godot stuff addGame("Faster Dave","Godot", "Game", "https://joyrider3774.github.io/my_browser_games/fasterdave_godot/index.icon.png","https://joyrider3774.github.io/my_browser_games/fasterdave_godot", false) //WASM4 stuff addGame("Formula 1","WASM4", "Game", "https://joyrider3774.github.io/my_browser_games/f1_wasm4/icon.png","https://joyrider3774.github.io/my_browser_games/f1_wasm4", false) addGame("Maze Thingie","WASM4", "Game", "https://joyrider3774.github.io/my_browser_games/mazethingie_wasm4/icon.png","https://joyrider3774.github.io/my_browser_games/mazethingie_wasm4", true) addGame("Rubdio","WASM4", "Game", "https://joyrider3774.github.io/my_browser_games/rubido_wasm4/icon.png","https://joyrider3774.github.io/my_browser_games/rubido_wasm4", false) addGame("Waternet","WASM4", "Game", "https://joyrider3774.github.io/my_browser_games/waternet_wasm4/icon.png","https://joyrider3774.github.io/my_browser_games/waternet_wasm4", false) //Arduboy stuff addGame("Waternet","Arduboy", "Game", "https://joyrider3774.github.io/my_browser_games/waternet_arduboy/icon.png","https://joyrider3774.github.io/my_browser_games/waternet_arduboy", false) //Gamebuino Meta stuff addGame("Waternet","Gamebuino", "Game", "https://joyrider3774.github.io/my_browser_games/waternet_gamebuino/icon.png","https://joyrider3774.github.io/my_browser_games/waternet_gamebuino", false) //Game boy Stuff addGame("Waternet","Game Boy", "Game", "https://joyrider3774.github.io/my_browser_games/waternet_gameboy/icon.png","https://joyrider3774.github.io/my_browser_games/waternet_gameboy", false) end sortfunc = function(a, b) keyA = a.title + a.itemtype + a.engine keyB = b.title + b.itemtype + b.engine if (sortkey == "engine") then keyA = a.engine + a.title + a.itemtype keyB = b.engine + b.title + b.itemtype end if(sortkey == "itemtype") then keyA = a.itemtype + a.title + a.engine keyB = b.itemtype + b.title + b.engine end if(sortdir != "▲") then tmp = keyA keyA = keyB keyB = tmp end // Compare the 2 dates if (keyA < keyB) then return -1 end if (keyA > keyB) then return 1 end return 0 end sortGames = function() games.sortList(sortfunc) end shuffle = function() local g = [] while games.length > 0 local game = games.removeAt(random.nextInt(games.length)) g += game end games = g end end() system.javascript(""" // javascript this.embed = function(url,close_button, isMicroStudioGame) { console.info(url); console.info("close_button = "+close_button) var canvas = document.querySelector("canvas") ; var parent = canvas.parentNode ; var iframe = document.createElement("iframe") ; iframe.src = url; //added fullscreen 'none' to prevent iframe page going fullscreen even on same domain iframe.allow = "autoplay; gamepad; midi; fullscreen 'none';"; iframe.style = "position: absolute ; top: 0 ; left: 0 ; width: 100% ; height: 100% ; border: none ; z-index: 0 ; transition-property: opacity ; transition-duration: 2s ; opacity: 0"; iframe.allowFullscreen = false ; canvas.style["transition-property"] = "opacity" ; canvas.style["transition-duration"] = "1s" ; parent.insertBefore(iframe,canvas) iframe.contentWindow.addEventListener("load",()=>{ //somehow using iframe.XXX caused errors in console //so just search for the frame let tmpframe = document.querySelector("iframe") if(tmpframe) { tmpframe.contentWindow.focus(); tmpframe.style.opacity = 1 ; } else console.log("warning iframe not found"); }) //for handling events send by games html pages to notify quit from gamepad //or start of game (so it fades from black to the game) window.addEventListener('message', (event) => { //console.log(event); data = JSON.parse(event.data); if(data.name == "quit"){ global.back_to_menu = true ; } if(data.name == "start") { //somehow using iframe.XXX caused errors in console //so just search for the frame let tmpframe = document.querySelector("iframe") if(tmpframe) { tmpframe.contentWindow.focus(); tmpframe.style.opacity = 1 ; } else console.log("warning iframe not found"); } }); iframe.contentWindow.addEventListener('keydown', (event) => { console.log('Keydown event in iframe:', event); if (event.key == "Escape") { global.back_to_menu = true ; } }); if (close_button) { var img = new Image() ; img.src = "sprites/exit.png" ; img.id = "exit-button" ; //increased the z-index //because wasm4 games set the z-index of the window (iframe) to some higher value img.style = "width: 5vw ; position: fixed ; top: 1.5vw ; right: 1.5vw ; opacity: .5 ; image-rendering: moz-crisp-edges; image-rendering: pixelated ; z-index: 9999999;" ; document.body.appendChild(img) ; img.addEventListener("click",()=>{global.back_to_menu = true}) } setTimeout(()=> { global.processactionsagain = false; canvas.style.opacity = 0 ; setTimeout(()=>{ canvas.style.display = "none" ; global.processactionsagain = true; },1000) },0) setTimeout(()=>{ },500) global.canvas = canvas global.iframe = iframe global.window = window } this.restore = function() { var iframe = document.querySelector("iframe") ; if (iframe) { iframe.parentNode.removeChild(iframe) ; } var canvas = document.querySelector("canvas") ; canvas.style.display = "block" ; setTimeout(()=>{ global.processactionsagain = false; canvas.style.opacity = 1 ; setTimeout(()=>{ global.processactionsagain = true; },500) },1) setTimeout(()=>{ },500) setTimeout(()=> { window.focus() },100) var exit = document.getElementById("exit-button") ; if (exit) { exit.parentNode.removeChild(exit) ; } } this.loadImage = function(url,callback) { var img = new Image() ; img.src = url ; img.onload = ()=> { callback(new global.Image(img)) } ; } /**/ """) function() CRT = function(size = 240,intensity = .5) if not CRT_BUFFER.type or size != CRT_BUFFER_SIZE or intensity != CRT_BUFFER_INTENSITY then CRT_BUFFER_SIZE = size size *= 2 CRT_BUFFER_INTENSITY = intensity CRT_BUFFER = new Image(size,size) CRT_BUFFER.setRadialGradient(size/2,size/2,size/2*1.4142,"rgba(0,0,0,0)","rgba(0,0,0,"+intensity+")") CRT_BUFFER.fillRect(0,0,size,size) CRT_BUFFER.setRadialGradient(size/2,size/2,size/2*3,"rgba(0,0,0,0)","rgba(0,0,0,"+intensity+")") for i=0 to size by 4 //CRT_BUFFER.drawLine(0,0,200,200) CRT_BUFFER.drawLine(0,i+.5,size,i+.5) end end screen.setPixelated(false) screen.drawImage(CRT_BUFFER,0,0,screen.width,screen.height) screen.setPixelated(true) end end() function() init = function() sortkey = "title" sortdir = "▲" addGames() sortGames() for game in games loadImage(game.iconurl,function(img) game.image = img end) end browse_position = 0 browse_selected = 0 target_position = 0 position_speed = 0 started = false back_to_menu = false dragging = false processactionsagain = true control_modes = ["keyboard","gamepad","touch"] control = object end clickable = [] mode = "browse" screen.setFont("Edunline") end update = function() if not started then if (mouse.press or keyboard.press.ENTER or gamepad.press.A) then started = true audio.playSound("microfxr/welcome",.125) end return end if processactionsagain and gamepad.press.RIGHT or gamepad.press.LEFT or gamepad.A or gamepad.Y then control_modes = ["gamepad"] end if processactionsagain and keyboard.press.Y or keyboard.press.RIGHT or keyboard.press.LEFT or keyboard.press.ENTER or keyboard.press.SPACE then control_modes = ["keyboard"] end //added processaction again //i could get the system stuck by fastly pressing escape and enter and mouse clicks //now when fading starts things will be disabled and renabled when fading ended control.LEFT = processactionsagain and gamepad.press.LEFT or keyboard.press.LEFT control.RIGHT = processactionsagain and gamepad.press.RIGHT or keyboard.press.RIGHT control.ACTION = processactionsagain and (gamepad.press.A or keyboard.press.ENTER or keyboard.press.SPACE) control.BACK = processactionsagain and (back_to_menu or gamepad.press.MENU or (gamepad.X and gamepad.B)) control.SORT = processactionsagain and gamepad.press.Y or keyboard.press.Y if touch.press and processactionsagain then control_modes = ["touch"] dragging = false if abs(touch.x+150)<10 and abs(touch.y)<25 then if target_position > 0 then target_position -= 1 browse_selected = target_position+1 audio.playSound("microfxr/switch",.125) end elsif abs(touch.x-150)<10 and abs(touch.y)<25 then if target_position < games.length-4 then target_position += 1 browse_selected = target_position+1 audio.playSound("microfxr/switch",.125) end elsif abs(touch.x)<140 and abs(touch.y)<50 then dragging = true drag_start = target_position drag_start_x = touch.x drag_moved = false browse_selected = round((touch.x+105)/70)+target_position //tap to sort elsif abs(touch.x)<36 and touch.y <= -85 and touch.y >=-95 then control.SORT = true end end if touch.touching and processactionsagain then if dragging then if abs(touch.x - drag_start_x) > 10 then drag_moved = true browse_selected = -1 end if drag_moved then target_position = max(0,min(games.length-4,drag_start+(drag_start_x-touch.x)/30)) end end end if touch.release and processactionsagain then if dragging then dragging = false if drag_moved then target_position = round(target_position) browse_selected = target_position + 1 else control.ACTION = true end end end if mode == "browse" then if control.SORT then audio.playSound("microfxr/switch",.125) if (sortdir == "▲") then sortdir = "▼" sortGames() else sortdir = "" end if(sortdir == "") then if (sortkey == "itemtype") then sortkey = "title" else if sortkey == "title" then sortkey = "engine" else sortkey = "itemtype" end end sortdir = "▲" end sortGames() end if control.RIGHT then if browse_selected < games.length-1 then browse_selected += 1 audio.playSound("microfxr/switch",.125) if target_position < browse_selected-2 then target_position += 1 target_position = min(games.length-4,target_position) end end end if (control.LEFT) and browse_selected > 0 then browse_selected -= 1 audio.playSound("microfxr/switch",.125) if target_position > browse_selected-1 and target_position > 0 then target_position -= 1 end end if control.ACTION then //remember it somehow selected wrong position //after quiting games browse_selected_pushed = browse_selected tartget_position_pushed = target_position mode = "play" audio.playSound("microfxr/enter",.125) local game = games[browse_selected] embed(game.url,control_modes[0] == "touch", game.isMicroStudioGame) end else if control.BACK then restore() mode = "browse" audio.playSound("microfxr/back",.125) //restore so we keep same selection and view browse_selected = browse_selected_pushed target_position = tartget_position_pushed back_to_menu = false end end position_speed += (target_position-browse_position)*.1 position_speed *= .5 browse_position += position_speed end draw = function() local background = "rgb(5,30,43)" screen.clear(background) if screen.width < screen.height then screen.setAlpha(.5) screen.drawSprite("rotate",0,0,48) screen.setAlpha(1) return end screen.setFont("Edunline") if not screen.isFontReady() then return end screen.drawText("Joyrider3774's",0,80,20,"rgb(65,120,147)") screen.drawText("BROWSER STUFF",0,55,20,"rgb(65,120,147)") if not started then screen.setFont("BitCell") local size = sin((system.time()%500)/500*PI*2) screen.fillRect(0,-25,60+size,18+size*.5,"rgb(197,87,87)") screen.drawText("START",0,-25,10,"#FFF") screen.drawSprite("icon_transparent",0,20) screen.drawText("Powered by",0,-70,6,"rgba(255,255,255,.5)") screen.setPixelated(false) screen.drawSprite("microstudio",0,-80,50) screen.setPixelated(true) return end // screen.drawSprite("icon",-120,65,20) screen.setFont("BitCell") for i=0 to games.length-1 by 1 local game = games[i] local x = (i-browse_position)*70-105 if game and game.image and abs(x) <160 then screen.setAlpha(max(0,min(1,3-abs(x)/160*3))) if i == browse_selected then screen.fillRect(x,0,55,55,"rgb(255,142,85)") screen.fillRect(x,0,51,51,background) else screen.fillRect(x,0,55,55,"rgba(255,255,255,.1)") end screen.drawSprite(game.image,x,0,50,50) screen.drawText(game.title,x,-35,7,"rgba(255,255,255,.8)") screen.drawText(game.itemtype,x,-42,7,"rgba(255,255,255,.8)") screen.drawText(game.engine,x,-49,7,"rgba(255,255,255,.8)") end end screen.setAlpha(.5) if target_position > 0 then screen.drawSprite("arrow_left",-150,0,8) end if target_position < games.length-4 then screen.drawSprite("arrow_right",150,0,8) end local dx = -(control_modes.length-1)/2*50 for c in control_modes screen.drawSprite(c,dx,-65,24) dx += 50 end if control_modes.length == 1 then if control_modes[0] == "keyboard" then screen.drawText("Sorted on: " + sortkey + sortdir, 0, -80, 8) screen.drawText("ENTER to start game, Y to Sort, ESC to exit game",0,-90,8) elsif control_modes[0] == "gamepad" then screen.drawText("Sorted on: " + sortkey + sortdir, 0, -80, 8) screen.drawText("[A] to start game - [Y] to Sort - [MENU] to exit game",0,-90,8) else screen.drawText("Tap to start game",-75,-90,8) screen.drawText("Sorted on: " + sortkey + sortdir, 0, -90, 8) screen.drawText("exit game with",70,-90,8) screen.setAlpha(1) screen.drawSprite("exit",100,-90) end end screen.setAlpha(1) // CRT() end end()