Game Development Community

Donkey Kong Attack State

by Ricardo Bencz · in Torque X Platformer Kit · 08/23/2010 (11:57 pm) · 4 replies

Hello everyone.

We are posting here several times about a simple attack state, but we didn't have any success.

What we need is only a state like "Donkey Kong Country 1", when pressing button "Y" in snes, the Donkey rolls to attack an enemy.

We've managed to trigger a custom animation by pressing the "X" button on the keyboard using ActionState native within torque, and it works.

Now we need to know what's the best way to continue:

Custom collision? Simple make a logic in DrillHeadKill component in OnRegister method? Or other way?

How we can implement this in our code, friends?

Thanks in advance.

Regards.

#1
08/25/2010 (5:17 pm)
I created a simple "Sword Component" for this instance. The sword follows the player around whereever he goes, and if he collides, he either does damage or doesn't.

Anyways, its such a simple component, I don't mind sharing it at this time. So have at it.

using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.Xna.Framework;

using GarageGames.Torque.Core;
using GarageGames.Torque.Sim;
using GarageGames.Torque.T2D;

using GarageGames.Torque.PlatformerFramework;

namespace GarageGames.Torque.PlatformerDemo
{
    [TorqueXmlSchemaType]
    public class swordComponent : TorqueComponent, ITickObject
    {
        //======================================================
        #region Static methods, fields, constructors
        #endregion

        //======================================================
        #region Constructors
        #endregion

        //======================================================
        #region Public properties, operators, constants, and enums

        public T2DSceneObject SceneObject
        {
            get { return Owner as T2DSceneObject; }
        }
        [TorqueXmlSchemaType]
        public static T2DOnCollisionDelegate OnCollisionDelegate
        {
            get { return _onCollisionDelegate; }
            set { _onCollisionDelegate = value; }
        }

        [TorqueXmlSchemaType(DefaultValue = "100")]
        public float AttackValue
        {
            get { return _attackValue; }
            set { _attackValue = value; }
        }

            
        [TorqueXmlSchemaType]
        public  T2DSceneObject OwnerPlayer
        {
            get { return _ownerPlayer; }
            set { _ownerPlayer = value; }
        }

        public ActorComponent OwnerActorCompenent
        {
            get { return _ownerActorComponent; }
            set { _ownerActorComponent = value; }
        }



        public static void OnCollision(T2DSceneObject ourObject, T2DSceneObject theirObject, T2DCollisionInfo info, ref T2DResolveCollisionDelegate resolve, ref T2DCollisionMaterial physicsMaterial)
        {
            ActorComponent thierActor = theirObject.Components.FindComponent<ActorComponent>();
            swordComponent ourSword = ourObject.Components.FindComponent<swordComponent>();

            if (thierActor != null && ourSword != null)
            {
                if (ourSword.OwnerActorCompenent.Attacking != true)
                    return;
                thierActor.TakeDamage(ourSword.AttackValue, ourObject);
            }
        } 

        #endregion

        //======================================================
        #region Public methods

        public virtual void ProcessTick(Move move, float dt)
        {
            _sceneObject.Position = _ownerPlayer.Position;
        }

        public virtual void InterpolateTick(float k)
        {
        }

        public override void CopyTo(TorqueComponent obj)
        {
            base.CopyTo(obj);
        }

        #endregion

        //======================================================
        #region Private, protected, internal methods

        protected override bool _OnRegister(TorqueObject owner)
        {
            if (!base._OnRegister(owner) || !(owner is T2DSceneObject))
                return false;
            _sceneObject = owner as T2DSceneObject;
            _sceneObject.Collision.CollidesWith += PlatformerData.EnemyObjectType;
            ProcessList.Instance.AddTickCallback(owner, this);
            _ownerActorComponent = _ownerPlayer.Components.FindComponent<ActorComponent>();
            return true;
        }
        protected override void _PostRegister()
        {
            base._PostRegister();
            SceneObject.Visible = false;
        }
        protected override void _OnUnregister()
        {
            base._OnUnregister();
        }

        protected override void _RegisterInterfaces(TorqueObject owner)
        {
            base._RegisterInterfaces(owner);
        }


        #endregion

        //======================================================
        #region Private, protected, internal fields
        static T2DOnCollisionDelegate _onCollisionDelegate = OnCollision;
        T2DSceneObject _sceneObject;
        T2DSceneObject _ownerPlayer;
        ActorComponent _ownerActorComponent;
        private float _attackValue = 100;
        #endregion
    }
}
#2
08/25/2010 (5:20 pm)
To use this in the editor, set up a scene object with a collision polygon bigger then your player, and add this component to it. Also make sure your acting component has a public property which say's if it's attacking or not.

Feel free to modify this component as much as you want, to get other custom behaviors.
#3
08/28/2010 (12:38 pm)
Hey Will, the system don't call your component OnCollision method.

What's wrong?

Regards.
#4
08/28/2010 (5:45 pm)
hmm.. did you set the OnCollision in the editor? I forgot to mention that you would also need to do that...

You should do the "Blaster" Tutorials as well as the others, they'll help you see obvious things such as that.