コード例 #1
0
 private void Start()
 {
     randomSpeed     = ReturnRandomCarSpeedBetween(minEnemySpeedOnLevels[LevelManager.currentLevel], maxEnemySpeedOnLevels[LevelManager.currentLevel]);
     rb              = GetComponent <Rigidbody>();
     playerTransform = GameObject.FindGameObjectWithTag("Player").transform;
     enemyCollision  = GetComponent <EnemyCollision>();
 }
コード例 #2
0
ファイル: EnemyEntity.cs プロジェクト: berhane02/MarioGame
 public GreenKoopaEntity(Vector2 loc) : base(loc)
 {
     IsLeft          = false;
     Sprite          = new GreenKoopa(loc);
     EntityCollision = new EnemyCollision(this);
     StartDirection();
 }
コード例 #3
0
    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        p1   = GameObject.FindGameObjectWithTag("Player");
        tr   = animator.gameObject.transform;
        rb   = animator.gameObject.GetComponent <Rigidbody2D>();
        coll = animator.gameObject.GetComponent <EnemyCollision>();



        if (tr.position.x < p1.transform.position.x)
        {
            P_right = true;
        }
        else if (tr.position.x > p1.transform.position.x)
        {
            P_right = false;
        }

        if (GroundCount < 1 && P_right == true)
        {
            invert(-1);
        }
        else if (GroundCount < 1 && P_right == true)
        {
            invert(1);
        }
    }
コード例 #4
0
ファイル: EnemyEntity.cs プロジェクト: berhane02/MarioGame
 public BowserEntity(Vector2 loc, MarioEntity mario) : base(loc)
 {
     Mario           = mario;
     EntityCollision = new EnemyCollision(this);
     Sprite          = new Bowser(loc);
     State           = new StandardBowserState(this);
 }
コード例 #5
0
ファイル: Bounce.cs プロジェクト: mateusruppel/MetroidVania_
 void Start()
 {
     tr          = gameObject.transform;
     rb          = gameObject.GetComponent <Rigidbody2D>();
     anim        = gameObject.GetComponent <Animator>();
     coll        = gameObject.GetComponent <EnemyCollision>();
     GroundCount = 0;
 }
コード例 #6
0
ファイル: EnemyEntity.cs プロジェクト: berhane02/MarioGame
        public RedKoopaEntity(Vector2 loc) : base(loc)
        {
            IsLeft = true;
            Sprite = new RedKoopa(loc);

            EntityCollision = new EnemyCollision(this);
            StartDirection();
        }
コード例 #7
0
ファイル: EnemyEntity.cs プロジェクト: berhane02/MarioGame
        public GoombaEntity(Vector2 loc) : base(loc)
        {
            Sprite          = new WalkingGoomba(loc);
            EntityCollision = new EnemyCollision(this);

            IsLeft = true;
            StartDirection();
        }
コード例 #8
0
 private void OnCollisionEnter(Collision collision)
 {
     if (collision.gameObject.CompareTag("enemy"))
     {
         _particle.Play();
         EnemyCollision.SafeInvoke(this, _type);
     }
 }
コード例 #9
0
    // Start is called before the first frame update
    void Awake()
    {
        enemy = GetComponent <RectTransform>();
        _anim = GetComponent <Animator>();

        shootCs = GetComponent <EnemyShoot>();
        col     = GetComponent <EnemyCollision>();
    }
コード例 #10
0
ファイル: ZoomController.cs プロジェクト: Nazarian44/Memento
    private void OnTriggerEnter2D(Collider2D collision)
    {
        this.enemyCollision = collision.GetComponent <EnemyCollision>();

        if (collision.gameObject.name == "Enemy")
        {
            camera.Zoom();
        }
    }
コード例 #11
0
    private void Start()
    {
        coll      = GetComponent <EnemyCollision>();
        alive     = transform.Find("Alive").gameObject;
        rbAlive   = alive.GetComponent <Rigidbody2D>();
        aliveAnim = alive.GetComponent <Animator>();

        currentHealth   = maxHealth;
        facingDirection = 1;
    }
