Shooting Problems

Started by R4L, Thu 12/01/2006 15:45:55

Previous topic - Next topic

R4L

Ok, I have this idea to make a top-down shoot out like game. I want a bullet (object 0) to travel at a speed of 3 where the mouse is pointing, while adding 10 to varible distance and turning it off when varible distance reaches 300, then positioning it to the main character with SetObjectPosition. I haven't the slightest clue as to how to do this. I keep on trying but the object doesn't move it just sits in front of my character and doesn't turn off. Can anyone please help me?

hedgefield

#1
Sounds complicated. I'm not much of a mathematic/scripting genius. I'm sure others are.

An easy work-around would be just to specify a click(maybe with only a certain cursormode) on your enemy as a gunshot. So you press a button, he dies. Just like real-life warfare ;) Sure you're accuracy would be 100%, but it'll be fun.

R4L

Yeah I was considering that but I wanted to add some sort of strategy to it. You know, you got to get the timing right to hit an enemy just like in real life. But if this all fails, this will be my only oppurtunity but it's not that bad

Khris

Code: ags
bool flying=false;
float x;
float y;
float dx;
float dy;
float mouse_dist;

function hit() {
Ã,  Object *target;
Ã,  target=Object.GetAtScreen(FloatToInt(x), FloatToInt(y));
Ã,  if (target!=null) {
Ã,  Ã,  game.score++;
Ã,  Ã,  target.Visible=false;
Ã,  Ã,  // reset(target);Ã,  // recreate target?Ã,  Ã,  
Ã,  Ã,  return 1;
Ã,  }
Ã,  return 0;
}

function repeatedly_execute() {
Ã,  if (IsTimerExpired(1)) {
Ã,  Ã,  x=x+dx;
Ã,  Ã,  y=y+dy;
Ã,  Ã,  oBullet.SetPosition(FloatToInt(x), FloatToInt(y));Ã,  Ã,  //Ã, <---- bullet object: oBullet
Ã,  Ã,  if (Maths.Sqrt(x*x+y*y)<300 && hit(x, y)==false) {
Ã,  Ã,  Ã,  SetTimer(1, 3);Ã,  // 3: speed
Ã,  Ã,  }
Ã,  Ã,  else {
Ã,  Ã,  Ã,  flying=false;
Ã,  Ã,  }
Ã,  }
}

function on_mouse_click(int button) {
Ã,  if (room==2 && button==eMouseLeft && flying==false) {Ã,  Ã, // shooting-range: room 2
Ã,  Ã,  dx=IntToFloat(mouse.x-player.x);
Ã,  Ã,  dy=IntToFloat(mouse.y-player.y);
Ã,  Ã,  mouse_dist=Maths.Sqrt(dx*dx+dy*dy);
Ã,  Ã,  dx=dx/mouse_dist; // move one pixel every speed/40 seconds
Ã,  Ã,  dy=dy/mouse_dist;
Ã,  Ã,  x=IntToFloat(player.x);
Ã,  Ã,  y=IntToFloat(player.y);
Ã,  Ã,  flying=true;
Ã,  Ã,  SetTimer(1,3);
Ã,  }
Ã,  ...
}


Try this. I didn't test it, but it should work.
Of course you have to edit the existing repeatedly_execute and on_mouse_click to look like my code.

R4L

nice code... but I don't have 2.71 I have 2.61... I really need internet at my own home... sorry I should of made that clear so you wouldn't have wasted your time. sorry dude.  :-\

SMF spam blocked by CleanTalk