Armour for characters

Started by Marienus, Sun 05/10/2014 12:29:04

Previous topic - Next topic

Marienus

So I'm quite new to AGS, and I just made my first "Game" (actually created to get the hang of it), and I would like to figure out a way how you can put armour on a character, first I was thinking of creating a view for every type of armour, but I realised that would not be a good idea (since I'd needed to make around 150 sets of sprites, I hope people understand why I will not do that.) I was personally thinking of putting an object on the character that stays fixed on it all the time, but before I'll start scripting I'd like to see what other people would use as a solution, because my idea could be a little inconvenient. Links to modules are welcome as well, of course. :)
Thanks for your time!

Ghost

#1
There is a tested solution to this: Make the armour a separate character that overlays your player. Then use the FollowCharacter command- it's covered in the manual but this bit here is the important thing:

"... There is also another special use for this command. You can pass the special value FOLLOW_EXACTLY as the DIST parameter rather than passing a number. If you do this, then CHARID will always remain at exactly the same X and Y co-ordinates as CHARTOFOLLOW. This might be useful for effects such as a temporary halo over the character and so forth.
...There is also another special use for this command. You can pass the special value FOLLOW_EXACTLY as the DIST parameter rather than passing a number. If you do this, then CHARID will always remain at exactly the same X and Y co-ordinates as CHARTOFOLLOW. This might be useful for effects such as a temporary halo over the character and so forth.
"


So basically, you want a character with a "plain clothes" view. Then create another character (cArmour maybe) and assign the armour view. Then use
cArmour.FollowCharacter(player, FollowExactly, 1);

The charm is that you can easily have several armours, since you can switch views for a character easily.

The downside is that you will need to create animations for both player AND armour walking, talking etc, but if you're not aiming at super-detailed sprites and animations, it's a practical approach.

__
edit:
Objects, as you mention in your post, won't get you very far. Objects are tied to a room (the can not change between rooms), only players can change between rooms. The beauty of FollowCharacter is that you just activate it once- and until you stop it, your armour character will always change rooms and keep its position.

Crimson Wizard

#2
You can utilize DynamicSprites for this.
Related topics in manual:
http://www.adventuregamestudio.co.uk/wiki/DynamicSprite_functions_and_properties
http://www.adventuregamestudio.co.uk/wiki/DrawingSurface_functions_and_properties
http://www.adventuregamestudio.co.uk/wiki/ViewFrame_functions_and_properties
http://www.adventuregamestudio.co.uk/wiki/Game_/_Global_functions#Game.GetViewFrame
Also probably this
http://www.adventuregamestudio.co.uk/wiki/Dynamic_Arrays

Create a dynamic sprite per character frame, then copy over "base" images of you character and an "armor" overlay; then apply this new sprite to character View.
This will require scripting a drawing system to make things cleaner, which would require some thinking and work, but should be doeable.

Since, as you say, you are new to AGS, I'd suggest you play with more basic scripting first to get a hand of it. Do simple tasks early, and leave complex ones for later times.

Anyway, here's "basic" example of what I was talking about:
Code: ags


//
// A generic function that dynamically creates a loop of frames with given parameters
//
DynamicSprite *[] CreateDynLoop(int CHARACTER_VIEW, int VIEW_LOOP, int FIRST_CHARACTER_SPRITE,
                                int FIRST_ARMOR_SPRITE, int NUM_OF_FRAMES)
{
   // create a new array of sprites
   DynamicSprite *dyn_loop[] = new DynamicSprite[NUM_OF_FRAMES];

   int i = 0;
   while (i < NUM_OF_FRAMES)
   {
       // Create a new dynamic sprite as a copy of "base" image
       DynamicSprite *spr = DynamicSprite.CreateFromExistingSprite(FIRST_CHARACTER_SPRITE + i);
       // Draw armor overlay
       DrawingSurface *ds = spr.GetDrawingSurface();
       ds.DrawImage(FIRST_ARMOR_SPRITE + i, 0, 0);
       ds.Release();
       // Now get the character View's left loop's Nth frame
       ViewFrame *frame = Game.GetViewFrame(CHARACTER_VIEW, VIEW_LOOP, i);
       // Assign new dynamic sprite to the View's frame
       frame.Graphic = spr.Graphic;
       // Store new sprite in prepared array so that it won't get "lost" while you are still using it
       dyn_loop[i] = spr;
       i++;
   }
   // return newly created array of sprites
   return dyn_loop;
}


// Global arrays to store dynamic sprites (otherwise they will get 'recycled')
DynamicSprite *DynLoop_Left[]; // a global array of dynamic sprites for "left" loop
DynamicSprite *DynLoop_Right[]; // a global array of dynamic sprites for "right" loop
DynamicSprite *DynLoop_Up[]; // a global array of dynamic sprites for "up" loop
DynamicSprite *DynLoop_Down[]; // a global array of dynamic sprites for "down" loop

// Function that creates all four loops
function CreateAllLoopsForCharacterWithArmor()
{
    // Create four directional loops with armor overlay
    // NOTE: put your own numbers for function parameters
    DynLoop_Left  = CreateDynLoop(MY_CHAR_VIEW, 1, FIRST_CHAR_LEFT_SPRITE, FIRST_ARMOR_LEFT_SPRITE, LENGTH_OF_LEFT_LOOP);
    DynLoop_Right = CreateDynLoop(MY_CHAR_VIEW, 2, FIRST_CHAR_RIGHT_SPRITE, FIRST_ARMOR_RIGHT_SPRITE, LENGTH_OF_RIGHT_LOOP);
    DynLoop_Up    = CreateDynLoop(MY_CHAR_VIEW, 3, FIRST_CHAR_UP_SPRITE, FIRST_ARMOR_UP_SPRITE, LENGTH_OF_UP_LOOP);
    DynLoop_Down  = CreateDynLoop(MY_CHAR_VIEW, 0, FIRST_CHAR_DOWN_SPRITE, FIRST_ARMOR_DOWN_SPRITE, LENGTH_OF_DOWN_LOOP);
}

After implementing similar code, you will be able to dynamically change the character view, combining different images.


//-------------------------
EDIT: Yeah, Ghost's solution is more simple :D.

Marienus

Thanks for all the solutions! I'll see if I can implement them. :)

SMF spam blocked by CleanTalk