GET LOGGED IN

 

 

 

 

HOME
ABOUT • HELP

 



How To Make A Virtual Robot in FLASH      ...     2661 Views
Author's name: WeRbots       Author's ratings = 0

I build robots. Little electromechanical machines that roll around the floor, seek light, avoid objects. Stuff like that.

I also run a little kid`s website called cybercritters. So I decided the kids might like a robot to drive around. If they like it enough I can expand it to run in 2 1/2 D, or avoid objects, or make it into an avoidance race, or whatever strikes my fancy.

I thought it would be fun to share how I put the little robot together using Flash. I use the old Macromedia Flash 8, I just can`t spring for the loot right now.

So here`s the inside scoop on how I built a robot that is virtual, and you can play with it for free on the web.

Here goes!

Author's Assigned Keywords:    FLASH Applications    Robots    Robot    Action Script 2    Virtual Pet Robot


Inside the Flash Game Engine     
It`s flash, so there are all kinds of things that could be done to it. But I started with the actual robot object. I made a body for the robot, encircled it with a little box that I could turn on and off when it collides with something (just the edges of the screen area in this version.)

Of course I can expand it to operate on the screen like the little virtual pets that work from your desktop on cybercritters.

Some things to look at in the scripts:

Note the little control panel and the code that allows you to drag the robot around the screen, should it crash.

Note use of the collision routine... Everything calls collsion checks before anything happens. Just like in a real-life non-virtual robot.

Action Script-Wise it looks like this:
In the FLA Source File     
#include "wirelessBugBot.as"

var divMove = 5; // divide obj by divMove and (controls speed inverse to size)

// make collision Var = true to set process in motion
var collision = false; // movie starts by making sure it is stopped
_root.NSEW.collisionBox._visible = false; // turn off collision box
_root.help._visible = false;

// Limits for Height Y And Width X of Entire Playing Area
var XlimitH = 890; // right margin roughly 100px from the right end
var XlimitL = 30; // creates a left margin
var YlimitH = 555; // bottom margin about 100px
var YlimitL = 25; // top margin

//////////////////////////////////////////////////
// Drag N Drop the robot anywhere on the screen
//
_root.NSEW.onPress = function() {
this.startDrag();
collision = false; // Stops any actions and holds the object as-is
};
_root.NSEW.onRelease = function() {
collision = false; // Stops any actions and holds the object as-is
_root.NSEW.collisionBox._visible = false; // turn off collision box
this.stopDrag();
};


///////////// HELP ///////////////
_root.helpMe.onRelease = function(){
_root.help._visible = true;
}
_root.help.close.onRelease = function() {
_root.help._visible = false;

}
The Action Script .as File Part 1.     
/////////////////////////////////////////////////////////////////////////////////////
//////// Control Mechanisms and things that work :-) ///////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
// (c) Copyright 2009, the ETECETERA group, all rights reserved.
//
// Author - Jim Huffman
// Orig 07/11/2009
// Release Version 02
//
/////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////////////////////////////////////
// Robot Relative Move Comands
// Here we have to check on the environmental conditions
// before the Raw movement routine is called

function collisionTest(){ // The Heart of the control here is this: The collision test ?? Have we exceeded limits of track?
if(collision){ // if the collision variable is true, then check deeper
//check the limits of the playing field top and bottom margins minus the height and width of the object
if (NSEW._y > YlimitH || NSEW._y < YlimitL) {
_root.NSEW.collisionBox._visible = true;
return false; // check vertical limits
}

if (NSEW._x > XlimitH || NSEW._x < XlimitL ){
_root.NSEW.collisionBox._visible = true;
return false;// check horizontal limits
}
else {
_root.NSEW.collisionBox._visible = false;
return true; // if not hit something - keep going
}
}
else {
//_root.NSEW.collisionBox._visible = true;
return false;
}
}

