/// <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); } }
public override void Draw() { DrawSelf(); //BossHealthBar rl.Rectangle BossHealthBack = new rl.Rectangle(8, Program.GameHeight * 0.9f, Program.GameWidth - 16, Program.GameHeight * 0.05f); rl.Rectangle BossHealthFront = BossHealthBack; BossHealthFront.width *= ((float)HP / (float)MaxHp); //Make bar transparent when near bar int Alpha = 255; if (gameScene.player.Position.y > Program.GameHeight * 0.8) { Alpha = 64; } DrawRectangleRec(BossHealthBack, new Color(Color.DARKGRAY.r, Color.DARKGRAY.g, Color.DARKGRAY.b, Alpha)); DrawRectangleRec(BossHealthFront, new Color(Color.RED.r, Color.RED.g, Color.RED.b, Alpha)); DrawRectangleLinesEx(BossHealthBack, 1, new Color(Color.BLACK.r, Color.BLACK.g, Color.BLACK.b, Alpha)); //Cursed, uncomment this and see what happens //rl.Vector2 LineTop = new rl.Vector2(BossHealthFront.x + BossHealthFront.width, BossHealthFront.y); //rl.Vector2 LineBottom = new rl.Vector2(BossHealthFront.x + BossHealthFront.width, BossHealthFront.y + BossHealthFront.height); //DrawLineV(LineTop, LineBottom, Color.WHITE); }
//Draw the bounding box to the screen public override void Draw() { Raylib.Rectangle rec = new Raylib.Rectangle( Left, Top, Width, Height); Raylib.Raylib.DrawRectangleLinesEx(rec, 2, _color); base.Draw(); }
private void Collision() { //Check if its out of bounds if (!CollisionFuncs.PointAABBcolliding(global.point, GameManager.screenBox)) { //Destroy the bullet FreeMemory(); return; } //Go through all core objects and check for collision with tanks foreach (GameObject obj in GameManager.coreObjects) { if (obj.tag != "Tank") { //We only want to collide with tanks continue; } //Cast to tank and get AABB TankClass tank = obj as TankClass; AABB tankAABB = CollisionFuncs.OBBtoAABB(tank.collider); //Check AABB first, then OBB if (CollisionFuncs.PointAABBcolliding(global.point, tankAABB)) { //If they are colliding, check OBB collision if (CollisionFuncs.PointOBBcolliding(global.point, tank.collider)) { tank.Hit(); //Enter 'smoke mode' to display an explosion for a short time before destroying itself hasHit = true; image = rl.Raylib.LoadTexture(GameManager.imageDir + @"Smoke\smokeOrange0.png"); //Update image based values imgSize = new rl.Vector2(image.width, image.height); sourceRec = new rl.Rectangle(0f, 0f, imgSize.x, imgSize.y); origin = imgSize / 2; return; } } } }