Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: jwalts37 on Mon 14/10/2013 01:44:27

Title: Hey Guys, I Could Use Some Help With Archery Style Game!
Post by: jwalts37 on Mon 14/10/2013 01:44:27
Hello to everyone! And thank you for taking the time to read this!
So, I'm trying to create an Archery-type game and am having alot of issues. Let me first start off by stating that I am not writing this to be lazy and have someone else do things for me. I really like to know what I'm doing and love to learn new things. So, this archery game is a room in the game and is first person (pov). The background of the room is simply a tree a bit in the distance with a target on it. I thought alot about the best way to implement an aiming type system and came to the conclusion that i'd like to have something like this happen(and maybe some of these are impossible or extremely complicated, thats why im asking!):


This may sound really newbie-like (that's what I am with AGS). But I'm really having a hard time implementing any of this. Steps 2-5 above is what i'm having trouble with and its quite discouraging to me because I see alot of you guys doing unbelievable things with your games. Hopefully one day ill be there too! But for now I'm willing to ask for some help/guidance. Any feedback is appreciated! So again, thank you for even taking the time to read this.
Thanks! -Josh

(PS: There are a few flash games that kind-of show what I mean, Gelert Archery (http://www.gamesloon.com/free-sports-12/hunting-games-140/gelert-archery-improved-53174.html) is one )
Title: Re: Hey Guys, I Could Use Some Help With Archery Style Game!
Post by: TGames on Mon 14/10/2013 04:47:51
an easy way to do an arrow animation would to just use scaling. You can start with a giant arrow near the front and when it hits the target it will be smaller.
Title: Re: Hey Guys, I Could Use Some Help With Archery Style Game!
Post by: Lupo4u2 on Mon 14/10/2013 10:04:03
So far i don't see any specific question, so it's hard to help you without writing complete functions for your needs. :P

You should break down what you need and start to create you Game step by step and when you have concrete problems with your code/stuff, ask for help.

I would start f.e. to create a target area in the room and print some information, when the mouse is clicked in the target area. (maybe use an object as target area? )
when this works as expected, add some zooming to the target (scale object? )
afterwards add the mouse jitter. (e.g. create a function which is always called, when the left MouseKey is pressed)
then you add what should happen after you've released the mouse key, like updating the target area, etc...
and so on...
Title: Re: Hey Guys, I Could Use Some Help With Archery Style Game!
Post by: jwalts37 on Wed 16/10/2013 04:23:27
Hey thanks for the replies guys and I apologize about the vague questioning. After a bunch of research, I finally got the mouse jitter working perfectly and it happening while the left mouse is clicked. I guess all I need to figure out now is the best way to actually represent the arrow shooting towards the target. And I was thinking scoring wise, To create a target (dynamicsprite maybe?) and make an overlay over each target ring (or draw a hotspot on each ring). But first things first which is representing shooting the actual arrow. I could either do it with some sort of crazy parabolic function or I could do it pseudo-like with scaling, like you said. But im still a bit new even with that. The target is in the distance on the field, and the arrow would most likely be an object and I know that characters have continuous scaling but i dont think objects do. Thanks guys.
Title: Re: Hey Guys, I Could Use Some Help With Archery Style Game!
Post by: Lupo4u2 on Wed 16/10/2013 08:42:56
For the target i would just use an area and calculate the shooting result by coordinates.
for example, something like your target area has a width=100px and height=100px at a position x=10,y=10 and when the user releases the left mouse, you get the mouse coordinates and compare them with your target area. When the area is hit, you can calculate the distance to center of your area and generate scores according to it.
In this case you're toallty independant of any extra hotpsots, overlays, etc... you only need a target sprite and maybe one hotspot for it, so you can determine if the target area was hit at all. the rest is simple math. ;)

You can use a character for your arrow and use the automatic scaling functions, so you can just move your 'arrow' character to the target and let it scale automatically.
Well, that will not generate a parabolic flight of the arrow... If you want something like that, you must write your own scaling function
Title: Re: Hey Guys, I Could Use Some Help With Archery Style Game!
Post by: jwalts37 on Fri 18/10/2013 03:18:03
K so, I got it working (in a very, VERY elemental state) Heres the code so far:
Code (ags) Select

// room script file

function room_AfterFadeIn()
{
 
  mouse.UseModeGraphic(eModeCrosshair);
  gIconbar.Visible = false;
  oProjectile.Visible = false;
 
}

  bool bow_pull = false;              // Game State


function crossHairShutter()           // All royalties go to Khris for this set of code. I have a hard time understanding it. But im trying! Thanks Chris!

  slow++;
  if (slow < 2) return;
  slow = 0;
 
  #define bound Maths.Pi*2.0
 
  timer_a += 0.1;
  if (timer_a > bound/2.0) timer_a -= bound;
 
  float t = timer_a;
 
  #define x Maths.Sin(t)
  #define y Maths.Sin(t*2.0)*0.5
 
  float x1 = x;
  float y1 = y;

  #define f 2.0
  #define s 0.4
 
  t = t + s;
  if (t > bound/2.0) t -= bound;
 
  float x2 = x;
  float y2 = y;
  int vx = FloatToInt(f*(x2-x1), eRoundNearest) + Random(2)-1;
  int vy = FloatToInt(f*(y2-y1), eRoundNearest) + Random(2)-1;
 
  Mouse.Update();
  Mouse.SetPosition(mouse.x + vx, mouse.y + vy);



function room_RepExec()
{

  oWeapon.X = mouse.x - 92;           //Did this to set the bow to the mouse's x axis only.
                                      //I also wanted the bow's arrow to be vertically aligned with the crosshair, but I noticed a large offset to the left,
                                      //and I realized its because of the bow sprites bounding box. The sprite is 170x150, so I thought i'd divide by two which
                                      //was 85. And that wasnt right, So trial and error began. Theres gotta be a better way.
                                      //Maybe mouse.x - (Game.SpriteWidth[corsshair_slot] / 2)? Im awful with math, except for with music.


  if (mouse.IsButtonDown(eMouseLeft)) 
    {
      bow_pull = true;
      crossHairShutter();
    } 
     
    else if (!mouse.IsButtonDown(eMouseLeft) && bow_pull == true)
     {
       oProjectile.Visible = true;
       oProjectile.X = mouse.x - 3;            //again, very strange math logic here, I dont know why it was like this. The crosshair sprite is 32x39
       oProjectile.Y = mouse.y + 4;
       bow_pull = false;
     }
       
  }


And so there is the very simple implementation. I realized I was probably going too far with it as this isn't an archery-only game. Only problem with above is that the user could just double click and get a shot. So im thinking about combating that by implementing a sort of power meter that will force the player to hold left click for a certain amount of time (the strength bar will show red when its okay to shoot). And a scoring system. Which i'm thinking the easiest way to do is make each ring of the target a hotspot etc etc. Thanks for all your help gentlemen. Let me know what you think.

PS: why is the function not working? or is it just on my end?

Edited by mod: Yeah, it's a bit confusing, as you need to use [code=ags] instead. The fact that the button in the tool-bar still generates [code] doesn't help, but as far as I remember, AGA said it's some kind of hack to the forum software for AGS scripts to work, and there isn't much that can be done to fix it ATM.