scrolling rooms but maintaining the character control

Started by Perkele2012, Sat 11/02/2012 15:35:16

Previous topic - Next topic

Perkele2012

im trying to get a room to autoscroll but letting the player remain in control of the character movement.


Khris

Scrolling and blocking walks aren't directly related, so what you're asking doesn't quite make sense without additional info.

Perkele2012

#2
sorry bout that  :( was in a hurry when i wrote it.

well the thing is that i tried to make my room scroll down.. like always scrolling down.
the room is a 2000x480 resolution in a 640x480 game.

i tried to use the setviewport and managed to get the room scrolling down, but the character movement was suspended and waited until the room had scrolled all the way down.

(most likely because the setviewport code segment i found in the help section used "while { }" and wait(1) )


sorry if i explain badly, butI'm still learning how to use AGS  ;D

so to be clear on what i want...

i want my room to scroll from Y 0 to Y 2000 at a comfortable speed,  :P and it will be up to the player to keep up with the pace, if you leave the top region. the game is over.

and any tips regarding uhm, gravity would be great  :P ( used a region over the room and used if player.y<2000) { player.y=player.y+2 } know of a better way... please let me know  :P

Khris

Ah ok, you need a timer. And since you wrote "scrolling down", isn't the room 640x2000?

Add the room's repeatedly_execute event and put this inside:

Code: ags
  if (IsTimerExpired(1) && GetViewportY() < 2000-480) {
    SetViewport(GetViewportX(), GetViewportY() + 1);
    SetTimer(1, 10);
  }


To simulate gravity, which accelerates the player, add a constant value to the player's y movement, not position.
Code: ags
  if (y_speed < y_limit) += gravity;
  if (y_speed > y_limit) y_speed = y_limit;
  player.y += y_speed;

Try different values.

Perkele2012

you are right :) its 640*2000... thanks ill try it out right away  ;D

Perkele2012

scrolling the room worked like a charm(except i had to put SetTimer(1,1) above the if sentence,and use 1,1 instead of 1,10 :D huge thanks for this Khris!!! going to try the gravity next. ;D

Perkele2012

is it possible to move the top edge of the room so that follows the top of the screen when its scrolling down?

Khris

Moving the SetTimer command outside the if doesn't make sense; I forgot to mention that you need an initial SetTimer(1,1) in room_AfterFadein for the scrolling to start though.

On the other hand, if you're going to move the viewport every frame, you don't need a timer anyway.

You can't change a room edge's position during the game.
To kill the player, just check their coordinate versus the viewport:

// in room_RepExec

Code: ags
  if (GetViewportY() < 2000-480) SetViewport(GetViewportX(), GetViewportY() + 1);

  if ((player.y - GetViewportY()) < Room.TopEdge) Killplayer();


This will use the distance set by the top edge, but you can just change it to any number.

Perkele2012


Khris


miguel

Quote from: Perkele2012 on Sun 12/02/2012 08:46:25
damn you´re good   :)



He's not good, he's the "soul" of this community, without him there would not be beginners starting out AGS with a chance to succeed in scripting. The amount of time he gives to beginners is huge!
Of course one should always RTFM but the knowledge base this thread holds is the backbone of any aspiring coder. Going through this thread and the more advanced one is 99% enough to start coding your games.

If nobody said this before, Khris, you're good!
Working on a RON game!!!!!

SMF spam blocked by CleanTalk