Show Posts

You can view here all posts made by this member. Note that you can only see posts made in areas to which you currently have access.

Messages - Khris

Pages: [1] 2 3 ... 528
Just re the candlelight code:
1. if the player picks up one of these items, then uses (and loses) it elsewhere, it will appear back in the room (unless that's what you want, of course)
2. distance in a 2D coordinate system:
Code: Adventure Game Studio
  1.   float dx = IntToFloat(mouse.x - Obj.X), dy = IntToFloat(mouse.y - Obj.Y);
  2.   int dist = FloatToInt(Math.Sqrt(dx * dx + dy * dy), eRoundNearest);
  3.   int trans = (dist <= 100) * dist + (dist > 100) * 100; // the multiplication casts the bools to 1 or 0

It sounds like all you need to do is disable manual saving and simply call SaveGameSlot(1); in on_event/eEventBeforeFadein. This way the one savegame always contains the current room's initial state and there's no need to reset anything in the first place. This should solve all three points.

The only way to get a division by zero is if the player and enemy have the same coordinates exactly.
Code: Adventure Game Studio
  1.   float l = Math.sqrt(dx * dx + dy * dy);
insert this:
Code: Adventure Game Studio
  1.   if (l == 0) return true;

It's simpler to do this with math. Afaik you already have a distance check implemented, so all that's left is the angle.
If you have the enemy's line of sight as degree int angle, you can get the normalized vector like this:
Code: Adventure Game Studio
  1.   float af = Maths.DegreesToRadians(IntToFloat(angle));
  2.   float ex = Math.Cos(af), ey = Math.Sin(af);
The vector towards the player is again
Code: Adventure Game Studio
  1.   float x = IntToFloat(enemy.x), y = IntToFloat(enemy.y);
  2.   float dx = IntToFloat(player.x - enemy.x);
  3.   float dy = IntToFloat(player.y - enemy.y);
  4.   // normalize vector
  5.   float l = Math.sqrt(dx * dx + dy * dy);
  6.   dx /= l;
  7.   dy /= l;
You can now calculate the dot product:
Code: Adventure Game Studio
  1.   float dot = dx * ex + dy * ey;
If the two vectors point in the same direction, this product is exactly 1. If they point 90 degrees apart, it's 0. In other words, all you need to check is if (dot > 0.5) and the player is inside the cone. Use a value closer to 1 for a narrower cone.

However I'm guessing you also want to display the cones for the player to see? You can for instance draw them on a semi-transparent, not clickable GUI, again using some Math and DrawTriangle()

Was a typo:

Code: Adventure Game Studio
  1.     float l = Math.sqrt(dx * dx + dy * dy);

Ok, so pixel-based? In that case you need to "walk" along the line from enemy to player and check every (or every other) pixel for being a wall, using a loop. Something like
Code: Adventure Game Studio
  1. bool SightBlocked(float fx, float fy) {
  2.   int x = FloatToInt(fx, eRoundNearest);
  3.   int y = FloatToInt(fy, eRoundNearest);
  4.   // check if room pixel x, y is blocking
  5.   return GetLocationType(x - GetViewportX(), y - GetViewportY()) == eLocationObject;
  6. }
  8. bool IsVisibleTo(this* Character, Character* enemy) {
  9.   float x = IntToFloat(enemy.x), y = IntToFloat(enemy.y);
  10.   float dx = IntToFloat(this.x - enemy.x);
  11.   float dy = IntToFloat(this.y - enemy.y);
  12.   float l = Math.sqrt(dx * dx + dy * dy);
  13.   // check every 2 pixels
  14.   dx /= l / 2.0;
  15.   dy /= l / 2.0;
  16.   int steps = FloatToInt(l / 2.0, eRoundDown);
  17.   for (int i = 0; i < steps; i++) {
  18.     x += dx; y += dy;
  19.     if (SightBlocked(x, y)) return false;
  20.   }
  21.   return true;
  22. }

Now you can use
Code: Adventure Game Studio
  1.   if (player.IsVisibleTo(cPatrol1)) ...

There's no one answer to this question. What exactly do you mean by "near complex"? What are you using for walls?
Turn-based often also means grid-based, which means walls are along grid lines. According LoS algorithms are all over the internet.

Did you check the Scripting -> Multimedia section of the manual?

If you use a single color for transparency, you can tell AGS which corner to grab it from during importing the sprite.
Or you use alpha transparency, in which case the image needs to be saved as PNG, with an alpha channel.

What's google paint? I googled it but didn't find anything besides some Chrome apps.

Usually, when a game crashes, you're presented with an error message... why not go ahead and paste that into your post, verbatim?

Advanced Technical Forum / Re: Flat Shaded 3D models
« on: 01 Jun 2018, 12:49 »
Yeah, you need to turn the mouse coordinates into 3D camera screen coordinates, unproject them into the world, then intersect the line camera-mouse with all triangles. Then find the closest one of all that get hit.

Advanced Technical Forum / Re: Flat Shaded 3D models
« on: 31 May 2018, 21:16 »
It's bugged (no visibility check, perspective is weird, and rotating camera opposite way around makes triangles appear all over the screen).
You can solve the 1st and 3rd issue with frustum culling, btw. Welcome to hell ;)