コード例 #12
0
 public Koopa(Game1 game, float x, float y) : base(new Vector2(x, y), new LVector2(Limit <Vector2> .NONE), new LVector2(Limit <Vector2> .NONE))
 {
     this.game = game;
     Bounds    = new Rectangle(0, 0, 1, 1);
     Movement  = new EntityMovement(game);
     Collision = new EnemyCollision();
     Speed     = 2;
     State     = new KoopaLeftMovingState(game, this);
     Flip      = false;
 }
コード例 #13
0
    void SpawnEnemy()
    {
        int        randIndex = Random.Range(0, 4);
        GameObject enemy     = GameObject.CreatePrimitive(PrimitiveType.Cube);

        enemy.AddComponent(typeof(Rigidbody));
        EnemyCollision enemyScript = enemy.AddComponent <EnemyCollision>();

        enemyScript.score        = score;
        enemyScript.gameOver     = gameOver;
        enemy.transform.position = directions[randIndex];
        Rigidbody enemyBody = enemy.GetComponent <Rigidbody>();

        enemy.GetComponent <Renderer>().material = color;
        enemyBody.AddForce(forceDirections[randIndex]);
    }
コード例 #14
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.tag.Equals("Crate") || collision.tag.Equals("PatrolEnemy"))
        {
            // Destory it
            EnemyHealth enemyHealth = collision.gameObject.GetComponent <EnemyHealth>();
            enemyHealth.StartKill();
        }

        if (collision.tag.Equals("Player"))
        {
            // Remove health
            EnemyCollision enemyCollision = collision.gameObject.GetComponent <EnemyCollision>();
            enemyCollision.RemoveHitPoints();
        }
    }
コード例 #15
0
    void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else
        {
            Destroy(gameObject);
            return;
        }

        // set ref for pause_ui, score_ui, game_over_ui
        pause_ui     = GameObject.FindWithTag("pause_ui");
        score_ui     = GameObject.FindWithTag("score_ui");
        game_over_ui = GameObject.FindWithTag("game_over_ui");

        enemyCollision = GameObject.FindObjectOfType <EnemyCollision>();
        audioManager   = (AudioManager)FindObjectOfType(typeof(AudioManager));
        audioManager.StopPlaying("ui");
        audioManager.Play("game");

        spawnPowerUp = GameObject.FindObjectOfType <SpawnPowerUp>();
    }
コード例 #16
0
 public BooEntity(MarioEntity mario, Vector2 position) : base(position)
 {
     Sprite          = new BooSprite(mario, position);
     this.mario      = mario;
     EntityCollision = new EnemyCollision(this);
 }
コード例 #17
0
 protected virtual void OnEnemyCollision()
 {
     EnemyCollision?.Invoke(this, EventArgs.Empty);
 }
