====== About the script ======
* Purpose : This script is will give you the possibility to play Snake in your launcher
* Author : F43nd1r
* Current Version : 1.0
* Link : https://plus.google.com/115366157037831519359/posts/66u6CJgMnGC
* Download available! (Check repository)
====== Changelog ======
* Version 1.0 (28/8/2014): initial release in wiki
====== How to use the script ======
* create a shortcut and hide it's label and icon
* Resize it to the wished game size
* set this script to the Touchevent
* Note: For this manual way you won't need the setup script
====== Issues and hints ======
* The Setup script won't work outside of the APK
//please report all bugs in the g+ community//
====== Setup Script ======
var MY_PKG="net.pierrox.lightning_launcher.llscript.snake";
// install (or update) a script given its id in the package, and its clear name in the launcher data
function installScript(id,name){
// load the script (if any) among the existing ones
var script=LL.getScriptByName(name);
var script_text=LL.loadRawResource(MY_PKG,id);
if(script==null){
// script not found: install it
script=LL.createScript(name,script_text,0);
}else{
// the script already exists: update its text
script.setText(script_text);
}
return script;
}
if(!confirm("Do you want to load Snake in this Container? It should be empty to avoid problems."))return;
var c=LL.getEvent().getContainer();
var i=c.getItemByName("SnakeField")||c.addShortcut("SnakeField",new Intent(),0,0);
i.setName("SnakeField");
var script=installScript("snake","Snake");
var editor=i.getProperties().edit();
editor.setEventHandler("i.touch",EventHandler.RUN_SCRIPT,script.getId());
editor.setBoolean("s.labelVisibility",false);
editor.setBoolean("s.iconVisibility",false);
editor.setBoolean("i.onGrid",false);
editor.commit();
i.setSize(c.getWidth(),c.getHeight());
i.setBoxBackground(LL.createImage(MY_PKG,"start_screen"),"nsf");
====== Snake Script ======
//config
var bgColor=0xffffffff;//has to be a solid color;
var headColor=0xff00ff00;
var tailColor=0xff008000;
var foodColor=0xff000090;
var borderColor=0xffff0000;
var tick=130;
var fieldSize=30;//the width of the field
//endconfig
var size=Math.min(item.getWidth(),item.getHeight())/fieldSize;
if(event.getAction()==MotionEvent.ACTION_DOWN)
{
pos=[event.getX(),event.getY()];
}
else if(event.getAction()==MotionEvent.ACTION_UP&&Math.abs(pos[0]-event.getX())Math.floor(item.getWidth()/size)-2||next[1]<1||next[1]>Math.floor(item.getHeight()/size)-2||contains(snake,next))
{
alive=false;
Android.makeNewToast("Lost! Score: "+score,false).show();
}
else
{
snake.unshift(next);
if(next[0]==food[0]&&next[1]==food[1])
{
score+=1;
newFood();
}
else snake.pop();
dirChanged=false;
draw();
setTimeout(move,tick);
}
}
function draw()
{
canvas.drawColor(bgColor);
paint.setColor(headColor);
canvas.drawRect(snake[0][0]*size,snake[0][1]*size,snake[0][0]*size+size,snake[0][1]*size+size,paint);
paint.setColor(tailColor);
for(var a=1;a