예제 #1
0
        /// <summary>
        /// Removes a child node from parent node, returns child node, possible issues with how it is detached
        /// </summary>
        /// <param name="node">Node you wish to detach</param>
        /// <returns>Detached node</returns>
        public SceneNode detachChild(ref SceneNode node)
        {
            foreach (SceneNode nodel in mChildren)
            {
                if (nodel == node)
                {
                    nodel.mParent = null;
                    mChildren.Remove(nodel);
                    return nodel;

                }

            }
            return null;
        }
예제 #2
0
        public World(RenderWindow window)
        {
            mWindow = window;
            mWorldView = window.DefaultView;
            mWorldBounds = new IntRect(0, 0, (int)mWorldView.Size.X, 2000); //have to explcitly cast Size.X from float to int because of cast issues between IntRect and FloatRect later on
            mSpawnPosition = new Vector2f(mWorldView.Size.X / 2, mWorldBounds.Height - mWorldView.Size.Y); //original code is mWorldBounds.Height - mWorldView.Size, but caused error
            mScrollSpeed = -50; //this is not included in book but in source code
            mSceneLayers = new SceneNode[(int)Layer.LayerCount];
            mTextures = new ResourceHolder<Texture, ResourceID>();
            mSceneGraph = new SceneNode();
            mPlayerAircraft = null;
            mCommandQueue = new CommandQueue();

            mWorldView.Center = mSpawnPosition;

            loadTextures();
            buildScene();
        }
예제 #3
0
        public void createBullets(SceneNode node, ResourceHolder<Texture,ResourceID> textures) 
        {
          Projectile.Type type = isAllied() ? Projectile.Type.AlliedBullet : Projectile.Type.EnemyBullet;
          switch (mSpreadLevel)
          {
              case 1:
                  createProjectile(node, type, 0.0f, 0.5f, textures);
                  break;

              case 2:
                  createProjectile(node, type, -0.33f, 0.33f, textures);
                  createProjectile(node, type, +0.33f, 0.33f, textures);
                  break;

              case 3:
                  createProjectile(node, type, -0.5f, 0.33f, textures);
                  createProjectile(node, type, 0.0f, 0.5f, textures);
                  createProjectile(node, type, +0.5f, 0.33f, textures);
                  break;
          }
        }
예제 #4
0
        public void createProjectile(SceneNode node, Projectile.Type type, float xOffset, float yOffset, ResourceHolder<Texture, ResourceID> textures)
        {
            Projectile projectile = new Projectile(type, textures);
            Vector2f offset = new Vector2f(xOffset * mSprite.GetGlobalBounds().Width, yOffset * mSprite.GetGlobalBounds().Height);
            Vector2f velocity = new Vector2f(0, projectile.getMaxSpeed());

            float sign = isAllied() ? -1 : +1;
            projectile.Position = getWorldPosition() + offset * sign;
            projectile.setVelocity(velocity * sign);
            node.attachChild(projectile);
        }
예제 #5
0
        private void buildScene()
        {
            for (int i = 0; i < (int)Layer.LayerCount; i++)
            {
                SceneNode layer = new SceneNode();
                mSceneLayers[i] = layer;

                mSceneGraph.attachChild(layer);


            }

            //background code
            Texture texture = mTextures.get(ResourceID.Desert);
            IntRect textureRect = mWorldBounds;
            texture.Repeated = true;

            SpriteNode backgroundSprite = new SpriteNode(texture, textureRect);

            backgroundSprite.Position = new Vector2f(mWorldBounds.Left, mWorldBounds.Top);
            mSceneLayers[(int)Layer.Background].attachChild(backgroundSprite);

            //AIRPLANES!
            Aircraft leader = new Aircraft(Aircraft.Type.Eagle, mTextures,mFonts);

            mPlayerAircraft = leader;
            mPlayerAircraft.Position = mSpawnPosition;
            mPlayerAircraft.setVelocity(0, mScrollSpeed); //should be mScrolSpeed
            mSceneLayers[(int)Layer.Air].attachChild(leader);

            addEnemies();
        }
예제 #6
0
 //constructor
 public SceneNode() { mParent = null; mChildren = new List<SceneNode>(); this.Position = new Vector2f(0, 0); }
예제 #7
0
 public void attachChild(SceneNode child) { child.mParent = this; mChildren.Add(child); }
예제 #8
0
 public void movefunc(SceneNode node, Time time)
 {
     Aircraft aircraft = (Aircraft)node; //I am having a really hard time converting the derivedAction method, so hopefully it will work by itself for now.
     aircraft.accelerate(velocity);
 }
예제 #9
0
 public void launchfunc(SceneNode node, Time time)
 {
     Aircraft aircraft = (Aircraft)node;
     aircraft.launchMissile();
 }
예제 #10
0
 public void shootfunc(SceneNode node, Time time)
 {
     Aircraft aircraft = (Aircraft)node;
     aircraft.fire();
 }