Maidens of the Kaleidoscope

~Hakurei Shrine~ => Rika and Nitori's Garage Experiments => Topic started by: Anunsew on February 23, 2012, 01:39:53 AM

Title: Some newbie game development questions
Post by: Anunsew on February 23, 2012, 01:39:53 AM
Hello everyone, Anunsew here.

I guess I don't really post in RaNGE, but here goes:

I've been working on a danmaku engine prototype for a class project (nothing too fancy, it's just to demonstrate an idea). I've been using Allegro 4.4.0.1 library to simply Windows and Hardware driver handling, as well as using Allegro's built-in routines for initialization, loading, display, and buffering. I'm using my own wrapper classes in order to use Allegro in C++ (which is natively supported for C)

So far, the basic stuff is fine:

So far, audio device handling has not been implemented yet (but is unnecessary for the current stage of the framework).

Anyway, here's my problem. While I can implement and call bullet functions without any problem, I have no support for [Angles]. Here's a rundown of my bullet structure (which is far from complete, but workable nonetheless):
Code: [Select]
/* Misc unnecessary stuff*/
/*~*/

class Meimu             //...don't ask
{
    protected:
        //coordinate of the bullets.
        //Is implemented as a struct with two ints (x,y).
        cord xyLoc;     

        //problem. Since my bullets have no angle implementation,
        // bullet trajectory is controlled
        //by pixel incremental.
        //Hence if the bullet travels at velocity (5,3)
        //and was created at xyLoc (10,10) then after one frame,
        //the next xyLoc would be (15, 13)
        int xVel;             
        int yVel;           
       
        //delays the increment by VelDel number of frames.
        //Note that the xVelDel
        //and YVelDel are  independent.
        //hence I can increment the
        //xyLoc's members at different frames.
        //Curving trajectories are possible
        //with this two variables.
        int xVelDel;     
        int yVelDel;     
       
        /*some other random parameters and methods that does not need to be documented...*/
    public:
        /*some other random parameters and methods that does not need to be documented...*/
};

As you can see, my Mei...er, Bullet class computes its trajectory by pixel increments. While this suits a primitive engine like mine, my class project requires me to create a spiraly-shaped pattern which is nearly impossible to do in my current implementation (without the use of badass mathematics which is currently out of my reach or abilities).

In my experience with danmakufu, the engine implements angle by degrees as well as abstraction of the computation from the programmer, hence he does not need to have a complete understanding of trigo to create complex patterns. My question is how to implement such an abstraction in my framework.

Take note that I don't need an exact code, just the ideal prototype which can help me start working in the right direction.

So far here are my thoughts about it:

In summary, my problem is how to implement angle computation in a prototype danmaku engine. For example, firing a bullet that travels at 2pps with an initial angle of 45 degrees from InitialPixel. I have no dreams of implementing a dynamic bullet angle yet (changing the angle while the bullet is still alive), but I might do it in the future if I can go past this roadblock.

I suppose I'll need to break off from coordinate manipulation, but I don't know what to do next. Any help or a point to the right direction would be nice.

I have no immediate plans to make it a full blown game engine (that is way over my head right now), but I need this to pass this semester's class. This angle problem has been the cause of more than two sleepless weeks. :blush:

As a side note, I'm using Keine's sprite and animation from IN as a boss object. No reason at all.
Title: Re: Some newbie game development questions
Post by: Blargel on February 23, 2012, 02:47:44 AM
I see you're using x velocity and y velocity instead of velocity and angle.

If you want an easy implementation of velocity and angle, you'll have to (obviously) first have a velocity and angle property. These are the values that the user will be passing in. When it's passed in, you can set your xVel and yVel variables according with the following formulas:

xVel = velocity * cos(angle)
yVel = velocity * sin(angle)

This will work with negative velocities as well, should you want your bullets to move backwards for whatever reason. You can then use those to adjust the x and y coordinates as you probably have been doing already.

EDIT: If may have some problems with the floats that sin and cos will give. Since you can't render an image on 0.37493 of a pixel, I would suggest storing the position as a float, but truncating/rounding it when passing it to the drawing.
Title: Re: Some newbie game development questions
Post by: Anunsew on February 23, 2012, 04:32:46 AM
Thanks for the reply!

I'll try the algorithm you suggested. I'll post whatever the results will bring.

About the floats, I can always cast them into an int to truncate the float values whenever I'm passing them to the draw method.

Anyways, thanks again for the fast reply. XD