Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Alen101 on Sat 21/11/2015 00:38:04

Title: ags shooter
Post by: Alen101 on Sat 21/11/2015 00:38:04
Hi guys i know ags is not the most suitable program to make a shooter,
But the thing is i am making an adventure game in where the player can access to a computer game, thats when the shooter enters the scene
so far i got this but i got lots of troubles and it doesnt seems to work.
So if someone can give me any help that would be great.

What i want to do is :
Just one character (zombie) walking towards the screen
you have to stop him from getting to the base of the screen //
(i used when the player reaches certain area y=123 for example the char steals you a life and teleport to the top of the screen as another zombie)
But this is not working also.
You got 3 bullets and if you hit the target like 10 times it will change the view to a dead one and disapear, and gives you some points.
maybe if you kill this char 3 times the game ends.





heres my code so far: (sadly this  is not working. It works if i use it out of the repexec. but i need the repexec to hear the sound of the gun for example, so i dont know what to do :( )

Code (ags) Select

int myCounter2 = 0;
function room_RepExec()
{
  {if (myCounter2 < 4)
  {
  myCounter2 += 1;
  }
  if (myCounter2 == 0)
  {
  }
  //////////////////////////////////////////////////////////////////
  if (myCounter2 == 1 && (mouse.IsButtonDown(eMouseLeft) && (Character.GetAtScreenXY(mouse.x, mouse.y) == cZombie)))
  {
    aUzi.Play(eAudioPriorityVeryHigh, eOnce);
    gBullet.Visible = false;  //gBullet is a gui with the form of a bullet, to know haw many bullets you have until you have to reload
    cZombie.Tint(100, 0, 0, 100, 90);
    Wait(15);
    cZombie.RemoveTint();
  }
  else
   {
    aUzi.Play(eAudioPriorityVeryHigh, eOnce);
    gBullet2.Visible = false;
    player.Say("Miss!.");
   } 
     //////////////////////////////////////////////////////////////////
  if (myCounter2 == 2)
  {
    aUzi.Play(eAudioPriorityVeryHigh, eOnce);
    gBullet.Visible = false; 
    cZombie.Tint(100, 0, 0, 100, 90);
    Wait(15);
    cZombie.RemoveTint();
  }
  else
   {
    aUzi.Play(eAudioPriorityVeryHigh, eOnce);
    gBullet2.Visible = false;
    player.Say("Im aiming like a blind person!.");
   } 
        //////////////////////////////////////////////////////////////////
  if (myCounter2 == 3)
  {
    aUzi.Play(eAudioPriorityVeryHigh, eOnce);
    gBullet.Visible = false; 
    cZombie.Tint(100, 0, 0, 100, 90);
    Wait(15);
    cZombie.RemoveTint();
  }
  else
   {
    aUzi.Play(eAudioPriorityVeryHigh, eOnce);
    gBullet2.Visible = false;
    player.Say("damn another miss!!.");
   } 
/////////////////////////////////////////////////////////////
      ////////////////////////////////////////////////////////////////////////
       

  if (myCounter2 == 4)
  {
player.Say("Reload reload!!!.");
myCounter2 = 0;
gBullet.Visible = true;
aReload.PlayQueued(eAudioPriorityHigh, eOnce);
Wait(40);
gBullet2.Visible = true;
aReload.PlayQueued(eAudioPriorityHigh, eOnce);
Wait(40);
gBullet3.Visible = true;
aReload.PlayQueued(eAudioPriorityHigh, eOnce);
Wait(40);
   }
}}
   
   
   
Title: Re: ags shooter
Post by: Khris on Sun 22/11/2015 12:49:01
The entire if-else logic is flawed.
During RepExec's first run, myCounter gets incremented to 1. Then the game will run through at least two of the else blocks, playing the Uzi fire sound multiple times even when the mouse isn't pressed at all.

Plus, in order to show the remaining bullets, the easiest way is to put a graphic of multiple bullets on a button, set the button to clip the image, then decrease the button's size.

You probably want this:
function on_mouse_click(Mousebutton button) {
  if (button != eMouseLeft) return; // only react to a left click

  // player performed a left click
  if (bBullets.Width == 0) {
    player.Say("I need to reload first.");
    return; // exit function here
  }

  // shots fired
  aUzi.Play(eAudioPriorityVeryHigh, eOnce);
  bBullets.Width -= 10;  // 10 pixels per bullet

  // check for hit
  Character *c = Character.GetAtScreenXY(mouse.x, mouse.y);
  if (c == cZombie) {
    // zombie dies
    // ...
  }
  else {
    // player says random miss message
  }
}
Title: Re: ags shooter
Post by: Alen101 on Mon 23/11/2015 05:23:31
It worked!!
Thank you very much Khris!!
Title: Re: ags shooter
Post by: Mouth for war on Tue 24/11/2015 09:14:53
And khris to the rescue again!!! I sometimes wonder what this community would do without you man. It would almost be like trying to live without kidneys or something :-D I'll stop sucking up....Right....abouuuut.....NOW! :-D
Title: Re: ags shooter
Post by: Khris on Wed 25/11/2015 22:31:47
Thanks, you're too kind :-D