Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - SuperV1234

Pages: 1 2 [3]
31
General / Resize window 2x
« on: June 17, 2010, 02:52:17 pm »
Is there a way to resize a 640x480 window to 2x the size?
I just want it to be a graphical resize, no effect on gameplay whatsoever.

Think about pixel-art games that run at 320x240, but you can upscale them at 3x, 4x. That's what I'm looking for.

32
General / Bullet Hell performance and optimization problems
« on: June 13, 2010, 10:21:43 pm »
Full source code: http://www.mediafire.com/?wgimixyjtbt


---


I'm making a bullet hell game (danmaku) using SFML.NET and C#.
My source of inspiration is Danmakufu, a game where you can create your bullet patterns, share them, play them, etc.


In Danmakufu I can easily spawn 300 bullets every frame staying at 58-60FPS all the time.
In my own game, when I spawn 300 bullets every 3 frames, the game becomes unplayable due to slowdown.


The biggest difference between my game and Danmakufu is that my game's resolution is 1024x768, Danmakufu is 800x600. But can that make an enormous difference?


---


My code for bullets is this:


Code: [Select]
public class Entity
    {
        public float X { get; set; }
        public float Y { get; set; }
        public Game Game { get; set; }
        public bool Alive { get; set; }
        public Sprite Sprite { get; set; }


        public Entity(Game game)
        {
            Game = game;
            Alive = true;
        }


        public virtual void Update()
        {
            Sprite.Position = new Vector2(X, Y);
        }
        public virtual void Draw()
        {
            Game.RenderWindow.Draw(Sprite);
        }
        public virtual void Destroy()
        {
            Alive = false;
        }
    }
Entity is the basic class for any object in the game; you can draw and update entities.


Code: [Select]
public class Bullet : Entity
    {
        private float _angle;
        public float Angle
        {
            set { _angle = Data.ANormalize(Data.ARadians(value)); }
            get { return Data.ADegrees(_angle); }
        }
        public float Speed { get; set; }


        public Bullet(Game game) : base(game)
        {
            Game.BulletManager.Entities.Add(this);
        }


        public override void Draw()
        {
            base.Draw();
        }
        public override void Update()
        {
            base.Update();


            X = X + Speed * (float)Math.Cos(_angle);
            Y = Y + Speed * (float)Math.Sin(_angle);
            Sprite.Rotation = 360-Angle;


            if(Game.Playfield.IsInPlayfield(X, Y) == false)
            {
                Destroy();
            }
        }
        public override void Destroy()
        {
            base.Destroy();
 
            Game.BulletManager.Entities.Remove(this);        
        }
    }
The Bullet class inherits from Entity. When it is spawned, it is added in the Game.BulletManager.Entities list. When it is deleted, it is removed from the same list.
If you're curious about the stuff happening in the "Angle" property, here are the related methods:
Code: [Select]
public static float ARadians(float angle)
        {
            return angle * 3.14f / 180f;
        }
        public static float ADegrees(float angle)
        {
            return angle * 180f / 3.14f;
        }
        public static float ANormalize(float angle)
        {
            if (angle > 360)
            {
                angle = angle - (360 * Convert.ToInt32((angle / 360)));
            }


            if (angle < 0)
            {
                angle = angle + (360 * Convert.ToInt32((angle / 360)));
            }


            return angle;
        }
---


Here's the code for the Manager class and the Game class:


Code: [Select]
public class Manager
    {
        public List<Entity> Entities { get; set; }


        public Manager()
        {
            Entities = new List<Entity>();
        }


        public void Update()
        {
            for (int index = 0; index < Entities.Count; index++)
            {
                Entity entity = Entities[index];
                if (entity.Alive)
                {
                    entity.Update();
                }
            }
        }


        public void Draw()
        {
            for (int index = 0; index < Entities.Count; index++)
            {
                Entity entity = Entities[index];
                if (entity.Alive)
                {
                    entity.Draw();
                }
            }
        }
    }
Pretty straightforward. Updating a manager updates all of its entities; drawing a manager draws all of its entities.


