[A83] Re: Tilemap


[Prev][Next][Index][Thread]

[A83] Re: Tilemap




See, there is this thing called programming.  That's where a person, usually
called a programmer, figures out what needs to happen and writes code to
actually make it happen.

You need to figure out an algorithm to do this.  Here's an example:

if moving left
{
  if sprite_x == left_threshold
    scroll_map_left
  else
    decrement sprite_x
}
else if moving right
{
  if sprite_x == right_threshhold
    scroll_map_right
  else
    increment sprite_x
}

Here's an example from a game I started for the 86 but never finished:

 ld a,(hl)                 ; get x coordinate
 cp 24                     ; check with left threshhold
 jr nz,MoveSliderLeftDone  ; not equal, skip scrolling
 push hl
 call ScrollLeft           ; try to scroll left
 pop hl
 jr c,MoveSliderLeftDone   ; didn't scroll, don't increment
 inc (hl)                  ; we scrolled, increment left
MoveSliderLeftDone:        ; no matter what, we decrement

I wrote the algorithm, then remembered the game, and decided to see if the
code was worth posting.  So it's not exactly like the algorithm, but close
enough.  Again, view with a fixed with font to see it clearly.  I added the
comments just now.  The main difference between the code and the algorithm
is that no matter what, the coordinate is decremented.  This is due to the
way that the code is structured.  So, if scrolling actually takes place, the
coordinate needs to be incremented first, so after it's decremented, it will
stay the same.

It should be obvious, but this is how programming works.  First think of
what you want to do, then figure out how to do it in abstract terms, and
finally write the code for it.  If you always expect people to do it for
you, then you aren't a programmer, and you won't ever get any better.

> wouldn't display properly. And How do I have the tilemap move when keys
> pressed, and then when the sprite moves close to the end of the map, stop
> scrolling and just move the sprite?
>
> Wow....... I hope you can do this for me.......






References: