Inheritance: EnemyBehavior
コード例 #1
0
    private void Update()
    {
        audioSource.volume = soundManager.GetVolume();

        if (Physics2D.OverlapCircle(transform.position, .2f, WhatActivatesButton))
        {
            GameObject otherObject = Physics2D.OverlapCircle(transform.position, .2f, WhatActivatesButton).gameObject;
            if (savedObject != otherObject)
            {
                savedObject      = otherObject;
                savedMovingBlock = savedObject.GetComponent <MovingBlock>();
            }
            if (savedObject.tag == FishTag)
            {
                if (savedMovingBlock.getBlockType() == neededFish)
                {
                    if (!buttonActivated)
                    {
                        buttonActivated = true;
                        anim.SetBool("isActivated", true);
                        audioSource.Play();
                    }
                }
            }
        }
        else
        {
            if (buttonActivated)
            {
                buttonActivated = false;
                anim.SetBool("isActivated", false);
                audioSource.Play();
            }
        }
    }
コード例 #2
0
ファイル: GameFlow.cs プロジェクト: GooRain/Tetrablock
        private void OnPlaceBlock(MovingBlock block)
        {
            block.onPlace = null;
            movingBlocks.Remove(block);

            if (movingBlocks.Count <= 0)
            {
                RespawnBlocks();
            }
        }
コード例 #3
0
 public void DumpSpeed()
 {
     MovingMap.DumpSpeed();
     MovingBlock.DumpSpeed();
     if (cam.fieldOfView > 62)
     {
         cam.fieldOfView -= Time.deltaTime * 2;
         speed           -= Time.deltaTime * 2;
     }
 }
コード例 #4
0
ファイル: TowerManager.cs プロジェクト: TFM-AEIS/TFM
 public void RetryLast()
 {
     this.Score--;
     this.feedbackText.text = "";
     GameObject.Destroy(this.currBlock.gameObject);
     this.currBlock = this.tower.Pop();
     this.currSpeed = this.currBlock.BlockSpeed;
     this.currBlock.InitValues(this.tower.Count == 0 ? this.GetComponent <Renderer>().bounds.size.x : (2 * this.tower.Peek().BlockExtents.x),
                               this.borderLeft, this.borderRight, this.currSpeed, true);
 }
コード例 #5
0
ファイル: TowerManager.cs プロジェクト: TFM-AEIS/TFM
    void Update()
    {
        if (Input.GetButtonDown("Fire1") && !EventSystem.current.IsPointerOverGameObject())
        {
            this.currBlock.Stop();

            float cropAmount = this.currBlock.transform.position.x
                               - (this.tower.Count == 0 ? 0 : this.tower.Peek().transform.position.x);

            float newWidth = 2 * this.currBlock.BlockExtents.x;

            if (Mathf.Abs(cropAmount) > marginError)   // Si el bloque supera el margen de error //
            {
                newWidth -= Mathf.Abs(cropAmount);

                if (newWidth <= 0) // GAME OVER
                {
                    this.feedbackText.text = "GAME OVER";
                    return;
                }

                this.currBlock.Resize(newWidth);
                this.currBlock.transform.position += Vector3.left * 0.5f * cropAmount;
                feedbackText.text = "MISSED!";
                this.currSpeed++;

                StartCoroutine(SliceBlock(cropAmount, 1));
            }
            else    // Si el bloque está dentro del margen de error //
            {
                this.currBlock.transform.position += Vector3.left * cropAmount;
                feedbackText.text = "PERFECT!";
            }

            this.Score++;
            if (this.Score % 10 == 0)
            {
                this.currSpeed++;
            }

            this.tower.Push(this.currBlock);

            this.currBlock = GameObject.Instantiate(this.blockPrefab, this.transform).GetComponent <MovingBlock>();
            this.currBlock.InitValues(newWidth, this.borderLeft, this.borderRight, this.currSpeed, this.tower.Peek().IsMovingLeft);
            this.currBlock.transform.position = this.tower.Peek().transform.position
                                                + new Vector3(0, this.tower.Peek().BlockExtents.y + this.currBlock.BlockExtents.y);
        }

        // Movimiento de cámara

        if (this.currBlock.transform.position.y > Camera.main.transform.position.y + cameraOffset)
        {
            Camera.main.transform.Translate(Vector3.up * this.cameraSpeed * Time.deltaTime);
        }
    }
