Beispiel #1
0
        public override void OnCreate()
        {
            entity.AddTag("Daemon");

            entity.name = "pixie";

            base.OnCreate();
            _renderer = entity.AddComponent <DaemonRenderer>();
            _renderer.SetTexture("pixie").SetLayer(ViewLayers.FOREGROUND);
            _renderer.SetTexture("pixie_lightmap", RenderMode.LIGHT_MAP);

            entity.AddComponent <BasicBody>().SetHitbox(new FloatRect(16, 16, 32, 32));
            //entity.AddComponent<Light>().AddLayer(ViewLayers.TERRAIN).SetColor(new Color(16, 32, 64));
            entity.body.noClip = true;
            //entity.AddComponent<Light>().SetColor(new Color(255, 0, 255)).SetRadius(200).AddLayer(ViewLayers.TERRAIN);

            LDWorld w = (LDWorld)world;

            referencePosition = new Vector2f(
                Random.Range(0, w.map.cells.sizeX),
                Random.Range(0, w.map.cells.sizeY)
                );

            _rand         = Random.Range(0f, 1000f);
            _wanderRadius = Random.Range(6f, 10f);
        }
Beispiel #2
0
        public override void OnUpdate()
        {
            Vector2f lastPosition = position;

            base.OnUpdate();
            position += new Vector2f(
                speed * world.delta * Mathf.Cos(rotation * Mathf.DEG2RAD),
                speed * world.delta * Mathf.Sin(rotation * Mathf.DEG2RAD)
                );
            entity.sprite.position = position * Game.TS;

            LDWorld ldworld = (LDWorld)world;

            if (ldworld.map.mapCollider.Collides(position))
            {
                entity.DestroyLater();
                PlayHitSound();
            }

            IEnumerable <Entity> enemies = world.GetTaggedEntities("Enemy");

            foreach (Entity e in enemies)
            {
                Daemon daemon = e.GetComponent <Daemon>();
                if (e.body.Collides(position))
                {
                    if (ldworld.dimension == 1)
                    {
                        //world.debugLines.DrawLine(position, lastPosition);
                        daemon.Hurt(1);
                        entity.DestroyLater();
                        PlayHitSound();
                    }
                    else if (!_traversedOnce)
                    {
                        PlayTraverseSound();
                        _traversedOnce = true;
                    }
                }
            }

            lifeTime += world.delta;
            if (lifeTime > 2f)
            {
                entity.DestroyLater();
            }
        }