コード例 #1
0
void EnemyEntity::SetHurt(Vector2 pos)
{
    AnimatedSprite2D* animatesprite = GetComponent<AnimatedSprite2D>();
    if(animatesprite->GetAnimation()!= "hurt")
    {
        animatesprite->SetAnimation("hurt", LM_FORCE_CLAMPED);
        isBusy = true;
        CurrentTime = 0;
        life-=2;
        if(life >= 0)
        {
            timeBusy = 0.26f;
            RigidBody2D* body = GetComponent<RigidBody2D>();
            if(pos.x_>node_->GetPosition2D().x_)
                body->ApplyLinearImpulse(Vector2(-0.5f,0.5f),node_->GetPosition2D(),true );
            else
                body->ApplyLinearImpulse(Vector2(0.5f,0.5f),node_->GetPosition2D(),true );
        }
        else{
            isDead = true;
            animatesprite->SetAnimation("dead", LM_FORCE_CLAMPED);
            timeBusy = 2.0f;
            node_->RemoveComponent<RigidBody2D>();
        }

    }
}
コード例 #2
0
void Urho2DSpriterAnimation::CreateScene()
{
    scene_ = new Scene(context_);
    scene_->CreateComponent<Octree>();

    // Create camera node
    cameraNode_ = scene_->CreateChild("Camera");
    // Set camera's position
    cameraNode_->SetPosition(Vector3(0.0f, 0.0f, -10.0f));

    Camera* camera = cameraNode_->CreateComponent<Camera>();
    camera->SetOrthographic(true);

    Graphics* graphics = GetSubsystem<Graphics>();
    camera->SetOrthoSize((float)graphics->GetHeight() * PIXEL_SIZE);
    camera->SetZoom(1.5f * Min((float)graphics->GetWidth() / 1280.0f, (float)graphics->GetHeight() / 800.0f)); // Set zoom according to user's resolution to ensure full visibility (initial zoom (1.5) is set for full visibility at 1280x800 resolution)

    ResourceCache* cache = GetSubsystem<ResourceCache>();
    AnimationSet2D* spriterAnimationSet = cache->GetResource<AnimationSet2D>("Urho2D/imp/imp.scml");
    if (!spriterAnimationSet)
        return;

    spriterNode_ = scene_->CreateChild("SpriterAnimation");
    AnimatedSprite2D* spriterAnimatedSprite = spriterNode_->CreateComponent<AnimatedSprite2D>();
    spriterAnimatedSprite->SetAnimationSet(spriterAnimationSet);
    spriterAnimatedSprite->SetAnimation(spriterAnimationSet->GetAnimation(spriterAnimationIndex_));
}
コード例 #3
0
void Urho2DSpriterAnimation::HandleMouseButtonDown(StringHash eventType, VariantMap& eventData)
{
    AnimatedSprite2D* spriterAnimatedSprite = spriterNode_->GetComponent<AnimatedSprite2D>();
    AnimationSet2D* spriterAnimationSet = spriterAnimatedSprite->GetAnimationSet();
    spriterAnimationIndex_ = (spriterAnimationIndex_ + 1) % spriterAnimationSet->GetNumAnimations();
    spriterAnimatedSprite->SetAnimation(spriterAnimationSet->GetAnimation(spriterAnimationIndex_), LM_FORCE_LOOPED);
}
コード例 #4
0
void EnemyEntity::Start()
{
    ResourceCache* cache = GetSubsystem<ResourceCache>();

    AnimationSet2D* animationSet = cache->GetResource<AnimationSet2D>("Urho2D/tortuga2.scml");
    if (!animationSet)
        return;

    AnimatedSprite2D* animatedSprite = node_->CreateComponent<AnimatedSprite2D>();
    animatedSprite->SetLayer(2);
    // Set animation
    animatedSprite->SetAnimationSet(animationSet);
    animatedSprite->SetAnimation("walk");
    animatedSprite->SetSpeed(1.0f);

    RigidBody2D* bodysprite = node_->CreateComponent<RigidBody2D>();
    bodysprite->SetBodyType(BT_DYNAMIC);
    bodysprite->SetFixedRotation(true);
    //bodysprite->SetBullet(false);
    //bodysprite->SetLinearVelocity(Vector2::ZERO);
    CollisionCircle2D* circle = node_->CreateComponent<CollisionCircle2D>();
    // Set radius
    circle->SetRadius(1.2f);
    circle->SetDensity(1.0f);
    circle->SetFriction(0.4f);
    circle->SetRestitution(0.0f);
    circle->SetCenter(0,0.35f);
    circle->SetCategoryBits(8192);
    circle->SetMaskBits(65533);

    vel = Vector2(-2.0f,0);
}
コード例 #5
0
ファイル: Urho2DSprite.cpp プロジェクト: cloudffx/Urho3D
void Urho2DSprite::CreateScene()
{
    scene_ = new Scene(context_);
    scene_->CreateComponent<Octree>();

    // Create camera node
    cameraNode_ = scene_->CreateChild("Camera");
    // Set camera's position
    cameraNode_->SetPosition(Vector3(0.0f, 0.0f, -10.0f));

    Camera* camera = cameraNode_->CreateComponent<Camera>();
    camera->SetOrthographic(true);

    Graphics* graphics = GetSubsystem<Graphics>();
    camera->SetOrthoSize((float)graphics->GetHeight() * PIXEL_SIZE);

    ResourceCache* cache = GetSubsystem<ResourceCache>();
    // Get sprite
    Sprite2D* sprite = cache->GetResource<Sprite2D>("Urho2D/Aster.png");
    if (!sprite)
        return;

    float halfWidth = graphics->GetWidth() * 0.5f * PIXEL_SIZE;
    float halfHeight = graphics->GetHeight() * 0.5f * PIXEL_SIZE;

    for (unsigned i = 0; i < NUM_SPRITES; ++i)
    {
        SharedPtr<Node> spriteNode(scene_->CreateChild("StaticSprite2D"));
        spriteNode->SetPosition(Vector3(Random(-halfWidth, halfWidth), Random(-halfHeight, halfHeight), 0.0f));

        StaticSprite2D* staticSprite = spriteNode->CreateComponent<StaticSprite2D>();
        // Set random color
        staticSprite->SetColor(Color(Random(1.0f), Random(1.0f), Random(1.0f), 1.0f));
        // Set blend mode
        staticSprite->SetBlendMode(BLEND_ALPHA);
        // Set sprite
        staticSprite->SetSprite(sprite);

        // Set move speed
        spriteNode->SetVar(VAR_MOVESPEED, Vector3(Random(-2.0f, 2.0f), Random(-2.0f, 2.0f), 0.0f));
        // Set rotate speed
        spriteNode->SetVar(VAR_ROTATESPEED, Random(-90.0f, 90.0f));

        // Add to sprite node vector
        spriteNodes_.Push(spriteNode);
    }

    // Get animation set
    AnimationSet2D* animationSet = cache->GetResource<AnimationSet2D>("Urho2D/GoldIcon.scml");
    if (!animationSet)
        return;

    SharedPtr<Node> spriteNode(scene_->CreateChild("AnimatedSprite2D"));
    spriteNode->SetPosition(Vector3(0.0f, 0.0f, -1.0f));

    AnimatedSprite2D* animatedSprite = spriteNode->CreateComponent<AnimatedSprite2D>();
    // Set animation
    animatedSprite->SetAnimation(animationSet, "idle");
}
コード例 #6
0
void EnemyEntity::SetAtack()
{
    AnimatedSprite2D* animatesprite = GetComponent<AnimatedSprite2D>();
    if(animatesprite->GetAnimation()!= "atack")
    {
        animatesprite->SetAnimation("atack", LM_FORCE_CLAMPED);
        isBusy = true;
        isCharge = true;
        CurrentTime = 0;
        timeBusy = 1.0f;
        timeChargue = 0.8f;
    }
}
コード例 #7
0
void Urho2DSpriterAnimation::HandleMouseButtonDown(StringHash eventType, VariantMap& eventData)
{
    AnimatedSprite2D* animatedSprite = spriteNode_->GetComponent<AnimatedSprite2D>();
    animationIndex_ = (animationIndex_ + 1) % 7;
    animatedSprite->SetAnimation(animationNames[animationIndex_], LM_FORCE_LOOPED);
}
コード例 #8
0
void SceneView3D::HandleDragEnterWidget(StringHash eventType, VariantMap& eventData)
{
    using namespace DragEnterWidget;

    UIWidget* widget = static_cast<UIWidget*>(eventData[P_WIDGET].GetPtr());

    if (widget != this)
        return;

    UIDragObject* dragObject = static_cast<UIDragObject*>(eventData[P_DRAGOBJECT].GetPtr());

    Object* object = dragObject->GetObject();

    if (!object)
        return;

    if (object->GetType() == Asset::GetTypeStatic())
    {
        Asset* asset = (Asset*) object;
        AssetImporter* importer = asset->GetImporter();

        if (!importer)
            return;

        StringHash importerType = importer->GetType();

        if (importerType == PrefabImporter::GetTypeStatic())
        {
            dragNode_ = scene_->CreateChild(asset->GetName());
            PrefabComponent* pc = dragNode_->CreateComponent<PrefabComponent>();
            pc->SetPrefabGUID(asset->GetGUID());
        }
        else if (importerType == ModelImporter::GetTypeNameStatic())
        {
            dragNode_ = scene_->CreateChild();

            SharedPtr<File> file(new File(context_, asset->GetCachePath()));
            SharedPtr<XMLFile> xml(new XMLFile(context_));

            if (!xml->Load(*file))
                return;

            dragNode_->LoadXML(xml->GetRoot());
            dragNode_->SetName(asset->GetName());
        }
        else if (importerType == SpriterImporter::GetTypeNameStatic())
        {
            AnimationSet2D* animationSet = GetSubsystem<ResourceCache>()->GetResource<AnimationSet2D>(asset->GetPath());

            String animationName;

            if (animationSet && animationSet->GetNumAnimations())
            {
                animationName = animationSet->GetAnimation(0)->GetName();
            }

            dragNode_ = scene_->CreateChild(asset->GetName());

            AnimatedSprite2D* sprite = dragNode_->CreateComponent<AnimatedSprite2D>();

            if (!animationName.Length())
                sprite->SetAnimationSet(animationSet);
            else
                sprite->SetAnimation(animationSet, animationName);

        }
        else if (importerType == TextureImporter::GetTypeNameStatic())
        {
            dragNode_ = scene_->CreateChild(asset->GetName());

            Sprite2D* spriteGraphic = GetSubsystem<ResourceCache>()->GetResource<Sprite2D>(asset->GetPath());

            StaticSprite2D* sprite = dragNode_->CreateComponent<StaticSprite2D>();

            sprite->SetSprite(spriteGraphic);
        }


        if (dragNode_.NotNull())
        {
            Input* input = GetSubsystem<Input>();
            IntVector2 pos = input->GetMousePosition();
            UpdateDragNode(pos.x_, pos.y_);
        }



        //LOGINFOF("Dropped %s : %s on SceneView3D", asset->GetPath().CString(), asset->GetGUID().CString());
    }

}
コード例 #9
0
void EnemyEntity::Update(float timeStep)
{
    if(isBusy && isDead)
    {
        CurrentTime+= timeStep;
        if(CurrentTime > timeChargue)
        {
            using namespace EnemyDied;
            VariantMap& eventData = GetEventDataMap();
            eventData[P_NODE] = node_;
            SendEvent(E_ENEMYDIED, eventData);
            isBusy = false;
        }
        return;
    }

    if(isDead)
        return;

    UpdateCast();
    RigidBody2D* body = GetComponent<RigidBody2D>();
    float y = body->GetLinearVelocity().y_;

    if(isBusy)
    {
        CurrentTime+= timeStep;
        if(isCharge)
        {
            if(CurrentTime > timeChargue)
            {
                isCharge = false;
                Shoot();
                isCooldDown = true;
                timeCoolDown = 1;
            }
        }
        if(CurrentTime > timeBusy)
        {
            isBusy = false;
            CurrentTime = 0;
        }
    }
    else
    {
        AnimatedSprite2D* animatesprite = GetComponent<AnimatedSprite2D>();
        if(isCooldDown)
        {
            if(animatesprite->GetAnimation()!= "idle")
            {
                animatesprite->SetAnimation("idle", LM_DEFAULT);
            }
            CurrentTime+= timeStep;
            if(CurrentTime > timeCoolDown)
                isCooldDown = false;
        }
        else
        {
            if(animatesprite->GetAnimation()!= "walk")
            {
                animatesprite->SetAnimation("walk", LM_DEFAULT);
            }
            body->SetLinearVelocity(Vector2::ZERO);
            body->SetLinearVelocity(Vector2(vel.x_, y));
        }
    }
}