public static void Initialize(IEventListener touchEventListener) { if (_initialized) return; /// Lack of constructors in native code, forces to /// initialize TouchPanel before we initialize event sink. /// We have only one touch panel right now. /// But this is to keep the options open for future. _activeTouchPanel = new TouchPanel(); _activeTouchPanel.Enabled = true; /// Add a touch event processor. EventSink.AddEventProcessor(EventCategory.Touch, new TouchEventProcessor()); /// Start the event sink process. This will pump /// events neatly out of the other world. EventSink.AddEventListener(EventCategory.Touch, touchEventListener); /// Also add generic for Gesture stuff. EventSink.AddEventListener(EventCategory.Gesture, touchEventListener); _initialized = true; }
private void UpdateMouse() { MouseState state = Mouse.GetState(); if (state.LeftButton != _oldMouseState.LeftButton) { PushTouchEvent(ref state, 0, state.LeftButton); } if (state.RightButton != _oldMouseState.RightButton) { PushTouchEvent(ref state, 1, state.RightButton); } if (state.MiddleButton != _oldMouseState.MiddleButton) { PushTouchEvent(ref state, 2, state.MiddleButton); } if (state.Position != _oldMouseState.Position) { TouchEvent ev = ObtainTouchEvent(ref state); ev.Type = TouchEventType.Moved; _touchEvents.Add(ev); if (state.LeftButton == ButtonState.Pressed || state.MiddleButton == ButtonState.Pressed || state.RightButton == ButtonState.Pressed) { ev = ObtainTouchEvent(ref state); ev.Type = TouchEventType.Dragged; _touchEvents.Add(ev); } } if (state.ScrollWheelValue != _oldMouseState.ScrollWheelValue) { TouchEvent ev = ObtainTouchEvent(ref state); ev.Type = TouchEventType.Scrolled; ev.ScrollAmount = state.ScrollWheelValue - _oldMouseState.ScrollWheelValue; _touchEvents.Add(ev); } _oldMouseState = state; TouchCollection touchState = TouchPanel.GetState(); TouchLocation touchLocation = (touchState.Count > 0) ? touchState[0] : new TouchLocation(0, TouchLocationState.Invalid, Vector2.Zero); if ((touchLocation.State & (TouchLocationState.Pressed | TouchLocationState.Moved)) != 0 && (_oldTouchLocation.State & (TouchLocationState.Pressed | TouchLocationState.Moved)) == 0) { PushTouchEvent(ref touchLocation, 0, ButtonState.Pressed); } if ((touchLocation.State & (TouchLocationState.Pressed | TouchLocationState.Moved)) == 0 && (_oldTouchLocation.State & (TouchLocationState.Pressed | TouchLocationState.Moved)) != 0) { if (touchLocation.State != TouchLocationState.Invalid) { PushTouchEvent(ref touchLocation, 0, ButtonState.Released); } else { PushTouchEvent(ref _oldTouchLocation, 0, ButtonState.Released); } } if (touchLocation.State == TouchLocationState.Moved) { TouchEvent ev = ObtainTouchEvent(ref touchLocation); ev.Type = TouchEventType.Moved; _touchEvents.Add(ev); ev = ObtainTouchEvent(ref touchLocation); ev.Type = TouchEventType.Dragged; _touchEvents.Add(ev); } _oldTouchLocation = touchLocation; }
/// <summary> /// Constructs a new input state. /// </summary> public InputState() { CurrentGamePadStates = GamePad.GetState(PlayerIndex.One); TouchStates = TouchPanel.GetState(); }
public override void ResetController() { #if IPHONE TouchPanel.Reset(); #endif }
protected override void Update(GameTime gameTime) { // Allows the game to exit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { this.Exit(); } bool canvasNeedsUpdate = false; int yMinUpdate = Int32.MaxValue, yMaxUpdate = 0; while (TouchPanel.IsGestureAvailable) { GestureSample gesture = TouchPanel.ReadGesture(); if (gesture.GestureType == GestureType.FreeDrag && gesture.Delta != Vector2.Zero) { Vector2 point1 = gesture.Position - gesture.Delta; Vector2 point2 = gesture.Position; float radius = 12; RoundCappedLine line = new RoundCappedLine(point1, point2, radius); int yMin = (int)(Math.Min(point1.Y, point2.Y) - radius - 1); int yMax = (int)(Math.Max(point1.Y, point2.Y) + radius + 1); yMin = Math.Max(0, Math.Min(canvas.Height, yMin)); yMax = Math.Max(0, Math.Min(canvas.Height, yMax)); for (int y = yMin; y < yMax; y++) { xCollection.Clear(); line.GetAllX(y, xCollection); if (xCollection.Count == 2) { int xMin = (int)(Math.Min(xCollection[0], xCollection[1]) + 0.5f); int xMax = (int)(Math.Max(xCollection[0], xCollection[1]) + 0.5f); xMin = Math.Max(0, Math.Min(canvas.Width, xMin)); xMax = Math.Max(0, Math.Min(canvas.Width, xMax)); for (int x = xMin; x < xMax; x++) { pixels[y * canvas.Width + x] = Color.Red; } yMinUpdate = Math.Min(yMinUpdate, yMin); yMaxUpdate = Math.Max(yMaxUpdate, yMax); canvasNeedsUpdate = true; } } } } if (canvasNeedsUpdate) { this.GraphicsDevice.Textures[0] = null; int height = yMaxUpdate - yMinUpdate; Rectangle rect = new Rectangle(0, yMinUpdate, canvas.Width, height); canvas.SetData <Color>(0, rect, pixels, yMinUpdate * canvas.Width, height * canvas.Width); } base.Update(gameTime); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } // TODO: Add your update logic here lastKeyState = keyState; keyState = Keyboard.GetState(); lastMouseState = mouseState; mouseState = Mouse.GetState(); if (WasPressed(Keys.Space)) { mode = (Mode)(((int)mode + 1) % 3); } var screenSize = new Vector2(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); var mousePosition = new Vector2(mouseState.X, mouseState.Y); previousTouches = touches; touches = TouchPanel.GetState(); if (touches.Count > 0 && CanAddNewBolt(gameTime.ElapsedGameTime.TotalMilliseconds)) { for (int i = 0; i < touches.Count; i++) { //if (touches[i].State != TouchLocationState.Pressed) //{ // continue; //} if (touches.Count == 1) { AddBolt(screenSize / 2, touches[i].Position); } else { if (i > 0) { AddBolt(touches[i - 1].Position, touches[i].Position); } } } } else { if (WasClicked()) { AddBolt(screenSize / 2, mousePosition); } } if (mode == Mode.LightningText) { lightningText.Update(); } foreach (var bolt in bolts) { bolt.Update(); } bolts = bolts.Where(x => !x.IsComplete).ToList(); base.Update(gameTime); }
public static void Update() { panel = TouchPanel.GetState(); }
/// <summary> /// Resolves the dependencies needed for this instance to work. /// </summary> protected override void ResolveDependencies() { base.ResolveDependencies(); this.UpdateTouchOrder(); this.Owner.FindComponent<Transform2D>().PropertyChanged += this.DrawOrderPropertyChanged; this.touchManager = WaveServices.TouchPanel; this.touchManager.Subscribe(this); }
protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { Exit(); } //timer currentTime += (float)gameTime.ElapsedGameTime.TotalSeconds; if (counter >= limit) { counter = 0; } currentTime2 += (float)gameTime.ElapsedGameTime.TotalSeconds; if (counter2 >= limit2) { counter2 = 0; } currentTime3 += (float)gameTime.ElapsedGameTime.TotalSeconds; if (counter3 >= limit3) { counter3 = 0; } //sound //controll TouchCollection touchPlaces = TouchPanel.GetState(); foreach (TouchLocation touch in touchPlaces) { Vector2 touchPosition = touch.Position; if (touch.State == TouchLocationState.Moved) { if (touchPosition.X > leftPosition.X && touchPosition.X < leftPosition.X + leftPosition.Width && touchPosition.Y > leftPosition.Y && touchPosition.Y < leftPosition.Y + leftPosition.Height && raiderPosition.X > 0 && dead == false && pause == false) { raiderPosition.X -= 5; raiderMovePosition.X -= 5; raiderMoveRPosition.X -= 5; raiderMoveLPosition.X -= 5; moveL = true; if (shoot == false) { bulletPosition.X -= 5; explosionPosition.X -= 5; } } if (touchPosition.X > rightPosition.X && touchPosition.X < rightPosition.X + rightPosition.Width && touchPosition.Y > rightPosition.Y && touchPosition.Y < rightPosition.Y + rightPosition.Height && raiderPosition.X < width - raiderTexture.Width * width / 1080 && dead == false && pause == false) { raiderPosition.X += 5; raiderMovePosition.X += 5; raiderMoveRPosition.X += 5; raiderMoveLPosition.X += 5; moveR = true; if (shoot == false) { bulletPosition.X += 5; explosionPosition.X += 5; } } if (touchPosition.X > upPosition.X && touchPosition.X < upPosition.X + upPosition.Width && touchPosition.Y > upPosition.Y && touchPosition.Y < upPosition.Y + upPosition.Height && raiderPosition.Y > 0 && dead == false && pause == false) { downY = 6; } if (touchPosition.X > downPosition.X && touchPosition.X < downPosition.X + downPosition.Width && touchPosition.Y > downPosition.Y && touchPosition.Y < downPosition.Y + upPosition.Height && raiderPosition.Y + (raiderTexture.Height * height / 1920) < panelPosition.Y && dead == false && pause == false) { downY = 1; } } if (touch.State == TouchLocationState.Pressed) { if (touchPosition.X > shootPosition.X && touchPosition.X < shootPosition.X + shootPosition.Width && touchPosition.Y > shootPosition.Y && touchPosition.Y < shootPosition.Y + shootPosition.Height && bulletPosition.Y > raiderPosition.Y && dead == false && pause == false) { shoot = true; soundEffects[3].Play(); } if (touchPosition.X > startPosition.X && touchPosition.X < startPosition.X + startPosition.Width && touchPosition.Y > startPosition.Y && touchPosition.Y < startPosition.Y + startPosition.Height && endGame == true) { endGame = false; point = 0; life = 4; dead = true; pointerPosition = new Rectangle(gaugePosition.X + gaugeTexture.Width * width / 1080 - pointerTexture.Width * width / 1080, gaugePosition.Y, (10 * width) / 1080, (80 * height) / 1920); } if (touchPosition.X > startPosition.X && touchPosition.X < startPosition.X + startPosition.Width && touchPosition.Y > startPosition.Y && touchPosition.Y < startPosition.Y + startPosition.Height && endGame == false) { pause = !pause; if (pause == true) { SoundEffect.MasterVolume = 0.0f; } } } if (touch.State == TouchLocationState.Released) { if (touchPosition.X > leftPosition.X && touchPosition.X < leftPosition.X + leftPosition.Width && touchPosition.Y > leftPosition.Y && touchPosition.Y < leftPosition.Y + leftPosition.Height && raiderPosition.X > 0) { moveL = false; } if (touchPosition.X > rightPosition.X && touchPosition.X < rightPosition.X + rightPosition.Width && touchPosition.Y > rightPosition.Y && touchPosition.Y < rightPosition.Y + rightPosition.Height && raiderPosition.X < width - raiderTexture.Width * width / 1080) { moveR = false; } if (touchPosition.X > upPosition.X && touchPosition.X < upPosition.X + upPosition.Width && touchPosition.Y > upPosition.Y && touchPosition.Y < upPosition.Y + upPosition.Height && raiderPosition.Y > 0) { downY = 3; } if (touchPosition.X > downPosition.X && touchPosition.X < downPosition.X + downPosition.Width && touchPosition.Y > downPosition.Y && touchPosition.Y < downPosition.Y + upPosition.Height && raiderPosition.Y + (raiderTexture.Height * height / 1920) < panelPosition.Y) { downY = 3; } } } //move if (life <= 0 || pointerPosition.X < gaugePosition.X) { endGame = true; SoundEffect.MasterVolume = 0.0f; } if (dead == false && endGame == false && pause == false) { SoundEffect.MasterVolume = 1.0f; edgeLeftPosition.Y += downY; edgeRightPosition.Y += downY; edgev2LeftPosition.Y += downY; edgev2RightPosition.Y += downY; bridgePosition.Y += downY; fuelPosition.Y += downY; jetLeftPosition.Y += downY; jetLeftPosition.X += jetLeftMove; jetRightPosition.Y += downY; jetRightPosition.X -= jetRightMove; ship1Position.Y += downY; ship1RPosition.Y += downY; ship2Position.Y += downY; ship2RPosition.Y += downY; heliLPosition.Y += downY; heliL2Position.Y += downY; if (ship1LtR == true) { ship1Position.X += ship1Move; ship1RPosition.X += ship1Move; } if (ship1LtR == false) { ship1Position.X -= ship1Move; ship1RPosition.X -= ship1Move; } if (ship2LtR == true) { ship2Position.X += ship1Move; ship2RPosition.X += ship1Move; } if (ship2LtR == false) { ship2Position.X -= ship1Move; ship2RPosition.X -= ship1Move; } if (raiderPosition.X > heliLPosition.X && heliLPosition.Y > height / 3) { heliLPosition.X += heliMove; heliL2Position.X += heliMove; } } if (currentTime >= countDuration1s)//timer wait 1s and do { counter++; currentTime -= countDuration1s; if (endGame == false && pause == false) { pointerPosition.X -= 4; } heliMoveEffect = !heliMoveEffect; if (hit == true) { explosionPosition = new Rectangle(raiderPosition.X + (raiderTexture.Width * width / 1080) / 2 - (explosionTexture.Width * width / 1080) / 2, raiderPosition.Y + (raiderTexture.Height * height / 1920) / 2, (60 * width) / 1080, (60 * height) / 1920); hit = false; shoot = false; } } if (currentTime2 >= countDuration3s) { counter2++; currentTime2 -= countDuration3s; if (dead == true) { SoundEffect.MasterVolume = 0.0f; edgeLeftPosition = new Rectangle(0, 0 - edgeLeftTexture.Height * height / 1920 + height - panelTexture.Height * height / 1920, (300 * width) / 1080, (8000 * height) / 1920);; edgeRightPosition = new Rectangle(width - edgeRightTexture.Width * width / 1080, 0 - edgeRightTexture.Height * height / 1920 + height - panelTexture.Height * height / 1920, (300 * width) / 1080, (8000 * height) / 1920); edgev2LeftPosition = new Rectangle(edgeLeftPosition.X, edgeLeftPosition.Y - (edgev2LeftTexture.Height * height / 1920), (300 * width) / 1080, (3000 * height) / 1920); edgev2RightPosition = new Rectangle(edgeRightPosition.X, edgeRightPosition.Y - (edgev2RightTexture.Height * height / 1920), (300 * width) / 1080, (3000 * height) / 1920); bridgePosition = new Rectangle(edgev2LeftPosition.X + edgev2LeftTexture.Width * width / 1080, edgev2LeftPosition.Y, (510 * width) / 1080, (200 * height) / 1920); explosionPosition = new Rectangle(raiderPosition.X + (raiderTexture.Width * width / 1080) / 2 - (explosionTexture.Width * width / 1080) / 2, raiderPosition.Y + (raiderTexture.Height * height / 1920) / 2, (60 * width) / 1080, (60 * height) / 1920); raiderPosition = new Rectangle(graphics.GraphicsDevice.Viewport.Width / 2 - (raiderTexture.Width * width / 1080) / 2, panelPosition.Y - (raiderTexture.Height * height / 1920) * 2, (105 * width) / 1080, (112 * height) / 1920); raiderMovePosition = new Rectangle(graphics.GraphicsDevice.Viewport.Width / 2 - (raiderMoveTexture.Width * width / 1080) / 2, panelPosition.Y - (raiderMoveTexture.Height * height / 1920) * 2, (105 * width) / 1080, (112 * height) / 1920); raiderMoveRPosition = new Rectangle(graphics.GraphicsDevice.Viewport.Width / 2 - (raiderMoveRTexture.Width * width / 1080) / 2, panelPosition.Y - (raiderMoveRTexture.Height * height / 1920) * 2, (75 * width) / 1080, (112 * height) / 1920); raiderMoveLPosition = new Rectangle(graphics.GraphicsDevice.Viewport.Width / 2 - (raiderMoveLTexture.Width * width / 1080) / 2, panelPosition.Y - (raiderMoveLTexture.Height * height / 1920) * 2, (75 * width) / 1080, (112 * height) / 1920); bulletPosition = new Rectangle(raiderPosition.X + (raiderTexture.Width * width / 1080) / 2, raiderPosition.Y + (raiderTexture.Height * height / 1920) / 2, (5 * width) / 1080, (20 * height) / 1920); dead = false; life -= 1; fuelX = random.Next(edgeLeftPosition.X + edgeLeftTexture.Width * width / 1080, width - edgeRightTexture.Width * width / 1080 - fuelTexture.Width * width / 1080); fuelY = random.Next(-40 - fuelTexture.Height, -20 - fuelTexture.Height); fuelPosition = new Rectangle(fuelX, fuelY, (90 * width) / 1080, (150 * height) / 1920); jetLeftPosition = new Rectangle(jetLeftX, jetLeftY, (80 * width) / 1080, (45 * height) / 1920); jetRightPosition = new Rectangle(jetRightX, jetRightY, (80 * width) / 1080, (45 * height) / 1920); ship1X = width / 2 - ship1Texture.Width; ship1Y = random.Next(-40 - ship1Texture.Height, -20 - ship1Texture.Height); ship1Position = new Rectangle(ship1X, ship1Y, (150 * width) / 1080, (75 * height) / 1920); ship1RPosition = new Rectangle(ship1X, ship1Y, (150 * width) / 1080, (75 * height) / 1920); ship2X = width / 2 - ship2Texture.Width; ship2Y = random.Next(-400 - ship2Texture.Height, -200 - ship2Texture.Height); ship2Position = new Rectangle(ship2X, ship2Y, (150 * width) / 1080, (75 * height) / 1920); ship2RPosition = new Rectangle(ship2X, ship2Y, (150 * width) / 1080, (75 * height) / 1920); heliLX = random.Next(edgeLeftPosition.X + edgeLeftTexture.Width * width / 1080, width / 3); heliLY = random.Next(-500, -200); heliLPosition = new Rectangle(heliLX, heliLY, (113 * width) / 1080, (64 * height) / 1920); heliL2Position = new Rectangle(heliLX, heliLY, (113 * width) / 1080, (64 * height) / 1920); // reset enemys bo inaczej wlatuja w strefe respawnu } } if (shoot == true && hit == false) { bulletPosition.Y -= 20; explosionPosition.Y -= 20; } if (shoot == false) { bulletPosition = new Rectangle(raiderPosition.X + (raiderTexture.Width * width / 1080) / 2, raiderPosition.Y + (raiderTexture.Height * height / 1920) / 2, (5 * width) / 1080, (20 * height) / 1920); explosionPosition = new Rectangle(raiderPosition.X + (raiderTexture.Width * width / 1080) / 2 - (explosionTexture.Width * width / 1080) / 2, raiderPosition.Y + (raiderTexture.Height * height / 1920) / 2, (60 * width) / 1080, (60 * height) / 1920); } if (bridgeshow == false) { if (edgev2LeftPosition.Y < 0) { bridgePosition = new Rectangle(edgev2LeftPosition.X + edgev2LeftTexture.Width * width / 1080, edgev2LeftPosition.Y, (510 * width) / 1080, (200 * height) / 1920); bridgeshow = true; } } //Rectangle (kolizje) if (bulletPosition.Y <= 0) { shoot = false; } if (raiderPosition.Intersects(fuelPosition) && pointerPosition.X + pointerTexture.Width < gaugePosition.X + gaugeTexture.Width * width / 1080) { pointerPosition.X += 1; if (currentTime3 >= countDuration13s)//timer wait 1s and do { counter3++; currentTime3 -= countDuration13s; soundEffects[1].Play(); } } if (edgeLeftPosition.Y > panelPosition.Y) { edgeLeftPosition = new Rectangle(edgev2LeftPosition.X, edgev2LeftPosition.Y - edgeLeftTexture.Height * height / 1920, (300 * width) / 1080, (8000 * height) / 1920); edgeRightPosition = new Rectangle(edgev2RightPosition.X, edgev2RightPosition.Y - edgeRightTexture.Height * height / 1920, (300 * width) / 1080, (8000 * height) / 1920); } if (edgev2LeftPosition.Y > panelPosition.Y) { edgev2LeftPosition = new Rectangle(edgeLeftPosition.X, edgeLeftPosition.Y - (edgev2LeftTexture.Width * width / 1080), (300 * width) / 1080, (1920 * height) / 1920); edgev2RightPosition = new Rectangle(edgeRightPosition.X, edgeRightPosition.Y - (edgev2RightTexture.Width * width / 1080), (300 * width) / 1080, (1920 * height) / 1920); } if (raiderPosition.Intersects(edgev2LeftPosition) || raiderPosition.Intersects(edgev2RightPosition)) { explosionPosition = new Rectangle(raiderPosition.X + (raiderTexture.Width * width / 1080) / 2 - (explosionTexture.Width * width / 1080) / 2, raiderPosition.Y + (raiderTexture.Height * height / 1920) / 2, (60 * width) / 1080, (60 * height) / 1920); dead = true; } if (IntersectsPixel(raiderPosition, raiderTextureData, edgeLeftPosition, edgeLeftTextureData)) { explosionPosition = new Rectangle(raiderPosition.X + (raiderTexture.Width * width / 1080) / 2 - (explosionTexture.Width * width / 1080) / 2, raiderPosition.Y + (raiderTexture.Height * height / 1920) / 2, (60 * width) / 1080, (60 * height) / 1920); dead = true; } if (IntersectsPixel(raiderPosition, raiderTextureData, edgeRightPosition, edgeRightTextureData)) { explosionPosition = new Rectangle(raiderPosition.X + (raiderTexture.Width * width / 1080) / 2 - (explosionTexture.Width * width / 1080) / 2, raiderPosition.Y + (raiderTexture.Height * height / 1920) / 2, (60 * width) / 1080, (60 * height) / 1920); dead = true; } if (fuelPosition.Y > panelPosition.Y) { fuelX = random.Next(edgeLeftPosition.X + edgeLeftTexture.Width * width / 1080, width - edgeRightTexture.Width * width / 1080 - fuelTexture.Width * width / 1080); fuelY = random.Next(-40 - fuelTexture.Height, -20 - fuelTexture.Height); fuelPosition = new Rectangle(fuelX, fuelY, (90 * width) / 1080, (150 * height) / 1920); } if (bulletPosition.Intersects(fuelPosition) && shoot == true && hit == false) { point += 80; fuelX = random.Next(edgeLeftPosition.X + edgeLeftTexture.Width * width / 1080, width - edgeRightTexture.Width * width / 1080 - fuelTexture.Width * width / 1080); fuelY = random.Next(-60 - fuelTexture.Height, -40 - fuelTexture.Height); fuelPosition = new Rectangle(fuelX, fuelY, (90 * width) / 1080, (150 * height) / 1920); hit = true; soundEffects[2].Play(); } if (bulletPosition.Intersects(jetLeftPosition) && shoot == true && hit == false) { point += 100; hit = true; soundEffects[2].Play(); jetLeftX = random.Next(-500, -200); jetLeftY = random.Next(0, height / 3); jetLeftPosition = new Rectangle(jetLeftX, jetLeftY, (80 * width) / 1080, (45 * height) / 1920); } if (jetLeftPosition.X > width + jetLeftTexture.Width) { jetLeftX = random.Next(-500, -200); jetLeftY = random.Next(0, height / 3); jetLeftPosition = new Rectangle(jetLeftX, jetLeftY, (80 * width) / 1080, (45 * height) / 1920); } if (raiderPosition.Intersects(jetLeftPosition)) { explosionPosition = new Rectangle(raiderPosition.X + (raiderTexture.Width * width / 1080) / 2 - (explosionTexture.Width * width / 1080) / 2, raiderPosition.Y + (raiderTexture.Height * height / 1920) / 2, (60 * width) / 1080, (60 * height) / 1920); dead = true; jetLeftX = random.Next(-500, -200); jetLeftY = random.Next(0, height / 3); jetLeftPosition = new Rectangle(jetLeftX, jetLeftY, (80 * width) / 1080, (45 * height) / 1920); } if (bulletPosition.Intersects(jetRightPosition) && shoot == true && hit == false) { point += 100; hit = true; soundEffects[2].Play(); jetRightX = random.Next(width, width + 500); jetRightY = random.Next(0, height / 3); jetRightPosition = new Rectangle(jetRightX, jetRightY, (80 * width) / 1080, (45 * height) / 1920); } if (jetRightPosition.X < 0 - jetRightTexture.Width) { jetRightX = random.Next(width, width + 500); jetRightY = random.Next(0, height / 3); jetRightPosition = new Rectangle(jetRightX, jetRightY, (80 * width) / 1080, (45 * height) / 1920); } if (raiderPosition.Intersects(jetRightPosition)) { explosionPosition = new Rectangle(raiderPosition.X + (raiderTexture.Width * width / 1080) / 2 - (explosionTexture.Width * width / 1080) / 2, raiderPosition.Y + (raiderTexture.Height * height / 1920) / 2, (60 * width) / 1080, (60 * height) / 1920); dead = true; jetRightX = random.Next(width + 50, width + 500); jetRightY = random.Next(0, height / 3); jetRightPosition = new Rectangle(jetRightX, jetRightY, (80 * width) / 1080, (45 * height) / 1920); } if (ship1Position.Y > panelPosition.Y) { ship1X = width / 2 - ship1Texture.Width; ship1Y = random.Next(-40 - ship1Texture.Height, -20 - ship1Texture.Height); ship1Position = new Rectangle(ship1X, ship1Y, (150 * width) / 1080, (75 * height) / 1920); ship1RPosition = new Rectangle(ship1X, ship1Y, (150 * width) / 1080, (75 * height) / 1920); } if (raiderPosition.Intersects(ship1Position)) { explosionPosition = new Rectangle(raiderPosition.X + (raiderTexture.Width * width / 1080) / 2 - (explosionTexture.Width * width / 1080) / 2, raiderPosition.Y + (raiderTexture.Height * height / 1920) / 2, (60 * width) / 1080, (60 * height) / 1920); dead = true; ship1X = width / 2 - ship1Texture.Width; ship1Y = random.Next(-60 - ship1Texture.Height, -40 - ship1Texture.Height); ship1Position = new Rectangle(ship1X, ship1Y, (150 * width) / 1080, (75 * height) / 1920); ship1RPosition = new Rectangle(ship1X, ship1Y, (150 * width) / 1080, (75 * height) / 1920); } if (bulletPosition.Intersects(ship1Position) && shoot == true && hit == false) { point += 30; hit = true; soundEffects[2].Play(); ship1X = width / 2 - ship1Texture.Width; ship1Y = random.Next(-40 - ship1Texture.Height, -20 - ship1Texture.Height); ship1Position = new Rectangle(ship1X, ship1Y, (150 * width) / 1080, (75 * height) / 1920); ship1RPosition = new Rectangle(ship1X, ship1Y, (150 * width) / 1080, (75 * height) / 1920); } if (ship1Position.Intersects(edgeLeftPosition) || ship1Position.Intersects(edgeRightPosition) || ship1Position.Intersects(edgev2LeftPosition) || ship1Position.Intersects(edgev2RightPosition)) { ship1LtR = !ship1LtR; } if (ship2Position.Y > panelPosition.Y) { ship2X = width / 2 - ship2Texture.Width; ship2Y = random.Next(-40 - ship2Texture.Height, -20 - ship2Texture.Height); ship2Position = new Rectangle(ship2X, ship2Y, (150 * width) / 1080, (75 * height) / 1920); ship2RPosition = new Rectangle(ship2X, ship2Y, (150 * width) / 1080, (75 * height) / 1920); } if (raiderPosition.Intersects(ship2Position)) { explosionPosition = new Rectangle(raiderPosition.X + (raiderTexture.Width * width / 1080) / 2 - (explosionTexture.Width * width / 1080) / 2, raiderPosition.Y + (raiderTexture.Height * height / 1920) / 2, (60 * width) / 1080, (60 * height) / 1920); dead = true; ship2X = width / 2 - ship2Texture.Width; ship2Y = random.Next(-40 - ship2Texture.Height, -20 - ship2Texture.Height); ship2Position = new Rectangle(ship2X, ship2Y, (150 * width) / 1080, (75 * height) / 1920); ship2RPosition = new Rectangle(ship2X, ship2Y, (150 * width) / 1080, (75 * height) / 1920); } if (bulletPosition.Intersects(ship2Position) && shoot == true && hit == false) { point += 30; hit = true; soundEffects[2].Play(); ship2X = width / 2 - ship2Texture.Width; ship2Y = random.Next(-40 - ship2Texture.Height, -20 - ship2Texture.Height); ship2Position = new Rectangle(ship2X, ship2Y, (150 * width) / 1080, (75 * height) / 1920); ship2RPosition = new Rectangle(ship2X, ship2Y, (150 * width) / 1080, (75 * height) / 1920); } if (ship2Position.Intersects(edgeLeftPosition) || ship2Position.Intersects(edgeRightPosition) || ship2Position.Intersects(edgev2LeftPosition) || ship2Position.Intersects(edgev2RightPosition)) { ship2LtR = !ship2LtR; } if (heliLPosition.Y > panelPosition.Y) { heliLX = random.Next(edgeLeftPosition.X + edgeLeftTexture.Width * width / 1080, width / 3); heliLY = random.Next(-500, -200); heliLPosition = new Rectangle(heliLX, heliLY, (113 * width) / 1080, (64 * height) / 1920); heliL2Position = new Rectangle(heliLX, heliLY, (113 * width) / 1080, (64 * height) / 1920); } if (raiderPosition.Intersects(heliLPosition)) { explosionPosition = new Rectangle(raiderPosition.X + (raiderTexture.Width * width / 1080) / 2 - (explosionTexture.Width * width / 1080) / 2, raiderPosition.Y + (raiderTexture.Height * height / 1920) / 2, (60 * width) / 1080, (60 * height) / 1920); dead = true; heliLX = random.Next(edgeLeftPosition.X + edgeLeftTexture.Width * width / 1080, width / 3); heliLY = random.Next(-500, -200); heliLPosition = new Rectangle(heliLX, heliLY, (113 * width) / 1080, (64 * height) / 1920); heliL2Position = new Rectangle(heliLX, heliLY, (113 * width) / 1080, (64 * height) / 1920); } if (bulletPosition.Intersects(heliLPosition) && shoot == true && hit == false) { point += 60; hit = true; soundEffects[2].Play(); heliLX = random.Next(edgeLeftPosition.X + edgeLeftTexture.Width * width / 1080, width / 3); heliLY = random.Next(-500, -200); heliLPosition = new Rectangle(heliLX, heliLY, (113 * width) / 1080, (64 * height) / 1920); heliL2Position = new Rectangle(heliLX, heliLY, (113 * width) / 1080, (64 * height) / 1920); } if (bulletPosition.Intersects(bridgePosition) && bridgeshow == true) { point += 500; hit = true; soundEffects[2].Play(); bridgeshow = false; } if (bridgePosition.Intersects(fuelPosition)) { fuelX = random.Next(edgeLeftPosition.X + edgeLeftTexture.Width * width / 1080, width - edgeRightTexture.Width * width / 1080 - fuelTexture.Width * width / 1080); fuelY = random.Next(-40 - fuelTexture.Height, -20 - fuelTexture.Height); fuelPosition = new Rectangle(fuelX, fuelY, (90 * width) / 1080, (150 * height) / 1920); } if (bridgePosition.Intersects(ship1Position)) { ship1X = width / 2 - ship1Texture.Width; ship1Y = random.Next(-40 - ship1Texture.Height, -20 - ship1Texture.Height); ship1Position = new Rectangle(ship1X, ship1Y, (150 * width) / 1080, (75 * height) / 1920); ship1RPosition = new Rectangle(ship1X, ship1Y, (150 * width) / 1080, (75 * height) / 1920); } if (bridgePosition.Intersects(ship2Position)) { ship2X = width / 2 - ship2Texture.Width; ship2Y = random.Next(-40 - ship2Texture.Height, -20 - ship2Texture.Height); ship2Position = new Rectangle(ship2X, ship2Y, (150 * width) / 1080, (75 * height) / 1920); ship2RPosition = new Rectangle(ship2X, ship2Y, (150 * width) / 1080, (75 * height) / 1920); } if (bridgePosition.Intersects(heliLPosition)) { heliLX = random.Next(edgeLeftPosition.X + edgeLeftTexture.Width * width / 1080, width / 3); heliLY = random.Next(-500, -200); heliLPosition = new Rectangle(heliLX, heliLY, (113 * width) / 1080, (64 * height) / 1920); heliL2Position = new Rectangle(heliLX, heliLY, (113 * width) / 1080, (64 * height) / 1920); } // TODO: Add your update logic here base.Update(gameTime); }
/// <summary> /// Take N samples. Speed is number of alternating taps over that period /// </summary> /// <param name="gameTime"></param> public override void Update(GameTime gameTime, ref InGameState gameState, bool justTransitioned) { if (justTransitioned) { SoundManager.Play(this._engineIdle); } if (_messageTime == TimeSpan.MinValue) { _messageTime = gameTime.TotalGameTime.Add(TimeSpan.FromSeconds(1.5)); } TouchCollection touchCollection = TouchPanel.GetState(); int activeTouches = 0; TouchLocation activeTouch = default(TouchLocation); foreach (TouchLocation touchLocation in touchCollection) { if (touchLocation.State == TouchLocationState.Pressed || touchLocation.State == TouchLocationState.Moved) { activeTouch = touchLocation; activeTouches++; } } if (activeTouches > 0) { if (_startTime == TimeSpan.MinValue) { _startTime = gameTime.TotalGameTime; _elapsedtime = TimeSpan.Zero; } } _elapsedtime = _elapsedtime.Add(gameTime.ElapsedGameTime); Point touchPoint = new Point((int)activeTouch.Position.X, (int)activeTouch.Position.Y); bool isActive = false; if (activeTouches > 0) { int y = 0; foreach (TilePiece[] col in _boardTiles) { int x = 0; foreach (TilePiece cell in col) { Rectangle bounds = new Rectangle(x * 80, y * 80, 80, 80); if (cell == TilePiece.Grass && bounds.Contains(touchPoint)) { return; // false } if (bounds.Contains(touchPoint)) { isActive = true; int xDiff = Math.Abs(x - _carPosition.X); int yDiff = Math.Abs(y - _carPosition.Y); int coordDiff = xDiff + yDiff; if (coordDiff == 1 || (xDiff == 1 && yDiff == 1)) { if (_prevPosition.X != x || _prevPosition.Y != y) { // we also need to make sure our move is valid if (IsMoveValid(_carPosition, new Point(x, y))) { _prevPosition = _carPosition; _prevCarAngle = _carAngle; _carPosition = new Point(x, y); switch (cell) { case TilePiece.Start: case TilePiece.TopLeft: { _carAngle = (float)((_carPosition.X < _prevPosition.X) ? Math.PI * 3 / 4 : -Math.PI / 4); } break; case TilePiece.Horizontal: { _carAngle = (float)((_carPosition.X > _prevPosition.X) ? 0 : Math.PI); } break; case TilePiece.Vertical: { _carAngle = (float)((_carPosition.Y > _prevPosition.Y) ? Math.PI / 2 : -Math.PI / 2); } break; case TilePiece.TopRight: { _carAngle = (float)((_carPosition.Y < _prevPosition.Y) ? -Math.PI * 3 / 4 : Math.PI / 4); } break; case TilePiece.BottomLeft: { _carAngle = (float)((_carPosition.X < _prevPosition.X) ? -Math.PI * 3 / 4 : Math.PI / 4); } break; case TilePiece.BottomRight: { _carAngle = (float)((_carPosition.Y < _prevPosition.Y) ? Math.PI * 3 / 4 : -Math.PI / 4); } break; } if (cell == TilePiece.TopLeft || cell == TilePiece.TopRight || cell == TilePiece.BottomLeft || cell == TilePiece.BottomRight) { SoundManager.Play(this._carScreech); } if (cell == TilePiece.Start) { _messageTime = TimeSpan.MinValue; _completedLaps++; if (RequiredLaps > _completedLaps) { SoundManager.Play(this._carHorn); } } } } } } x++; } y++; } } if (isActive) { // Break up the cell into float xOffset = Math.Min(40, Math.Max(-40, _carPosition.X * 80 + 40 - touchPoint.X)); float yOffset = Math.Min(40, Math.Max(-40, _carPosition.Y * 80 + 40 - touchPoint.Y)); switch (_boardTiles[_carPosition.Y][_carPosition.X]) { case TilePiece.Start: case TilePiece.TopLeft: case TilePiece.TopRight: case TilePiece.BottomLeft: case TilePiece.BottomRight: { yOffset = Math.Max(-10, Math.Min(10, yOffset)); xOffset = Math.Max(-10, Math.Min(10, xOffset)); } break; case TilePiece.Horizontal: { yOffset = 0; } break; case TilePiece.Vertical: { xOffset = 0; } break; } _carOffset = new Point((int)xOffset, (int)yOffset); } if (_completedLaps == RequiredLaps) { SoundManager.Stop(this._engineIdle); FingerGames.Instance.GameManager.Players[_playerIndex].Score = _elapsedtime.TotalSeconds; gameState = InGameState.End; // sweet! } return; // false }
public void Update(GameTime time, bool hasFocus) { State.Time = time; State.PreviousKeyboardState = State.KeyboardState; State.FrameTextInput = TextCharacters; var touchMode = FSOEnvironment.SoftwareKeyboard; if (touchMode) { State.KeyboardState = new KeyboardState(); TouchCollection touches = TouchPanel.GetState(); var missing = new HashSet <MultiMouse>(State.MouseStates); //relate touches to their last virtual mouse foreach (var touch in touches) { var mouse = State.MouseStates.FirstOrDefault(x => x.ID == touch.Id); if (mouse == null) { mouse = new MultiMouse { ID = touch.Id }; State.MouseStates.Add(mouse); } missing.Remove(mouse); mouse.MouseState = new MouseState( (int)touch.Position.X, (int)touch.Position.Y, 0, ButtonState.Pressed, ButtonState.Released, ButtonState.Released, ButtonState.Released, ButtonState.Released ); } //if virtual mouses no longer have their touch, they are performing a "mouse up" //if the state has mouseovers, we should record the mouse state as being lifted. foreach (var miss in missing) { if (miss.LastMouseOver == null && miss.LastMouseDown == null) { State.MouseStates.Remove(miss); } else { miss.MouseState = new MouseState(miss.MouseState.X, miss.MouseState.Y, 0, ButtonState.Released, ButtonState.Released, ButtonState.Released, ButtonState.Released, ButtonState.Released); miss.Dead = true; } } } else { //single mouse state if (hasFocus) { State.MouseState = Mouse.GetState(); State.KeyboardState = Keyboard.GetState(); } else { State.MouseState = new MouseState(); State.KeyboardState = new KeyboardState(); } if (State.KeyboardState.IsKeyDown(Keys.LeftAlt) && State.MouseState.LeftButton == ButtonState.Pressed) { //emulated middle click with alt var ms = State.MouseState; State.MouseState = new MouseState(ms.X, ms.Y, ms.ScrollWheelValue, ButtonState.Released, ButtonState.Pressed, ms.RightButton, ms.XButton1, ms.XButton2); } if (State.MouseStates.Count == 0) { State.MouseStates.Add(new MultiMouse { ID = 1 }); } State.MouseStates[0].MouseState = State.MouseState; } State.SharedData.Clear(); State.Update(); foreach (var layer in Layers) { layer.Update(State); } TextCharacters.Clear(); }
private void TouchStub(UpdateState state) { var test = TouchPanel.EnableMouseTouchPoint; TouchCollection touches = TouchPanel.GetState(); if (touches.Count != lastTouchCount) { touchedFrames = 0; } lastTouchCount = touches.Count; if (touches.Count > 0) { Vector2 avg = new Vector2(); for (int i = 0; i < touches.Count; i++) { avg += touches[i].Position; } avg /= touches.Count; if (touchedFrames < TOUCH_ACCEPT_TIME) { avg = prevTouchAvg ?? avg; state.MouseState = new MouseState( (int)avg.X, (int)avg.Y, state.MouseState.ScrollWheelValue, ButtonState.Released, ButtonState.Released, ButtonState.Released, ButtonState.Released, ButtonState.Released ); touchedFrames++; } else { state.MouseState = new MouseState( (int)avg.X, (int)avg.Y, state.MouseState.ScrollWheelValue, (touches.Count > 1) ? ButtonState.Released : ButtonState.Pressed, (touches.Count > 1) ? ButtonState.Pressed : ButtonState.Released, (touches.Count > 1) ? ButtonState.Pressed : ButtonState.Released, ButtonState.Released, ButtonState.Released ); prevTouchAvg = avg; state.TouchMode = true; } } else { prevTouchAvg = null; touchedFrames = 0; if (state.TouchMode) { state.MouseState = new MouseState( lastMouseState.X, lastMouseState.Y, state.MouseState.ScrollWheelValue, ButtonState.Released, ButtonState.Released, ButtonState.Released, ButtonState.Released, ButtonState.Released ); } //state.TouchMode = false; } lastMouseState = state.MouseState; }
public virtual void update(GameTime gameTime) { touches = TouchPanel.GetState(); }
public GestureSample ReadGesture() { return(TouchPanel.ReadGesture()); }
public TouchPanelCapabilities GetCapabilities() { return(TouchPanel.GetCapabilities()); }
//=== @interface ITouchPanelEventObserver public void Touching(TouchPanel panel) { if (this.gas <= 0) { return; } this.IsTouched = true; this.animator.SetBool("Touched", this.IsTouched); var b = this.transform.position - this.planet.transform.position; b.Normalize (); var cross = Vector3.Cross (b, Vector3.forward); cross.Normalize (); var dir = b + cross; dir.Normalize (); var dot = Vector3.Dot (Vector3.up, b); dot = (dot - 1.0f)*90; if (b.x < 0.0f) { dot = 360 -dot; } this.transform.rotation = Quaternion.AngleAxis(dot, Vector3.forward); this.rigidbody.angularVelocity = Vector3.zero; this.rigidbody.AddForce(dir * this.boost, ForceMode.Impulse); var prevGas = this.gas; this.gas -= 0.1f; if (prevGas > 0 && this.gas <= 0) { this.lastDir = cross; } this.SetBoostLevel(this.gas, this.animator); }
public void Down(TouchPanel panel) { if (this.gas <= 0) { return; } this.jetSE.PlayOneShot (this.jetSE.clip); this.PlayBoostEffect(); }
private void HandleTouchInput() { // we use raw touch points for selection, since they are more appropriate // for that use than gestures. so we need to get that raw touch data. TouchCollection touches = TouchPanel.GetState(); // see if we have a new primary point down. when the first touch // goes down, we do hit detection to try and select one of our sprites. if (touches.Count > 0 && touches[0].State == TouchLocationState.Pressed) { // convert the touch position into a Point for hit testing Point touchPoint = new Point((int)touches[0].Position.X, (int)touches[0].Position.Y); // iterate our sprites to find which sprite is being touched. we iterate backwards // since that will cause sprites that are drawn on top to be selected before // sprites drawn on the bottom. selectedSprite = null; for (int i = sprites.Count - 1; i >= 0; i--) { Sprite sprite = sprites[i]; if (sprite.HitBounds.Contains(touchPoint)) { selectedSprite = sprite; break; } } if (selectedSprite != null) { // make sure we stop selected sprites selectedSprite.Velocity = Vector2.Zero; // we also move the sprite to the end of the list so it // draws on top of the other sprites sprites.Remove(selectedSprite); sprites.Add(selectedSprite); } } // next we handle all of the gestures. since we may have multiple gestures available, // we use a loop to read in all of the gestures. this is important to make sure the // TouchPanel's queue doesn't get backed up with old data while (TouchPanel.IsGestureAvailable) { // read the next gesture from the queue GestureSample gesture = TouchPanel.ReadGesture(); // we can use the type of gesture to determine our behavior switch (gesture.GestureType) { // on taps, we change the color of the selected sprite case GestureType.Tap: case GestureType.DoubleTap: if (selectedSprite != null) { selectedSprite.ChangeColor(); } break; // on holds, if no sprite is selected, we add a new sprite at the // hold position and make it our selected sprite. otherwise we // remove our selected sprite. case GestureType.Hold: if (selectedSprite == null) { // create the new sprite selectedSprite = new Sprite(cat); selectedSprite.Center = gesture.Position; // add it to our list sprites.Add(selectedSprite); } else { sprites.Remove(selectedSprite); selectedSprite = null; } break; // on drags, we just want to move the selected sprite with the drag case GestureType.FreeDrag: if (selectedSprite != null) { selectedSprite.Center += gesture.Delta; } break; // on flicks, we want to update the selected sprite's velocity with // the flick velocity, which is in pixels per second. case GestureType.Flick: if (selectedSprite != null) { selectedSprite.Velocity = gesture.Delta; } break; // on pinches, we want to scale the selected sprite case GestureType.Pinch: if (selectedSprite != null) { // get the current and previous locations of the two fingers Vector2 a = gesture.Position; Vector2 aOld = gesture.Position - gesture.Delta; Vector2 b = gesture.Position2; Vector2 bOld = gesture.Position2 - gesture.Delta2; // figure out the distance between the current and previous locations float d = Vector2.Distance(a, b); float dOld = Vector2.Distance(aOld, bOld); // calculate the difference between the two and use that to alter the scale float scaleChange = (d - dOld) * .01f; selectedSprite.Scale += scaleChange; } break; } } // lastly, if there are no raw touch points, we make sure no sprites are selected. // this happens after we handle gestures because some gestures like taps and flicks // will come in on the same frame as our raw touch points report no touches and we // still want to use the selected sprite for those gestures. if (touches.Count == 0) { selectedSprite = null; } }
static void PanelTest() { Panel MainPanel = CreateMainPanel(); Pan= new Controller.TouchPanel("Com18"); MainPanel.OnMenuSelect += MainPanel_OnMenuSelect; Pan.Attatch(MainPanel); //Pan.ClearScreen(LayerConst.Layer1); //Pan.ClearScreen(LayerConst.Layer2); //for (int i = 1; i <7; i++) // Pan.ShowString(LayerConst.Layer2, i, "hello,中華民國103年", Color.White, Color.Black); // Pan.ShowString(LayerConst.Layer2, 7, "Message area!", Color.Red, Color.Black); }
private void ProcessTouch() { if (this.m_pDelegate != null) { this.m_currentTouchCollection = TouchPanel.GetState(); List <CCTouch> cCTouches = new List <CCTouch>(); List <CCTouch> cCTouches1 = new List <CCTouch>(); List <CCTouch> cCTouches2 = new List <CCTouch>(); foreach (TouchLocation mCurrentTouchCollection in this.m_currentTouchCollection) { switch (mCurrentTouchCollection.State) { case TouchLocationState.Released: { if (!this.m_pTouchMap.ContainsKey(mCurrentTouchCollection.Id)) { continue; } cCTouches2.Add(this.m_pTouchMap[mCurrentTouchCollection.Id].Value); this.m_pTouches.Remove(this.m_pTouchMap[mCurrentTouchCollection.Id]); this.m_pTouchMap.Remove(mCurrentTouchCollection.Id); continue; } case TouchLocationState.Pressed: { if (!this.m_rcViewPort.Contains((int)mCurrentTouchCollection.Position.X, (int)mCurrentTouchCollection.Position.Y)) { continue; } this.m_pTouches.AddLast(new CCTouch(mCurrentTouchCollection.Id, mCurrentTouchCollection.Position.X - (float)this.m_rcViewPort.Left / this.m_fScreenScaleFactor, mCurrentTouchCollection.Position.Y - (float)this.m_rcViewPort.Top / this.m_fScreenScaleFactor)); this.m_pTouchMap[mCurrentTouchCollection.Id] = this.m_pTouches.Last; cCTouches.Add(this.m_pTouches.Last.Value); continue; } case TouchLocationState.Moved: { if (!this.m_pTouchMap.ContainsKey(mCurrentTouchCollection.Id)) { continue; } cCTouches1.Add(this.m_pTouchMap[mCurrentTouchCollection.Id].Value); this.m_pTouchMap[mCurrentTouchCollection.Id].Value.SetTouchInfo(mCurrentTouchCollection.Id, mCurrentTouchCollection.Position.X - (float)this.m_rcViewPort.Left / this.m_fScreenScaleFactor, mCurrentTouchCollection.Position.Y - (float)this.m_rcViewPort.Top / this.m_fScreenScaleFactor); continue; } } throw new ArgumentOutOfRangeException(); } if (cCTouches.Count > 0) { this.m_pDelegate.touchesBegan(cCTouches, null); } if (cCTouches1.Count > 0) { this.m_pDelegate.touchesMoved(cCTouches1, null); } if (cCTouches2.Count > 0) { this.m_pDelegate.touchesEnded(cCTouches2, null); } } }
private void UpdatePlayer(GameTime gameTime) { player.Update(gameTime); // Windows Phone Controls while (TouchPanel.IsGestureAvailable) { GestureSample gesture = TouchPanel.ReadGesture(); if (gesture.GestureType == GestureType.FreeDrag) { player.Position += gesture.Delta; } } // Get Thumbstick Controls player.Position.X += currentGamePadState.ThumbSticks.Left.X * playerMoveSpeed; player.Position.Y -= currentGamePadState.ThumbSticks.Left.Y * playerMoveSpeed; // Use the Keyboard / Dpad if (currentKeyboardState.IsKeyDown(Keys.Left) || currentGamePadState.DPad.Left == ButtonState.Pressed) { player.Position.X -= playerMoveSpeed; } if (currentKeyboardState.IsKeyDown(Keys.Right) || currentGamePadState.DPad.Right == ButtonState.Pressed) { player.Position.X += playerMoveSpeed; } if (currentKeyboardState.IsKeyDown(Keys.Up) || currentGamePadState.DPad.Up == ButtonState.Pressed) { player.Position.Y -= playerMoveSpeed; } if (currentKeyboardState.IsKeyDown(Keys.Down) || currentGamePadState.DPad.Down == ButtonState.Pressed) { player.Position.Y += playerMoveSpeed; } // Make sure that the player does not go out of bounds player.Position.X = MathHelper.Clamp(player.Position.X, 0, GraphicsDevice.Viewport.Width - player.Width); player.Position.Y = MathHelper.Clamp(player.Position.Y, 0, GraphicsDevice.Viewport.Height - player.Height); // Fire only every interval we set as the fireTime if (gameTime.TotalGameTime - previousFireTime > fireTime) { // Reset our current time previousFireTime = gameTime.TotalGameTime; // Add the projectile, but add it to the front and center of the player AddProjectile(player.Position + new Vector2(player.Width / 2, 0)); // Play the laser sound laserSound.Play(); } // reset score if player health goes to zero if (player.Health <= 0) { player.Health = 100; score = 0; } }
public static bool inputUpsellScreen() { if (!Upsell.showUpsell) { return(false); } Upsell.pressed_button = -1; if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { if (Upsell.anm_progress != -1) { Upsell.anm_progress = -1; return(true); } Upsell.disposeUpsellScreen(); if (Upsell.buy_scr_work != null) { Upsell.buy_scr_work.result[0] = 2; AppMain.DmSndBgmPlayerPlayBgm(0); } else { AppMain.SyDecideEvtCase((short)1); AppMain.SyChangeNextEvt(); } return(true); } TouchCollection state = TouchPanel.GetState(); if (state.Count == 0) { if (Upsell.px == 0 && Upsell.py == 0) { return(true); } Upsell.curState = 1; Upsell.cx = Upsell.px; Upsell.cy = Upsell.py; Upsell.px = 0; Upsell.py = 0; } else { TouchLocation touchLocation = state[0]; if (touchLocation.State == TouchLocationState.Pressed || touchLocation.State == TouchLocationState.Moved) { Upsell.curState = 0; Upsell.cx = (int)touchLocation.Position.X; Upsell.cy = (int)touchLocation.Position.Y; } if (touchLocation.State == TouchLocationState.Released || touchLocation.State == TouchLocationState.Invalid) { Upsell.curState = 1; Upsell.cx = Upsell.px; Upsell.cy = Upsell.py; Upsell.px = 0; Upsell.py = 0; } } Upsell.hl_buttons[0] = false; Upsell.hl_buttons[1] = false; if (Upsell.anm_progress > 100) { Upsell.anm_progress = -Upsell.anm_progress; Upsell.curState = 1; Upsell.cx = Upsell.px; Upsell.cy = Upsell.py; Upsell.px = 0; Upsell.py = 0; return(true); } if (Upsell.anm_progress != -1) { return(true); } for (int index = 0; index < 5; ++index) { if (Upsell.rects[index].Contains(Upsell.cx, Upsell.cy)) { Upsell.pressed_button = index; break; } } switch (Upsell.pressed_button) { case 0: if (Upsell.curState == 0) { Upsell.hl_buttons[0] = true; break; } Upsell.disposeUpsellScreen(); if (Upsell.buy_scr_work != null) { Upsell.buy_scr_work.result[0] = 2; AppMain.DmSndBgmPlayerPlayBgm(0); break; } AppMain.SyDecideEvtCase((short)1); AppMain.SyChangeNextEvt(); break; case 1: if (Upsell.curState == 0) { Upsell.hl_buttons[1] = true; break; } Upsell.wasUpsell = true; XBOXLive.showGuide(); break; case 2: if (Upsell.curState == 1) { --Upsell.ss_num; if (Upsell.ss_num < 1) { Upsell.ss_num = 5; } Upsell.screenshot.Dispose(); Upsell.screenshot = Texture2D.FromStream(LiveFeature.GAME.GraphicsDevice, TitleContainer.OpenStream("Content\\UPSELL\\s4us_ss_" + (object)Upsell.ss_num + ".png")); break; } break; case 3: if (Upsell.curState == 1) { ++Upsell.ss_num; if (Upsell.ss_num >= 5) { Upsell.ss_num = 1; } Upsell.screenshot.Dispose(); Upsell.screenshot = Texture2D.FromStream(LiveFeature.GAME.GraphicsDevice, TitleContainer.OpenStream("Content\\UPSELL\\s4us_ss_" + (object)Upsell.ss_num + ".png")); break; } break; case 4: if (Upsell.curState == 0) { Upsell.anm_progress = 0; break; } break; } if (Upsell.curState == 0) { Upsell.px = Upsell.cx; Upsell.py = Upsell.cy; } else { Upsell.curState = -1; } return(true); }
internal bool InnerLoopTick() { SDL.SDL_Event evt; #if !THREADED_GL Threading.Run(); #endif while (SDL.SDL_PollEvent(out evt) == 1) { // Keyboard if (evt.type == SDL.SDL_EventType.SDL_KEYDOWN) { #if USE_SCANCODES Keys key = SDL2_KeyboardUtil.ToXNA(evt.key.keysym.scancode); #else Keys key = SDL2_KeyboardUtil.ToXNA(evt.key.keysym.sym); #endif if (!keys.Contains(key)) { keys.Add(key); INTERNAL_TextInputIn(key); } } else if (evt.type == SDL.SDL_EventType.SDL_KEYUP) { #if USE_SCANCODES Keys key = SDL2_KeyboardUtil.ToXNA(evt.key.keysym.scancode); #else Keys key = SDL2_KeyboardUtil.ToXNA(evt.key.keysym.sym); #endif if (keys.Remove(key)) { INTERNAL_TextInputOut(key); } } // Mouse Input else if (evt.type == SDL.SDL_EventType.SDL_MOUSEMOTION) { Mouse.INTERNAL_IsWarped = false; } else if (evt.type == SDL.SDL_EventType.SDL_MOUSEWHEEL) { // 120 units per notch. Because reasons. Mouse.INTERNAL_MouseWheel += evt.wheel.y * 120; } // Touch Input else if (evt.type == SDL.SDL_EventType.SDL_FINGERDOWN) { TouchPanel.AddEvent( (int)evt.tfinger.touchId, TouchLocationState.Pressed, new Vector2( evt.tfinger.x, evt.tfinger.y ) ); } else if (evt.type == SDL.SDL_EventType.SDL_FINGERUP) { TouchPanel.AddEvent( (int)evt.tfinger.touchId, TouchLocationState.Released, new Vector2( evt.tfinger.x, evt.tfinger.y ) ); } else if (evt.type == SDL.SDL_EventType.SDL_FINGERMOTION) { TouchPanel.AddEvent( (int)evt.tfinger.touchId, TouchLocationState.Moved, new Vector2( evt.tfinger.x, evt.tfinger.y ) ); } // Various Window Events... else if (evt.type == SDL.SDL_EventType.SDL_WINDOWEVENT) { // Window Focus if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_GAINED) { IsActive = true; if (!INTERNAL_useFullscreenSpaces) { // If we alt-tab away, we lose the 'fullscreen desktop' flag on some WMs SDL.SDL_SetWindowFullscreen( Window.Handle, Game.GraphicsDevice.PresentationParameters.IsFullScreen ? (uint)SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP : 0 ); } // Disable the screensaver when we're back. SDL.SDL_DisableScreenSaver(); } else if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_LOST) { IsActive = false; if (!INTERNAL_useFullscreenSpaces) { SDL.SDL_SetWindowFullscreen(Window.Handle, 0); } // Give the screensaver back, we're not that important now. SDL.SDL_EnableScreenSaver(); } // Window Resize else if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_RESIZED) { Mouse.INTERNAL_WindowWidth = evt.window.data1; Mouse.INTERNAL_WindowHeight = evt.window.data2; // Should be called on user resize only, NOT ApplyChanges! ((SDL2_GameWindow)Window).INTERNAL_ClientSizeChanged(); } else if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_SIZE_CHANGED) { Mouse.INTERNAL_WindowWidth = evt.window.data1; Mouse.INTERNAL_WindowHeight = evt.window.data2; // Need to reset the graphics device any time the window size changes if (Game.graphicsDeviceManager.IsFullScreen) { GraphicsDevice device = Game.GraphicsDevice; Game.graphicsDeviceManager.INTERNAL_ResizeGraphicsDevice( device.GLDevice.Backbuffer.Width, device.GLDevice.Backbuffer.Height ); } else { Game.graphicsDeviceManager.INTERNAL_ResizeGraphicsDevice( evt.window.data1, evt.window.data2 ); } } // Window Move else if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_MOVED) { /* Apparently if you move the window to a new * display, a GraphicsDevice Reset occurs. * -flibit */ int newIndex = SDL.SDL_GetWindowDisplayIndex( Window.Handle ); if (newIndex != displayIndex) { displayIndex = newIndex; INTERNAL_GenerateDisplayModes(); Game.GraphicsDevice.Reset(); } } // Mouse Focus else if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_ENTER) { SDL.SDL_DisableScreenSaver(); } else if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_LEAVE) { SDL.SDL_EnableScreenSaver(); } } // Controller device management else if (evt.type == SDL.SDL_EventType.SDL_JOYDEVICEADDED) { GamePad.INTERNAL_AddInstance(evt.jdevice.which); } else if (evt.type == SDL.SDL_EventType.SDL_JOYDEVICEREMOVED) { GamePad.INTERNAL_RemoveInstance(evt.jdevice.which); } // Text Input else if (evt.type == SDL.SDL_EventType.SDL_TEXTINPUT && !INTERNAL_TextInputSuppress) { string text; // Based on the SDL2# LPUtf8StrMarshaler unsafe { byte *endPtr = evt.text.text; while (*endPtr != 0) { endPtr++; } byte[] bytes = new byte[endPtr - evt.text.text]; Marshal.Copy((IntPtr)evt.text.text, bytes, 0, bytes.Length); text = System.Text.Encoding.UTF8.GetString(bytes); } if (text.Length > 0) { TextInputEXT.OnTextInput(text[0]); } } // Quit else if (evt.type == SDL.SDL_EventType.SDL_QUIT) { INTERNAL_runApplication = false; break; } } // Text Input Controls Key Handling INTERNAL_TextInputUpdate(); Keyboard.SetKeys(keys); Game.Tick(); return(INTERNAL_runApplication); }
/// <summary> /// Reads the latest state of the keyboard and gamepad and mouse/touchpad. /// </summary> public void Update(GameTime gameTime) { _lastKeyboardState = _currentKeyboardState; _lastGamePadState = _currentGamePadState; _lastMouseState = _currentMouseState; if (_handleVirtualStick) { _lastVirtualState = _currentVirtualState; } _currentKeyboardState = Keyboard.GetState(); _currentGamePadState = GamePad.GetState(PlayerIndex.One); _currentMouseState = Mouse.GetState(); if (_handleVirtualStick) { if (GamePad.GetState(PlayerIndex.One).IsConnected) { _currentVirtualState = GamePad.GetState(PlayerIndex.One); } else { _currentVirtualState = HandleVirtualStickWin(); } } _gestures.Clear(); while (TouchPanel.IsGestureAvailable) { _gestures.Add(TouchPanel.ReadGesture()); } // Update cursor Vector2 oldCursor = _cursor; if (_currentGamePadState.IsConnected && _currentGamePadState.ThumbSticks.Left != Vector2.Zero) { Vector2 temp = _currentGamePadState.ThumbSticks.Left; _cursor += temp * new Vector2(300f, -300f) * (float)gameTime.ElapsedGameTime.TotalSeconds; Mouse.SetPosition((int)_cursor.X, (int)_cursor.Y); } else { _cursor.X = _currentMouseState.X; _cursor.Y = _currentMouseState.Y; } _cursor.X = MathHelper.Clamp(_cursor.X, 0f, _viewport.Width); _cursor.Y = MathHelper.Clamp(_cursor.Y, 0f, _viewport.Height); if (_cursorIsValid && oldCursor != _cursor) { _cursorMoved = true; } else { _cursorMoved = false; } if (_viewport.Bounds.Contains(_currentMouseState.X, _currentMouseState.Y)) { _cursorIsValid = true; } else { _cursorIsValid = false; } }
/// <summary> /// Handle the input of the sample. /// </summary> private void HandleInput() { TouchCollection touchCollection = TouchPanel.GetState(); if (touchCollection.Count > 0) { TouchLocation touch = touchCollection[0]; // If the tank is moving he can not be relocated if (!tank.IsMoving) { if (touch.State == TouchLocationState.Pressed && !isDragingTank) { Rectangle toucRect = new Rectangle((int)touch.Position.X - 5, (int)touch.Position.Y - 5, 10, 10); if (tank.Bounds.Intersects(toucRect)) { isDragingTank = true; } } else if (touch.State == TouchLocationState.Moved && isDragingTank) { tank.Move(touch.Position); } else if (touch.State == TouchLocationState.Released && isDragingTank) { isDragingTank = false; } } } // Read all gesture while (TouchPanel.IsGestureAvailable) { GestureSample sample = TouchPanel.ReadGesture(); // If the search button is clicked, the button will handle it. if (serachButton.HandleInput(sample)) { return; } // If the switch button is clicked, the button will handle it. if (switchViewButton.HandleInput(sample)) { return; } // If the change mode button is clicked, the button will handle it. if (changeRotuingModeButton.HandleInput(sample)) { return; } if (tank.IsMoving) { // If the draw route button is clicked, the button will handle it. if (drawRouteButton.HandleInput(sample)) { return; } // If the clear all pushpins button is clicked, the button will handle it. if (clearPushPinsButton.HandleInput(sample)) { return; } } if (sample.GestureType == GestureType.Tap) { // Gets the position on the displayed map Vector2 positionOnMap = TileSystem.LatLongToPixelXY(bingMapsViewer.CenterGeoCoordinate, ZoomLevel) - bingMapsViewer.Offset; // Gets the distance between the gesture and the center of the screen Vector2 distance = sample.Position - BingMapsViewer.ScreenCenter; // Calculate the distance between the center of the screen and the position on the map Vector2 positionOfGesture = positionOnMap + distance; PushPin pushPin = new PushPin(bingMapsViewer, TileSystem.PixelXYToLatLong(positionOfGesture, ZoomLevel), pushPinTexture2D); pushPins.AddLast(pushPin); // Indicates to the Tank that new push pin is added tank.AddPushPin(pushPin); } else if (sample.GestureType == GestureType.FreeDrag) { if (!isDragingTank) { // Move the map when dragging bingMapsViewer.MoveByOffset(sample.Delta); } } // When an hold gesture is caught on push pin ask if wants to delete else if (sample.GestureType == GestureType.Hold) { // Creates a rectangle around the gesture Rectangle touchRectangle = new Rectangle( (int)sample.Position.X - 20, (int)sample.Position.Y - 40, 60, 100); foreach (PushPin pushPin in pushPins) { // Gets the center of the map displayed Vector2 center = TileSystem.LatLongToPixelXY(bingMapsViewer.CenterGeoCoordinate, bingMapsViewer.ZoomLevel); // Gets the position of the push pin on the map Vector2 position = TileSystem.LatLongToPixelXY(pushPin.Location, bingMapsViewer.ZoomLevel); // Calculate the distance between them in screen scale Vector2 targetPosition = (position - center) + BingMapsViewer.ScreenCenter + bingMapsViewer.Offset; // Checks if the push pin is in side the gesture rectangle if (touchRectangle.Contains(new Rectangle((int)targetPosition.X, (int)targetPosition.Y, 1, 1))) { Guide.BeginShowMessageBox("Warning!", "Are you sure you want to delete this push pin?", new List <string>() { "OK", "Cancel" }, 0, MessageBoxIcon.Alert, DeletePushPinCallBack, pushPin); return; } } } } }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) {/* * if (null == baseEffect) * { * baseEffect = new BasicEffect(GraphicsDevice); * baseEffect.World = Matrix.Identity; * baseEffect.View = Matrix.Identity; * baseEffect.Projection = Matrix.CreateOrthographicOffCenter(0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 0, -1f); * baseEffect.VertexColorEnabled = true; * baseEffect.TextureEnabled = true; * baseEffect.Texture = _captureNet; * } * * if (countUp) * { * //animCount += 8; * } * else * { * //animCount -= 8; * } * * if (animCount == 256) * { * //animCount -= 8; * countUp = false; * } * if (animCount == 0) * { * //animCount += 8; * countUp = true; * } * //_orbSpots.OrderBy(new Func<Vector2, int>(Sort)); * GraphicsDevice.Clear(Color.Black); * * this._spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Additive, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone, baseEffect); * VertexPositionTexture[] verts = new VertexPositionTexture[3]; * * // ABC * // ACB * * verts[0].Position = new Vector3(_orbSpots[0], 0); * verts[1].Position = new Vector3(_orbSpots[1], 0); * verts[2].Position = new Vector3(_orbSpots[2], 0); * verts[0].TextureCoordinate = new Vector2(0, .25f); * verts[1].TextureCoordinate = new Vector2(0, .75f); * verts[2].TextureCoordinate = new Vector2(1, .5f); * * List<VertexPositionColorTexture> colors = new List<VertexPositionColorTexture>(); * * List<short> indices = new List<short>(); * Vector2 prevSpot = _orbSpots[_orbSpots.Length - 1]; * * foreach (Vector2 orbSpot in _orbSpots) * { * VertexPositionColorTexture pos = new VertexPositionColorTexture(); * pos.Position = new Vector3(orbSpot, 0); * pos.Color = new Color(255, 255, 255); * pos.TextureCoordinate = verts[2].TextureCoordinate; * * colors.Add(pos); * } * * for (int ind = 0; ind < _orbSpots.Length; ++ind) * { * Vector2 vec = _orbSpots[ind]; * * int orthogInd = (ind + 1) % _orbSpots.Length; * Vector2 orthog = _orbSpots[orthogInd]; * * for (int i = 1; i < 16; ++i) * { * VertexPositionColorTexture pos = new VertexPositionColorTexture(); * pos.Position = new Vector3(vec + i * (prevSpot - vec) / 16, 0); * pos.Color = new Color(255 - 0, 255 - 0, 255 - 0); * pos.TextureCoordinate = verts[i%2].TextureCoordinate; * * colors.Add(pos); * if (i % 3 == 0) * { * indices.Add((short)orthogInd); * indices.Add((short)(colors.Count - 1)); * indices.Add((short)(colors.Count - 2)); * } * } * * prevSpot = vec; * } * * * foreach (EffectPass pass in baseEffect.CurrentTechnique.Passes) * { * pass.Apply(); * GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionColorTexture>(PrimitiveType.TriangleList, colors.ToArray(), 0, colors.Count, indices.ToArray(), 0, indices.Count / 3); * //GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleList, verts, 0, 1); * } * this._spriteBatch.End(); * * this._spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend); * //this._spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.LinearWrap, null, null); * * // * * * prevSpot = _orbSpots[_orbSpots.Length - 1]; * foreach (Vector2 orbSpot in _orbSpots) * { * double rotationAngle = Math.Atan2(prevSpot.Y - orbSpot.Y, prevSpot.X - orbSpot.X); * double distance = Math.Sqrt(Math.Pow(prevSpot.Y - orbSpot.Y, 2) + Math.Pow(prevSpot.X - orbSpot.X, 2)); * this._spriteBatch.Draw(_captureBar, new Rectangle((int)orbSpot.X, (int)orbSpot.Y, (int)distance, _captureBar.Height), null, Color.White, (float)rotationAngle, new Vector2(0, _captureBar.Height / 2), SpriteEffects.None, 0); * * prevSpot = orbSpot; * } * * Vector2 orbSize = new Vector2(_captureOrb.Width, _captureOrb.Height); * foreach (Vector2 orbSpot in _orbSpots) * { * this._spriteBatch.Draw(_captureOrb, orbSpot - orbSize / 2, Color.White); * } * * this._spriteBatch.End(); * return; */ GraphicsDevice.Clear(Color.Black); this._spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend); _activeStage.Draw(gameTime); base.Draw(gameTime); if (_isTransitioning) { this._spriteBatch.Draw(this._pixel, new Rectangle(0, 0, 800, 480), new Color(0, 0, 0, _transitionOpacity)); } if (Settings.Instance.ArrowsEnabled) { // calculate the rotation angle TouchCollection touchCollection = TouchPanel.GetState(); foreach (TouchLocation touchLocation in touchCollection) { if (touchLocation.State == TouchLocationState.Pressed || touchLocation.State == TouchLocationState.Moved) { double angle = Math.Atan2(touchLocation.Position.Y - 240, touchLocation.Position.X - 400); this._spriteBatch.Draw(this._arrow, new Vector2(touchLocation.Position.X, touchLocation.Position.Y), null, new Color(255, 255, 255, 180), (float)angle, new Vector2(_arrow.Width, _arrow.Height / 2), 2.0f, SpriteEffects.None, 0); } } } this._spriteBatch.End(); return; }
/// <summary> /// Reads the latest state of the keyboard and gamepad. /// </summary> public void Update() { LastGamePadStates = CurrentGamePadStates; CurrentGamePadStates = GamePad.GetState(PlayerIndex.One); TouchStates = TouchPanel.GetState(); }
void CheckTapInput(GameTime gameTime) { // jump on two finger tap touches = TouchPanel.GetState(); // reduce speed if no input has been given in a while timeSinceLastHit += gameTime.ElapsedGameTime.Milliseconds; if (timeSinceLastHit > currentTolerance) { currentRunningSpeed--; timeSinceLastHit = 0f; } if (!player.IsGrounded) { previousDrumSide = DrumSide.side.NONE; return; } if (touches.Count == 1 && touches[0].State == TouchLocationState.Pressed) { if (CheckDrumHit(touches, leftDrum) && (previousDrumSide != DrumSide.side.LEFT || previousDrumSide == DrumSide.side.NONE)) { bongo1.Play(); //if (CheckDrumTiming(leftDrum, gameTime)) //{ // successCounter++; // if (successCounter % 10 == 0) // { // currentTempo += 1; // successCounter = 0; // } // dino.physics.Velocity -= Vector2.UnitX * 0.1f; // previousDrumSide = leftDrum.drumSide; // //player.physics.AddForce(Vector2.UnitX * 2000); //} //else //{ // dino.physics.Velocity += Vector2.UnitX * 0.08f; //} timeSinceLastHit = 0f; currentRunningSpeed++; previousDrumSide = leftDrum.drumSide; dino.transform.Position -= Vector2.UnitX * Math.Max(1, maxRunningSpeed / (currentRunningSpeed)); } else if (CheckDrumHit(touches, rightDrum) && (previousDrumSide != DrumSide.side.RIGHT || previousDrumSide == DrumSide.side.NONE)) { bongo2.Play(); //if (CheckDrumTiming(rightDrum, gameTime)) //{ // successCounter++; // if(successCounter % 10 == 0) // { // currentTempo += 2; // successCounter = 0; // } // dino.physics.Velocity -= Vector2.UnitX * 0.1f; // previousDrumSide = rightDrum.drumSide; // //player.physics.AddForce(Vector2.UnitX * 2000); //} //else //{ // dino.physics.Velocity += Vector2.UnitX * 0.25f; //} timeSinceLastHit = 0f; currentRunningSpeed++; previousDrumSide = rightDrum.drumSide; dino.transform.Position -= Vector2.UnitX * Math.Max(1, maxRunningSpeed / (currentRunningSpeed)); } } else if (touches.Count == 2 && CheckDrumHit(touches, leftDrum, rightDrum) && (touches[0].State == TouchLocationState.Pressed || touches[0].State == TouchLocationState.Moved) && (touches[1].State == TouchLocationState.Pressed || touches[1].State == TouchLocationState.Moved)) { player.Jump(); } // clamp tempo to maxTempo if (currentRunningSpeed > maxRunningSpeed) { currentRunningSpeed = maxRunningSpeed; } }
public override void Update(GameTime Time, FlyingDisc FlyingDisc) { base.Update(Time, FlyingDisc); HandPosition = Position + new Vector2(45, 55); if (Vector2.Distance(HandPosition, FlyingDisc.Position) < 100) { if (!FlyingDiscExiting) { HasFlyingDisc = true; } } else { FlyingDiscExiting = false; } foreach (TouchLocation Touch in Input.Touches) { if (Touch.State == TouchLocationState.Moved || Touch.State == TouchLocationState.Pressed) { if (Touch.Position.X < Graphics.Width / 2) { this.Force = base.Grounded ? new Vector2(-50, 0) : new Vector2(-25, 0); base.Direction = SpriteEffects.FlipHorizontally; } else { this.Force = base.Grounded ? new Vector2(50, 0) : new Vector2(25, 0); base.Direction = SpriteEffects.None; } } } if (HasFlyingDisc) { while (TouchPanel.IsGestureAvailable) { GestureSample sample = TouchPanel.ReadGesture(); if (sample.GestureType == GestureType.Flick) { if (sample.Delta.Length() > 3) { double Rotation = Math.Atan2(sample.Delta.Y, sample.Delta.X); if (Rotation > 0 && Rotation < MathHelper.PiOver2) { ///fixxxxxxx Throw(FlyingDisc, sample); } } } } } if (HasFlyingDisc) { FlyingDisc.Position = HandPosition - FlyingDisc.Origin; } }
private void HandleInput() { // get all of our input states keyboardState = Keyboard.GetState(); gamePadState = GamePad.GetState(PlayerIndex.One); touchState = TouchPanel.GetState(); accelerometerState = Accelerometer.GetState(); //Pause game when p is pressed if (keyboardState.IsKeyDown(Keys.P) && state == Gamestate.Game) { state = Gamestate.Pause; } //Reset Level if paused and r is pressed if (keyboardState.IsKeyDown(Keys.R) && state == Gamestate.Pause) { ReloadCurrentLevel(); state = Gamestate.Game; } //Resume Game upon Enter if (keyboardState.IsKeyDown(Keys.Space) && state != Gamestate.Game) { state = Gamestate.Game; } // Exit the game when back is pressed. if (gamePadState.Buttons.Back == ButtonState.Pressed) { Exit(); } bool continuePressed = keyboardState.IsKeyDown(Keys.Space) || gamePadState.IsButtonDown(Buttons.A) || touchState.AnyTouch(); // Perform the appropriate action to advance the game and // to get the player back to playing. if (!wasContinuePressed && continuePressed) { if (!level.Player.IsAlive) { level.StartNewLife(); ReloadCurrentLevel(); } else if (level.TimeRemaining == TimeSpan.Zero) { if (level.ReachedExit) { LoadNextLevel(); } else { ReloadCurrentLevel(); } } } wasContinuePressed = continuePressed; }
private void ProcessTouch() { if (m_pDelegate != null) { newTouches.Clear(); movedTouches.Clear(); endedTouches.Clear(); CCRect viewPort = CCDrawManager.ViewPortRect; CCPoint pos; // TODO: allow configuration to treat the game pad as a touch device. #if WINDOWS || WINDOWSGL || MACOS _prevMouseState = _lastMouseState; _lastMouseState = Mouse.GetState(); if (_prevMouseState.LeftButton == ButtonState.Released && _lastMouseState.LeftButton == ButtonState.Pressed) { #if NETFX_CORE pos = TransformPoint(_lastMouseState.X, _lastMouseState.Y); pos = CCDrawManager.ScreenToWorld(pos.X, pos.Y); #else pos = CCDrawManager.ScreenToWorld(_lastMouseState.X, _lastMouseState.Y); #endif _lastMouseId++; m_pTouches.AddLast(new CCTouch(_lastMouseId, pos.X, pos.Y)); m_pTouchMap.Add(_lastMouseId, m_pTouches.Last); newTouches.Add(m_pTouches.Last.Value); m_bCaptured = true; } else if (_prevMouseState.LeftButton == ButtonState.Pressed && _lastMouseState.LeftButton == ButtonState.Pressed) { if (m_pTouchMap.ContainsKey(_lastMouseId)) { if (_prevMouseState.X != _lastMouseState.X || _prevMouseState.Y != _lastMouseState.Y) { #if NETFX_CORE pos = TransformPoint(_lastMouseState.X, _lastMouseState.Y); pos = CCDrawManager.ScreenToWorld(pos.X, pos.Y); #else pos = CCDrawManager.ScreenToWorld(_lastMouseState.X, _lastMouseState.Y); #endif movedTouches.Add(m_pTouchMap[_lastMouseId].Value); m_pTouchMap[_lastMouseId].Value.SetTouchInfo(_lastMouseId, pos.X, pos.Y); } } } else if (_prevMouseState.LeftButton == ButtonState.Pressed && _lastMouseState.LeftButton == ButtonState.Released) { if (m_pTouchMap.ContainsKey(_lastMouseId)) { endedTouches.Add(m_pTouchMap[_lastMouseId].Value); m_pTouches.Remove(m_pTouchMap[_lastMouseId]); m_pTouchMap.Remove(_lastMouseId); } } #endif TouchCollection touchCollection = TouchPanel.GetState(); foreach (TouchLocation touch in touchCollection) { switch (touch.State) { case TouchLocationState.Pressed: if (m_pTouchMap.ContainsKey(touch.Id)) { break; } if (viewPort.ContainsPoint(touch.Position.X, touch.Position.Y)) { pos = CCDrawManager.ScreenToWorld(touch.Position.X, touch.Position.Y); m_pTouches.AddLast(new CCTouch(touch.Id, pos.X, pos.Y)); m_pTouchMap.Add(touch.Id, m_pTouches.Last); newTouches.Add(m_pTouches.Last.Value); } break; case TouchLocationState.Moved: LinkedListNode <CCTouch> existingTouch; if (m_pTouchMap.TryGetValue(touch.Id, out existingTouch)) { pos = CCDrawManager.ScreenToWorld(touch.Position.X, touch.Position.Y); var delta = existingTouch.Value.LocationInView - pos; if (delta.LengthSQ > 1.0f) { movedTouches.Add(existingTouch.Value); existingTouch.Value.SetTouchInfo(touch.Id, pos.X, pos.Y); } } break; case TouchLocationState.Released: if (m_pTouchMap.TryGetValue(touch.Id, out existingTouch)) { endedTouches.Add(existingTouch.Value); m_pTouches.Remove(existingTouch); m_pTouchMap.Remove(touch.Id); } break; default: throw new ArgumentOutOfRangeException(); } } if (newTouches.Count > 0) { m_pDelegate.TouchesBegan(newTouches); } if (movedTouches.Count > 0) { m_pDelegate.TouchesMoved(movedTouches); } if (endedTouches.Count > 0) { m_pDelegate.TouchesEnded(endedTouches); } } }
public override void Update(GameTime gametime) { #if ANDROID CurrentTouchState = TouchPanel.GetState(); if (CurrentTouchState.Count == 1) { PreviousGesturePosition = CurrentGesturePosition; CurrentGesturePosition = CurrentTouchState[0].Position; } while (TouchPanel.IsGestureAvailable) { GestureSample gesture = TouchPanel.ReadGesture(); switch (gesture.GestureType) { case GestureType.None: clearColor = Color.CornflowerBlue; break; case GestureType.DoubleTap: clearColor = clearColor == Color.CornflowerBlue ? Color.Red : Color.CornflowerBlue; break; case GestureType.Tap: clearColor = clearColor == Color.CornflowerBlue ? Color.Black : Color.CornflowerBlue; break; case GestureType.Flick: clearColor = clearColor == Color.CornflowerBlue ? Color.Pink : Color.CornflowerBlue; break; case GestureType.HorizontalDrag: clearColor = clearColor == Color.CornflowerBlue ? Color.Peru : Color.CornflowerBlue; break; case GestureType.VerticalDrag: clearColor = clearColor == Color.CornflowerBlue ? Color.Wheat : Color.CornflowerBlue; break; } currentGestureType = gesture.GestureType; } #endif #if WINDOWS PreviousPadState = currentPadState; previousKeyState = currentKeyState; currentPadState = GamePad.GetState(PlayerIndex.One); currentKeyState = Keyboard.GetState(); previousMouseState = currentMouseState; currentMousePos = new Vector2(Mouse.GetState().X, Mouse.GetState().Y); currentMouseState = Mouse.GetState(); KeysPressedInLastFrame.Clear(); CheckForTextInput(); UpdateControls(); thumbStick = ApplyDeadZone(currentPadState.ThumbSticks); UpdateRumble((float)gametime.ElapsedGameTime.TotalSeconds); #endif base.Update(gametime); }
public void Release(TouchPanel panel) { this.IsTouched = false; this.animator.SetBool("Touched", this.IsTouched); this.StopBoostEffect(); }
void ProcessTouch(CCWindow window) { if (window.EventDispatcher.IsEventListenersFor(CCEventListenerTouchOneByOne.LISTENER_ID) || window.EventDispatcher.IsEventListenersFor(CCEventListenerTouchAllAtOnce.LISTENER_ID)) { newTouches.Clear(); movedTouches.Clear(); endedTouches.Clear(); CCPoint pos = CCPoint.Zero; // TODO: allow configuration to treat the game pad as a touch device. #if WINDOWS || WINDOWSGL || MACOS pos = new CCPoint(lastMouseState.X, lastMouseState.Y); prevMouseState = lastMouseState; lastMouseState = Mouse.GetState(); if (prevMouseState.LeftButton == ButtonState.Released && lastMouseState.LeftButton == ButtonState.Pressed) { lastMouseId++; touches.AddLast(new CCTouch(lastMouseId, pos.X, pos.Y)); touchMap.Add(lastMouseId, touches.Last); newTouches.Add(touches.Last.Value); } else if (prevMouseState.LeftButton == ButtonState.Pressed && lastMouseState.LeftButton == ButtonState.Pressed) { if (touchMap.ContainsKey(lastMouseId)) { if (prevMouseState.X != lastMouseState.X || prevMouseState.Y != lastMouseState.Y) { movedTouches.Add(touchMap[lastMouseId].Value); touchMap[lastMouseId].Value.SetTouchInfo(lastMouseId, pos.X, pos.Y); } } } else if (prevMouseState.LeftButton == ButtonState.Pressed && lastMouseState.LeftButton == ButtonState.Released) { if (touchMap.ContainsKey(lastMouseId)) { endedTouches.Add(touchMap[lastMouseId].Value); touches.Remove(touchMap[lastMouseId]); touchMap.Remove(lastMouseId); } } #endif TouchCollection touchCollection = TouchPanel.GetState(); foreach (TouchLocation touch in touchCollection) { switch (touch.State) { case TouchLocationState.Pressed: if (touchMap.ContainsKey(touch.Id)) { break; } pos = new CCPoint(touch.Position.X, touch.Position.Y); touches.AddLast(new CCTouch(touch.Id, pos.X, pos.Y)); touchMap.Add(touch.Id, touches.Last); newTouches.Add(touches.Last.Value); break; case TouchLocationState.Moved: LinkedListNode <CCTouch> existingTouch; if (touchMap.TryGetValue(touch.Id, out existingTouch)) { pos = new CCPoint(touch.Position.X, touch.Position.Y); var delta = existingTouch.Value.LocationOnScreen - pos; if (delta.LengthSquared > 1.0f) { movedTouches.Add(existingTouch.Value); existingTouch.Value.SetTouchInfo(touch.Id, pos.X, pos.Y); } } break; case TouchLocationState.Released: if (touchMap.TryGetValue(touch.Id, out existingTouch)) { endedTouches.Add(existingTouch.Value); touches.Remove(existingTouch); touchMap.Remove(touch.Id); } break; default: throw new ArgumentOutOfRangeException(); } } var touchEvent = new CCEventTouch(CCEventCode.BEGAN); if (newTouches.Count > 0) { touchEvent.Touches = newTouches; //m_pDelegate.TouchesBegan(newTouches); window.EventDispatcher.DispatchEvent(touchEvent); } if (movedTouches.Count > 0) { touchEvent.EventCode = CCEventCode.MOVED; touchEvent.Touches = movedTouches; window.EventDispatcher.DispatchEvent(touchEvent); } if (endedTouches.Count > 0) { touchEvent.EventCode = CCEventCode.ENDED; touchEvent.Touches = endedTouches; window.EventDispatcher.DispatchEvent(touchEvent); } } }
public void Clicked(TouchPanel panel) { // No action. }
protected override void Update(GameTime gameTime) { ks = Keyboard.GetState(); touch = TouchPanel.GetState(); if (touch.Count > 0 && touch[0].State == TouchLocationState.Moved) { spriteSpeed = touch[0].Position - sprite.Position; spriteSpeed.X /= 12; spriteSpeed.Y /= 12; sprite.Speed = spriteSpeed; sprite.Update(gameTime); elapsedTime += gameTime.ElapsedGameTime; if (elapsedTime >= generateSpriteTime && spriteSpeed.Length() > 0.005f) { particles.Add(new ParticleSprite(Content.Load <Texture2D>("WhitePixel"), sprite.Position, sprite.Color, spriteSpeed, 15, 40, TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(2000))); elapsedTime = new TimeSpan(); } } for (int i = 0; i < particles.Count; i++) { particles[i].Update(gameTime); if (particles[i].Dead) { particles.Remove(particles[i]); i--; } } sprite.Rotation += .025f; sprite.Scale = new Vector2(sprite.Scale.X + spriteGrowSpeed, sprite.Scale.Y + spriteGrowSpeed); if (sprite.Scale.X >= 310 * GraphicsDevice.Viewport.Height / 1440f || sprite.Scale.X <= 100 * GraphicsDevice.Viewport.Height / 1440f) { spriteGrowSpeed = -spriteGrowSpeed; } if (sprite.Color.R < 255 && sprite.Color.G == 0 && sprite.Color.B == 0) { sprite.Color = new Color(sprite.Color.R + rColorChange, sprite.Color.G, sprite.Color.B); } else if (sprite.Color.R == 255 && sprite.Color.G < 255 && sprite.Color.B == 0) { sprite.Color = new Color(sprite.Color.R, sprite.Color.G + gColorChange, sprite.Color.B); } else if (sprite.Color.R == 255 && sprite.Color.G == 255 && sprite.Color.B < 255) { sprite.Color = new Color(sprite.Color.R, sprite.Color.G, sprite.Color.B + bColorChange); } else if (sprite.Color.R > 0 && sprite.Color.G == 255 && sprite.Color.B == 255) { sprite.Color = new Color(sprite.Color.R - rColorChange, sprite.Color.G, sprite.Color.B); } else if (sprite.Color.R == 0 && sprite.Color.G > 0 && sprite.Color.B == 255) { sprite.Color = new Color(sprite.Color.R, sprite.Color.G - gColorChange, sprite.Color.B); } else if (sprite.Color.R == 0 && sprite.Color.G == 0 && sprite.Color.B > 0) { sprite.Color = new Color(sprite.Color.R, sprite.Color.G, sprite.Color.B - bColorChange); } base.Update(gameTime); }
private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(TouchControl)); this._rightClickButton = new ImageButton(); this._leftClickButton = new ImageButton(); this._touchPanel = new TouchPanel(); this.SuspendLayout(); // // _rightClickButton // this._rightClickButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this._rightClickButton.DownImage = ((System.Drawing.Bitmap)(resources.GetObject("_rightClickButton.DownImage"))); this._rightClickButton.Image = ((System.Drawing.Bitmap)(resources.GetObject("_rightClickButton.Image"))); this._rightClickButton.Location = new System.Drawing.Point(241, 465); this._rightClickButton.Name = "_rightClickButton"; this._rightClickButton.SelectedImage = ((System.Drawing.Bitmap)(resources.GetObject("_rightClickButton.SelectedImage"))); this._rightClickButton.Size = new System.Drawing.Size(239, 95); this._rightClickButton.TabIndex = 1; this._rightClickButton.ButtonUp += new System.EventHandler(this._rightClickButton_ButtonUp); this._rightClickButton.ButtonClick += new System.EventHandler(this._rightClickButton_ButtonClick); this._rightClickButton.ButtonDoubleClick += new EventHandler(this._rightClickButton_ButtonDoubleClick); this._rightClickButton.ButtonHold += new System.EventHandler(this._rightClickButton_ButtonHold); // // _leftClickButton // this._leftClickButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this._leftClickButton.DownImage = ((System.Drawing.Bitmap)(resources.GetObject("_leftClickButton.DownImage"))); this._leftClickButton.Image = ((System.Drawing.Bitmap)(resources.GetObject("_leftClickButton.Image"))); this._leftClickButton.Location = new System.Drawing.Point(0, 465); this._leftClickButton.Name = "_leftClickButton"; this._leftClickButton.SelectedImage = ((System.Drawing.Bitmap)(resources.GetObject("_leftClickButton.SelectedImage"))); this._leftClickButton.Size = new System.Drawing.Size(239, 95); this._leftClickButton.TabIndex = 0; this._leftClickButton.ButtonUp += new System.EventHandler(this._rightClickButton_ButtonUp); this._leftClickButton.ButtonClick += new System.EventHandler(this._rightClickButton_ButtonClick); this._leftClickButton.ButtonDoubleClick += new EventHandler(this._rightClickButton_ButtonDoubleClick); this._leftClickButton.ButtonHold += new System.EventHandler(this._rightClickButton_ButtonHold); // // _touchPanel // this._touchPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this._touchPanel.Location = new System.Drawing.Point(0, 0); this._touchPanel.Name = "_touchPanel"; this._touchPanel.Size = new System.Drawing.Size(480, 465); this._touchPanel.TabIndex = 2; this._touchPanel.MouseDelta += new System.EventHandler<TouchPanelEventArgs>(this._touchPanel_MouseDelta); this._touchPanel.ButtonClick += new EventHandler(_rightClickButton_ButtonClick); this._touchPanel.ButtonDoubleClick += new EventHandler(_touchPanel_ButtonDoubleClick); // // TouchControl // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; this.Controls.Add(this._rightClickButton); this.Controls.Add(this._leftClickButton); this.Controls.Add(this._touchPanel); this.Name = "TouchControl"; this.Size = new System.Drawing.Size(480, 560); this.ResumeLayout(false); }
static InputManager() { panel = TouchPanel.GetState(); }