User Tag List

Results 1 to 10 of 10

Thread: Gun script

  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,613
    Level
    25
    vBActivity - Bars
    Lv. Percent
    0.17%

    Gun script

    I'll check this out when I get home, but just coded up a gun script.

    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 = speed of the projectile
    // 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.)
    // NOTE - 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.
    // ==========================================
    
    ffc script gun{
    
    	void run(int shot_delay, int projectile_ffc_number, int projectile_speed, 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 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.
    
    		projectile = ffc Screen->LoadFFC(projectile_ffc_number);
    
    		while (true){
    
    			if (gun_state == 0){
    
    				if ( (shoots_north == 1) && (Link->X < this->X+16) && (Link->X > this->X-1) && (Link->Y < this->Y)){
    		
    					projectile->X = this->X;
    					projectile->Y = this->Y;
    					projectile->Vy = -projectile_speed;
    					projectile->Vx = 0;
    					gun_state = 1;	
    					this->Data++;
    				}
    
    				if ( (shoots_south == 1) && (Link->X < this->X+16) && (Link->X > this->X-1) && (Link->Y > this->Y)){
    			
    					projectile->X = this->X;
    					projectile->Y = this->Y;
    					projectile->Vy = projectile_speed;
    					projectile->Vx = 0;
    					gun_state = 1;	
    					this->Data++;
    				}
    
    				if ( (shoots_east == 1) && (Link->Y < this->Y+16) && (Link->Y > this->Y-1) && (Link->X > this->X)){
    		
    					projectile->X = this->X;
    					projectile->Y = this->Y;
    					projectile->Vx = projectile_speed;
    					projectile->Vy = 0;
    					gun_state = 1;	
    					this->Data++;
    				}
    	
    				if ( (shoots_west == 1) && (Link->Y < this->Y+16) && (Link->Y > this->Y-1) && (Link->X < this->X)){
    			
    					projectile->X = this->X;
    					projectile->Y = this->Y;
    					projectile->Vx = -projectile_speed;
    					projectile->Vy = 0;
    					gun_state = 1;	
    					this->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
    		
    					if(Link->X = this->X){
    				   		if ( Link->Y > this->Y){
    							projectile->X = this->X;
    							projectile->Y = this->Y;
    							projectile->Vy = projectile_speed;
    							projectile->Vx = 0;
    							gun_state = 1;	
    							this->Data++;
    						}
    						if ( Link->Y < this->Y){
    							projectile->X = this->X;
    							projectile->Y = this->Y;
    							projectile->Vy = -projectile_speed;
    							projectile->Vx = 0;
    							gun_state = 1;	
    							this->Data++;
    						}
    
    					// If not, calculate the angle to move the shooter.
    					else{
    
    						side_A = this->Y - Link->y; // length of side of right triangle parallel to X axis
    						side_B = this->X; // length of side of right triangle perpendicular to X axis
    						side_C = Sqrt( (side_A*sideA) + (sideB*sideB) ); // length of hypotenuse
    
    						projectile->X = this->X;
    						projectile->Y = this->Y;
    
    						projectile->Vy = speed * (side_A / side_C); // Sin of the angle is opp/hyp
    						projectile->Vx = speed * (side_B / side_C); // Cos of the angle is adj/hyp
    
    						gun_state = 1;	
    						this->Data++;
    					}		
    				}
    	
    			} // end of state 0
    	
    			if ( gun_state == 1){
    
    				if(firing_delay >= 0){
    					firing_delay--;
    				}
    				else{
    					firing_delay = 20;
    					this->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 is off the screen) {
    
    				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

  2. #2
    Lynel Majora's Avatar
    Join Date
    Mar 2006
    Age
    32
    Posts
    1,197
    Mentioned
    24 Post(s)
    Tagged
    7 Thread(s)
    vBActivity - Stats
    Points
    4,390
    Level
    20
    vBActivity - Bars
    Lv. Percent
    94.35%

    Re: Gun script

    Is this gun like a shooter enemy? or does it make Link a GTA character?

  3. #3
    Lynel Revfan9's Avatar
    Join Date
    Jun 2005
    Location
    In front of a screen. I never leave.
    Age
    31
    Posts
    1,160
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    3,391
    Level
    18
    vBActivity - Bars
    Lv. Percent
    71.47%

    Re: Gun script

    Yes MW, it's like a shooting enemy. Pretty cool C-Dawg.

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

    Re: Gun script

    It's buggy. I'm fixing it now, it'll be in script showcase in a moment.

    Or not. I'm getting wierd behavior now.

    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 = speed of the projectile
    // 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.)
    // NOTE - 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.
    // ==========================================
    
    ffc script gun{
    
    	void run(int shot_delay, int projectile_ffc_number, int projectile_speed, 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 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);
    
    		while (true){
    
    			if (gun_state == 0){
    
    				if ( (shoots_north == 1) && (Link->X < this->X+16) && (Link->X > this->X-1) && (Link->Y < this->Y)){
    		
    					projectile->X = this->X;
    					projectile->Y = this->Y;
    					projectile->Vy = -projectile_speed;
    					projectile->Vx = 0;
    					gun_state = 1;	
    					this->Data++;
    				}
    
    				if ( (shoots_south == 1) && (Link->X < this->X+16) && (Link->X > this->X-1) && (Link->Y > this->Y)){
    			
    					projectile->X = this->X;
    					projectile->Y = this->Y;
    					projectile->Vy = projectile_speed;
    					projectile->Vx = 0;
    					gun_state = 1;	
    					this->Data++;
    				}
    
    				if ( (shoots_east == 1) && (Link->Y < this->Y+16) && (Link->Y > this->Y-1) && (Link->X > this->X)){
    		
    					projectile->X = this->X;
    					projectile->Y = this->Y;
    					projectile->Vx = projectile_speed;
    					projectile->Vy = 0;
    					gun_state = 1;	
    					this->Data++;
    				}
    	
    				if ( (shoots_west == 1) && (Link->Y < this->Y+16) && (Link->Y > this->Y-1) && (Link->X < this->X)){
    			
    					projectile->X = this->X;
    					projectile->Y = this->Y;
    					projectile->Vx = -projectile_speed;
    					projectile->Vy = 0;
    					gun_state = 1;	
    					this->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
    		
    					if(Link->X == this->X){
    				   		if ( Link->Y > this->Y){
    								projectile->X = this->X;
    								projectile->Y = this->Y;
    								projectile->Vy = projectile_speed;
    								projectile->Vx = 0;
    								gun_state = 1;	
    								this->Data++;
    							}
    							else{
    								projectile->X = this->X;
    								projectile->Y = this->Y;
    								projectile->Vy = -projectile_speed;
    								projectile->Vx = 0;
    								gun_state = 1;	
    								this->Data++;
    							}
    					}
    					// If not, calculate the angle to move the shooter.
    					else{
    
    						side_A = this->Y - Link->Y; // length of side of right triangle parallel to X axis
    						side_B = this->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->X;
    						projectile->Y = this->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->Data++;	
    					}
    				}
    	
    			} // end of state 0
    	
    			if ( gun_state == 1){
    
    				if(firing_delay >= 0){
    					firing_delay--;
    				}
    				else{
    					firing_delay = 20;
    					this->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
    A gun shooting N, S, E, or W works just fine. But add a second gun to the same screen and it gets all weird. Unpredictable effects. THIS SHOULD NOT HAPPEN THERE ARE NO GLOBAL VARIABLES.

    The omnidirectional gun doesn't seem to work at all. It fires towards the upper right constantly in my test.

  5. #5
    Developer
    ZC Developer

    Join Date
    Aug 2006
    Location
    Australia
    Age
    37
    Posts
    2,777
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    6,852
    Level
    25
    vBActivity - Bars
    Lv. Percent
    37.98%

    Re: Gun script

    The scripting system was made under the assumption that no two FFCs would ever run the same script. See here for what's being done about it.

  6. #6
    Developer
    ZC Developer
    jman2050's Avatar
    Join Date
    Jun 2001
    Location
    Do you really need to know
    Age
    37
    Posts
    3,883
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    5,711
    Level
    23
    vBActivity - Bars
    Lv. Percent
    46.48%

    Re: Gun script

    An alternative, for the time being, is to copy the script and have it compile it two or three different times, depending on how many you want on-screen simultaneously. It wastes script slots, but until the scripting system is tweaked I don't see a choice.
    AGN's Resident Zelda Classic Developer and Sonic the Hedgehog Fanboy

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

    Re: Gun script

    Not a problem. If I max out the script slots, I'll just whine for you guys to increase the number.

    Still, it's awfully nice to have a grip on why multiple FFCs go haywire now. I've been using ZQuest long enough to have made my peace with workarounds. Hell, they usually lead to new ways to use the engine.

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

    Re: Gun script

    Actually, I don't think that works. Anyone actually tried making multiple copies of the same FFC script with different names? It seems like all of the scripts keep working as if they were all running on FFC1 or something.

  9. #9
    Is this the end?
    ZC Developer
    Saffith's Avatar
    Join Date
    Jan 2001
    Age
    41
    Posts
    3,389
    Mentioned
    178 Post(s)
    Tagged
    6 Thread(s)
    vBActivity - Stats
    Points
    6,434
    Level
    24
    vBActivity - Bars
    Lv. Percent
    70.35%

    Re: Gun script

    Yeah, that seems to be exactly what it's doing. Apparently, each FFC's script affects FFC #1 instead of whichever it's attached to. Another problem with REFFFC, perhaps?
    Sigh. It'd be great if all this stuff would work right, but...

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

    Re: Gun script

    The problem seems to be that "this->whatever" always points to FFC1. That doesn't sound too hard to fix. (DarkDragon?)

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