コード例 #6
0
ファイル: TowerManager.cs プロジェクト: TFM-AEIS/TFM
    void Start()
    {
        this.tower = new Stack <MovingBlock>();

        this.borderLeft  = Camera.main.ScreenToWorldPoint(Vector3.zero).x;
        this.borderRight = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, 0, 0)).x;

        this.currBlock = GameObject.Instantiate(blockPrefab, this.transform).GetComponent <MovingBlock>();
        this.currBlock.InitValues(this.GetComponent <Renderer>().bounds.size.x, this.borderLeft, this.borderRight, this.currSpeed, true);
        this.currBlock.transform.position = new Vector3(0, this.GetComponent <Renderer>().bounds.max.y + this.currBlock.BlockExtents.y, 0);
    }
コード例 #7
0
    public void ActivateWarning(MovingBlock blockWeCollidedWith) // Activate this player's warning system.
    {
        incomingBlock = blockWeCollidedWith;                     // Set the incoming block.
        // Calculate the position of the block relative to what we can see. If the block is on our blindsides, display the warning symbol.
        Vector3 blockPositon = (incomingBlock.transform.position - associatedPlayer.transform.position).normalized;
        float   direction    = Vector3.SignedAngle(Camera.main.transform.forward.normalized, blockPositon, Vector3.up);

        if (direction > 60 || direction < -60)
        {
            warnings.gameObject.SetActive(true);
        }
    }
コード例 #8
0
ファイル: Cannon.cs プロジェクト: gbdb71/Cubed_In_unity
    void Shoot()
    {
        //create a moving block
        GameObject go = (GameObject)Instantiate(movingBlock, transform.position + gamemanager.instance.Get3DPos(shootingDir), Quaternion.identity);

        //fetch script
        MovingBlock m = go.GetComponent <MovingBlock>();

        //add to delegate
        gamemanager.instance.updateDelegate += m.PassTime;

        //set direction block should move
        m.movingDir = shootingDir;
    }
コード例 #9
0
    public void turnGas()
    {
        isBreak = false;
        MovingMap.SpeedUp();
        MovingBlock.SpeedUp();

        if (cam.fieldOfView < 67)
        {
            cam.fieldOfView += Time.deltaTime * 2;
            speed           += Time.deltaTime * 2;
        }
        else
        {
            speed = 5;
        }
    }
コード例 #10
0
ファイル: TowerManager.cs プロジェクト: TFM-AEIS/TFM
    private IEnumerator SliceBlock(float cropAmount, float waitTime)
    {
        MovingBlock sliceBlock = GameObject.Instantiate(this.blockPrefab, this.transform).GetComponent <MovingBlock>();

        sliceBlock.GetComponent <SpriteRenderer>().color = Color.red;
        sliceBlock.Resize(Mathf.Abs(cropAmount));
        sliceBlock.transform.position = this.currBlock.transform.position
                                        + Mathf.Sign(cropAmount) * Vector3.right * (this.currBlock.BlockExtents.x + 0.5f * Mathf.Abs(cropAmount));

        for (float i = 0; i < waitTime; i += Time.deltaTime)
        {
            sliceBlock.transform.Translate(Vector3.down * Time.deltaTime);
            yield return(new WaitForEndOfFrame());
        }

        GameObject.Destroy(sliceBlock.gameObject);
    }
コード例 #11
0
    void OnTriggerEnter(Collider obj)
    {
        if (!m_IngorePlayers)        //If players aren't ignored
        {
            if (obj.gameObject.tag == Constants.PLAYER_STRING)
            {
                m_List.Add(obj.gameObject);                 //Add the gameobject to the list if it was a player
            }
        }

        if (obj.gameObject.tag == Constants.MOVING_BLOCK_TAG_STRING) //If the gameobject is a moving block
        {
            m_List.Add(obj.gameObject);                              //Add  it to the list and set it's destination as the stop point
            MovingBlock block = obj.gameObject.GetComponent(typeof(MovingBlock)) as MovingBlock;

            block.setPressurePlateDestination(m_MovingBoxStopPoint.transform.position);
        }
    }
