gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > MovePlayer moves MoveMap or MoveMap on MovePlayer

#105586 - QuantumDoja - Mon Oct 09, 2006 9:51 pm

Hi, here is my basic loop:


while(;;) {
getInput
}

getInput - checks for key presses, if we are moving left/right, we call MovePlayer , MovePlayer then decides if we need to update the map.

My Main player sprite has a limited subsection of the screen in which he can move before we decide to scroll the map: - is this a bad idea?
(Imagine the ascie art is a box in a box)
_____________________
|.....______________.....|
|.....|.........................|.....|
|.....|.........................|.....|
|.....|.........................|.....|
|.....|.........................|.....|
|.....|.........................|.....|
|.....|____________|.....|
|___________________|

I want to create movement effects like mario, or at least a nice arch when im jumping.

I can create velocity in the x and y co-ordinates, should I then update x and y each frame? or whats this fixed point math im hearing about!

please help
_________________
Chris Davis

#105590 - keldon - Mon Oct 09, 2006 10:11 pm

How I would do it (conceptually) ...

Code:

checkInput (){
   foreach ( inputHandler ){
      inputHandler.handleInput ( input );
   }
}

// movePlayer is an input handler
movePlayer (input) {
   direction = inputToDirection ( input );
   updatePlayerPosition (direction);
   player.alertListeners();
}

player.alertListeners (){
   for each ( listener ) {
      listener.alert ( position );
   }
}

// cameraPlayerListener is a player alertListener
cameraPlayerListener ( playerPosition ){
   camera.followPlayer ( playerPosition );
}

camera.followPlayer ( playerPosition ) {
   // in this method you will decide how to handle the camera
}


Now you don't need to write all of these methods, but the concept behind them is a good one to follow or at least think of when developing your system. This is the observer pattern, and a lot of these design patterns are useful to think about when designing and implementing your systems.

In google type and hit I'm feeling lucky for "design pattern wikipedia" and "fixed point maths wikipedia".

#105612 - tepples - Tue Oct 10, 2006 4:07 am

QuantumDoja wrote:
My Main player sprite has a limited subsection of the screen in which he can move before we decide to scroll the map: - is this a bad idea?

I've played Lode Runner for NES. That game's scrolling was horrible, as the inner box was rawther large. If you get close to the edge of the inner box, you can only see a few spaces in front of the guy, often making it too late to turn around when you see a Bomberman coming right for you. (Yes, the enemies in Lode Runner are Bombermen.) First try doing what Pok?mon for Game Boy does: always scroll such that the player's sprite is strictly in the center of the screen.

Quote:
I want to create movement effects like mario, or at least a nice arch when im jumping.

[[Kinematics]]

Quote:
I can create velocity in the x and y co-ordinates, should I then update x and y each frame?

Yes.

Quote:
or whats this fixed point math im hearing about!

[[Fixed-point arithmetic]]
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#106263 - QuantumDoja - Tue Oct 17, 2006 10:32 am

Thanks, i think Ill hook the sprite up to move the map whens its in the middle.
_________________
Chris Davis