Example #1
0
    private Vector3 InstantiateAsteroid(GameObject AsteroidPrefab, Vector3 YMovement)
    {
        GameObject Asteroid;

        if (AsteroidModelsList.Length > 0)
        {
            //Generate Random Prefab
            int SelectedIndex = Random.Range(0, AsteroidModelsList.Length);
            Asteroid = Instantiate(AsteroidModelsList[SelectedIndex], YMovement, Random.rotation) as GameObject;
            Asteroid.transform.parent = transform;

            //Generate Random Size
            if (SetRandomSizes)
            {
                float RandomSize = Random.RandomRange(MinAsteroidSize, MaxAsteroidSize);
                Asteroid.transform.localScale += new Vector3(RandomSize, RandomSize, RandomSize);
            }

            // Attach Animation Script
            if (SetAnimation)
            {
                Asteroid.AddComponent <AsteroidAnimation>();
                //Get Asteroid Animaion Handler
                AsteroidAnimation AstAnim = Asteroid.GetComponent <AsteroidAnimation>();
                AstAnim.speed = AnimationSpeed;
            }
        }
        else
        {
            Asteroid = Instantiate(AsteroidPrefab, YMovement, Random.rotation) as GameObject;
            Asteroid.transform.parent = transform;

            //Generate Random Size
            if (SetRandomSizes)
            {
                float RandomSize = Random.RandomRange(MinAsteroidSize, MaxAsteroidSize);
                Asteroid.transform.localScale += new Vector3(RandomSize, RandomSize, RandomSize);
            }

            // Attach Animation Script
            if (SetAnimation)
            {
                Asteroid.AddComponent <AsteroidAnimation>();
                //Get Asteroid Animaion Handler
                AsteroidAnimation AstAnim = Asteroid.GetComponent <AsteroidAnimation>();
                AstAnim.speed = AnimationSpeed;
            }
        }
        return(YMovement);
    }
Example #2
0
        public void LoadResource(Game game)
        {
            Player p1 = new Player();

            p1.Transformation.Position.X = 300;
            p1.Transformation.Position.Y = 300;
            SpriteComponent sprite = new SpriteComponent(p1.Transformation, 3);
            ThrustComponent thrust = new ThrustComponent(2);

            p1.AddComponent(thrust);
            p1.AddComponent(sprite);
            thrust.GenerateParticles(600);
            Texture texture = game.LoadTexture(@"C:\Source\escape-aliens\Resources\SpaceShipRed.png");

            SDL.SDL_Rect renderRect;
            SDL.SDL_Rect sourceRect;
            renderRect.x = 0;
            renderRect.y = 0;
            renderRect.w = 80;
            renderRect.h = 80;

            sourceRect.w = 167;
            sourceRect.h = 170;
            sourceRect.x = 0;
            sourceRect.y = 0;

            texture.RenderRectangle = renderRect;
            texture.SourceRectangle = sourceRect;
            sprite.AddAnimationFrame(texture);

            game.Input.KeyboardBindings.AddMapping(SDL.SDL_Scancode.SDL_SCANCODE_D, p1.RotateRight);
            game.Input.KeyboardBindings.AddMapping(SDL.SDL_Scancode.SDL_SCANCODE_A, p1.RotateLeft);
            game.Input.KeyboardBindings.AddMapping(SDL.SDL_Scancode.SDL_SCANCODE_W, p1.Forward);
            game.AddObject(p1);

            Polygon2D poly = new Polygon2D();

            poly.AddPoint(300, 300);
            poly.AddPoint(600, 400);
            poly.AddPoint(400, 500);
            Texture         polyText      = game.LoadTexture(@"C:\Source\escape-aliens\Resources\MapForeground.png");
            FilledPolygon2D filledPolygon = new FilledPolygon2D(poly, polyText);
            Asteroid        asteroid      = new Asteroid();

            asteroid.AddComponent(filledPolygon);
            game.AddObject(asteroid);
        }