in a HUD and made a small pocket game.
It already lets the player move, jump and duck down and has some simple functions
like score count but has potential for more great stuff!
Also i hope to find some committed scripters for further developing of it.
The game object is easy to rebuild but if you feel afraid of or just to lazy
feel free to TP to the http://slurl.com/secondlife/Kaseyo/17/122/66 and get a full perms version as freebie.
Its contained in the set of HUD games beside a few more games like fruits, TicTacToe and the new Blox3D game.
(Edit: My server and home pc broke so the template pictures mentioned next is currently missing. Best to do is teleport to my shop and grap a full perms apple game. its containing all scripts and can be rebuild easy. As soon i get the time for i'll fix that.)
The picture above shows a game item with 9 prims but not all are necessary.
The root prim is the one yellow highlightend and will contain the control script.
The grey frame prim is a hollowed box and just encloses the background prim
that shows the tree and its environment.
Then comes 3 apple prims made by cylinders
with the apple texture found in the library used for.
Well it can be more or less than 3 apples. Its up to you
but each apple has to contain the fruit script.
The player prim is just a flat box with a alpha texture for the basket
and the player script in it. The float text prim can be made by any prim
and has to contain the float text script.
There is another grey prim shown on the pic that has no function yet
but may be used for a menu button.
Now the scripts:
take control script
CODE
// Mini Game
// take control script
// by revochen 5/6/08
// Updates: None so far
// this script handles control input
// reserved link msg channels:
// 1000 for key commands (left,right,up ... aso)
key user=NULL_KEY; // to store current players key
default
{
attach(key id)
{
if(id!=NULL_KEY)
{
llMessageLinked(LINK_SET,1000,"reset","");
}
else
{
user=NULL_KEY;
llOwnerSay("Good bye :)");
}
}
touch_start(integer num)
{
// next code line is for debuging
// llOwnerSay((string)llDetectedLinkNumber(0));
// uncomment the line above to find out a prims link number
// next we have to ask if 'user' is set
if(user==NULL_KEY) // if its null_key our game is free to play
{
// and agent gets a permission request to track key input
llRequestPermissions(llGetPermissionsKey(), PERMISSION_TAKE_CONTROLS);
}
// next case we have to ask for
// is if agent who touchd is same as 'user'
else if(llDetectedKey(0)==user)
{
// if so the agent wants to leave the game
llOwnerSay("You left the game :)");
llReleaseControls(); // release the control
user=NULL_KEY; // and set 'user' to null_key
}
}
run_time_permissions(integer perm)
{
if (perm & PERMISSION_TAKE_CONTROLS)
{
// lets give a message for granted permissions
llOwnerSay("Permissions granted. Ready to Play :)");
user=llGetPermissionsKey(); // 'user' will become agent key of who granted permissions
llMessageLinked(LINK_SET,1000,"reset","");
// and take the key control we need
llTakeControls(CONTROL_UP |
CONTROL_DOWN |
CONTROL_FWD |
CONTROL_BACK |
CONTROL_LEFT |
CONTROL_RIGHT |
CONTROL_ROT_LEFT |
CONTROL_ROT_RIGHT, TRUE,FALSE);
}
}
control(key id, integer held, integer change)
{
if (held & CONTROL_UP)
{
llOwnerSay("control up");
}
if (change & held & CONTROL_DOWN)
{
llOwnerSay("control down");
}
if (change & held & CONTROL_LEFT)
{
llOwnerSay("control left");
}
if (change & held & CONTROL_RIGHT)
{
llOwnerSay("control right");
}
if (change & held & CONTROL_FWD)
{
llMessageLinked(LINK_ALL_CHILDREN,1000,"forward","");
}
if (change & held & CONTROL_BACK)
{
llMessageLinked(LINK_ALL_CHILDREN,1000,"back","");
}
if (change & held & CONTROL_ROT_LEFT)
{
llMessageLinked(LINK_ALL_CHILDREN,1000,"left","");
}
else if (change & held & CONTROL_ROT_RIGHT)
{
llMessageLinked(LINK_ALL_CHILDREN,1000,"right","");
}
}
}
player script
CODE
// Mini Game
// player script
// by revochen 5/6/08
vector default_pos=<-0.01645, 0.04668, -0.14657>; // start position for the player prim
vector local_pos; // actual local position of the prim
vector set_back; // value to store a distance to set back
integer steps; // value to count the steps made to the left or right side
default
{
state_entry()
{
llSetPrimitiveParams([PRIM_POSITION,default_pos]);
local_pos=llGetLocalPos();
//llSay(0, (string)local_pos);
}
link_message(integer send, integer ch, string msg, key id)
{
if(ch==9000)
{
vector fruit_pos=(vector)msg;
if(local_pos.y-.03<=fruit_pos.y&&local_pos.y+.03>=fruit_pos.y)
{
llSetLinkAlpha(send,0,ALL_SIDES);
llMessageLinked(LINK_SET,8000,"hit apple","");
}
// llOwnerSay("fruit at "+msg); // debug
}
if(ch!=1000) return;
vector pos;
integer count;
if(msg=="left"&&steps>-3)
{
--steps;
local_pos+=<0,.05,0>;
if(steps<=-2)
{
set_back+=<0,.05,0>;
llSetTimerEvent(1);
++steps;
llMessageLinked(LINK_ALL_CHILDREN,2000,"scene_left","");
}
}
else if(msg=="right"&&steps<3)
{
++steps;
local_pos+=<0,-.05,0>;
if(steps>=2)
{
set_back+=<0,-.05,0>;
llSetTimerEvent(1);
--steps;
llMessageLinked(LINK_ALL_CHILDREN,2000,"scene_right","");
}
}
else if(msg=="forward")
{
local_pos+=<0,0,.1>;
set_back+=<0,0,.1>;
llSetPrimitiveParams([PRIM_POSITION,local_pos]);
llSetTimerEvent(1);
}
else if(msg=="back")
{
//local_pos+=<0,0,-.01>;
llSetScale(<.06,.08,.01>);
llSetPos(local_pos+<0,0,-.02>);
llSleep(1);
llSetScale(<.1,.08,.01>);
}
else if(msg=="reset")
{
llResetScript();
}
llSetPrimitiveParams([PRIM_POSITION,local_pos]);
}
timer()
{
llSetTimerEvent(0);
//llSetPrimitiveParams([PRIM_POSITION,local_pos+<0,0,-.1>]);
local_pos-=set_back;
llSetPrimitiveParams([PRIM_POSITION,local_pos]);
set_back=<0,0,0>;
}
}
fruit script
CODE
// Mini Game
// fruit script
// by revochen 5/6/08
// This script handles the fruit grow and fall-down process
// and gives a msg to the float text script on channel 9000
// Reserved link channels:
// 9000 to send a position msg to the float script
// as collisions are not working its a workaround
// to detect if fruit and basket are at the same position
Init()
{
llSetPos(<-0.01645,llFrand(.2)-.1,.12>);
llSetScale(<.01,.01,.01>);
llSetLinkAlpha(llGetLinkNumber(),1,ALL_SIDES);
llSetTimerEvent(1.3);
}
fallDown()
{
vector pos=llGetLocalPos();
float count;
for(count=0; count<.2; count+=.01)
{
llSetPos(pos+<0,0,-count>);
}
llMessageLinked(LINK_ALL_CHILDREN,9000,(string)llGetLocalPos(),"");
for(count=count; count<.3; count+=.01)
{
llSetPos(pos+<0,0,-count>);
}
llSleep(3);
llResetScript();
}
default
{
state_entry()
{
Init();
//llSay(0, "Hello, Avatar!");
}
timer()
{
vector size=llGetScale();
llSetScale(size+<.003,.003,0>);
if(size.x>.03)
{
llSetTimerEvent(0);
fallDown();
}
}
}
float text script
CODE
// Mini Game
// float text script
// by revochen 5/6/08
// This script shows the score as float text
// It receives messages by the player and control script
integer score;
set_text(string message)
{
llSetText(message,<1,1,0>,1);
}
default
{
state_entry()
{
set_text("Points: 0");
}
link_message(integer send, integer ch, string msg, key id)
{
//if(ch!=8000) return;
if(msg=="hit apple")
{
score+=50;
}
else if(msg=="reset")
{
llResetScript();
}
else return;
set_text("Points: "+(string)score);
//set_text(msg);
//llSetTimerEvent(3);
}
//timer()
//{
// set_text("Points: "+(string)score);
// llSetTimerEvent(0);
//}
}
Feel free to discuss about it, improve the code or just use it and play some games in your free time. But pls keep me updated as i try to update improvements for the scripts at my blog. TY
Enjoy =)