Exemple #1
0
 public void Init()
 {
     //Initilizes(sets its position and rotation in center of the screen) the tank and all of its sprites.
     stopwatch.Start();
     lastTime = stopwatch.ElapsedMilliseconds;
     tankSprite.Load("resources/tankBody_green.png");
     // sprite is facing the wrong way... fix that here
     tankSprite.SetRotate(-90 * (float)(Math.PI / 180.0f));
     // sets an offset for the base, so it rotates around the centre
     tankSprite.SetPosition(-tankSprite.Width / 2.0f, tankSprite.Height /
                            2.0f);
     turretSprite.Load(Turrets[0]);
     turretSprite.SetRotate(-90 * (float)(Math.PI / 180.0f));
     // set the turret offset from the tank base
     // set up the scene object hierarchy - parent the turret to the base,
     // then the base to the tank sceneObject
     turretObject.AddChild(turretSprite);
     tankObject.AddChild(tankSprite);
     tankObject.AddChild(turretObject);
     tankObject.AddChild(tankAABB);
     tankObject.AddChild(tankAABB2);
     tankAABB.SetPosition((tankSprite.Width / 2) - 5, tankSprite.Height / 2);
     tankAABB2.SetPosition((-tankSprite.Width / 2), (-tankSprite.Height / 2) - 5);
     turretObject.SetPosition(-10, -2);
     turretSprite.SetPosition(-10, turretSprite.Width / 2.3f);
     turretObject.AddChild(BulletSpawn);
     turretObject.AddChild(BulletSpawn2);
     // having an empty object for the tank parent means we can set the
     // position/rotation of the tank withoutl
     // affecting the offset of the base sprite
     tankObject.SetPosition(GetScreenWidth() / 2.0f, GetScreenHeight() / 2.0f);
     bulletText      = LoadTextureFromImage(LoadImage("resources/bulletDark1.png"));
     AmmoPack        = LoadTextureFromImage(LoadImage("resources/AmmoPack.png"));
     BulletExplosion = LoadTextureFromImage(LoadImage("resources/explosion2.png"));
     TargetText      = LoadTextureFromImage(LoadImage("resources/Target.png"));
     //Messing with camera. (Didn't figure out how to use it and I didnt have time to spare to actually do any research into how to use it.)
     camera.target = new Vector2(tankObject.GlobalTransform.x3 + 20, tankObject.GlobalTransform.y3 + 20);
     camera.offset = new Vector2(GetScreenWidth() / 2, GetScreenHeight() / 2);
     camera.zoom   = 10000f;
 }
Exemple #2
0
        //init happening when game first opens
        public void Init()
        {
            stopwatch.Start();
            lastTime = stopwatch.ElapsedMilliseconds;



            //blade object init positions and adding sprite as child to obj
            bladeSprite.Load("../../Images/blade.png");
            bladeSprite.SetRotateZ(-90 * (float)(Math.PI / 180.0f));
            bladeSprite.SetPosition(-bladeSprite.Width / 2.0f, bladeSprite.Height / 2.0f);
            bladeObject.AddChild(bladeSprite);
            bladeObject.SetPosition(1800, 450);

            //left side target init positions
            targetSprite1.Load("../../Images/target.png");
            targetSprite1.SetRotateZ(-90 * (float)(Math.PI / 180.0f));
            targetSprite1.SetPosition(-targetSprite1.Width / 2.0f, targetSprite1.Height / 2.0f);
            targetObject1.AddChild(targetSprite1);
            targetObject1.SetPosition(100, 700);
            targetObject1.RotateZ(-90 * (float)(Math.PI / 180.0f));

            //right side target init positions
            targetSprite2.Load("../../Images/target.png");
            targetSprite2.SetRotateZ(-90 * (float)(Math.PI / 180.0f));
            targetSprite2.SetPosition(-targetSprite2.Width / 2.0f, targetSprite2.Height / 2.0f);
            targetObject2.AddChild(targetSprite2);
            targetObject2.SetPosition(1300, 700);
            targetObject2.RotateZ(-90 * (float)(Math.PI / 180.0f));

            //middle wall init position
            middleWallSprite.Load("../../Images/dirtMiddleWall.png");
            middleWallObject.AddChild(middleWallSprite);
            middleWallObject.SetPosition(rl.Raylib.GetScreenWidth() / 2.0f, 0);

            //TANK 1
            tankSprite1.Load("../../Images/tankBlue_outline.png");
            tankSprite1.SetRotateZ(-90 * (float)(Math.PI / 180.0f));
            // sets an offset for the base, so it rotates around the centre
            tankSprite1.SetPosition(-tankSprite1.Width / 2.0f, tankSprite1.Height / 2.0f);

            turretSprite1.Load("../../Images/barrelBlue.png");
            turretSprite1.SetRotateZ(-90 * (float)(Math.PI / 180.0f));
            // sets an offset for the base, so it rotates around the centre
            turretSprite1.SetPosition(0, turretSprite1.Width / 2.0f);

            // set up the scene object hierarchy - parent the turret to the base,
            // then the base to the tank sceneObject
            turretObject1.AddChild(turretSprite1);
            tankObject1.AddChild(tankSprite1);
            tankObject1.AddChild(turretObject1);

            // having an empty object for the tank parent means we can set the
            // position/rotation of the tank without
            // affecting the offset of the base sprite
            tankObject1.SetPosition(rl.Raylib.GetScreenWidth() / 3.0f, rl.Raylib.GetScreenHeight() / 2.0f);

            //TANK 2
            tankSprite2.Load("../../Images/tankRed_outline.png");
            tankSprite2.SetRotateZ(-90 * (float)(Math.PI / 180.0f));
            tankSprite2.SetPosition(-tankSprite2.Width / 2.0f, tankSprite2.Height / 2.0f);
            turretSprite2.Load("../../Images/barrelRed.png");
            turretSprite2.SetRotateZ(-90 * (float)(Math.PI / 180.0f));
            turretSprite2.SetPosition(0, turretSprite2.Width / 2.0f);
            tankObject2.RotateZ(-180 * (float)(Math.PI / 180.0f));
            turretObject2.AddChild(turretSprite2);
            tankObject2.AddChild(tankSprite2);
            tankObject2.AddChild(turretObject2);
            tankObject2.SetPosition(1200, rl.Raylib.GetScreenHeight() / 2.0f);
        }