Ejemplo n.º 1
0
        private void creatEnemy()
        {
            int enemyId = EnemyHelper.getRandomEnemyFromLevel(level);

            int   blankRand = Random.Range(0, 2);
            float xBlank    = (blankRand == 0) ? 50 : 0;
            float zBlank    = (blankRand == 1) ? 50 : 0;

            float xPos  = Random.Range(0, 50);
            int   xRand = (Random.Range(0, 2) == 0) ? 1:-1;

            xPos  = (xPos + xBlank) * xRand;
            xPos += transform.position.x;

            float zPos  = Random.Range(0, 50);
            int   zRand = (Random.Range(0, 2) == 0) ? 1 : -1;

            zPos  = (zPos + zBlank) * zRand;
            zPos += transform.position.z;

            float yPos = Terrain.activeTerrain.terrainData.GetInterpolatedHeight(
                xPos / Terrain.activeTerrain.terrainData.size.x,
                zPos / Terrain.activeTerrain.terrainData.size.z
                );

            var enemy = EnemyMasterManager.getInstance().getEnemyFromId(enemyId);

            enemy.getContainer().transform.position = new Vector3(xPos, yPos, zPos);
        }
Ejemplo n.º 2
0
        public static World.Enemy SpawnEnemy(Vector3 position, Character <Enemies> viewModel, Transform parent, bool active = false)
        {
            RectTransform transform = Spawn(position, Game.Graphics.Enemy, parent, active);

            // We grab the class's type based on the enum name, and the namespace we use for enemies
            World.Enemy enemy = (World.Enemy)transform.gameObject.AddComponent(EnemyHelper.GetEnemyClass(viewModel.Type));
            if (active)
            {
                enemy.Initialize(viewModel);
            }

            return(enemy);
        }
Ejemplo n.º 3
0
    void FixedUpdate()
    {
        float distanceToPlayer = Vector2.Distance(this.transform.position, StaticPlayer.playerTransform.position);

        if (currentState == State.Wandering)
        {
            wanderTimer += Time.fixedDeltaTime;

            if (wanderTimer >= directionDuration)
            {
                wanderDirection = RandomWanderingDirection();
            }

            EnemyHelper.RotateSpriteToDirection(wanderDirection, spriteTF);
            rb2d.velocity = wanderDirection * moveSpeed;

            if (distanceToPlayer <= noticeDistance)
            {
                if (CheckLineOfSight())
                {
                    currentState = State.Shooting;
                }
            }
        }
        else if (currentState == State.Shooting)
        {
            shootingTimer += Time.fixedDeltaTime;

            // The Shooter wanders in case he is far away or has no direct line of sight
            if (distanceToPlayer > noticeDistance || !CheckLineOfSight())
            {
                currentState = State.Wandering;
            }
            else
            {
                Vector2 aimDirection = StaticPlayer.playerTransform.position - this.transform.position;
                EnemyHelper.RotateSpriteToDirection(aimDirection, spriteTF);

                if (shootingTimer > shootDelay)
                {
                    ShootTowardsPlayer();
                }
            }
        }
    }
Ejemplo n.º 4
0
        // This is called from Initialize in World.Character
        protected override void SetAnimationBase()
        {
            Animation = gameObject.AddComponent <Base.Animation>();
            SetFrameRates();
            List <Color> colors       = new();
            var          animationKey = CharacterType.ToString();

            // TODOJEF: Need to use default colors when creating the animationKey
            if (Colors != null)
            {
                for (var i = 0; i < Colors.Length; i += 2)
                {
                    var color2 = Colors[i + 1];
                    colors.Add(Colors[i].GetColor());
                    colors.Add(color2.GetColor());
                    animationKey += color2.ToString();
                }
            }

            Animation.AnimationSprites = EnemyHelper.GetAnimations(CharacterType, animationKey, colors.ToArray());
        }
Ejemplo n.º 5
0
    public Enemy(EnemyClass _enemyType)
    {
        enemyClass     = _enemyType;
        EnemiesCounter = EnemiesCounter + 1;
        Life           = EnemyHelper.GetInitialLifeByElementType(enemyClass);


        switch (enemyClass)
        {
        case EnemyClass.orco:
            // ........... Orco
            break;

        case EnemyClass.goblin:
            // ........... Enemy
            break;

        default:
            break;
        }
    }
