Page 1 of 2

Creating a 2.5d game

Posted: Wed Dec 02, 2015 12:00 am
by pactace
So I am going to making a beat em up so do I need to make a small restricted area where the characters can move up and down and left to right

Re: Creating a 2.5d game

Posted: Wed Dec 02, 2015 12:51 am
by Jeeper
No.

But seriously, there is no reasonable question here. How should we know what you should or should not do.

Re: Creating a 2.5d game

Posted: Wed Dec 02, 2015 1:44 am
by Calandriel
You can use meshes to draw your textures, and draw every vertex with algebra that will help you simulate the distortion. Im planning to use something like this:
http://www.flipcode.com/archives/Plotti ... reen.shtml
but I believe that you dont really need this in your game. all you need is check if the entities(player, enemies) are at a same height. if higher, then you're behind them, if lower, you're in front. It's really simple. Btw, could you be more specific about the features you want in your game :)

Re: Creating a 2.5d game

Posted: Thu Dec 03, 2015 11:55 am
by bluedudex2
You can check this quick file I made. The base code to make the player stay where you want him is

Code: Select all

	if player_x < 100 then
		player_x = 100
	elseif player_x + player_w > 700 then
		player_x = 700 - player_w
	end 
	if player_y + player_h < 400 then
		player_y = 400 - player_h
	elseif player_y + player_h > 500 then
		player_y = 500 - player_h
	end
In the demo, it is basically saying if character's Y + it's height goes over (or bellow) the upper Y and lower Y of the blue box then keep him within that box. Hopefully it makes sense and I added an X bound as well but that is not required for what you want. So with collision instead of thinking about it as a 3d plane think about it as boxes on a 2d plane and drawing graphics to give the illusion of depth.

And BTW I hard coded quite a bit with this code and it may be a bit sloppy but I just wanted to get the basic idea across.

Re: Creating a 2.5d game

Posted: Thu Dec 03, 2015 8:35 pm
by Jasoco
bluedudex2 wrote:

Code: Select all

	if player_x < 100 then
		player_x = 100
	elseif player_x + player_w > 700 then
		player_x = 700 - player_w
	end 
	if player_y + player_h < 400 then
		player_y = 400 - player_h
	elseif player_y + player_h > 500 then
		player_y = 500 - player_h
	end
This should accomplish the same thing: (Untested)

Code: Select all

player_x = math.max(math.min(player_x, 700 - player_w), 100)
player_y = math.max(math.min(player_y, 500 - player_h), 400)

Re: Creating a 2.5d game

Posted: Fri Dec 04, 2015 4:08 am
by bluedudex2
Jasoco wrote: This should accomplish the same thing: (Untested)

Code: Select all

player_x = math.max(math.min(player_x, 700 - player_w), 100)
player_y = math.max(math.min(player_y, 500 - player_h), 400)
Like I said, I just made sloppy prof of concept. :)
Anyway, I always forget about the basic math functions like math.min/max, that is way simpler!

Re: Creating a 2.5d game

Posted: Fri Dec 04, 2015 4:53 am
by Jasoco
Test it first and make sure it works the same way but I'm pretty confident that should be exactly the same outcome. Don't ask if there's any performance loss. Most likely not.

You could also simplify it more if you create a clamp function and use that instead.

Re: Creating a 2.5d game

Posted: Sat Dec 05, 2015 4:11 am
by bluedudex2
Couldn't get around to testing it until now and when I do try it, it keeps throwing up an error saying: Bad argument #1 to 'min' (number expected, got nil)

Re: Creating a 2.5d game

Posted: Sat Dec 05, 2015 6:41 am
by Jasoco
The first argument in math.min is the player position. The fault lies with your code. Are you making sure player_x and player_y are actually number values first?

Re: Creating a 2.5d game

Posted: Sat Dec 05, 2015 1:16 pm
by bluedudex2
Jasoco wrote:The first argument in math.min is the player position. The fault lies with your code. Are you making sure player_x and player_y are actually number values first?
Stupid mistake on my part. The code works but I edited so that the bottom of the player stops when it hits the top of the blue square (well at least giving the illusion of the bottom of the player stopping at the top of the blue square)

Code: Select all

player_x = math.max(math.min(player_x, 700 - player_w), 100)
player_y = math.max(math.min(player_y, 500 - player_h), 400 - player_h)