コード例 #18
0
ファイル: Level2.cs プロジェクト: mcbe1985/2D_Game_GameDev
        /// <summary>
        /// Constructor for the class.
        /// Initializes and creates enemies, which type of tile is used where and starts the collision for both hero and enemies alike.
        /// </summary>
        /// <param name="_content"></param>
        /// <param name="myHero"></param>
        public Level2(ContentManager _content, Hero myHero)
        {
            enemies = new List <Enemies>();
            CreateEnemies(_content);
            tileArray = new byte[, ]
            {
                { 2, 1, 1, 1, 1, 1, 1, 1 },
                { 0, 0, 2, 0, 0, 0, 2, 1 },
                { 0, 0, 2, 0, 0, 0, 2, 1 },
                { 0, 0, 2, 0, 0, 0, 2, 1 },
                { 0, 0, 0, 0, 0, 0, 2, 1 },
                { 0, 0, 0, 0, 0, 0, 2, 1 },
                { 2, 1, 1, 1, 0, 0, 2, 1 },
                { 0, 0, 0, 0, 0, 0, 3, 1 },
                { 0, 0, 0, 0, 0, 2, 3, 1 },
                { 0, 0, 0, 0, 0, 0, 3, 1 },
                { 0, 0, 0, 0, 0, 0, 3, 1 },
                { 0, 0, 0, 0, 2, 1, 1, 1 },
                { 0, 0, 0, 0, 2, 1, 1, 1 },
                { 0, 0, 0, 2, 1, 1, 1, 1 },
                { 0, 0, 0, 0, 0, 0, 3, 1 },
                { 0, 0, 0, 0, 0, 0, 3, 1 },
                { 0, 0, 2, 0, 0, 0, 3, 1 },
                { 0, 0, 0, 0, 0, 0, 3, 1 },
                { 0, 0, 0, 0, 0, 0, 3, 1 },
                { 0, 0, 0, 0, 2, 0, 3, 1 },
                { 0, 0, 0, 0, 0, 2, 1, 1 },
                { 0, 0, 0, 2, 0, 0, 2, 1 },
                { 0, 0, 2, 0, 0, 0, 2, 1 },
                { 0, 0, 2, 0, 0, 0, 2, 1 },
                { 0, 0, 2, 0, 0, 0, 2, 1 },
                { 0, 0, 0, 0, 0, 0, 2, 1 },
                { 0, 0, 0, 0, 0, 0, 2, 1 },
                { 0, 0, 0, 0, 2, 1, 1, 1 },
                { 0, 0, 0, 0, 0, 2, 1, 1 },
                { 0, 0, 0, 2, 0, 0, 2, 1 },
                { 0, 0, 0, 0, 0, 0, 2, 1 },
                { 0, 0, 0, 0, 0, 0, 2, 1 },
                { 0, 0, 0, 2, 0, 0, 2, 1 },
                { 0, 0, 0, 0, 0, 0, 2, 1 },
                { 0, 0, 2, 0, 0, 0, 2, 1 },
                { 0, 0, 2, 0, 0, 0, 3, 1 },
                { 0, 0, 0, 0, 0, 0, 3, 1 },
                { 0, 0, 0, 2, 0, 0, 3, 1 },
                { 0, 0, 0, 0, 0, 0, 3, 1 },
                { 0, 0, 0, 0, 0, 0, 3, 1 },
                { 0, 0, 0, 2, 1, 1, 1, 1 },
                { 0, 0, 0, 2, 1, 1, 1, 1 },
                { 0, 0, 2, 1, 1, 1, 1, 1 },
                { 0, 0, 0, 0, 0, 0, 3, 1 },
                { 0, 0, 0, 0, 0, 0, 3, 1 },
                { 0, 0, 0, 2, 0, 0, 3, 1 },
                { 0, 0, 0, 0, 0, 0, 3, 1 },
                { 0, 0, 0, 0, 0, 0, 3, 1 },
                { 0, 0, 0, 0, 2, 0, 3, 1 },
                { 0, 0, 0, 0, 0, 0, 3, 1 },
                { 0, 0, 0, 2, 0, 0, 3, 1 },
                { 0, 0, 0, 0, 0, 0, 3, 1 },
                { 0, 0, 0, 0, 0, 2, 1, 1 },
                { 0, 0, 0, 0, 0, 0, 2, 1 },
                { 0, 0, 0, 0, 0, 0, 0, 2 },
                { 0, 0, 0, 0, 2, 0, 0, 2 },
                { 0, 0, 0, 0, 2, 0, 2, 1 },
                { 0, 0, 0, 0, 0, 0, 3, 1 },
                { 0, 0, 0, 2, 0, 0, 3, 1 },
                { 0, 0, 0, 0, 0, 0, 3, 1 },
                { 0, 0, 2, 0, 0, 0, 3, 1 },
                { 0, 0, 0, 0, 0, 0, 3, 1 },
                { 0, 0, 0, 0, 2, 0, 3, 1 },
                { 0, 0, 0, 0, 0, 2, 1, 1 },
                { 0, 0, 0, 0, 0, 0, 2, 1 },
                { 0, 0, 0, 2, 0, 0, 2, 1 },
                { 0, 0, 2, 0, 0, 0, 2, 1 },
                { 0, 0, 0, 0, 0, 0, 0, 2 },
                { 0, 0, 0, 0, 0, 0, 0, 2 },
                { 0, 0, 2, 1, 0, 0, 0, 2 },
                { 0, 0, 2, 0, 0, 0, 0, 2 },
                { 0, 0, 2, 0, 0, 0, 0, 2 },
                { 0, 0, 0, 0, 0, 0, 0, 2 },
                { 0, 0, 0, 0, 0, 0, 0, 2 },
                { 0, 0, 0, 2, 0, 0, 0, 2 },
                { 0, 0, 0, 0, 0, 0, 0, 2 },
                { 0, 0, 0, 0, 2, 1, 1, 1 },
                { 0, 0, 0, 0, 0, 2, 1, 1 },
                { 0, 0, 0, 2, 0, 0, 2, 1 },
                { 0, 0, 0, 2, 0, 0, 2, 1 },
                { 0, 0, 0, 0, 0, 0, 2, 1 },
                { 0, 0, 0, 0, 0, 0, 2, 1 },
                { 0, 0, 0, 2, 0, 0, 3, 1 },
                { 0, 0, 0, 0, 0, 0, 3, 1 },
                { 0, 0, 0, 0, 0, 0, 2, 1 },
                { 0, 0, 2, 0, 0, 0, 0, 2 },
                { 0, 0, 0, 0, 0, 0, 0, 2 },
                { 0, 0, 2, 0, 0, 2, 1, 1 },
                { 0, 0, 0, 0, 0, 0, 2, 1 },
                { 0, 0, 0, 0, 2, 0, 2, 1 },
                { 0, 0, 0, 0, 2, 0, 0, 2 },
                { 0, 0, 0, 0, 2, 0, 2, 1 },
                { 0, 0, 0, 0, 0, 0, 3, 1 },
                { 0, 0, 0, 2, 0, 0, 3, 1 },
                { 0, 0, 0, 0, 0, 0, 3, 1 },
                { 0, 0, 2, 0, 0, 0, 3, 1 },
                { 0, 0, 0, 0, 0, 0, 2, 1 },
                { 0, 0, 0, 0, 0, 2, 1, 1 },
                { 0, 0, 0, 0, 2, 1, 1, 1 },
                { 0, 0, 0, 2, 1, 1, 1, 1 },
                { 0, 0, 2, 1, 1, 1, 1, 1 },
                { 0, 0, 0, 0, 0, 0, 2, 1 },
                { 0, 0, 0, 0, 0, 0, 2, 1 },
                { 0, 0, 0, 0, 0, 0, 2, 1 },
                { 0, 0, 0, 0, 0, 0, 2, 1 },
                { 0, 0, 0, 0, 0, 25, 2, 1 },
                { 2, 1, 1, 1, 1, 1, 1, 1 },
            };

            blokArray             = new Blok[tileArray.GetLength(0), tileArray.GetLength(1)];
            heroCollisionChecker  = new HeroCollisionWithEnemies(myHero, blokArray, enemies);
            enemyCollisionChecker = new EnemyCollision(blokArray, enemies);
        }
