예제 #1
0
        /// <summary>
        /// Instantiate the object
        /// </summary>
        /// <param name="parent">The object this is a child of. Pass null if it has no parent</param>
        /// <param name="image">The image this object should be displayed as</param>
        public GameObject(GameObject parent, rl.Image image)
        {
            //Add this to list in game manager
            GameManager.objects.Add(this);
            //Set local and global to 0
            local.point     = new MthLib.Vector3(0, 0, 0);
            local.rotation  = 0f;
            global.point    = new MthLib.Vector3(0, 0, 0);
            global.rotation = 0f;

            //Set image and relevant drawing values
            this.image = rl.Raylib.LoadTextureFromImage(image);
            imgSize    = new rl.Vector2(this.image.width, this.image.height);
            sourceRec  = new rl.Rectangle(0f, 0f, imgSize.x, imgSize.y);

            //Set the origin to the center by default
            origin = imgSize / 2;

            //If the object has a parent, add this object to its children
            if (parent != null)
            {
                hasParent = true;
                parent.children.Add(this);
            }
            else
            {
                hasParent = false;
                //Add this to list of obj with no parent in game manager
                GameManager.coreObjects.Add(this);
            }
        }
예제 #2
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];
        }
예제 #3
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];
        }
예제 #4
0
        private static void StartGame()
        {
            //Create tank object and set its location
            rl.Image   img  = rl.Raylib.LoadImage(imageDir + @"Tanks\tankBlue.png");
            GameObject tank = new TankClass(null, img, 5, 25, 80, "p1", new rl.KeyboardKey[4] {
                rl.KeyboardKey.KEY_W, rl.KeyboardKey.KEY_S, rl.KeyboardKey.KEY_A, rl.KeyboardKey.KEY_D
            });

            rl.Raylib.UnloadImage(img);
            tank.SetLocation(rl.Raylib.GetScreenWidth() * 0.3f, rl.Raylib.GetScreenHeight() * 0.5f);

            //Create turret object as a child of tank
            img = rl.Raylib.LoadImage(imageDir + @"fish_blue.png");
            rl.Raylib.ImageRotateCCW(ref img);
            new TurretClass(tank, img, 100, @"Bullets\bulletBlue.png", new rl.KeyboardKey[3] {
                rl.KeyboardKey.KEY_Q, rl.KeyboardKey.KEY_E, rl.KeyboardKey.KEY_SPACE
            });
            rl.Raylib.UnloadImage(img);


            //Create a second tank with different controls
            img  = rl.Raylib.LoadImage(imageDir + @"Tanks\tankRed.png");
            tank = new TankClass(null, img, 5, 25, 80, "p2", new rl.KeyboardKey[4] {
                rl.KeyboardKey.KEY_I, rl.KeyboardKey.KEY_K, rl.KeyboardKey.KEY_J, rl.KeyboardKey.KEY_L
            });
            rl.Raylib.UnloadImage(img);
            tank.SetLocation(rl.Raylib.GetScreenWidth() * 0.7f, rl.Raylib.GetScreenHeight() * 0.5f);

            img = rl.Raylib.LoadImage(imageDir + @"fish_orange.png");
            rl.Raylib.ImageRotateCCW(ref img);
            new TurretClass(tank, img, 100, @"Bullets\bulletRed.png", new rl.KeyboardKey[3] {
                rl.KeyboardKey.KEY_U, rl.KeyboardKey.KEY_O, rl.KeyboardKey.KEY_N
            });
            rl.Raylib.UnloadImage(img);


            //Display controls
            Console.WriteLine("\n\n");
            Console.WriteLine("Player 1 moves with WASD, aims with QE and fires with SPACE");
            Console.WriteLine("Player 2 moves with IJKL, aims with UO and fires with N");
        }
예제 #5
0
 // Loads the texture
 public void Load(string filename)
 {
     rl.Image img = LoadImage(filename);
     texture = LoadTextureFromImage(img);
 }
예제 #6
0
 public BulletClass(GameObject parent, rl.Image image, float speed, float rotation) : base(parent, image)
 {
     this.speed     = speed;
     local.rotation = rotation;
 }