Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: leafy on January 21, 2011, 12:06:35 am

Title: Physics Tilemapper
Post by: leafy on January 21, 2011, 12:06:35 am
I've thought about it for a long time, but I can't figure out how to do it. How do you make a tilemapper scroll both horizontally and vertically but retain physics elements like gravity?
Sample code would be nice.
Thanks in advance.
Title: Re: Physics Tilemapper
Post by: Masinini on January 21, 2011, 04:35:16 pm
I have never done this personally. So I'm just gonna post what I would do. I would have your character in the middle of the screen, and stay there. When you move, the screen scrolls, instead of you actually moving. Then, when your guy falls, he just need to scroll when he falls, and add in code so he can move sideways. If this seems, confusing, sorry, but it's the simplest way that I could figure through my limited experience.
Title: Re: Physics Tilemapper
Post by: Ashbad on January 21, 2011, 04:40:30 pm
I can say a few things, though codewise it's not like a little thing; it could be dozens and dozens of lines just for the mapper/configurer.  But I can give some hints:

- Don't use horizontal/vertical commands, they are VERY slow; use an offset as a way of scrolling instead.
- While scrolling with your char moving around the screen at the same time is very nice, it can be slow too, and very complicated.  Don't take that on unless you really know what you're doing.
- For collision detection (and for the physics part) I'm sure you'll use velocities to move the character, like if the Y velocity is 2 then the character moves down 2 pixels next redraw.  Use a For(Var, 0, amount of pixels you'll move) statement to check all possible positions along the way of the movement and to also make sure you don't fall through floors when you move at increments of more than one pixel at a time.
Title: Re: Physics Tilemapper
Post by: Binder News on January 21, 2011, 04:41:54 pm
Attached is the source for my solution to the problem.
I wrote it for the game I'm working on, but you can use it, just credit me.
Title: Re: Physics Tilemapper
Post by: leafy on January 21, 2011, 06:02:16 pm
kthx all. I'm viewing this more of a challenge than an actual project, though if I get it i'll use it in Graviter.
Title: Re: Physics Tilemapper
Post by: leafy on January 21, 2011, 07:09:58 pm
I was thinking more of something along the lines of tloz's platformer:
http://www.omnimaga.org/index.php?action=dlattach;topic=4479.0;attach=3319

I'm going to examine the code and try to understand it more.
Title: Re: Physics Tilemapper
Post by: Builderboy on January 22, 2011, 03:10:29 am
- Don't use horizontal/vertical commands, they are VERY slow; use an offset as a way of scrolling instead.

Correct me if i'm wrong, but I believe there is tilemapper posted in the tilemapper thread by Runner that used horizonal and vertical commands that got 60 FPS :)

Regular 8x8 monochrome seems to work pretty fast for me. I get about 60 fps scrolling for the most part (about 75 for aligned vertical scrolling). The screen is updated after every arrow key has been checked and the buffer image has been scrolled for each pressed key.

(http://www.omnimaga.org/index.php?action=dlattach;topic=5168.0;attach=4318;image)
Title: Re: Physics Tilemapper
Post by: Binder News on January 22, 2011, 10:10:23 am
Yup, however, I don't really get his code (It can be kinda weird), and it doesn't have physics.
Title: Re: Physics Tilemapper
Post by: leafy on January 22, 2011, 12:53:22 pm
So would using horizontal and vertical, then filling in the missing tiles be faster than regenerating the map every frame? what's the most optimized method?
Title: Re: Physics Tilemapper
Post by: Binder News on January 22, 2011, 02:48:11 pm
If you're going for size, regenerate the map every frame. However, doing that means that the bigger the map, the longer it takes to draw. (That's only if you are drawing the whole map. If you find a way to only draw the tiles which are on-screen, it would be faster).

The fastest way (I think) would be to use Horizontal and Vertical, then fill in the missing tiles.
Title: Re: Physics Tilemapper
Post by: Builderboy on January 22, 2011, 02:56:09 pm
I believe Runner posted the source to his program in a different point in that topic so you could check it out or even ask him if you could use it :D
Title: Re: Physics Tilemapper
Post by: leafy on January 22, 2011, 06:07:26 pm
Okay, I don't get the code (This is from tloz's tilemapper) attached in the word document - If someone could elucidate that would be great.
Title: Re: Physics Tilemapper
Post by: leafy on January 24, 2011, 02:19:18 am
Okay, I made one using BuilderBoy's algorithm and mapping it every single frame. It's acceptable on full, but lags on normal.
Run DRAW.8xp, the rest are source.
Title: Re: Physics Tilemapper
Post by: leafy on January 24, 2011, 05:42:52 pm
Sorry about the triple post (My bad) but I'm still kind of confused as to how to do tile detection for collisions with platforms. I'll attach my attempts (first value x+z, second value y+theta, third value collision tile value) also you need the dependencies in the previous post to compile. If anybody could help that would be great.