Code: [Select]
public class Game
    {
        public bool Running { get; set; }
        public RenderWindow RenderWindow { get; set; }
        public Manager BulletManager { get; set; }
        public Playfield Playfield { get; set; }
        public int Frame { get; set; }


        //DEBUG---
        public int DebugFrame { get; set; }
        private int kk = 0;
        private int ff = 1;
        private bool kkb = true;
        Image image = new Image(Environment.CurrentDirectory + @"/Data/Images/b_pellet.png");
        //--------


        public Game()
        {
            Running = true;
            RenderWindow = new RenderWindow(new VideoMode(1024,768), "Bullet Hell Test");
            RenderWindow.UseVerticalSync(true);
            RenderWindow.Show(true);
            BulletManager = new Manager();
            Playfield = new Playfield(this, 250, 50, 774, 718) {Offset = 25};
            Frame = 0;
           
            Debug();


            Run();
        }


        public void Run()
        {
            while(Running)
            {
                Update();
                Draw();
            }
        }


        public void Update()
        {
            BulletManager.Update();


            if(DebugFrame == 10)
            {
                Debug();
                DebugFrame = 0;
            }


            DebugFrame++;
            Frame++;


            Console.WriteLine("{0} --- {1}", Convert.ToInt32(RenderWindow.GetFrameTime() * 1000), BulletManager.Entities.Count);
        }
        public void Draw()
        {
            RenderWindow.Clear(Color.White);
            Playfield.DrawInside();
            BulletManager.Draw();
            Playfield.DrawOutside();
            RenderWindow.Display();
        }


        //--------------------------------------------------------------------------------------------


        public Bullet CreateBullet()
        {
            return new Bullet(this);
        }


        //--------------------------------------------------------------------------------------------


        public void Debug()
        {
            float step = 300;    


            for(int i = 0; i < step; i++)
            {
                Bullet temp = new Bullet(this);
                   
                        temp.Angle = (i*(360/step));
                        temp.Speed = 5f;
                        temp.Sprite = new Sprite(image);
                        temp.X = Playfield.GetCenter().X;
                        temp.Y = Playfield.GetCenter().Y;
            }


            if (kk < 120)
            {
                kk = kk + 5;
            }
            else
            {
                kk = 120;
            }


            ff = ff + 22;
        }
    }
This one is pretty straightforward too, ignoring the debug variables that I used before to create cool-looking patterns.
Update calls the "Debug" method every 10 frames, which spawns bullets.
Bullets aren't spawned by recycling, but instead by creating "new" bullets. I've chosen this because I haven't noticed big performance improvements recycling bullets in the past.
Draw draws bullets and the playfield, which creates the usual "shoot 'em up" borders around the playing screen.


---


So, I've created this thread to kindly ask you what am I doing wrong; why can't my game spawn the same amount of bullets as Danmakufu without slowing down?


Is it a SFML.NET limitation?

---


I have also another problem:


Game.BulletManager.Entities.Remove(this); --- this line in the Bullet -> Destroy method makes a single bullet move in a strange way while uncommented.


I think this is because the for loops skips or makes an unnecessary additional cycle.
How can I prevent this?


---

Thanks.

33
SFML projects / Bullet hell (Touhou) fangame
« on: April 05, 2010, 01:09:34 pm »
I've only been using SFML since a day and I've already started an ambitious project. It's a Touhou fangame. Touhou is a bullet hell game, a shoot'em up focused on dodging a lot of bullets. Here's a video of my progress for now.



Anyone interested in giving an hand?

I'm planning to make boss battles non-hardcoded, instead scripted in external .lua files that are loaded using LuaInterface.

Oh, the project is written in C#, not C++.

34
Graphics / 8-direction movement problem
« on: April 05, 2010, 11:40:01 am »
I created a simple 8-dir movement for my game, however when moving in a diagonal direction the player goes faster than intended.

This is the code. How can I prevent it?

Quote

            switch (input)
            {
                case KeyCode.Left:
                    nextX = -1;
                    break;
                case KeyCode.Right:
                    nextX = 1;
                    break;
                case KeyCode.Up:
                    nextY = -1;
                    break;
                case KeyCode.Down:
                    nextY = 1;
                    break;
            }

            X = X + nextX * speed;
            Y = Y + nextY * speed;

            nextX = 0;
            nextY = 0;

35
Graphics / .Center and .Scale
« on: April 04, 2010, 09:46:13 pm »
If I modify the .Scale of a Sprite, and then set the .Center to:
.Center = new Vector2(.Width / 2, .Height / 2);

...the center is not in the correct place. How do I prevent this?

36
SFML projects / Best way to create a tile-based game
« on: April 04, 2010, 06:22:47 pm »
Hello, I'm new to SFML and its forum, so if this is the wrong section sorry.

I want to create a tile-based game, similar to Sokoban, for example.

I'm using C# and SFML.NET to create it. What is the best object-oriented way to create it?

---

I was thinking to have a class called Entity:
Entity(int x, int y, int z, string type)

And a class called EntityManager that contains a List<Entity>.

Then, for example, to move the player, I search in EntityManager's list an Entity with the type "player", and once I find it, I change its x to x -1.

---

Is there an easier or better way to make a Sokoban clone?

Pages: 1 2 [3]
anything