コード例 #12
0
ファイル: PlayerController.cs プロジェクト: ajweeks/NJ01
    public void SetBlockRiding(MovingBlock block)
    {
        if (_blockRiding == block)
        {
            return;
        }

        if (_blockRiding != null)
        {
            _blockRiding.RemoveRider(this);
        }

        _blockRiding = block;

        if (_blockRiding)
        {
            _blockRidingPrevPos = _blockRiding.transform.position;
        }
    }
コード例 #13
0
    // Use this for initialization
    void Start()
    {
        for (int i = 0; i < maze.GetLength(0); i++)
        {
            for (int j = 0; j < maze.GetLength(1); j++)
            {
                if (maze[i, j] >= 1)
                {
                    GameObject spawnedBlock = Instantiate(blocks[maze[i, j] - 1]);
                    spawnedBlock.transform.position = new Vector3((i + 0.5f) * 2.0f, 0.0f, (j + 0.5f) * 2.0f);
                    spawnedBlock.transform.parent   = blockParent;

                    if (maze[i, j] == 2)
                    {
                        int[,] dir = new int[4, 2] {
                            { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 }
                        };

                        for (int d = 0; d < 4; d++)
                        {
                            int nx = i + dir[d, 0], ny = j + dir[d, 1];

                            if (nx < 0 || nx >= maze.GetLength(0) || ny < 0 || ny >= maze.GetLength(1))
                            {
                                continue;
                            }

                            if (maze[nx, ny] == -2)
                            {
                                MovingBlock movingBlockScript = spawnedBlock.GetComponent <MovingBlock>();
                                movingBlockScript.originPos = new Vector3((i + 0.5f) * 2.0f, 1.0f, (j + 0.5f) * 2.0f);
                                movingBlockScript.newPos    = new Vector3((nx + 0.5f) * 2.0f, 1.0f, (ny + 0.5f) * 2.0f);

                                maze[nx, ny] = 0;
                            }
                        }
                    }
                }
            }
        }
    }
コード例 #14
0
    public void ResetPooling()
    {
        ChooseMaterials();

        for (int i = 0; i < allStaticBlocks.Count; i++)
        {
            allStaticBlocks[i].GetComponent <MeshRenderer>().material = staticBlocksMaterial;
        }

        for (int i = 0; i < allMovingBlocks.Count; i++)
        {
            allMovingBlocks[i].GetComponent <MeshRenderer>().material = movingBlocksMaterial;
        }

        while (activeObjectsParent.transform.childCount > 0)
        {
            MovingBlock movingBlock = activeObjectsParent.transform.GetChild(0).GetComponent <MovingBlock>();
            if (movingBlock != null)
            {
                movingBlock.GetComponent <MeshRenderer>().material = movingBlocksMaterial;
                DestroyMovingBlock(movingBlock.gameObject);
            }
            else
            {
                Collectable collectable = activeObjectsParent.transform.GetChild(0).GetComponent <Collectable>();
                if (collectable != null)
                {
                    DestroyCollectable(collectable.gameObject, collectable.type);
                }
                else
                {
                    activeObjectsParent.transform.GetChild(0).gameObject.GetComponent <MeshRenderer>().material = staticBlocksMaterial;
                    DestroyStaticBlock(activeObjectsParent.transform.GetChild(0).gameObject);
                }
            }
        }
    }
コード例 #15
0
 MovingBlock(MovingBlock other)
 {
     blockspeed = other.blockspeed;
     startPos   = other.startPos;
     endPos     = other.endPos;
 }
