User Tag List

Results 1 to 3 of 3

Thread: Gun Script (almost fully functional)

  1. #1
    Wizrobe C-Dawg's Avatar
    Join Date
    Jan 2002
    Posts
    4,205
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    6,611
    Level
    24
    vBActivity - Bars
    Lv. Percent
    99.77%

    Gun Script (almost fully functional)

    This script requires two FFCs. The first is the "gun," which fires whenever Link is within target range. The second is the "projectile." You tell the FFC (using D0-7) which directions you want the gun to fire in. When Link is lined up in those directions, the "gun" FFC changes to the next ffc (gun animation) and the projectile zips out. Make the projectile a damage combo for a weapon, or maybe a warp or trigger combo for other effects.

    Some of the variables are hard-coded (but can be changed by a designer, of course.)

    This script works perfectly well on a MOVING FFC, although it has to be linked to another FFC that is actually running a moving script.

    Best part is - multiple guns on the same screen work FINE. (Each needs their own projectile, though)

    The omnidirectional firing bit doesn't work correctly yet.

    Code:
    // ===================================
    // gun - This FFC will act as a gun.  The user
    // specifies which direction the gun will fire.  When
    // the player is lined up with the proper direction,
    // the gun will briefly switch to the next combo.  
    // It will move the projectile FFC to its location, and 
    // send it outwards in the proper direction.  Projectiles will
    // be blocked by solid combos on layer 0.
    // D0 = delay between shots.
    // D1 = FFC number of the projectile combo
    // D2 = FFC number of this combo (necessary to overcome problems
    //      with the "this->" function in ZCb2.15
    // D3 = 1 if the gun can shoot north
    // D4 = 1 if the gun can shoot south
    // D5 = 1 if the gun can shoot east
    // D6 = 1 if the gun can shoot west
    // D7 = 1 if the gun is omnidirectional (meaning it will
    // fire at angles, regardless of where the player is.)
    // NOTES ON USE - 
    // If you make the projectile move too fast, it may zip off
    // of the screen before the script can save it.  Keep the speed under
    // 16 to prevent this.
    // There are not enough Data variables to specify
    // the speed of the projectile, sound effects, and the time the gun spends in it's
    // "shooting" animation.  To modify these variables, you need to change
    // the values loaded into "projectile_speed," "sound," and "firing_delay" below.
    // ==========================================
    
    ffc script gun{
    
    	void run(int shot_delay, int projectile_ffc_number, int this_ffc_number, int shoots_north,
    		int shoots_south, int shoots_east, int shoots_west, int omnidirectional){
    
    		int gun_state = 0;	// 0 = primed and waiting for the player to come in range.
    					// 1 = firing 
    					// 2 = waiting 
    	
    		int projectile_speed = 4; // Hard-coded speed of projectile.
    
    		int firing_delay = 20;	// Hard-coded delay while gun animation plays. Counter for state 1.
    	
    		int delay_counter = shot_delay;	// Counter for state 2.
    
            int side_A; int side_B; int side_C;       // Used to calculate the angle in an omnidirectional gun.
    
    		ffc projectile = Screen->LoadFFC(projectile_ffc_number);
    
    		ffc this_ffc = Screen->LoadFFC(this_ffc_number);
    
    		int sound = 26;
    
    		while (true){
    
    			if (gun_state == 0){
    
    				if ( (shoots_north == 1) && (Link->X < this_ffc->X+16) && (Link->X > this_ffc->X-1) && (Link->Y < this_ffc->Y)){
    		
    					Game->PlaySound(sound);
    					projectile->X = this_ffc->X;
    					projectile->Y = this_ffc->Y;
    					projectile->Vy = -projectile_speed;
    					projectile->Vx = 0;
    					gun_state = 1;	
    					this_ffc->Data++;
    				}
    
    				if ( (shoots_south == 1) && (Link->X < this_ffc->X+16) && (Link->X > this_ffc->X-1) && (Link->Y > this_ffc->Y)){
    			
    					Game->PlaySound(sound);
    					projectile->X = this_ffc->X;
    					projectile->Y = this_ffc->Y;
    					projectile->Vy = projectile_speed;
    					projectile->Vx = 0;
    					gun_state = 1;	
    					this_ffc->Data++;
    				}
    
    				if ( (shoots_east == 1) && (Link->Y < this_ffc->Y+16) && (Link->Y > this_ffc->Y-1) && (Link->X > this_ffc->X)){
    		
    					Game->PlaySound(sound);
    					projectile->X = this_ffc->X;
    					projectile->Y = this_ffc->Y;
    					projectile->Vx = projectile_speed;
    					projectile->Vy = 0;
    					gun_state = 1;	
    					this_ffc->Data++;
    				}
    	
    				if ( (shoots_west == 1) && (Link->Y < this_ffc->Y+16) && (Link->Y > this_ffc->Y-1) && (Link->X < this_ffc->X)){
    			
    					Game->PlaySound(sound);
    					projectile->X = this_ffc->X;
    					projectile->Y = this_ffc->Y;
    					projectile->Vx = -projectile_speed;
    					projectile->Vy = 0;
    					gun_state = 1;	
    					this_ffc->Data++;
    				}
    
    				if(omnidirectional == 1){
    		
    					 // First, check to see if the player is linked up vertically with the gun.  Need to do this
     					// because, otherwise, the angle checking code will divide by zero OH SHI
    		
    					Game->PlaySound(sound);
    
    					if(Link->X == this_ffc->X){
    				   		if ( Link->Y > this_ffc->Y){
    								projectile->X = this_ffc->X;
    								projectile->Y = this_ffc->Y;
    								projectile->Vy = projectile_speed;
    								projectile->Vx = 0;
    								gun_state = 1;	
    								this_ffc->Data++;
    							}
    							else{
    								projectile->X = this_ffc->X;
    								projectile->Y = this_ffc->Y;
    								projectile->Vy = -projectile_speed;
    								projectile->Vx = 0;
    								gun_state = 1;	
    								this_ffc->Data++;
    							}
    					}
    					// If not, calculate the angle to move the shooter.
    					else{
    
    						side_A = this_ffc->Y - Link->Y; // length of side of right triangle parallel to X axis
    						side_B = this_ffc->X; // length of side of right triangle perpendicular to X axis
    						side_C = Sqrt( (side_A*side_A) + (side_B*side_B) ); // length of hypotenuse
    
    						projectile->X = this_ffc->X;
    						projectile->Y = this_ffc->Y;
    
    						projectile->Vy = projectile_speed * (side_A / side_C); // Sin of the angle is opp/hyp
    						projectile->Vx = projectile_speed * (side_B / side_C); // Cos of the angle is adj/hyp
    
    						gun_state = 1;	
    						this_ffc->Data++;	
    					}
    				}
    	
    			} // end of state 0
    	
    			if ( gun_state == 1){
    
    				if(firing_delay >= 0){
    					firing_delay--;
    				}
    				else{
    					firing_delay = 20;
    					this_ffc->Data--;
    					gun_state = 2;
    				}
    
    			} // end of state 1
    
    			if ( gun_state == 2){
    
    				if(delay_counter >= 0){
    					delay_counter--;
    				}
    				else{
    					delay_counter = shot_delay;
    					gun_state = 0;
    				}
    			} // end of state 2
    
    			if ( (projectile->X < 0) || (projectile->Y < 0) ||
    				 (projectile->Y > 160) || (projectile->X > 240) ) {
    
    				projectile->Vx = 0;	
    				projectile->Vy = 0;
    				projectile->X = 0;
    				projectile->Y = -16;
    			}
    	
    			Waitframe();
    
    		} // end of while loop
    
    	} // end of void run
    
    } // end of ffc script
    EDIT: This got posted in "scripting" isntead of "script showcase." Sorry about that, Mods.

  2. #2
    On top of the world ShadowTiger's Avatar
    Join Date
    Jun 2002
    Location
    Southeastern New York
    Posts
    12,231
    Mentioned
    31 Post(s)
    Tagged
    3 Thread(s)
    vBActivity - Stats
    Points
    29,578
    Level
    46
    vBActivity - Bars
    Lv. Percent
    60.3%
    Achievements It's over 9000!

    Re: Gun Script (almost fully functional)

    No it didn't. teehee, .. etc.


    So can this script be used to emulate those roving 1x1 wall cannons in the boss key room of ALTTP's second dungeon? (The sand dungeon in the southeast overworld.)

  3. #3
    Wizrobe C-Dawg's Avatar
    Join Date
    Jan 2002
    Posts
    4,205
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    6,611
    Level
    24
    vBActivity - Bars
    Lv. Percent
    99.77%

    Re: Gun Script (almost fully functional)

    Yea, but I dont think those roving wall cannons cared about Link's position. As is, this one will only fire when Link steps in line with it.

    Other than that, sure. Just have the FFC moving along a path you set up, and it will fire when Link is in line. I'd reduce the speed of the projectile though, as it's currently set to be REALLY fast.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Armageddon Games is a game development group founded in 1997. We are extremely passionate about our work and our inspirations are mostly drawn from games of the 8-bit and 16-bit era.
Social