示例#1
0
        public Game()
        {
            mWindow = new RenderWindow(new VideoMode(640, 480), "SFML App", Styles.Close);

            mWorld = new World(mWindow);
            commmands = mWorld.getCommandQueue();
            mPlayer = new Player(commmands);//possibly initialized in World?
            eventqueue = new Queue<Event>();

            mWindow.Closed += onClosed;
            mWindow.GainedFocus += gainedFocus;
            mWindow.LostFocus += lostFocus;
            mWindow.KeyPressed += keyPressed;
        }
示例#2
0
        public override void updateCurrent(Time dt,CommandQueue queue) 
        {
           

            if (isDestroyed())
            {
                mIsMarkedForRemoval = true;
                return;
            }
            checkProjectileLaunch(dt,queue);

            updateMovementPattern(dt);
            base.updateCurrent(dt,queue);
            updateTexts();

        }
示例#3
0
        public override void updateCurrent(SFML.Time.Time dt, CommandQueue queue)
        {
            	if (isGuided())
	            {
		            const float approachRate = 200;

                    Vector2f newVelocity = Utility.unitVector(new Vector2f((float)approachRate * (float)dt.Seconds * (float)mTargetDirection.X + (float)getVelocity().X, (float)approachRate * (float)dt.Seconds * (float)mTargetDirection.Y + (float)getVelocity().Y));
		            newVelocity *= getMaxSpeed();
		            float angle = (float)Math.Atan2(newVelocity.Y, newVelocity.X);

                    Rotation = Utility.toDegree(angle)+90;
		            setVelocity(newVelocity);
	            }

	            base.updateCurrent(dt, queue);
        }
示例#4
0
        public Player(CommandQueue commands)
        {
            this.commands = commands;
            mKeyBinding = new Dictionary<Keyboard.Key, Action>();
            mActionBinding = new Dictionary<Action, Command>();

            // Set initial key bindings
            mKeyBinding[Keyboard.Key.Left] = Action.MoveLeft;
            mKeyBinding[Keyboard.Key.Right] = Action.MoveRight;
            mKeyBinding[Keyboard.Key.Up] = Action.MoveUp;
            mKeyBinding[Keyboard.Key.Down] = Action.MoveDown;

            // Set initial action bindings
            initializeActions();

            foreach (KeyValuePair<Action, Command> pair in mActionBinding) pair.Value.category = (uint)Category.PlayerAircraft;
        }
示例#5
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();
        }
示例#6
0
        public void checkProjectileLaunch(Time dt, CommandQueue commands)
        {
            
            if (mIsFiring && mFireCountdown <= Time.Zero)
            {
                
                commands.push(mFireCommand); //POSSIBLE ISSUE WITH MFIRECOMMAND NOT POINTING TO PROPER FUNC
                mFireCountdown += Time.FromSeconds((float)1 / ((float)mFireRateLevel + (float)1));
                mIsFiring = false;
                
            }
            else if (mFireCountdown > Time.Zero) mFireCountdown -= dt;
            if (mIsLaunchingMissile)
            {
                commands.push(mLaunchCommand);
                mIsLaunchingMissile = false;
            }

        }
示例#7
0
 public override  void updateCurrent(Time dt,CommandQueue queue) 
 {
     this.Position = new Vector2f(this.Position.X + mVelocity.X * (float)dt.Seconds, this.Position.Y + mVelocity.Y * (float)dt.Seconds);
     
 } 
示例#8
0
 public virtual void updateCurrent(Time dt,CommandQueue queue) { }
示例#9
0
 public void update(Time dt,CommandQueue queue)
 {
     updateCurrent(dt,queue);
     updateChildren(dt,queue);
 }
示例#10
0
 private void updateChildren(Time dt, CommandQueue queue)
 {
     foreach (SceneNode child in mChildren) child.update(dt,queue);
 }
示例#11
0
 public void handleRealtimeInput(CommandQueue commands)
 {
     foreach (KeyValuePair<Keyboard.Key, Action> pair in mKeyBinding)
     {
         if (Keyboard.IsKeyPressed(pair.Key) && isRealtimeAction(pair.Value)) commands.push(mActionBinding[pair.Value]);
     }
 }
示例#12
0
 public void handleEvent(Event even, CommandQueue commands)
 {
     if (even.Type == (uint)EventType.KeyPressed)
     {
         foreach (KeyValuePair<Keyboard.Key, Action> pair in mKeyBinding)
         {
             if (Keyboard.IsKeyPressed(pair.Key) && isRealtimeAction(pair.Value))
             {
                 
                 commands.push(mActionBinding[pair.Value]);
             }
         }
     }
 }