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; }
public override void updateCurrent(Time dt,CommandQueue queue) { if (isDestroyed()) { mIsMarkedForRemoval = true; return; } checkProjectileLaunch(dt,queue); updateMovementPattern(dt); base.updateCurrent(dt,queue); updateTexts(); }
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); }
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; }
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(); }
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; } }
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); }
public virtual void updateCurrent(Time dt,CommandQueue queue) { }
public void update(Time dt,CommandQueue queue) { updateCurrent(dt,queue); updateChildren(dt,queue); }
private void updateChildren(Time dt, CommandQueue queue) { foreach (SceneNode child in mChildren) child.update(dt,queue); }
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]); } }
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]); } } } }