コード例 #19
0
ファイル: Snake.cs プロジェクト: DanielGaull/MazeSnake
        public void Update(GameTime gameTime, List <PowerUp> powerUps, List <Wall> walls, Random rand, int windowWidth, int windowHeight, ref User player, List <Enemy> enemies)
        {
            this.windowWidth  = windowWidth;
            this.windowHeight = windowHeight;

            #region Handle Wall Collisions & Moving

            //if (!shouldMove)
            //{
            //    HandleWallCollisions(direction, walls, ref player);
            //}
            if (shouldMove)
            {
                Move(direction);
            }
            if (!ShouldMove(direction, walls, ref player))
            {
                HandleWallCollisions(direction, walls, ref player);
            }

            #endregion

            #region Updating With Enemies

            for (int i = 0; i < enemies.Count; i++)
            {
                if (enemies[i].Intersects(drawRectangle))
                {
                    if (SnakeEffect == Effect.Forcefield)
                    {
                        if (!enemiesCollided.Contains(enemies[i].Id))
                        {
                            player.EnemiesAvoided++;
                            enemiesCollided.Add(enemies[i].Id);
                        }
                    }
                    else
                    {
                        EnemyCollision?.Invoke();
                    }
                }
            }

            #endregion

            #region Handling Powerups

            CheckPowerUpPickup(powerUps, rand, walls, windowWidth, windowHeight, ref player);
            secondsTimer.Update(gameTime);

            if (SnakeEffect == Effect.Speed && secondsTimer.QueryWaitTime(gameTime))
            {
                // We've had speed for one second
                player.AddToStat(Stat.SpeedSeconds, 1);
            }

            if (SnakeEffect == Effect.Frozen && secondsTimer.QueryWaitTime(gameTime))
            {
                // We've been frozen for one second
                player.AddToStat(Stat.TimeFrozen, 1);
            }
            if (SnakeEffect == Effect.Frozen)
            {
                frozenTimer.Update(gameTime);
                if (frozenTimer.QueryWaitTime(gameTime))
                {
                    SnakeEffect = Effect.None;
                }
            }

            if (SnakeEffect == Effect.WallBreaker)
            {
                wallBreakTimer.Update(gameTime);
                if (wallBreakTimer.QueryWaitTime(gameTime))
                {
                    SnakeEffect = Effect.None;
                    if (Sound.IsPlaying(Sounds.Buzzing))
                    {
                        Sound.Stop(Sounds.Buzzing);
                    }
                }
                else
                {
                    if (!Sound.IsPlaying(Sounds.Buzzing))
                    {
                        Sound.PlaySound(Sounds.Buzzing);
                    }
                }
            }
            if (SnakeEffect != Effect.WallBreaker && Sound.IsPlaying(Sounds.Buzzing))
            {
                Sound.Stop(Sounds.Buzzing);
            }

            if (SnakeEffect == Effect.Forcefield)
            {
                forcefieldTimer.Update(gameTime);
                if (forcefieldTimer.QueryWaitTime(gameTime))
                {
                    SnakeEffect = Effect.None;
                }

                forcefieldRect.X = drawRectangle.X;
                forcefieldRect.Y = drawRectangle.Y - (forcefieldRect.Height / 2 - drawRectangle.Height / 2);
            }

            speedTimer.Update(gameTime);
            if (SnakeEffect == Effect.Speed && speedTimer.QueryWaitTime(gameTime))
            {
                SnakeEffect = Effect.None;
                speedTimer.Reset();
            }
            if (SnakeEffect == Effect.Speed)
            {
                speed = PW_SPD;
            }
            else
            {
                speed = REG_SPD;
            }

            if (lightningStrip != null)
            {
                animationTimer.Update(gameTime);
                if (SnakeEffect == Effect.WallBreaker && animationTimer.QueryWaitTime(gameTime))
                {
                    if (currentFrame + 1 >= L_FRAMES_PER_ROW)
                    {
                        currentFrame = 0;
                        sourceRect.X = 0;
                    }
                    else
                    {
                        currentFrame++;
                        sourceRect.X += L_ANIMATION_WIDTH;
                    }
                }
                lightningLocationRect.X      = drawRectangle.X;
                lightningLocationRect.Y      = drawRectangle.Y;
                lightningLocationRect.Width  = drawRectangle.Width;
                lightningLocationRect.Height = drawRectangle.Height;
            }

            hatRect.X = drawRectangle.X + (2 * hatSpacingX);
            hatRect.Y = drawRectangle.Y - hatRect.Height;

            #endregion

            #region PC Controls
            keyState = Keyboard.GetState();
            GamePadState gamePad = GamePad.GetState(PlayerIndex.One);

            shouldMove = false;

            // Check if any control keys are pressed.
            // PC controls
            if (keyState.IsKeyDown(Keys.Up) || keyState.IsKeyDown(Keys.W) && keyState.IsKeyUp(Keys.LeftControl) && keyState.IsKeyUp(Keys.RightControl) &&
                keyState.IsKeyUp(Keys.LeftAlt) && keyState.IsKeyUp(Keys.RightAlt))
            {
                direction = Direction.Up;
                //shouldMove = ShouldMove(direction, walls, ref player);
                shouldMove = true;
            }
            else if (keyState.IsKeyDown(Keys.Down) || keyState.IsKeyDown(Keys.S) && keyState.IsKeyUp(Keys.LeftAlt) && keyState.IsKeyUp(Keys.RightAlt))
            {
                direction = Direction.Down;
                //shouldMove = ShouldMove(direction, walls, ref player);
                shouldMove = true;
            }
            else if (keyState.IsKeyDown(Keys.Right) || keyState.IsKeyDown(Keys.D))
            {
                direction = Direction.Right;
                //shouldMove = ShouldMove(direction, walls, ref player);
                shouldMove = true;
                effect     = SpriteEffects.None;
            }
            else if (keyState.IsKeyDown(Keys.Left) || keyState.IsKeyDown(Keys.A))
            {
                direction = Direction.Left;
                //shouldMove = ShouldMove(direction, walls, ref player);
                shouldMove = true;
                effect     = SpriteEffects.FlipHorizontally;
            }
            #endregion

            #region Clamping

            // Clamp the snake so the player cannot navigate it out of the window.
            if (drawRectangle.X <= minX)
            {
                drawRectangle.X = minX;
            }
            if (drawRectangle.X >= windowWidth - drawRectangle.Width)
            {
                drawRectangle.X = windowWidth - drawRectangle.Width;
            }
            if (drawRectangle.Y <= minY)
            {
                drawRectangle.Y = minY;
            }
            if (drawRectangle.Y >= windowHeight - drawRectangle.Height)
            {
                drawRectangle.Y = windowHeight - drawRectangle.Height;
            }

            #endregion

            #region Hat Updating

            if (HasHat)
            {
                SetHatRectValues();
            }

            #endregion
        }