function move(strg){ // All movement requests come here before object moves
// always check if there is an existing collision (Maybe a STOP?)
if (collisionTest()) { // collision test returns true - choose proper movements
var x = 0;
if (strg == `up`){
this.onEnterFrame = function(){
if(x++ > 10) {
if (collisionTest()) moveUp(NSEW);
}
}
}
if (strg == `Lft`){
this.onEnterFrame = function(){
if(x++ > 10) {
if (collisionTest()) moveLft(NSEW);
}
}
}
if (strg == `Rt`){
this.onEnterFrame = function(){
if(x++ > 10) {
if (collisionTest()) moveRt(NSEW);
}
}
}
if (strg == `Dwn`){
this.onEnterFrame = function(){
if(x++ > 10) {
if (collisionTest()) moveDwn(NSEW);
}
}
}
if (strg == `DiaUp`){
this.onEnterFrame = function(){
if(x++ > 10) {
if (collisionTest()) moveDiaUp(NSEW);
}
}
}
if (strg == `DiaRup`){
this.onEnterFrame = function(){
if(x++ > 10) {
if (collisionTest()) moveDiaRup(NSEW);
}
}
}
if (strg == `DiaDn`){
this.onEnterFrame = function(){
if(x++ > 10) {
if (collisionTest()) moveDiaDn(NSEW);
}
}
}
if (strg == `DiaRdn`){
this.onEnterFrame = function(){
if(x++ > 10) {
if (collisionTest()) moveDiaRdn(NSEW);
}
}
}
}
}

The Action Script .as File Part 2.     
//////////////////////////////////////
// Raw Object Moves happen here
// These routines ignore the overall limit and collision rules
function moveUp(object) {
oY = object._y;
oH = object._height ;
object._y = oY - oH /divMove ; // move it out of the gate
}

function moveDwn(object) {
oY = object._y;
oH = object._height ;
object._y = oY + oH /divMove ; // move it out of the gate
}

function moveLft(object) {
oX = object._x;
oW = object._width ;
object._x = oX - oW /divMove ; // move it out of the gate
}

function moveRt (object) {
oX = object._x;
oW = object._width ;
object._x = oX + oW /divMove ; // move it out of the gate
}

function moveDiaUp (object) {
oY = object._y;
oH = object._height ;
object._y = oY - oH /(divMove + 6 );
oX = object._x;
oW = object._width ;
object._x = oX - oW /(divMove + 6 );
}

function moveDiaDn (object) {
oY = object._y;
oH = object._height ;
object._y = oY + oH /(divMove + 6 ) ;
oX = object._x;
oW = object._width ;
object._x = oX + oW /(divMove + 6 ) ;
}

function moveDiaRup (object) {
oY = object._y;
oH = object._height ;
object._y = oY - oH /(divMove + 6 ) ;
oX = object._x;
oW = object._width ;
object._x = oX + oW /(divMove + 6 ) ;
}

function moveDiaRdn (object) {
oY = object._y;
oH = object._height ;
object._y = oY + oH /(divMove + 6 );
oX = object._x;
oW = object._width ;
object._x = oX - oW /(divMove + 6 ) ;
}

///////////////////////////////////////////////////
// Controller commands Virtual Joystick
// stick points character in correct direction
// moves character one width in the direction pointed
// then calls the move() routine appropriately

this.stick.STOP.onPress = function () { // Screeechhh
collision = false; // Stops any actions and holds the object as-is
_root.NSEW.collisionBox._visible = false; // turn off collision box
}

this.stick.N.onPress = function () { // Move one "space" north
_root.NSEW.gotoAndStop(`N`); // point away from operator
collision = true;
moveUp(NSEW);
move(`up`);
}

this.stick.S.onPress = function () {// Move one "space" south
_root.NSEW.gotoAndStop(1);
collision = true;
moveDwn(NSEW);
move(`Dwn`);
}

this.stick.W.onPress = function () {// Move one "space" west
_root.NSEW.gotoAndStop(2);
collision = true;
moveLft(NSEW);
move(`Lft`);
}

this.stick.E.onPress = function () {// Move one "space" east
_root.NSEW.gotoAndStop(4);
collision = true;
moveRt(NSEW);
move(`Rt`);
}

this.stick.NW.onPress = function () {// Move one "space" northwest
_root.NSEW.gotoAndStop(6);
collision = true;
moveDiaUp(NSEW);
move(`DiaUp`);
}