コード例 #16
0
        /// <summary>
        /// Maakt de blok aan
        /// </summary>
        /// <param name="id">Afhankelijk van de id zullen we een bepaalde blok aanmaken</param>
        /// <param name="content">ContentManager object dat we gebruiken om textures te laden</param>
        /// <returns>De aangemaakt blok</returns>
        protected override GameObject CreateBlock(int id, ContentManager content)
        {
            GameObject b = null;

            if (id == 1)
            {
                b = new DirtBlock(content, "01");
            }
            else if (id == 2)
            {
                b = new GrassTopBlock(content, "04");
            }
            else if (id == 3)
            {
                b = new GrassRightBLock(content, "08");
            }
            else if (id == 4)
            {
                b = new LeftTopCornerBlock(content, "03");
            }
            else if (id == 5)
            {
                b = new RightTopCornerBlock(content, "02");
            }
            else if (id == 6)
            {
                b = new AcidMudLeftAndBottomBlock(content, "19");
            }
            else if (id == 7)
            {
                b = new AcidMudBottomBlock(content, "15");
            }
            else if (id == 8)
            {
                b = new AcidMudRightAndBottomBlock(content, "22");
            }
            else if (id == 9)
            {
                b = new GrassLeftBlock(content, "07");
            }
            else if (id == 10)
            {
                b = new LeftBottomCornerBlock(content, "10");
            }
            else if (id == 11)
            {
                b = new RightBottomCornerBlock(content, "09");
            }
            else if (id == 12)
            {
                b = new PlatformBlock(content, "plate1");
            }
            else if (id == 13)
            {
                b = new BoxFirstVariant(content, "box1");
            }
            else if (id == 14)
            {
                b = new BoxSecondVariant(content, "box2");
            }
            else if (id == 15)
            {
                b = new Scarecrow(content, "scarecrow");
            }
            else if (id == 16)
            {
                b = new Pointer(content, "pointer");
            }
            else if (id == 17)
            {
                b = new OrangeTree(content, "tree1");
            }
            else if (id == 18)
            {
                b = new YellowTree(content, "tree2");
            }
            else if (id == 19)
            {
                b = new MovingBlock(content, "plate1");
            }
            else if (id == 20)
            {
                b = new MovingBlock(content, "plate1")
                {
                    Invert = true
                }
            }
            ;
            else if (id == 21)
            {
                b = new StarCollectable(content, "star");
            }
            else if (id == 22)
            {
                b = new BouncingAcidBall(content, "LavaFireballSprite");
            }
            else if (id == 23)
            {
                b = new UpUnderBlock(content, "bovenonder");
            }
            else if (id == 24)
            {
                b = new LeftOverRoofBlock(content, "linksoverkaping");
            }
            else if (id == 25)
            {
                b = new RightOverRoofBlock(content, "rechtsoverkaping");
            }
            else if (id == 26)
            {
                b = new UnderBlock(content, "13");
            }
            else if (id == 27)
            {
                b = new FullBlock(content, "11");
            }
            else if (id == 30)
            {
                b = new GreenGoblin(content, "GreenGoblinSprite");
            }
            else if (id == 31)
            {
                b = new Giant(content, "GiantSprite");
            }
            else if (id == 32)
            {
                b = new Orc(content, "BlackGoblin");
            }
            else if (id == 33)
            {
                b = new BlueGoblin(content, "BlueMonster");
            }
            else if (id == 40)
            {
                b = new InvisibleBlock(content, "legeBlok");
            }
            else if (id == 50)
            {
                b = new ButtonNextLevel(content, "button");
            }
            return(b);
        }
