Ejemplo n.º 1
0
        public void Update(Vector2 pos, MouseState mouse, GamePadState gps, GameTime gameTime)
        {
            nave.Update();
            fisica.Update();
            //RESET GAME OR WHAT EVER DEPENDING ON ENERGY LEVELS
            if (nave.energia <= 0)
            {
                Reset();
            }
            else if (fisica.acumEnergy >= 1)
            {
                // Aumentar el nivel actual
                Properties.currentLevel = (Properties.currentLevel + 1) % niveles.defNiveles.Count;
                Reset();//PASA AL SIGUIENTE NIVEL
            }

            //check user Drag Drop Events
            if (mouse.LeftButton == ButtonState.Pressed || gps.Buttons.A == ButtonState.Pressed)
            {
                //CHECK BUTTONS
                int clickedID = getClickedID(new Vector2(pos.X, pos.Y));
                if (clickedID >= 0)
                {
                    switch (clickedID)
                    {
                        case 1:
                            // Ir a pantalla de menu
                            main.stateManager.loadNextScreen(1, 0, gameTime);
                            break;
                        case 2:
                            Reset();
                            break;
                        case 3:
                             main.lastState = 2;
                            main.stateManager.loadNextScreen(5, 0, gameTime);
                            break;
                        default: break;
                    }

                    Console.WriteLine("BUTTON PRESSED: clickedID: " + clickedID);
                    //APACURRO BOTONES
                }
                if (pressedFlag)
                {
                    lastPressedAtractor.setPosicion(new Vector2(pos.X, pos.Y));
                }

                Atractor pressedAtractor = fisica.getAtractorUnderMouse(new Vector2(pos.X, pos.Y));
                if (pressedAtractor != null && !pressedFlag)
                {
                    lastPressedAtractor = pressedAtractor;
                    //USER IS PRESSING PLANET
                    pressedFlag = true;

                }
            }
            else
            {
                pressedFlag = false;
            }
        }
Ejemplo n.º 2
0
        private bool gravitate(Atractor a, Particle p)
        {
            float dx = p.Position.X - a.Posicion.X;
            float dy = p.Position.Y - a.Posicion.Y;
            float distSQ = dx * dx + dy * dy;
            float dist = (float)Math.Sqrt(distSQ);
            float fuerza = a.Mass * p.Mass / distSQ;
            float ax = fuerza * dx / dist;
            float ay = fuerza * dy / dist;
            /*** sólo cambiar velocidad de la particula ***/
            Vector2 vel = p.Velocity;
            vel.X -= ax / p.Mass;
            vel.Y -= ay / p.Mass;
            p.Velocity = vel;

            /*** return true -> la particula choca en el objeto ***/
            if (dist <= a.Radio)
            {
                return true;
            }
            return false;
        }