Ejemplo n.º 6
0
        public ExterminationQuest(FlagList flags, Client client)
        {
            this.LEVEL  = client.Level;
            this.client = client;
            this.flags  = flags;

            this.TARGET_ID = EnemyHelper.getRandomEnemyFromLevel(LEVEL);

            this.INTERNAL_NUMBER = flags.getEnemyKilled(TARGET_ID);

            var compensationTypes    = Enum.GetValues(typeof(CompentionType));
            int compensationTypeRand = UnityEngine.Random.Range(0, compensationTypes.Length - 1);

            this.compentionType = (CompentionType)compensationTypes.GetValue(compensationTypeRand);

            EXTERMINATION_NUMBER = LEVEL + UnityEngine.Random.Range(2, 6);

            var targetName = EnemyMasterManager.getInstance().getEnemyBuilderFromId(TARGET_ID).getName();

            NAME        = "駆除依頼";
            DESCRIPTION = targetName + "を" + EXTERMINATION_NUMBER + "匹倒す";
            FLAVOR_TEXT = "最近問題になっている" + targetName + "を駆除しよう";
        }
Ejemplo n.º 7
0
 private Vector2 RandomWanderingDirection()
 {
     wanderTimer       = 0f;
     directionDuration = Random.Range(2f, 3f);
     return(EnemyHelper.GetRandomDirection());
 }
Ejemplo n.º 8
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            // Set the sharing mode of the graphics device to turn on XNA rendering
            SharedGraphicsDeviceManager.Current.GraphicsDevice.SetSharingMode(true);

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(SharedGraphicsDeviceManager.Current.GraphicsDevice);

            // TODO: use this.content to load your game content here
            playerTexture   = contentManager.Load <Texture2D>("player");
            laserTexture    = contentManager.Load <Texture2D>("laser");
            starTexture     = contentManager.Load <Texture2D>("star");
            font            = contentManager.Load <SpriteFont>("font");
            explosion       = contentManager.Load <Texture2D>("explosion0");
            gameOverTexture = contentManager.Load <Texture2D>("gameover");

            //background = new FlowingBackground(this.contentManager.Load<Texture2D>("sky1"), 0.15f, SharedGraphicsDeviceManager.Current.GraphicsDevice.Viewport.Width, SharedGraphicsDeviceManager.Current.GraphicsDevice.Viewport.Height);

            centerX         = SharedGraphicsDeviceManager.Current.GraphicsDevice.Viewport.Width / 2;
            playerYposition = SharedGraphicsDeviceManager.Current.GraphicsDevice.Viewport.Height - 50;
            centerPosition  = new Vector2(centerX, SharedGraphicsDeviceManager.Current.GraphicsDevice.Viewport.Height / 2);
            player          = new Player(playerTexture, centerX, playerYposition, explosion);

            enemyHelper  = new EnemyHelper(explosion);
            endGameScore = new EndGameScore(new Vector2(centerPosition.X, 380), font, gameOverTexture);


            if (e.NavigationMode == NavigationMode.Back)
            {
                elementRenderer = new UIElementRenderer(this, 800, 480);
                isGameOver      = (bool)PhoneApplicationService.Current.State["isGameOver"];

                if (particleSystem == null)
                {
                    particleSystem = (Application.Current as App).BackgroundParticleSystem;

                    LinkedList <Particle> particles = (LinkedList <Particle>)PhoneApplicationService.Current.State["particles"];

                    foreach (var item in particles)
                    {
                        item.Parent = particleSystem.EmitterList.FirstOrDefault();
                    }

                    var emitter = particleSystem.EmitterList.FirstOrDefault();

                    if (emitter != null)
                    {
                        emitter.ActiveParticles = particles;
                    }
                }

                if (enemies == null || PhoneApplicationService.Current.State.ContainsKey("enemies"))
                {
                    enemies = (List <Enemy>)PhoneApplicationService.Current.State["enemies"];

                    enemies = (from en in enemies
                               select new Enemy(font, en, explosion)).ToList();
                }

                //if (bullets == null || PhoneApplicationService.Current.State.ContainsKey("bullets"))
                //{
                //    bullets = (List<LaserBullet>)PhoneApplicationService.Current.State["bullets"];
                //}

                if (PhoneApplicationService.Current.State.ContainsKey("score"))
                {
                    score = (int)PhoneApplicationService.Current.State["score"];
                }

                if (PhoneApplicationService.Current.State.ContainsKey("wave"))
                {
                    wave = (int)PhoneApplicationService.Current.State["wave"];
                }
            }
            else
            {
                isGameOver     = false;
                particleSystem = (Application.Current as App).BackgroundParticleSystem;
            }

            // Start the timer
            timer.Start();

            base.OnNavigatedTo(e);
        }