コード例 #17
0
    public override void FixedUpdate()
    {
        base.FixedUpdate();

        // add force towards horizontal target
        if (!moveCooldown.cooldown)
        {
            body.AddForce(
                (horizontalTarget - new Vector3(transform.position.x, 0f, transform.position.z)).normalized *
                (Vector3.Distance(horizontalTarget, new Vector3(transform.position.x, 0f, transform.position.z)) / horizontalDistance) *
                horizontalForce,
                ForceMode.Force);
        }

        // apply jump
        if (jump)
        {
            Audio.Play(jumpSound, "sfx", 0.75f * Audio.Attenuate(transform.position));

            // only jump once
            jump = false;

            // clear existing vertical velocity
            body.velocity = new Vector3(
                body.velocity.x,
                0f,
                body.velocity.z);

            // add jump force
            body.AddForce(
                Vector3.up * (sprint ? jumpForceSprint : jumpForce),
                ForceMode.Impulse);

            // reset fall duration
            fallDuration = 0f;

            // start jump jelly animation
            if (jelly)
            {
                modelScaleTarget = Vector3.one +
                                   new Vector3(jumpSquash, jumpStretch, jumpSquash);
            }

            // start jump cooldown
            jumpCooldown.StartCooldown(sprint ? jumpCooldownTimeSprint : jumpCooldownTime);

            // reset idle
            idle          = false;
            idleState     = false;
            idleDelayWait = 0f;
        }

        // store previous grounded
        bool previousGrounded = grounded;

        // reset grounded
        grounded = false;

        // reset moving block
        if (attachedMovingBlock != null)
        {
            attachedMovingBlock.players.Remove(this);
            attachedMovingBlock = null;
        }

        // check grounded if not jumping
        if (!jumpCooldown.cooldown)
        {
            foreach (Vector3 sensorPosition in sensorPositions)
            {
                // raycast to ground
                RaycastHit hit;
                if (Physics.SphereCast(
                        transform.TransformPoint(sensorPosition),
                        sensorThickness,
                        Vector3.down,
                        out hit,
                        sensorExtends))
                {
                    // spawn damage
                    if (firstSpawn && spawnDamage > 0)
                    {
                        firstSpawn = false;

                        if (!firstGrounded)
                        {
                            Audio.Play(hammerDown2, "sfx", 0.75f * Audio.Attenuate(transform.position));
                            Audio.Play(hardLandSound, "sfx", 1f * Audio.Attenuate(transform.position));
                            Audio.Play(hardLandSound, "sfx", 1f * Audio.Attenuate(transform.position));
                            Audio.Play(hardLandSound, "sfx", 1f * Audio.Attenuate(transform.position));

                            // rumble
                            if (inputEnabled)
                            {
                                StartCoroutine(xInput.Rumble(playerId, 1000f, 0.25f));
                            }

                            GameObject spawnSmash = (GameObject)GameObject.Instantiate(Resources.Load("Prefabs/Particles/SpawnSmash"));
                            spawnSmash.transform.position = transform.position;
                        }

                        // apply damage to surrounding enemies
                        Collider[] spawnHits = Physics.OverlapSphere(
                            transform.position,
                            spawnDamageRadius);
                        foreach (Collider spawnHit in spawnHits)
                        {
                            if (spawnHit.attachedRigidbody != null &&
                                spawnHit.attachedRigidbody.GetComponent <Enemy> () != null &&                          // is enemy
                                spawnHit.attachedRigidbody.gameObject != gameObject)                                   // not self

                            // apply damage
                            {
                                spawnHit.attachedRigidbody.GetComponent <PlayerHealth> ().health -= spawnDamage;
                            }
                        }
                    }

                    // set grounded
                    grounded = true;

                    // play land sound
                    if (grounded && !previousGrounded && !firstGrounded)
                    {
                        Audio.Play(landSound, "sfx", 0.25f * Audio.Attenuate(transform.position));
                    }

                    firstGrounded = false;

                    // set last grounded y position
                    lastGroundedY = transform.position.y;

                    // reset horizontal target
                    horizontalTarget = new Vector3(
                        snapToGrid ? Mathf.Round(transform.position.x) : transform.position.x,
                        0f,
                        snapToGrid ? Mathf.Round(transform.position.z) : transform.position.z);

                    // on a moving block
                    if (hit.collider.gameObject.GetComponent <MovingBlock> () != null)
                    {
                        // attach player to moving block
                        attachedMovingBlock = hit.collider.gameObject.GetComponent <MovingBlock> ();
                        if (!attachedMovingBlock.players.Contains(this))
                        {
                            attachedMovingBlock.players.Add(this);
                        }

                        // override horizontal target to match moving block
                        //if (snapToGrid) {
                        horizontalTarget = new Vector3(
                            attachedMovingBlock.transform.position.x,
                            0f,
                            attachedMovingBlock.transform.position.z);
                        //}
                    }

                    // set last grounded position if not trap
                    if (hit.collider.gameObject.GetComponent <Trap> () == null)
                    {
                        RaycastHit checkHit;
                        if (Physics.Raycast(
                                hit.point + Vector3.up * lastGroundedCheckHeight,
                                Vector3.down,
                                out checkHit,
                                lastGroundedCheckDistance) &&
                            checkHit.collider.gameObject.GetComponent <Trap> () == null)
                        {
                            lastGroundedPosition = new Vector3(
                                Mathf.Round(hit.point.x),
                                hit.point.y,
                                Mathf.Round(hit.point.z));
                            lastGroundedMovingBlock = attachedMovingBlock;
                        }
                    }

                    // screen shake on long fall
                    if (fallDuration >= minTimeShake)
                    {
                        PlayerCamera.ShakeAll(
                            minShake +
                            ((fallDuration - minTimeShake) / (maxTimeShake - minTimeShake)) *
                            (maxShake - minShake),
                            shakeTime,
                            transform.position);

                        Audio.Play(hardLandSound, "sfx", 0.75f * Audio.Attenuate(transform.position));
                        Audio.Play(hardLandSound, "sfx", 0.75f * Audio.Attenuate(transform.position));
                    }

                    // reset fall duration
                    fallDuration = 0f;

                    // increment idle delay wait
                    idleDelayWait += Time.fixedDeltaTime;

                    break;
                }
            }
        }

        // increment fall duration
        fallDuration += Time.fixedDeltaTime;
    }
