Author Topic: Shooter to any random point  (Read 1442 times)

wkohlenberg

  • Guest
Shooter to any random point
« on: February 17, 2013, 03:11:26 am »
Hey,

I make a shooter, but I don´t know how I shoot a bullet in any direction form a point. I don´t know how I solve this problem. I have tried many things, but without success.
The bullets come form the coordinates(10, 10) and go to any random point.

How do I solve this problem.

I had searched with the search function, but i didn't find a topic like this.
Thanks for helping.

Walter.

DeadSn0wMan

  • Guest
Re: Shooter to any random point
« Reply #1 on: February 17, 2013, 04:45:01 am »
Try using physics in Box2D

ciuffolo

  • Guest
Re: Shooter to any random point
« Reply #2 on: February 17, 2013, 05:11:55 am »
1)I think that Box2d is excessive to this,for him, but...yes. Box2d is better.
2)Post some links when you advise something, like these:
http://www.dragonfiresdk.net/wiki/index.php?title=Tutorial%3AThe_DragonFireSDK_Box2D_Sample_Explained
http://www.dragonfiresdk.net/wiki/index.php?title=Tutorial%3ACreating_a_world,_creating_a_ball_and_then_dropping_it_in_Box2d
http://www.dragonfiresdk.net/wiki/index.php?title=Tutorial%3AJumping_in_Box2d
3)I have some exeamples:
It's a bit hard, this code come from the forum, I only used it several times and can explain it.

Code: [Select]

#include "DragonFireSDK.h"
#include <time.h>
int view,image,randomx,randomy;
float startx,starty;
float step,x,y;//increment step for the speed
void AppMain()
{
image=ImageAdd("Image/YOUIMAGE.png");//load you image
startx=160.0;starty=240.0;//set the start position to the center
view=ViewAdd(image,startx,starty);//create your bullet
RandomSetSeed(time(NULL));//random seed
randomx=Random(320);//take a random y number, max 320 (screen display x)
randomy=Random(480);//take a random x number, max 480 (screen display y)
}

void AppExit()
{

}


 

void OnTimer()
{

   step+=0.01; //step implementation
   x = step*randomx+(1.0-step)*startx;//implement the x coordinates by the step in the random point direction
   y = step*randomy+(1.0-step)*starty;//implement the y coordinates by the step in the random point direction
   ViewSetxy(view,x,y);//set the x and y coordinates

}


If there is something that you don't understand...ask ;)

wkohlenberg

  • Guest
Re: Shooter to any random point
« Reply #3 on: February 18, 2013, 02:54:27 am »
Thanks for the codes.
I have no experience with box2d, so I will try.