Advanced Technical Forum / Re: Flat Shaded 3D models
« on: 31 May 2018, 17:24 »
I'll necro-post again because I was asked for the source and saw you asking for it, too.
Here it is:

I didn't read the last few posts so in case this doesn't apply, please ignore.

There's on_event / eEventMouseGUIUp/Down, which I've used in the past to handle arbitrary GUI clicks.

1. Deactivate Windows Game Explorer integration in General settings.
2. Try compiling again. If you get an error about how saving/generating the exe file failed, just try again.

Part of the problem is that the links don't lead to the actual manual entry because for some reason the anchor in the link is turned to lowercase. Whenever I link to a command in the online manual I have to fix the anchor part.

Crimson is talking about GUI.ZOrder, a property you can set in scripts or the editor to determine which GUI covers which. Just change your text label GUI's .ZOrder value to a higher one than the VerbCoin GUI's and it will appear on top of the coin.

If you're using exactly what you've posted here, you forgot to replace all instances of x and y with Posx and Posy. Given that you already have x and y, that can lead to weird results. (lines 8 and 11 of your snippet)

As for GetTextWidth, if you're using @OVERHOTSPOT@ as label text, I'm not sure using GetTextWidth will work as expected. A better solution is to do something like this:

Code: Adventure Game Studio
  1.   // before calculating the position, set label and GUI width based on text
  2.   String ln = Game.GetLocationName(mouse.x, mouse.y);
  3.   lblOverhotspot.Text = ln;
  4.   lblOverhotspot.Width = GetTextWidth(ln, lblOverhotspot.Font) + 2; // small error margin to ensure text doesn't wrap
  5.   gOverhotspot.Width = lblOverhotspot.Width; // assuming label's x coordinate on GUI is 0
  6.   // gui position calculations here

If you want the GUI to be centered on the mouse cursor horizontally, but the gui's width keeps changing, you cannot use a fixed value.
Instead of
Code: Adventure Game Studio
  1.   int Posx = mouse.x - SOME_FIXED_VALUE;

you'll want
Code: Adventure Game Studio
  1.   int Posx = mouse.x - gOverhotspot.Width / 2;

Here's the full example code (which should work as-is):
Code: Adventure Game Studio
  1. function repeatedly_execute() {
  2.   gOverhotspot.Visible = true;
  3.   // calculate coordinates assuming for now that GUI doesn't have to be moved
  4.   int x = mouse.x - 198; int y = mouse.y - 90;
  5.   // horizontal check
  6.   if (x < 0) x = 0;
  7.   if (x + gOverhotspot.Width > System.ViewportWidth) x = System.ViewportWidth - gOverhotspot.Width;
  8.   // vertical check
  9.   if (y < 0) y = 0;
  10.   if (y + gOverhotspot.Height > System.ViewportHeight) y = System.ViewportHeight - gOverhotspot.Height;
  11.   // finally, actually move GUI there
  12.   gOverhotspot.SetPosition(x, y);
  13. }

Edit: removed brackets

Pages: [1] 2 3 ... 528