public void Update(ref Raylib.Vector2 CameraPos) { //DeltaTime lastTime = currentTime; currentTime = stopwatch.ElapsedMilliseconds; cleandeltaTime = (currentTime - lastTime) / 1000.0f; timer += deltaTime; if (timer >= 1) { frames = 0; timer -= 1; } frames++; //ScreenShake if (ScreenShakeTimer > 0) { ScreenShakeTimer -= deltaTime; CameraPos.x = (Rand.Next(-ScreenShakeStrength, ScreenShakeStrength)); CameraPos.y = (Rand.Next(-ScreenShakeStrength, ScreenShakeStrength)); } else // Make sure screens aligned { CameraPos = Raylib.Vector2.Zero; } //Game Running currentRunningScene.Update(); }
/// <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 void PressStartButtonMenuPhase() { //Center Text rl.Vector2 Measure = MeasureTextEx(Program.Romulus, "TNK", 36, 2); DrawTextEx(Program.Romulus, "TNK", new rl.Vector2(Program.GameWidth / 2 - (Measure.x / 2), Program.GameHeight / 3 - (Measure.y / 2)), 36, 2, Color.BLACK); rl.Vector2 Pos = new rl.Vector2(Program.GameWidth / 2, Program.GameHeight / 3 * 2); if (!MenuTran) { DrawRectangleRec(new rl.Rectangle(0, Pos.y - 8, Program.GameWidth, 16), Color.BLACK); if (MenuTimer % 20 > 5) { Measure = MeasureTextEx(Program.Romulus, "Press Space", 12, 1); DrawTextEx(Program.Romulus, "Press Space", new rl.Vector2(Pos.x - (Measure.x / 2), Pos.y - (Measure.y / 2)), 12, 1, Color.WHITE); } } else if (MenuTimer % 5 > 2) { DrawRectangleRec(new rl.Rectangle(0, Pos.y - 8, Program.GameWidth, 16), Color.BLACK); Measure = MeasureTextEx(Program.Romulus, "Press Space", 12, 1); DrawTextEx(Program.Romulus, "Press Space", new rl.Vector2(Pos.x - (Measure.x / 2), Pos.y - (Measure.y / 2)), 12, 1, Color.WHITE); } }
// Called in game every step to render each Entitiy in game public void Draw() { OnDraw?.Invoke(); // Clear the screen. Console.Clear(); RL.ClearBackground(Color.BLACK); // Length = size of the screen. char[,] display = new char[_sizeX, _sizeY]; foreach (Entity e in _entities) { // Position each Entity's icon in the display. int x = (int)e.XAbsolute; int y = (int)e.YAbsolute; if (x >= 0 && x < _sizeX && y >= 0 && y < _sizeY) { display[x, y] = e.Icon; } } // Render the display grid to the screen. for (int i = 0; i < _sizeY; i++) { for (int j = 0; j < _sizeX; j++) { Console.Write(display[j, i]); foreach (Entity e in _tracking[j, i]) { if (e.Sprite == null) { continue; // Skips this item in _tracking } // RL.DrawTexture(e.Sprite, (int)(e.X * Game.SizeX), (int)(e.Y * Game.SizeY), Color.PURPLE); // Texture Texture2D texture = e.Sprite.Texture; // Position float positionX = e.Sprite.XAbsolute * Game.UnitSize.x + Game.UnitSize.x / 2; float positionY = e.Sprite.YAbsolute * Game.UnitSize.y + Game.UnitSize.y / 2; Raylib.Vector2 position = new Raylib.Vector2(positionX, positionY); // Rotation float rotation = e.Rotation * (float)(180.0f / Math.PI); // Scale float scale = e.Sprite.Size; // Draw RL.DrawTextureEx(texture, position, rotation, scale, Color.PURPLE); } } Console.WriteLine(); } foreach (Entity e in _entities) { //Call the Entity's Update events e.Draw(); } // Console.Write("Say Oi Boi: " + counter); }
public void Draw() { OnDraw?.Invoke(); //clear the screen Console.Clear(); RL.ClearBackground(Color.DARKBROWN); char[,] display = new char[_sizeX, _sizeY]; foreach (Entity e in _entities) { int x = (int)Math.Round(e.XAbsolute); int y = (int)Math.Round(e.YAbsolute); //posistion each Entity's icon in the display if (x >= 0 && x < _sizeX && y >= 0 && y < _sizeY) { display[x, y] = e.Icon; } //e.Draw(); } for (int i = 0; i < _sizeY; i++) { for (int j = 0; j < _sizeX; j++) { Console.Write(display[j, i]); foreach (Entity e in _tracking[j, i]) { if (e.Sprite == null) { continue; } //RL.DrawTexture(e.Sprite, (int)e.x * 16, (int)e.y * 16, Color.WHITE); Texture2D texture = e.Sprite.Texture; //position float positionx = e.Sprite.XAbsolute * Game.UnitSize.X + Game.UnitSize.X / 2; float positiony = e.Sprite.YAbsolute * Game.UnitSize.Y + Game.UnitSize.Y / 2; Raylib.Vector2 position = new Raylib.Vector2(positionx, positiony); //scale float scale = e.Sprite.Size; //rotation float rotation = e.Rotation * (float)(180.0f / Math.PI); //Draw RL.DrawTextureEx(texture, position, rotation, scale, Color.WHITE); } } Console.WriteLine(); } foreach (Entity e in _entities) { e.Draw(); } }
//Called in Game every step to render each Entity in the Scene public void Draw() { OnDraw?.Invoke(); //Clear the screen Console.Clear(); RL.ClearBackground(Color.GOLD); //Create the display grid char[,] display = new char[_sizeX, _sizeY]; foreach (Entity e in _entities) { //Call the Entity's Draw events e.Draw(); //Position the Entity's icon in the display int x = (int)Math.Round(e.XAbsolute); int y = (int)Math.Round(e.YAbsolute); if (x >= 0 && x < _sizeX && y >= 0 && y < _sizeY) { display[x, y] = e.Icon; } } //Render the display grid to the screen for (int y = 0; y < _sizeY; y++) { for (int x = 0; x < _sizeX; x++) { Console.Write(display[x, y]); foreach (Entity e in _tracking[x, y]) { if (e.Sprite == null) { continue; } //RL.DrawTexture(e.Sprite, (int)e.X * Game.SizeX, (int)e.Y * Game.Sizey, Color.WHITE); Texture2D texture = e.Sprite.Texture; float positionX = e.Sprite.XAbsolute * Game.UnitSize.x / 2; float positionY = e.Sprite.YAbsolute * Game.UnitSize.y / 2; Raylib.Vector2 position = new Raylib.Vector2(positionX, positionY); float rotation = e.Rotation * (float)(180.0f / Math.PI); float scale = e.Sprite.Size; RL.DrawTextureEx(texture, position, rotation, scale, Color.WHITE); } } Console.WriteLine(); } foreach (Entity e in _entities) { //Call the Entity's Draw events e.Draw(); } }
/// <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]; }
public void Draw() { OnUpdate?.Invoke(); //clear the screen Console.Clear(); RL.ClearBackground(Color.BLACK); //Console.Write(counter); char[,] display = new char[_sizeX, _sizeY]; foreach (Entity e in _entities) { //Position each Entity's icon in the display int x = (int)e.XAbsolute; int y = (int)e.YAbsolute; if (e.X >= 0 && e.X < _sizeX && e.Y >= 0 && e.Y < _sizeY) { display[(int)e.XAbsolute, (int)e.YAbsolute] = e.Icon; } } //Render the display grid to the screen for (int y = 0; y < _sizeY; y++) { for (int x = 0; x < _sizeX; x++) { Console.Write(display[x, y]); foreach (Entity e in _tracking[x, y]) { //RL.DrawTexture(e.Sprite, (int)(e.X * Game.SizeX), (int)(e.Y * Game.SizeY), Color.WHITE); Texture2D texture = e.Sprite; Raylib.Vector2 position = new Raylib.Vector2(e.XAbsolute * Game.SizeX, e.YAbsolute * Game.SizeY); float rotation = e.Rotation * (float)(180.0f / Math.PI); float scale = e.Size; RL.DrawTextureEx(texture, position, rotation, scale, Color.WHITE); } } Console.WriteLine(); } foreach (Entity e in _entities) { e.Draw(); } }
public void SetUpAI(Tank me, Tank target) { if (me != null && target != null) { this.AddChild(bulletSprite); bulletSprite.Load(bulletImage); this.SetPosition(me.position); collider = new BoxCollider(this, bulletSprite); point = target.position - me.position; pointNormalized = Vector3.Normalize(point); float angle = 0; float diff = CUtils.Distance(point + me.position, me.position, out angle); this.SetRotate(angle + 90); collider.Draw(); } }
// Setups the bullet so it will be ready to use. public void SetUp(Tank tank) { if (tank != null) { this.AddChild(bulletSprite); bulletSprite.Load(bulletImage); this.SetPosition(tank.position); collider = new BoxCollider(this, bulletSprite); point = GetMousePosition() - tank.position; pointNormalized = Vector3.Normalize(point); float angle = 0; float diff = CUtils.Distance(point + tank.position, tank.position, out angle); this.SetRotate(angle + 90); collider.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; } } } }
public override void Draw() { if (!BeenHit || HitTimer % 5 == 0) { DrawSelf(); GunDraw(); } //Draw HealthBar Rectangle PlayerHealthBack = new Rectangle(8, 8, 96, Program.GameHeight * 0.05f); Rectangle PlayerHealthFront = new Rectangle(PlayerHealthBack.x, PlayerHealthBack.y, PlayerHealthBack.width, PlayerHealthBack.height); HP = (int)Clamp(HP, 0, MaxHp); PlayerHealthFront.width *= ((float)HP / (float)MaxHp); int Alpha = 255; DrawRectangleRec(MathMore.toRayRect(PlayerHealthBack), new Color(Color.DARKGRAY.r, Color.DARKGRAY.g, Color.DARKGRAY.b, Alpha)); DrawRectangleRec(MathMore.toRayRect(PlayerHealthFront), new Color(Color.GREEN.r, Color.GREEN.g, Color.GREEN.b, Alpha)); DrawRectangleLinesEx(MathMore.toRayRect(PlayerHealthBack), 1, new Color(Color.BLACK.r, Color.BLACK.g, Color.BLACK.b, Alpha)); //Draw Dead Text if (HP <= 0) { DeadTimer++; Vector2 Pos = new Vector2(Program.GameWidth / 2, Program.GameHeight / 2); DrawRectangleRec(MathMore.toRayRect(new Rectangle(0, Pos.y - 8, Program.GameWidth, 16)), Color.BLACK); if (DeadTimer % 20 > 5) { Raylib.Vector2 Measure = MeasureTextEx(Program.Romulus, "Dead", 12, 1); DrawTextEx(Program.Romulus, "Dead", new Raylib.Vector2(Pos.x - (Measure.x / 2), Pos.y - (Measure.y / 2)), 12, 1, Color.WHITE); } if (!HasDied && DeadTimer > 60) { gameScene.game.CurrentGameScene = new GameScene(gameScene.game); HasDied = true; } } }
// Does the updating and stuff public void Run(float deltaTime) { rl.Vector2 face = pointNormalized * bulletSpeed * deltaTime; this.Translate(face); }
public void DrawDialougeBox() { if (!Visible) { return; } DrawRectangleRec(boxRect, Color.WHITE); DrawRectangleLinesEx(boxRect, 2, Color.BLACK); //Set up some basic variables float CharWidth = 0; int YLine = 0; rl.Vector2 topLeft = new rl.Vector2(boxRect.x + 8, boxRect.y + 8); Font fnt = Program.Romulus; string mess = Messages[CurrentMessage]; if (LetterCount >= mess.Length - 1) { //Go to next message if (IsKeyPressed(KeyboardKey.KEY_SPACE) || IsMouseButtonPressed(MouseButton.MOUSE_LEFT_BUTTON)) { CurrentMessage++; LetterCount = 0; if (CurrentMessage >= Messages.Count) { Messages.Clear(); CurrentMessage = 0; Visible = false; } } } else //TypeWritter Effect { if (IsKeyDown(KeyboardKey.KEY_SPACE) || IsMouseButtonDown(MouseButton.MOUSE_LEFT_BUTTON)) { TypeWritterTimer = 3; } if (TypeWritterTimer > 2) { LetterCount = Numbers.Approach(LetterCount, mess.Length - 1, 1); TypeWritterTimer = 0; } TypeWritterTimer++; } Modifier = 0; //Draw Text for (int i = 0; i <= LetterCount; i++) { char currentChar = mess[i]; if (currentChar == '/') { Int32.TryParse(mess[i + 1].ToString(), out Modifier); i += 2; if (i > LetterCount) { break; } } float temp = 0; int length = 0; while (mess[i].ToString() != " " && i < mess.Length - 1) { temp += MeasureTextEx(fnt, mess[i].ToString(), 12, 1).x + 1; i++; length++; } CharWidth += temp; if (CharWidth >= boxRect.width - 16) { CharWidth = 0; YLine += 1; } else { CharWidth -= temp; } i -= length; currentChar = mess[i]; switch (Modifier) // System does not scale at all { case 0: // Normal Draw { DrawTextEx(fnt, currentChar.ToString(), new rl.Vector2(topLeft.x + CharWidth, topLeft.y + (12 * YLine)), 12, 1, Color.BLACK); break; } case 1: // ShakeyDraw { DrawTextEx(fnt, currentChar.ToString(), new rl.Vector2(topLeft.x + CharWidth + rand.Next(-1, 1), topLeft.y + (12 * YLine) + rand.Next(-1, 1)), 12, 1, Color.BLACK); break; } case 2: // Blue Draw { DrawTextEx(fnt, currentChar.ToString(), new rl.Vector2(topLeft.x + CharWidth, topLeft.y + (12 * YLine)), 12, 1, Color.DARKBLUE); break; } case 3: // Gray Draw { DrawTextEx(fnt, currentChar.ToString(), new rl.Vector2(topLeft.x + CharWidth, topLeft.y + (12 * YLine)), 12, 1, Color.LIGHTGRAY); break; } } CharWidth += MeasureTextEx(fnt, mess[i].ToString(), 12, 1).x + 1; } }