Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411430 Posts in 69363 Topics- by 58416 Members - Latest Member: JamesAGreen

April 19, 2024, 10:07:29 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsCommunityTownhallForum IssuesArchived subforums (read only)Archived ProjectsIndie BrawlIntro to Indie Brawl's Code
Pages: [1]
Print
Author Topic: Intro to Indie Brawl's Code  (Read 5491 times)
Soulliard
Level 10
*****


The artist formerly known as Nightshade


View Profile WWW
« on: November 05, 2011, 03:06:45 PM »

Several people approached me about working with IB's code, since it can be a little intimidating at first. The organization is a bit non-traditional, since I was relatively new to programming when I started working on it, but I've cleaned up most of the messy portions of the code, so once you understand how it is organized, it should be pretty easy to work with.


Adding Characters

First, you'll need to set up the character's stats. This is done in the finish_creation script. Refer to the comments in Naija's portion of this code for a summary of what all these stats mean.

To add the character's portrait, add the sprite to the 'portraits' list in the Create event of the Control object.

We need to make the character selectable, so we need to look in the menu/Character Select folder. We'll need to create a portrait object like the ones already existing, and we'll need to update the step event of the char_select object.

Next, you'll need to add the character's attacks. Each attack involves a number of separate steps. At each step, the character may enter a new animation, change speed or position, or strike an enemy. This can be a little confusing, so here is a summary of how a single attack was programmed - Nikujin's upward slash.

The action script is where each attack begins. To find the attack, you'll need to navigate a nested switch statement - first to the character number (3), then to the attack number (5, for upwards attack). Here's what you'll see:
Code:
//This line is normally included. It prevents the attack from being used immediately after another attack in the air.
            if(air_attack){
//If airdrift is set to 1, the character will not decelerate naturally during the attack while airborne.
                airdrift = 1;
               
//Set the sprite and animation speed.
                current_sprite = s_nikujin_upslash;
                sprite_speed = 1;
                frame_number = -sprite_speed;
               
//Set the alarm for the windup portion of the attack. In 6 frames, the next step will execute, and Nikujin will swing his sword.
//In the air, the attack only has 4 frames of windup.
                if(onground){
                    alarm[0] = 6;
                }
                else{
                    alarm[0] = 4;
                    frame_number += 2;
                }
               
//This sets a few common variables for the attack, and should almost always be called.
                attack_start();
            }
            break;

Once that alarm hits 0, the next step of the attack will execute. Let's see what happens then:
Code:
//Create the attack itself. We'll get into the attack object a little later.
                attack_create (katana_highslash);
//Identify the attack's next step, and the number of frames before that step is reached.
                next_step = 2;
                alarm [0] = 11;
                break;
A lot of attacks will set variables like xmomentum in this step. This is used to modify the character's movement.

Now let's look at step 2, which is the final step for this attack:
Code:
//Reset all the variables we changed for the attack
            airdrift = 0;
//This script sets a few variables common to most attacks, and should usually be called at an attack's end
            attack_end();
            break;

Now let's look at the attack itself. The sprite for katana_highslash matches the area covered by Nikujin's sword during the attack. It's parent, attack_template, is common to all melee attacks.

The create event sets some important attack variables:
Code:
//Set the duration for the attack. Since this attack is a sword slash, it's hitbox appears very briefly.
alarm[0] = 3;

event_inherited();

//Set the attack's damage, which is only moderate
pow = 5;
//Set the horizontal knockback, which is very low
kbx = .1;
//Set the vertical knockback, which is very high, and aimed upwards
kby = -1.6;
//Set how long the target is stunned for (and unable to attack)
kbtime = 3;
//If two characters hit each other at the same time, the attack with higher priority takes effect. 7 is fairly high.
priority = 7;

//Play the sound for the attack
FMODSoundPlay(Control.sMiss);

Now let's see what happens when the attack hits another character (a collision event)
Code:
//We always call this function to make sure the character is a valid target.
//It must be on an opposing team, and not currently immune to the character's attacks.
attack_aim(alarm[0]);

//If the previous function was successful, target will be set to true, otherwise it will be false
if(target){
//Resolve the effect of the attack hitting. The second variable should always be 5 - it's a relic of previous versions of the game
    attack_hit(pow,5,kbx,kby,kbtime,unblockable);

//If the attack was a successful hit (it was not blocked), the following code will execute
    if(shield_break){
//player_id refers to the character that made the attack. Nikujin's jumps are reset each time he lands an aerial attack.
        player_id.doublejump = player_id.maxjumps;
        player_id.walljumps = player_id.maxwjumps;
        player_id.up_attack = 1;
//Generate sound effects and particles.
        FMODSoundPlay(Control.m_sword_hit);
        part_particles_create(Control.p_sys,other.x+image_xscale*3,other.y,Control.p_nik_sword,1);
    }
}

event_inherited();


Adding Items

First, you need to add the item object. Each item must have a unique item_number, under 100 for thrown items, and over 100 for buffs.

If it's a thrown item, you also need to add the item's attack object. This works just like creating a character attack object. Then, you'll need to add the item's sprite  and objects to a few lists in the Create event of the Control object.

If it's not a thrown item, you'll need to add it's effect to the action script. Near the top of the script is a section where it generates different effects for picking up items. For complex item effects, you may need to add additional code for the Character object's creation and step events. Look at how other items are handled for reference.

Of course, you'll also need to make it possible for the game to generate the item. Add it to the create_item script.


Adding Stages

When placing level terrain, it's important to keep in mind the different types of terrain:
Walls are completely solid, and can't be moved through in any direction.
Characters can jump up through Floors, and drop through them, too.
Semisolids are like Floors, but you can't drop through them. They should be used instead of floors if there's no realistic reason to drop through it.

Each stage needs to have a Control object, which must be placed somewhere in the stage. All this object really needs to do is set character and item spawning locations, but it also usually handles backgrounds and music.


Adding Sounds and Particles

For consistency, this is done in the Create Event of the Control object. When you add a new sound, make sure you also remove it in the Game End event of the Control object!
Logged

Garlicguy
Level 3
***


Good vibes all around.


View Profile
« Reply #1 on: November 05, 2011, 04:02:35 PM »

Ok this is great.
I'll need to get my hands on the player input script to add the ai, some time.
Logged

Soulliard
Level 10
*****


The artist formerly known as Nightshade


View Profile WWW
« Reply #2 on: November 06, 2011, 06:52:46 PM »

All the scripts that deal with control are in the controls directory. The only places they're called is in the Step event of the Character object, and in a few attack scripts.
Logged

thatbrod
Level 0
***



View Profile
« Reply #3 on: May 09, 2013, 07:41:36 AM »

hi. I'd like to work on the code. I had one idea that I believe would make working on this a lot simpler. I noticed that for attacks and such you use a bunch of timing related stuff, so why not use timelines to do it? I wanted to take all the code from your step stuff and implement it into timelines, because I believe that'd be much simpler and organized. so, yeah, I wanted to run it by you to make sure you'd be cool with that.
Logged

Soulliard
Level 10
*****


The artist formerly known as Nightshade


View Profile WWW
« Reply #4 on: May 18, 2013, 01:08:32 PM »

I don't have time to work on this any more, so you can feel free to do whatever you want with the code. If you want to take over the coding, you have my blessing. I would love to see this project completed!
Logged

tnr
Level 1
*


View Profile
« Reply #5 on: May 18, 2013, 02:52:32 PM »

I know that I'm pretty overjoyed that somebody is taking over the coding for this project. When I found it I was so disappointed that it wasn't finished. I'm eager for it to become finished.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic