10.03.2019 - Round 1 results of our "A Love Letter For FreeBASIC" game dev competition have been published. Please be sure to check the results thread: http://games.freebasic.net/forum/index.php?topic=629.0. Don't forget that the competition is continuing with a round 2, lasting till 29th of April, 300 USD first prize. Stay tuned!

Author Topic: A screen by screen scrolling engine with a map editor (ver. 0.4.2) - 10.02.08  (Read 31561 times)

Lachie Dazdarian

  • Double dipper
  • Administrator
  • Forum Sage
  • *****
  • Posts: 1308
    • Yahoo Instant Messenger - lachie13
    • View Profile
    • The Maker Of Stuff
    • Email
Re: A screen by screen scrolling engine with a map editor (ver. 0.3) - 02.02.08
« Reply #15 on: February 02, 2008, 06:20:34 PM »
New version 0.3 is available (check the first post for download)!

Changes/additions:

* pixel perfect collision layer fully implemented
* foreground layer fixed (related to being behind or in front of objects in that layer)
* added a necessary overlay layer for object always drawn in front of the player
* stuff

Anyway, for all this to give a desired effect you need to draw the appropriate sprites and place them in the appropriate layers. Anyway, I think the example maps illustrate this quite well.

All that is left to be done is a layer with objects that you can slide off, and improved map editor.

Edit: Small update. Version 0.3.2. Pixel perfect collision improved and few fence tiles corrected.
« Last Edit: February 02, 2008, 07:10:37 PM by Lachie Dazdarian »
"Things like Basic and Free Basic provide much-needed therapy and a return to sanity and a correct appreciation of people. The arrogant folk really hate a word like 'Basic' - fine, and good riddance." ~ pragmatist

ShadowLoneWolf

  • Amoeba
  • *
  • Posts: 8
    • View Profile
    • Email
Very Nice;
it looks good; now too bad your not making a game; some of your graphics would work for a good game, others didn't catch my good side, if you know what i mean

mysoft

  • Recruit
  • **
  • Posts: 49
    • MSN Messenger - mysoft@bol.com.br
    • View Profile
    • MyTDT Software
    • Email
hum... c00l, interesting idea...

but you need especific tiles to use in the collision layer, i dunno if this is good or not =] altough it makes the collisions probabily a bit more realistic
Programming is like love... you will never acomplish anything by treating your language as if it was a tool, or a slave of yours...

Lachie Dazdarian

  • Double dipper
  • Administrator
  • Forum Sage
  • *****
  • Posts: 1308
    • Yahoo Instant Messenger - lachie13
    • View Profile
    • The Maker Of Stuff
    • Email
Well, I have no idea how to solve this otherwise. I mean, how to mark specific pixels for each foreground sprite that are colliding? A colliding layer is a much simpler solution.
"Things like Basic and Free Basic provide much-needed therapy and a return to sanity and a correct appreciation of people. The arrogant folk really hate a word like 'Basic' - fine, and good riddance." ~ pragmatist

notthecheatr

  • Global Moderator
  • Forum Sage
  • *****
  • Posts: 351
  • Who's the guy from 21 Jump Street?
    • AOL Instant Messenger - notthecheatr
    • Yahoo Instant Messenger - TheMysteriousStrangerFromMars
    • View Profile
    • notthecheatr Home
    • Email
If you have a separate image attached to your sprite (specified in a config file, probably) that is the same thing but only has the feet in the picture, then you base collisions on the CollisionSprite while drawing the DrawingSprite.

Another solution is simply bounding box at the feet.  Basically, you want to check the feet.  And of course Pritchard's 2.5D tutorial uses a bounding box in pseudo-3d.
The funniest thing happened yesterday.

Lachie Dazdarian

  • Double dipper
  • Administrator
  • Forum Sage
  • *****
  • Posts: 1308
    • Yahoo Instant Messenger - lachie13
    • View Profile
    • The Maker Of Stuff
    • Email
Hrm...I don't think you thought about this in details...or checked the code of the latest version.

I'm already using walk sprites (basically, it's the bottom third of my main sprite) for collision with the collision layer. And collision layer objects also need to feature parts of objects in the foreground layer that are meant to be colliding, them too representing the bottom of those objects (like with the fence). As I already said (not sure if here), foreground layer represents those objects that are in level with the player (the player can be in front and behind them) and they are pasted over the base layer.

For the player to be able to appear behind and in front of them I need to loop through the foreground objects twice, once before the player pasting and once after. I don't how this can be solved without some sorting, but it's pretty much the same.

In the currently scheme it's - check for foreground sprites above the player and paste them, paste the player, check for foreground sprites below the player and paste them. With sorting it would prolly be, sort foreground sprites according to player's position, paste the first group, paste the player, paste the second group of sorted foreground sprites. The second doesn't sound better.

The only way to avoid collision layer definition I can think of is foreground tiles pointing to colliding tiles in the tileset, so I wouldn't have to manually define the collision layer. This, on the other hand, would mean forcing a certain tile arrangement format to the user (like the appropriate collision sprite following the foreground sprite in the tileset).
"Things like Basic and Free Basic provide much-needed therapy and a return to sanity and a correct appreciation of people. The arrogant folk really hate a word like 'Basic' - fine, and good riddance." ~ pragmatist

notthecheatr

  • Global Moderator
  • Forum Sage
  • *****
  • Posts: 351
  • Who's the guy from 21 Jump Street?
    • AOL Instant Messenger - notthecheatr
    • Yahoo Instant Messenger - TheMysteriousStrangerFromMars
    • View Profile
    • notthecheatr Home
    • Email
Yeah, you're probably right...
The funniest thing happened yesterday.

Xerol

  • Recruit
  • **
  • Posts: 26
    • View Profile
    • Email
Re: A screen by screen scrolling engine with a map editor (ver. 0.2) - updated!
« Reply #22 on: February 04, 2008, 09:19:31 PM »
By the way, you can make your character's speed based on the fps.  I don't bother with fps limiting, I just do it this way:

Code: [Select]
charSpeedX = speedConst/fps
charSpeedY = speedConst/fps

where speedConst is some value you'll have to experiment with to get the speed just right.

It's easy to do and it will make your character keep a consistent speed no matter the fps (you can experiment for example in different resolutions and you'll see that as the fps changes, the speed doesn't seem to.

That's highly dependent on accurate FPS calculations (which aren't always perfect). A much better way to do it is to track the time elapsed since the last frame, and then define all your speeds in units/second.

Code: [Select]
'In the beginning of the program
dim shared as double elapsed, lasttime
lasttime = timer

'Somewhere else in the setup (or loaded from config, or whatever)
dim shared as integer charspeed = 128 'pixels/sec

'main loop
do
  elapsed = timer - lasttime
  lasttime = timer

  'Rest of main loop code

  if (keys.left) then
    char.x -= charspeed*elapsed
  end if

  if (keys.right) then
    char.x += charspeed*elasped
  end if

  'etc

  flip
loop