コード例 #20
0
ファイル: Enemy.cs プロジェクト: pampersrocker/STAR
 private void InitializeVariables()
 {
     if (!string.IsNullOrEmpty(enemyvariables[EnemyVariables.MovementType]))
         movementType = (MovementType)int.Parse(enemyvariables[EnemyVariables.MovementType]);
     else
         movementType = MovementType.Normal;
     if (!string.IsNullOrEmpty(enemyvariables[EnemyVariables.MaxSpeed]))
         maxSpeed = float.Parse(enemyvariables[EnemyVariables.MaxSpeed], CultureInfo.CreateSpecificCulture("en-us"));
     else
         maxSpeed = 0;
     if (!string.IsNullOrEmpty(enemyvariables[EnemyVariables.EnemyCollision]))
         collision = (EnemyCollision)int.Parse(enemyvariables[EnemyVariables.EnemyCollision]);
     else
         collision = EnemyCollision.Normal;
     if (!string.IsNullOrEmpty(enemyvariables[EnemyVariables.StandardDirection]))
         standardirection = (StandardDirection)int.Parse(enemyvariables[EnemyVariables.StandardDirection]);
     else
         standardirection = StandardDirection.Left;
     if (!string.IsNullOrEmpty(enemyvariables[EnemyVariables.StandardDirection]))
         rundirection = (StandardDirection)int.Parse(enemyvariables[EnemyVariables.StandardDirection]);
     else
         rundirection = StandardDirection.Left;
     string[] boundingBox = enemyvariables[EnemyVariables.BoundingBox].Split(',');
     if (boundingBox.Length >= 4)
     {
         int x = int.Parse(boundingBox[0]);
         int y = int.Parse(boundingBox[1]);
         int width = int.Parse(boundingBox[2]);
         int height = int.Parse(boundingBox[3]);
         orgcollisionrect = new Rectangle(x, y, width, height);
     }
     else
     {
         orgcollisionrect = new Rectangle();
     }
 }
