About Store Forum Documentation Contact



Post Reply 
02 Drawing (Layers)
Author Message
lucifer1101 Offline
Member

Post: #1
02 Drawing (Layers)
I have just been trying to edit tute 02 drawing, but some pictures were over the other others under the other.

To fix this all you have to do is edit the drawing process right..
12-25-2008 01:12 AM
Find all posts by this user Quote this message in a reply
lucifer1101 Offline
Member

Post: #2
Re: 02 Drawing (few q's)
ok it worked and i have a moveable green circle, but now i want to do some 2d colliosion detection, but there isnt really anything on it... is it even possible.

My aim of this is to make a basic 2d game of collect dots while going through a maze...

also is there any tool to make 2d levels, if not it would make a great addition

for anybody unsure about the layers heres a template for 2d layers...

Code:
/******************************************************************************/
void Draw()
{
   D.clear(WHITE); // clear to white

   // layer1
   {  
      //draw here1
   }

   // layer2
   {
     //draw here2
   }

   // layer3
   {
     //draw here3
   }
    
   // layer4
   {
     //draw here4
   }
}
/******************************************************************************/

so on and so on

Im an official Esenthel Nooblet
12-25-2008 01:25 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #3
Re: 02 Drawing (Layers)
Hi,

2d game creation isn't documented since I've focused on 3d games, however making 2d games is fully supported.
First of for 2d games don't use Physics (PhysX) as it's only for 3d,
Second - there are some basic 2d collision detection routines already implemented, check out various headers in "Math" tab, for shapes like circle, edge, you've got various functions starting with "Cuts*" which do collision detection
Thanks for the idea of a 2D level editor, I'll add it to my task list
12-25-2008 02:20 PM
Find all posts by this user Quote this message in a reply
lucifer1101 Offline
Member

Post: #4
Re: 02 Drawing (Layers)
i belive i found where i should be looking, but i do not know which one to use and how to actually use it...

Quote:Functions
Int CutsStrCircle (Vec2 &point, Vec2 &normal, Circle &circle, Vec2 *p1=NULL, Vec2 *p2=NULL, Flt *width=NULL)
Int CutsCircleCircle (Circle &c1, Circle &c2, Vec2 *p1=NULL, Vec2 *p2=NULL, Flt *width=NULL)
Bool CutsPOINTCircle (Vec2 &point, Vec2 &move, Circle &circle, Flt *hit_frac=NULL, Vec2 *hit_normal=NULL)
Bool CutsPOINTCircle (VecD2 &point, VecD2 &move, CircleD &circle, Dbl *hit_frac=NULL, VecD2 *hit_normal=NULL)
Bool CutsEDGECircle (Edge2 &edge, Vec2 &move, Circle &circle, Flt *hit_frac=NULL, Vec2 *hit_normal=NULL)
Bool CutsEDGECircle (EdgeD2 &edge, VecD2 &move, CircleD &circle, Dbl *hit_frac=NULL, VecD2 *hit_normal=NULL)
Bool CutsCIRCLECircle (Circle &circle, Vec2 &move, Circle &c2, Flt *hit_frac=NULL, Vec2 *hit_normal=NULL)
Bool CutsCIRCLECircle (CircleD &circle, VecD2 &move, CircleD &c2, Dbl *hit_frac=NULL, VecD2 *hit_normal=NULL)
Bool CutsCIRCLEPoint (Circle &circle, Vec2 &move, Vec2 &point, Flt *hit_frac=NULL, Vec2 *hit_normal=NULL)
Bool CutsCIRCLEPoint (CircleD &circle, VecD2 &move, VecD2 &point, Dbl *hit_frac=NULL, VecD2 *hit_normal=NULL)
Bool CutsCIRCLEEdge (Circle &circle, Vec2 &move, Edge2 &edge, Flt *hit_frac=NULL, Vec2 *hit_normal=NULL)
Bool CutsCIRCLEEdge (CircleD &circle, VecD2 &move, EdgeD2 &edge, Dbl *hit_frac=NULL, VecD2 *hit_normal=NULL)

a little more information would be very helpful...

Im an official Esenthel Nooblet
12-25-2008 11:59 PM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #5
Re: 02 Drawing (Layers)
you've got comments with those functions
which one to use depends on what you want to achieve
if you want to assume that your character is a 2D Circle (in physics term) and you want to use collision detection for a moving circle and static edges (level), then use those functions which have a comment named 'if a moving circle cuts through static edge'
as I recall its this function
Bool CutsCIRCLEEdge (Circle &circle, Vec2 &move, Edge2 &edge, Flt *hit_frac=NULL, Vec2 *hit_normal=NULL)
you perform a test if a moving by 'move' vector 'circle' (your player) encounters a non moving 'edge'-wall
returns true if it hit an edge, and false if they don't collide
if you pass hit_frac it will return 0..1 value indicating at which fraction of the movement collision encountered
'hit_normal' stands for normal vector of collision
having this function you'd need to have a level built of 2D edges.
2D edges will allow you for complex levels with walls at different angles.
if you want simplier code, and you'll have a level limited to square tiles, with the fact that the characters will move slowly you can do it simplier
have a 2D map of tiles:
Code:
Byte tile[16][16]=
{
   {1,1,1,1,1,1,1,1,1,1...}, // 16 values here, where '1'=wall, '0'=floor
   {1,0,0,0,0,0,0,0,0,0...},
   {1,0,1,1,1,0,0,0,0,0...},
   {1,0,1,0,1,0,0,0,0,0...},
   {1,0,1,0,0,0,0,0,0,0...},
   {1,0,1,1,1,1,1,1,0,0...},
};
and then work out manually your collision detection, start with a 2d point
Vec2 point; // player position
write a position testing function
Code:
Bool PositionValid(Vec2 &pos)
{
   int x=Trunc(pos.x),
       y=Trunc(pos.y);
   if(x>=0 && y>=0 && x<16 && y<16)return tile[y][x]==0; // tile at pos vector is floor
  return false;
}
then write an updating position function
Code:
void UpdatePlayerPosition(Vec2 &pos)
{
   Vec2 dir=Vec2(Kb.b(KB_D)-Kb.b(LB_A), Kb.b(KB_W)-Kb.b(KB_S))*Tm.d*0.5f;
   Vec2 new_pos = pos + dir;
   if(PositionValid(new_pos)) // if new position is valid - floor
  {
      pos=new_pos; // set players position
  }
}
these are just the basics
12-26-2008 12:15 PM
Find all posts by this user Quote this message in a reply
lucifer1101 Offline
Member

Post: #6
Re: 02 Drawing (Layers)
i cannot comprehend what you have written here, is there any simpler way of saying "iscollidable true"

for an object that has been drawn

Im an official Esenthel Nooblet
12-27-2008 06:44 AM
Find all posts by this user Quote this message in a reply
Esenthel Offline
Administrator

Post: #7
Re: 02 Drawing (Layers)
well when writing collision detection manually
Code:
Bool PositionValid(Vec2 &pos)
{
   int x=Trunc(pos.x),
       y=Trunc(pos.y);
   if(x>=0 && y>=0 && x<16 && y<16)return tile[y][x]==0; // tile at pos vector is floor
  return false;
}
is almost as simple code as it can be

I'd gladly start working on a 2d level game functions (including automatic collision detection) where all would be already implemented but first I've got some stuff in the rest of programming to do
I'll add automatic 2d collisions and 2d level editor to my task list
12-27-2008 11:13 AM
Find all posts by this user Quote this message in a reply
Post Reply