This way you can also use multiple frames to compute the FPS (and a very momentary CPU slowdown won't send your character shooting off at .999c for a whole second). It's also easy to do variable speed this way.

Lachie Dazdarian

  • Double dipper
  • Administrator
  • Forum Sage
  • *****
  • Posts: 1308
    • Yahoo Instant Messenger - lachie13
    • View Profile
    • The Maker Of Stuff
    • Email
Yeah, time-based movement is something I need to implement, but I keep postponing that as there is always some other features to implement.

Anyway, I just realized that if I implement NPCs, I need a quite different scheme for the foreground layer drawing.

The best I could think of for now is:

First draw the ENTIRE foreground layer over the base. Sort the NPC according to their Y position (so they wouldn’t overlap each other inappropriately). Draw those above the player, draw the player, and then draw those below the player. The second time the foreground layer is drawn I would check for those foreground tiles around the player and NPCs (right, a nested FOR loop, ack!) and redraw foreground tiles "in front" of them if necessary.

Luckily, as this is a screen by screen scrolling engine and there shouldn't be really too many NPCs on one screen (20 tops), this shouldn't be too slow.

Uh-oh, another thing to play with the next weekend.
"Things like Basic and Free Basic provide much-needed therapy and a return to sanity and a correct appreciation of people. The arrogant folk really hate a word like 'Basic' - fine, and good riddance." ~ pragmatist

notthecheatr

  • Global Moderator
  • Forum Sage
  • *****
  • Posts: 351
  • Who's the guy from 21 Jump Street?
    • AOL Instant Messenger - notthecheatr
    • Yahoo Instant Messenger - TheMysteriousStrangerFromMars
    • View Profile
    • notthecheatr Home
    • Email
First draw the ENTIRE foreground layer over the base. Sort the NPC according to their Y position (so they wouldn’t overlap each other inappropriately).

Inappropriate NPC overlap!  This sounds very interesting!
The funniest thing happened yesterday.

Lachie Dazdarian

  • Double dipper
  • Administrator
  • Forum Sage
  • *****
  • Posts: 1308
    • Yahoo Instant Messenger - lachie13
    • View Profile
    • The Maker Of Stuff
    • Email
Hey! Don't mock my English!

Well, maybe I deserved it. :P

I have no idea why I didn't use the word «incorrectly». Bah.
"Things like Basic and Free Basic provide much-needed therapy and a return to sanity and a correct appreciation of people. The arrogant folk really hate a word like 'Basic' - fine, and good riddance." ~ pragmatist

notthecheatr

  • Global Moderator
  • Forum Sage
  • *****
  • Posts: 351
  • Who's the guy from 21 Jump Street?
    • AOL Instant Messenger - notthecheatr
    • Yahoo Instant Messenger - TheMysteriousStrangerFromMars
    • View Profile
    • notthecheatr Home
    • Email
Re: A screen by screen scrolling engine with a map editor (ver. 0.2) - updated!
« Reply #26 on: February 07, 2008, 04:38:36 PM »
By the way, you can make your character's speed based on the fps.  I don't bother with fps limiting, I just do it this way:

Code: [Select]
charSpeedX = speedConst/fps
charSpeedY = speedConst/fps

where speedConst is some value you'll have to experiment with to get the speed just right.

It's easy to do and it will make your character keep a consistent speed no matter the fps (you can experiment for example in different resolutions and you'll see that as the fps changes, the speed doesn't seem to.

That's highly dependent on accurate FPS calculations (which aren't always perfect). A much better way to do it is to track the time elapsed since the last frame, and then define all your speeds in units/second.

Code: [Select]
'In the beginning of the program
dim shared as double elapsed, lasttime
lasttime = timer

'Somewhere else in the setup (or loaded from config, or whatever)
dim shared as integer charspeed = 128 'pixels/sec

'main loop
do
  elapsed = timer - lasttime
  lasttime = timer

  'Rest of main loop code

  if (keys.left) then
    char.x -= charspeed*elapsed
  end if

  if (keys.right) then
    char.x += charspeed*elasped
  end if

  'etc

  flip
loop

This way you can also use multiple frames to compute the FPS (and a very momentary CPU slowdown won't send your character shooting off at .999c for a whole second). It's also easy to do variable speed this way.

Yes, that is much better, especially since it doesn't require division like mine does :P
The funniest thing happened yesterday.

Lachie Dazdarian

  • Double dipper
  • Administrator
  • Forum Sage
  • *****
  • Posts: 1308
    • Yahoo Instant Messenger - lachie13
    • View Profile
    • The Maker Of Stuff
    • Email
Ok, a new version.

I implemented NPCs (they are on the third screen to the right) and a very smart method to sort the foreground objects, the player and NPCs so they would cover each other correctly according to their Y positions.

Nothing new beside that, but that thing was a big step and I quite like the new code.

I plan now to create an infrastructure for implementing/managing NPCs.
"Things like Basic and Free Basic provide much-needed therapy and a return to sanity and a correct appreciation of people. The arrogant folk really hate a word like 'Basic' - fine, and good riddance." ~ pragmatist

ShadowLoneWolf

  • Amoeba
  • *
  • Posts: 8
    • View Profile
    • Email
Re: A screen by screen scrolling engine with a map editor (ver. 0.4) - 09.02.08
« Reply #28 on: February 09, 2008, 03:06:18 PM »
nice improvement; it's good that you corrected that, I'd hate to dig into code just to fix that...I'd hate to dig into code to fix anything! lol.
 keep up the good work, looking forward to see any screen shots.

Eponasoft

  • Guest
Re: A screen by screen scrolling engine with a map editor (ver. 0.4) - 09.02.08
« Reply #29 on: February 09, 2008, 03:09:48 PM »
Nice work, Lachie. Some collision softening might be in order, but otherwise a very solid piece of work.

My only suggestion would be to implement early Zelda-type scrolling between areas. That would give a real classy feel to it.