コード例 #21
0
    // Use this for initialization

    void Awake()
    {
        body2d         = GetComponent <Rigidbody2D>();
        inputState     = GetComponent <InputState>();
        enemyCollision = GetComponent <EnemyCollision>();
    }
コード例 #22
0
 // Start is called before the first frame update
 void Start()
 {
     SR         = GetComponent <SpriteRenderer>();
     SR.enabled = true;
     EC         = GetComponentInParent <EnemyCollision>();
 }
コード例 #23
0
ファイル: EnemyManager.cs プロジェクト: robc/OnslaughtInSpace
    private void EnemyDestroyed(EnemyCollision enemy)
    {
        // Trigger an explosion effect.

        spawnedEnemies.Remove(enemy);
        Destroy(enemy.gameObject);

        if (OnEnemyDestroyed != null)
            OnEnemyDestroyed();
    }
コード例 #24
0
ファイル: EnemyManager.cs プロジェクト: robc/OnslaughtInSpace
    private void EnemyReachedTarget(EnemyCollision enemy)
    {
        EnemyCollision [] enemies = spawnedEnemies.ToArray();
        spawnedEnemies.Clear();

        for (int count = 0; count < enemies.Length; count++)
            Destroy(enemies[count].gameObject);

        if (OnTargetReached != null)
            OnTargetReached();
    }