MouseClicking-Fight in my Game

Started by Digital Mosaic Games, Sun 17/10/2010 19:23:20

Previous topic - Next topic

Digital Mosaic Games

Hey AGS-Friends,

I want to have something like a mini-ability-game in my adventure. When it starts the player should click on the enemy and click as fast as he can against the computer. There should be also something like a score-bar(GUI) on the screen. If it is full the player wins. The computer reduces your score more and more and you have to click against the computer. But remember the mouse has to be on the enemy-character otherwise it has no effect. The system of the fight is very simple but I don't know how to script it. I'm sure I would need an extra script and create new functions but to be honest I haven't much experience in this modules.
It would be great to have a function like "StartCombat(*Enemy-Character name, *Computer-Speed)"
With "Computer-Speed" I mean the Speed of the reduction of the Score-Bar.
I forgot to mention that I've made 11 Pictures for the Scorebar(0-10)
How can I flow this in the script? 0 is Death and 10 the Win.

I would be very pleased if I would get some foods for thought or maybe a module from you! :-*

Thanks!

Digital Mosaic Games

I'm waitin now for three days. Is there really no idea how to do this? :'(
I know it's a bit strange to do thid with ags but I think that must be possible. It would be great to have some foods for thought because I don't know really how to begun.

Khris

#2
Something like this should work:

Create a non-clickable GUI named "gBattle" with a button "bFight". Set its visibility to "Normal, initially off".

Make sure the images have consecutive slot numbers, e.g. empty bar is 134, full bar 144.

Then put this in a new script:
Code: ags
// header

import void StartCombat(Character*c, int timeout);


Code: ags
// put the slot of the first image (empty bar) for x
#define FIRST_SLOT x

bool battle;
Character*battlechar;
int to;

void StartCombat(Character*c, int t) {
  bFight.NormalGraphic = FIRST_SLOT + 5;  // start with bar half full
  battle = true;
  battlechar = c;
  to = t;
  SetTimer(20, to);
}

void repeatedly_execute() {
  if (!battle) return;

  if (IsTimerExpired(20)) {
    if (bFight.Graphic > FIRST_SLOT) {
      bFight.NormalGraphic = bFight.Graphic - 1;
      SetTimer(20, to);
    }
    else {
      battle = false;
      gBattle.Visible = false;

      // battle is lost

    }
  }
}

void on_mouse_click(MouseButton button) {
  if (!battle) return;
  if (Character.GetAtScreen(mouse.x, mouse.y) != battlechar) return;
  ClaimEvent();

  if (bFight.Graphic < FIRST_SLOT + 10) bFight.NormalGraphic = bFight.Graphic + 1;
  else {
    battle = false;
    gBattle.Visible = false;

    // battle is won

  }
}


You can use this like
  StartCombat(cGuy, 20);
20 means that the bar goes down every half second. Decrease the value to make it faster.

Edit: fixed stupid code error :)

Digital Mosaic Games

Thanks! I've sent you a message. :)

SMF spam blocked by CleanTalk