예제 #1
0
파일: Game.cs 프로젝트: Devonlg98/IntroToC-
        public void Update()
        {
            tankBulletObject1.Set(turretObject1);

            tank1.MyTankPoints[0] = new Vector2(tankHitBoxTL1.Position.x, tankHitBoxTL1.Position.y);
            tank1.MyTankPoints[1] = new Vector2(tankHitBoxTR1.Position.x, tankHitBoxTR1.Position.y);
            tank1.MyTankPoints[2] = new Vector2(tankHitBoxBR1.Position.x, tankHitBoxBR1.Position.y);
            tank1.MyTankPoints[3] = new Vector2(tankHitBoxBL1.Position.x, tankHitBoxBL1.Position.y);

            tankBullet1.MyTankPoints[0] = new Vector2(tankBulletHitBoxTL1.Position.x, tankBulletHitBoxTL1.Position.y);
            tankBullet1.MyTankPoints[1] = new Vector2(tankBulletHitBoxTR1.Position.x, tankBulletHitBoxTR1.Position.y);
            tankBullet1.MyTankPoints[2] = new Vector2(tankBulletHitBoxBR1.Position.x, tankBulletHitBoxBR1.Position.y);
            tankBullet1.MyTankPoints[3] = new Vector2(tankBulletHitBoxBL1.Position.x, tankBulletHitBoxBL1.Position.y);

            tank2.MyTankPoints[0] = new Vector2(tankHitBoxTL2.Position.x, tankHitBoxTL2.Position.y);
            tank2.MyTankPoints[1] = new Vector2(tankHitBoxTR2.Position.x, tankHitBoxTR2.Position.y);
            tank2.MyTankPoints[2] = new Vector2(tankHitBoxBR2.Position.x, tankHitBoxBR2.Position.y);
            tank2.MyTankPoints[3] = new Vector2(tankHitBoxBL2.Position.x, tankHitBoxBL2.Position.y);



            deltaTime = gameTime.GetDeltaTime();
            timer    += deltaTime;
            if (timer >= 1)
            {
                fps    = frames;
                frames = 0;
                timer -= 1;
            }
            frames++;

            if (IsKeyPressed(KeyboardKey.KEY_SPACE))
            {
                tankBulletFired1 = true;
                tankBulletObject1.Rotate(-deltaTime);

                bulletCoolDown1 -= deltaTime;
                do
                {
                    Vector3 facing = new Vector3(
                        tankObject1.LocalTransform.m1,
                        tankObject1.LocalTransform.m2, 1) * deltaTime * 100;
                    tankObject1.Translate(facing.x, facing.y);
                } while (bulletCoolDown1 > deltaTime);
            }
            if (deltaTime > bulletCoolDown1)
            {
                tankBulletFired1 = false;
            }
            //Player 1 movement
            if (IsKeyDown(KeyboardKey.KEY_A))
            {
                tankObject1.Rotate(-deltaTime);
            }
            if (IsKeyDown(KeyboardKey.KEY_D))
            {
                tankObject1.Rotate(deltaTime);
            }
            if (IsKeyDown(KeyboardKey.KEY_W))
            {
                Vector3 facing = new Vector3(
                    tankObject1.LocalTransform.m1,
                    tankObject1.LocalTransform.m2, 1) * deltaTime * 100;
                tankObject1.Translate(facing.x, facing.y);
            }
            if (IsKeyDown(KeyboardKey.KEY_S))
            {
                Vector3 facing = new Vector3(
                    tankObject1.LocalTransform.m1,
                    tankObject1.LocalTransform.m2, 1) * deltaTime * -100;
                tankObject1.Translate(facing.x, facing.y);
            }
            tankObject1.Update(deltaTime);

            if (IsKeyDown(KeyboardKey.KEY_Q))
            {
                turretObject1.Rotate(-deltaTime);
            }
            if (IsKeyDown(KeyboardKey.KEY_E))
            {
                turretObject1.Rotate(deltaTime);
            }

            //Player 2 movement

            if (IsKeyDown(KeyboardKey.KEY_KP_4))
            {
                tankObject2.Rotate(-deltaTime);
            }
            if (IsKeyDown(KeyboardKey.KEY_KP_6))
            {
                tankObject2.Rotate(deltaTime);
            }
            if (IsKeyDown(KeyboardKey.KEY_KP_8))
            {
                Vector3 facing = new Vector3(
                    tankObject2.LocalTransform.m1,
                    tankObject2.LocalTransform.m2, 1) * deltaTime * 100;
                tankObject2.Translate(facing.x, facing.y);
            }
            if (IsKeyDown(KeyboardKey.KEY_KP_5))
            {
                Vector3 facing = new Vector3(
                    tankObject2.LocalTransform.m1,
                    tankObject2.LocalTransform.m2, 1) * deltaTime * -100;
                tankObject2.Translate(facing.x, facing.y);
            }
            tankObject2.Update(deltaTime);

            if (IsKeyDown(KeyboardKey.KEY_KP_7))
            {
                turretObject2.Rotate(-deltaTime);
            }
            if (IsKeyDown(KeyboardKey.KEY_KP_9))
            {
                turretObject2.Rotate(deltaTime);
            }
        }