this.stick.NE.onPress = function () {// Move one "space" northeast
_root.NSEW.gotoAndStop(5);
collision = true;
moveDiaRup(NSEW);
move(`DiaRup`);
}

this.stick.SE.onPress = function () {// Move one "space" southeast
_root.NSEW.gotoAndStop(7);
collision = true;
moveDiaDn(NSEW);
move(`DiaDn`);
}

this.stick.SW.onPress = function () {// Move one "space" southwest
_root.NSEW.gotoAndStop(8);
collision = true;
moveDiaRdn(NSEW);
move(`DiaRdn`);
}

///////////////////////////////////////////////////////////////////
//////// END Control Mechanisms /////////////////////////////////
///////////////////////////////////////////////////////////////////

Insert Your Comments
Subject:
Message:


ADD COMMENT | CLOSE COMMENT
close window

It's Easy To Show Your Skills:

C - What - I - Did

• Sign up - Get ID and Password

• Plan and Create a Project That Someone Might Enjoy and May Even Want to Build

• Link to your creation on your favorite social networking site or blog.

• Become famous! Because your projects get a lot of Hits!

 

No parts list with this project. Scan the 'Junkbox Reviewer' below! Find projects by clicking on their parts. Got something in your junkbox? Here's your spot to find something fun to make or build!

 

Junk Box Reviewer

Itching To Start Building A DIY Do It Yourself Project? Got Some Parts of Your Own in your JunkBox? Find projects by Surfing' the Parts List!
TA8080K
Toshiba
$2.00
  
Web Frame Work
ExtJS
$0.00
  
Robo Quad
Wowee
$70
  
picAxe 08m
MicroChip
$3
  
Twin Motor Gearbox
Tamiya
$10.95
  
RFL Upright Robot
Active-Innovations
$119.95
  
Andrei And Jim
Web Developers
$.02
  
Scribbler Robot
Parallax
$79.95
  
L 298 Compact Motor Driver Kit
Solarbotics
$18.95
  
Account On CwhatIcanDo
CwhatIcanDo.com
$0.00
  
Tribot
Wowee
$79.00
  
Microrobot Avoider Jr
Microrobot
$75??
  
picAxe 14m
MicroChip
$4.00
  
Wall Hugging Mouse
Tamiya
$20
  
Brilliant Blue/Green LED
Surplus
$1.00 (4)
  
PICAXE 8 Pin Motor Driver Board
SparkFun
$15.95
  
Tracked Vehicle Chassis Kit
Tamiya
$17.50
  
Twin Motor Gearbox
Tamiya
$10.95
  
PICAXE 8 Pin Motor Driver Board
SparkFun
$15.95
  
Infrared Proximity Sensor Short Range - Sharp GP2D120XJ00F
Sharp
$13.95
  
PICAXE 8 Pin Motor Driver Board
SparkFun
$15.95
  
Infrared Proximity Sensor Short Range - Sharp GP2D120XJ00F
Sharp
$13.95
  
Gear Motor 2 - 224:1 Offset Shaft
SolarBotics
$5.75
  
4 X AA Cell battery holder plus on/off switch
Powerize
$1.59
  
PICAXE 8 Pin Motor Driver Board
SparkFun
$15.95
  
Infrared Proximity Sensor Short Range - Sharp GP2D120XJ00F
Sharp
$13.95
  
4 Section In-Ground Batting Net
battingnets.com
$750.00
  
DROID
Motorola
$600.00
  
battery
NEC/Tokin
$1.95
  
IR LED
Any TV remote compatible
$0.25
  
Butterfly Lite
Gadget Factory
$99.99
  
picAxe 08m
MicroChip
$3
  
picAxe 08m
picAxe
$2.95
  
PICAXE 8 Pin Motor Driver Board
SparkFun
$15.95
  
hexbug
bandai
$$10
  
Rumble Bot
USED
$4-30
  
Morphibian Land Shark
Kid Galaxy
$~30
  
SCC2433-B solar cell
Solarbotics
$6.50
  
3 VDC Motor
Hankscraft
$
  
bamboo or dowels
$
  
Mylar Film W hologram
garden centers
$10.00
  
©Copyright 2008 - , cwhatidid.com, all rights reserved.