Author Topic: Some newbie game development questions  (Read 1882 times)

Anunsew

  • No errors for 5 seconds!
  • *
  • Currently fueled by Infinite Love!
Some newbie game development questions
« 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:
  • Can display and handle multiple objects on screen, handle collisions and change the object parameters
  • Uses double buffering to avoid flickers
  • Uses a separate backbuffers for the background and game layers before it is drawn to the video buffer
  • Usage of a backbuffer gives me the power to scroll the background freely without introducing artifacts. It does introduce tearing with legacy cards. However, it was tested in faster video cards with satisfactory results.
  • Usage of a backbuffer also gives me the power to implement animation through the use of an array. However this is implemented via hard coding.
  • Uses a timer routine to keep the fps at 60 (through a routine I created based from Allegro's timer tutorial)
  • Parallel timing for draw and logic methods (to avoid input overkill and conserve memory)
  • Preloads and Finalization, as well as loading and releasing objects at runtime (handled by Allegro)

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:
  • I can use trigo functions to compute the angle of the InitialPixel(the creation point of a bullet) in relation to the location of the target (using sine,cos, tan).
  • However, despite KNOWING the angle, I do not know how to implement it to the bullet firing method. Since I cannot always know the direct trajectory of a bullet during it's creation, controlling a bullet using vectoral velocity from initialization is kind of clunky.

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.
« Last Edit: February 23, 2012, 01:47:31 AM by Anunsew »

Blargel

  • RAWR!
  • I'M AN ANGRY LOLI!
Re: Some newbie game development questions
« Reply #1 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.
« Last Edit: February 23, 2012, 02:55:40 AM by Blargel »
<WorkingKeine> when i get home i just go to the ps3 and beat people up in blazblue with a loli
<Azure> Keine: Danmakufu helper by day, violent loli by night.

Anunsew

  • No errors for 5 seconds!
  • *
  • Currently fueled by Infinite Love!
Re: Some newbie game development questions
« Reply #2 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