Lock a character to the screen (SOLVED) + Transporting a player (SOLVED)

Started by Creator, Tue 25/05/2010 07:24:06

Previous topic - Next topic

Creator

I'm trying to lock a character to a certain point on the screen as a indicator. It changes colour in certain conditions so the player knows they can do something. The best example I can think of is the question mark in Trilby's Notes. It's always at the top left (or top right) of the screen, even in scrolling rooms (which my first room is).

I tried this:
Code: ags

cIndicator.x = System.ScreenWidth - (System.ScreenWidth - 20);
cIndicator.y = 50;


But that put him at the actual rooms 20, 50.

Gilbert

Try putting this in repeatedly_execute_always():

Code: ags

cIndicator.x = GetViewportX()+20;
cIndicator.y = GetViewportY()+50; //Ditch the GetViewportY() part if no room will scroll vertically


HOWEVER, a more logical solution is to use a GUI instead of a character (which I'm fairly sure that most other games, possibly including Trilby's Notes do this). GUIs use screen coordinates and you do not need to reposition them repeatedly to deal with scrolling.

Creator

#2
Thanks Gilbert, that worked.
I was thinking GetViewPort, but forgot and didn't try it.
I also thought about using a GUI right after submitting the post. I'll experiment with both for while and see which works better.

Creator

Yeah, another problem now.  >:(

I'm making a Portal-type game, but the character won't transport from the blue portal to the orange, only the orange to blue.
I've marked part of the code below that doesn't work:

Code: ags

//Code is in on_key_press
  if (keycode == eKeyT)
  {
    if (cIndicator.Loop == 3) //indicator is green
    {
      FadeCharacterOut_NoBlock(player, 100, -2); //Fading things non-blocking module related
      Wait(80);
      if (player.Loop == 0)
      {
        player.Loop = 3;
      }
      else if (player.Loop == 3)
      {
        player.Loop = 0;
      }
      if ((player.y >= cOrange.y) && (player.y < cOrange.y + 30)) //This always runs
      {
        player.x = cBlue.x;
        player.y = cBlue.y+1;
      }
      else if ((player.y >= cBlue.y) && (player.y < cBlue.y + 30)) //This never runs
      {
        player.x = cOrange.x;
        player.y = cOrange.y+1;
      }
      FadeCharacterIn_NoBlock(player, 0, -2);
      Wait(40);
    }
  }


When you're standing next to the blue portal and press T, it doesnt transport you anywhere. You fade back in at the blue portal.

Gilbert

Hmmm. Will the ranges [cBlue.y, cBlue.y+30] and [cOrange.y, cOrange.y+30] overlap?

Creator

No. Blue and orange are on the opposite sides of the screen. I'm going to try my best to make sure the portals never overlap.

Gilbert

I meant their Y coordinates, as your codes check only the Y coordinate of the player, so if the player is standing at a Y coordinate that's in-range of the orange and the blue one at the same time only the first condition will be executed.

A better way is to check whether the player is in a rectangular range (i.e. check also his X coordinate), or if appropriate, you may simply use player.IsCollidingWithChar() to check whether the player collides with a gate.

Creator

Quote from: Gilbet V7000a on Tue 25/05/2010 09:21:53
I meant their Y coordinates

Oh yes, of course. Both portals are at the same Y co-ord. I'll just have to copy-paste the X co-ord from the code for the indicator, as that contains it. Thanks again Gilbert.

SMF spam blocked by CleanTalk