Exemplo n.º 1
0
    void fireProjectile(MovementComponent movementComponent, Translation translation, float3 directionToPlayer)
    {
        Vector2 dirNormalize;

        dirNormalize.x = directionToPlayer.x;
        dirNormalize.y = directionToPlayer.y;
        dirNormalize.Normalize();

        directionToPlayer.x = dirNormalize.x;
        directionToPlayer.y = dirNormalize.y;

        Entity e = PostUpdateCommands.CreateEntity(ProjectileBehaviour.GetArchetype());

        PostUpdateCommands.SetComponent(e, new ProjectileStatsComponent
        {
            SpeedModifier = 10f,
            Alive         = true,
            IsFromPlayer  = true,
            Direction     = directionToPlayer
        });
        PostUpdateCommands.SetComponent(e, new MovementComponent
        {
            currMovementDirection = movementComponent.currMovementDirection
        });
        PostUpdateCommands.SetComponent(e, new Translation
        {
            Value = translation.Value
        });
        PostUpdateCommands.SetComponent(e, new Scale
        {
            Value = 0.4f
        });
        PostUpdateCommands.SetComponent(e, new ColliderComponent
        {
            Size = .2f
        });
        PostUpdateCommands.SetSharedComponent(e, new RenderMesh
        {
            mesh     = GlobalObjects.mesh,
            material = GlobalObjects.material
        });

        projectileFired = true;
    }
Exemplo n.º 2
0
    void Shoot(float3 enemyPos, float3 playerPos)
    {
        float3  directionToPlayer = playerPos - enemyPos;
        Vector2 dirNormalize;

        dirNormalize.x = directionToPlayer.x;
        dirNormalize.y = directionToPlayer.y;
        dirNormalize.Normalize();

        directionToPlayer.x = dirNormalize.x;
        directionToPlayer.y = dirNormalize.y;

        Entity e = PostUpdateCommands.CreateEntity(ProjectileBehaviour.GetArchetype());

        PostUpdateCommands.SetComponent(e, new ProjectileStatsComponent
        {
            SpeedModifier = 10f,
            Alive         = true,
            IsFromPlayer  = false,
            Direction     = directionToPlayer
        });

        PostUpdateCommands.SetComponent(e, new Translation
        {
            Value = enemyPos
        });
        PostUpdateCommands.SetComponent(e, new Scale
        {
            Value = 0.4f
        });
        PostUpdateCommands.SetComponent(e, new ColliderComponent
        {
            Size = .2f
        });
        PostUpdateCommands.SetSharedComponent(e, new RenderMesh
        {
            mesh     = GlobalObjects.mesh,
            material = GlobalObjects.material
        });
    }