Example #1
0
    public override void _Process(float delta)
    {
        if (Input.IsActionPressed("exit"))
        {
            GetTree().Quit();
        }

        if (Input.IsActionJustPressed("view_cube_demo"))
        {
            GetTree().ChangeScene("res://assets/demo_scene.tscn");
            return;
        }

        if (_isParentReady)
        {
            RotateX(delta * (Input.GetActionStrength("move_back") - Input.GetActionStrength("move_forward")));
            RotateY(delta * (Input.GetActionStrength("move_right") - Input.GetActionStrength("move_left")));
            RotateZ(delta * (Input.GetActionStrength("move_counterclockwise") - Input.GetActionStrength("move_clockwise")));
            if (Input.IsActionJustPressed("reset_position"))
            {
                Transform = Transform.Identity;
            }
            for (int i = 0; i < 27; i++)
            {
                _cubePointsMath[i].GlobalTransform = _cubeMathSpatials[i].GlobalTransform;
            }
        }
        else
        {
            // This code block will be run only once. It's not in _Ready() because the parent isn't set up there.
            for (int i = 0; i < 27; i++)
            {
                PackedScene myCubePointScene = cubePointScene.Duplicate(true) as PackedScene;
                Node25D     cubePoint        = myCubePointScene.Instance() as Node25D;
                cubePoint.Name     = "CubePoint #" + i;
                _cubePointsMath[i] = cubePoint.GetChild <Spatial>(0);
                _parent.AddChild(cubePoint);
            }
            _isParentReady = true;
        }
    }
Example #2
0
    private void SpawnEnemies()
    {
        //The amount of enemies we want to spawn
        int AmountOfEnemies = 20;
        //If the position on the tile map is open
        bool gotPos = false;
        //The random number generator used for the selection of the position
        RandomNumberGenerator rand = new RandomNumberGenerator();

        //Runn throught the loop the amount of times we want to spawn an enemy
        for (int i = 0; i < AmountOfEnemies; i++)
        {
            gotPos = false;
            //Run the loop until we find a open spot where the enemy can be spawned
            while (!gotPos)
            {
                //Randomize the generator every loop to make sure we get random placement
                rand.Randomize();
                //Generate the x and y positions
                int xPos = (int)rand.RandiRange(0, (int)mapSize.x);
                int yPos = (int)rand.RandiRange(0, (int)mapSize.y);
                //Check if the map tile is a floor
                if (tileMap.GetCell(xPos, yPos) == 0)
                {
                    gotPos = true;
                    PackedScene tempEnemy = new PackedScene();
                    tempEnemy = enemyScene.Duplicate(true) as PackedScene;
                    //Instance the enemy - need to spawn multiple enemies, needs to be done later
                    enemy      = tempEnemy.Instance();
                    enemy.Name = "Enemy";
                    ((Node2D)enemy).Position = new Vector2(xPos * 32, yPos * 32);
                    AddChild(enemy);
                    enemyList.Add(enemy);
                }
            }
        }
    }