Beispiel #1
0
 public void SetControls(rl.KeyboardKey f, rl.KeyboardKey b, rl.KeyboardKey l, rl.KeyboardKey r, rl.KeyboardKey tl, rl.KeyboardKey tr, rl.KeyboardKey sh)
 {
     forward     = f;
     back        = b;
     left        = l;
     right       = r;
     turretLeft  = tl;
     turretRight = tr;
     shoot       = sh;
 }
Beispiel #2
0
 //player collisions with aabb boxes
 public void PlayerCollision(AABB whichPlayerCollider, AABB collidingWith, rl.KeyboardKey forwardKey, rl.KeyboardKey backwardsKey, SceneObject whichTankObj)
 {
     if (whichPlayerCollider.Overlaps(collidingWith) && (rl.Raylib.IsKeyDown(forwardKey)))
     {
         MoveBackwards(whichTankObj);
     }
     else if (whichPlayerCollider.Overlaps(collidingWith) && (rl.Raylib.IsKeyDown(backwardsKey)))
     {
         MoveForward(whichTankObj);
     }
 }
Beispiel #3
0
        /// <param name="bulletPath">File path from \Images\ to the image used for this turret's bullets</param>
        public TurretClass(GameObject parent, rl.Image image, float rotSpeed, string bulletPath, rl.KeyboardKey[] controls) : base(parent, image)
        {
            this.rotSpeed  = rotSpeed;
            this.bulletImg = rl.Raylib.LoadImage(GameManager.imageDir + bulletPath);

            //Set origin to be at the base of the image
            float x = image.width / 2f;
            float y = image.height * 0.9f;

            origin = new rl.Vector2(x, y);

            left  = controls[0];
            right = controls[1];
            shoot = controls[2];
        }
Beispiel #4
0
        //player movements / shoot
        public void TankMovement(SceneObject whichTank, SceneObject whichTurret, rl.KeyboardKey left, rl.KeyboardKey right, rl.KeyboardKey forward,
                                 rl.KeyboardKey reverse, rl.KeyboardKey turretLeft, rl.KeyboardKey turretRight, rl.KeyboardKey shoot, List <Projectile> whichList, ref float WhichPlayersShootTimer)
        {
            //rotate player left on A pressed
            if (rl.Raylib.IsKeyDown(left))
            {
                whichTank.RotateZ(-deltaTime * 5);
            }
            //rotate player right on D pressed
            if (rl.Raylib.IsKeyDown(right))
            {
                whichTank.RotateZ(deltaTime * 5);
            }

            //move player forward on W pressed
            if (rl.Raylib.IsKeyDown(forward))
            {
                MoveForward(whichTank);
            }
            //move player backwards on S pressed
            if (rl.Raylib.IsKeyDown(reverse))
            {
                MoveBackwards(whichTank);
            }
            //rotate turret top left on Q pressed
            if (rl.Raylib.IsKeyDown(turretLeft))
            {
                whichTurret.RotateZ(-deltaTime * 2);
            }
            //rotate turret top right on E pressed
            if (rl.Raylib.IsKeyDown(turretRight))
            {
                whichTurret.RotateZ(deltaTime * 2);
            }
            //updates tank in delta time
            whichTank.Update(deltaTime);

            //shoots bullet when SPACE pressed and timer is >= 1 seconds
            if (rl.Raylib.IsKeyPressed(shoot) && WhichPlayersShootTimer >= shootCoolDown)
            {
                WhichPlayersShootTimer = 0;
                Projectile newBullet = new Projectile(whichTurret.globalTransform.m5, -whichTurret.globalTransform.m4);
                newBullet.SetPosition(whichTurret.globalTransform.m7, whichTurret.globalTransform.m8);
                //adds bullet to list
                whichList.Add(newBullet);
            }
        }
Beispiel #5
0
        public TankClass(GameObject parent, rl.Image image, float maxSpeed, float acceleration, float rotSpeed, string name, rl.KeyboardKey[] controls) : base(parent, image)
        {
            tag               = "Tank";
            this.maxSpeed     = maxSpeed;
            this.acceleration = acceleration;
            this.rotSpeed     = rotSpeed;
            this.name         = name;

            //Set OBB half extents
            collider.m1 = imgSize.x / 2;
            collider.m5 = imgSize.y / 2;

            up    = controls[0];
            down  = controls[1];
            left  = controls[2];
            right = controls[3];
        }