Code Wars
Main
Home
About Me
Guest-Globe
Links
Site Stats

Photos
Family
Kit Car
Scotland
Various
Index

Geek Stuff
Hardware
Software
3D Scanning
Code Wars
Java
Visuals
R2 Vis
R4 Vis
Tutorials

Feedback
Forum
Contact Me

 
  Code for "enemy"
// Setup Robot colours
// R,G,B format, as bytes packed into an integer
DEFINE RCOLORB,0
DEFINE RCOLORF,16711680
// Setup Robot Image - binary data
DEFINE RIMG0,255
DEFINE RIMG1,129
DEFINE RIMG2,255
DEFINE RIMG3,129
DEFINE RIMG4,129
DEFINE RIMG5,255
DEFINE RIMG6,129
DEFINE RIMG7,255
// Setup what we have on each side...
DEFINE RSIDE1,SDEYE         // Front
DEFINE RSIDE2,SDEYE         // Right
DEFINE RSIDE3,SDGUN         // Back
DEFINE RSIDE4,SDSHIELD      // Left

DEFINE OBJDIST,64           // Data register which contains the distance to the object

// ------------------------------- Main Code
Start       : MOV_RL        PCOMMAND,CMUSE2     // Look out of the right-hand side
						// See what we are looking at...
              SNE_RL        PPARAM2,LROBOT      
              GOTO_L        RobotAttack         // If a robot, attack it
              SNE_RL        PPARAM2,LAMMO       // If health or ammo, go and get it     
              GOTO_L        GetItem      
              SNE_RL        PPARAM2,LHEALTH
              GOTO_L        GetItem

              MOV_RL        PCOMMAND,CMUSE1     // Look out the front
	      SNE_RL        PPARAM1,0           
	      GOTO_L        Turn                // If something is blocking our way, turn
              GOTO_L        Step 

Step        : MOV_RL        PPARAM1,8           // Get a Random number between 0 and 7	     
              MOV_RL        PCOMMAND,CMRANDOM
	      SNE_RL        PPARAM1,0           // if the number is 0, turn
	      GOTO_L        Turn
	      MOV_RL        PCOMMAND,CMMOVE     // otherwise move forward
     	      GOTO_L        Start

Turn        :
	      MOV_RL        PCOMMAND,CMLEFT     // turn left
	      GOTO_L        Start               //

RobotAttack : MOV_RL        PCOMMAND,CMLEFT     // Turn so back faces robot
              CALL_L        subFire             // Fire at it
	      MOV_RL        PCOMMAND,CMRIGHT    // Turn back to where we were
	      GOTO_L        Start               // 

GetItem     : MOV_RL        PCOMMAND,CMRIGHT    // Turn to face the item
              CALL_L        subGoDirect         // Go and get the item
	      GOTO_L        Start               // 

// ---------------------------------------------------------------------------- SUBROUTINES
// Go directly forwards the number of times specified in OBJDIST
subGoDirect : MOV_RL        PCOMMAND,CMMOVE     // Move Forwards 
              ADD_RL        OBJDIST,-1          // Decrease the distance count
              SLT_RL        OBJDIST,0           // Check distace (loop if OBJDIST>=0)
	      GOTO_L        subGoDirect         // If we haven't reached it yet, move again
	      RETURN_                           // We have reached it, so go back

// FIRE!!!
subFire     : MOV_RL        PCOMMAND,CMUSE3     // Fire off 4 missiles
              MOV_RL        PCOMMAND,CMUSE3
              MOV_RL        PCOMMAND,CMUSE3
              MOV_RL        PCOMMAND,CMUSE3
	      RETURN_
           
             

Created by and Copyright (c) Gordon Williams 2003