コード例 #18
0
ファイル: MovingBlock.cs プロジェクト: BenDy557/TheFall
	MovingBlock(MovingBlock other)
	{
		blockspeed = other.blockspeed;
		startPos = other.startPos;
		endPos = other.endPos;
	}
コード例 #19
0
ファイル: MovingBlock.cs プロジェクト: BenDy557/TheFall
	public void CopyMovingBlock(MovingBlock other)
	{
		blockspeed = other.blockspeed;
		startPos = other.startPos;
		endPos = other.endPos;
	}
コード例 #20
0
ファイル: World.cs プロジェクト: vczh-codeplex/vlpp
        public void CreateWorldObjects(int oldTop, int newTop)
        {
            int createUnit = Math.Min(128, 64 + 40 * this.Score / 5000);

            while (this.previousCreateObjectTop <= newTop)
            {
                int x = this.random.Next(this.Size.Width - 100);
                int y = this.previousCreateObjectTop + createUnit;

                this.previousCreateObjectTop = y;
                WorldObject block             = null;
                int         blockId           = this.random.Next(Math.Min(500, this.Score / 75), 1000);
                bool        acceptAccelerator = false;

                if (0 <= blockId && blockId < 500)
                {
                    block             = new StaticBlock(new Point(x, y));
                    acceptAccelerator = true;
                }
                else if (500 <= blockId && blockId < 700)
                {
                    block             = new MovingBlock(new Point(x, y));
                    acceptAccelerator = true;
                }
                else if (700 <= blockId && blockId < 800)
                {
                    block = new JumpAndBreakBlock(new Point(x, y));
                }
                else if (800 <= blockId && blockId < 900)
                {
                    block = new TimeoutAndBreakBlock(new Point(x, y));
                }
                else if (this.lastOneIsBrokenBlock)
                {
                    block = new JumpAndBreakBlock(new Point(x, y));
                }
                else
                {
                    block = new BrokenBlock(new Point(x, y));
                }
                this.lastOneIsBrokenBlock = block is BrokenBlock || block is TimeoutAndBreakBlock;
                AddObject(block);

                if (acceptAccelerator)
                {
                    WorldObject accelerator   = null;
                    int         acceleratorId = this.random.Next(1000);

                    if (0 <= acceleratorId && acceleratorId < 100)
                    {
                        accelerator = new JumperAccelerator(block);
                    }
                    else if (100 <= acceleratorId && acceleratorId < 120)
                    {
                        accelerator = new FlyingHatAccelerator(block);
                    }
                    else if (120 <= acceleratorId && acceleratorId < 130)
                    {
                        accelerator = new RocketAccelerator(block);
                    }
                    else if (130 <= acceleratorId && acceleratorId < 200)
                    {
                        if (this.Score >= 5000)
                        {
                            accelerator = new Shield(block);
                            int monsterId = random.Next(100);
                            if (0 <= monsterId && monsterId < 50)
                            {
                                AddObject(new MonsterBat(new Point(x, y + 500), this.Size.Width, this.random));
                            }
                            else
                            {
                                AddObject(new MonsterMildew(new Point(x, y + 500), this.Size.Width, this.random));
                            }
                        }
                    }

                    if (accelerator != null)
                    {
                        AddObject(accelerator);
                    }
                }
            }
        }
コード例 #21
0
 public void CopyMovingBlock(MovingBlock other)
 {
     blockspeed = other.blockspeed;
     startPos   = other.startPos;
     endPos     = other.endPos;
 }