Creating a 2.5d game

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
pactace
Prole
Posts: 38
Joined: Fri Jan 30, 2015 1:25 am

Creating a 2.5d game

Post 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
Very new programmer dont judge
User avatar
Jeeper
Party member
Posts: 611
Joined: Tue Mar 12, 2013 7:11 pm
Contact:

Re: Creating a 2.5d game

Post by Jeeper »

No.

But seriously, there is no reasonable question here. How should we know what you should or should not do.
User avatar
Calandriel
Prole
Posts: 39
Joined: Wed Apr 22, 2015 9:00 am

Re: Creating a 2.5d game

Post 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 :)
If violence is not solving all your problems, You're simply not using enough of it.
Twitter: https://twitter.com/Calandriell Some news about wtf I'm doing.
Tumblr:https://www.tumblr.com/blog/calandriell I use to draw some random stuff.
User avatar
bluedudex2
Prole
Posts: 11
Joined: Thu Aug 27, 2015 8:56 am

Re: Creating a 2.5d game

Post 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.
Attachments
main.love
(531 Bytes) Downloaded 162 times
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Creating a 2.5d game

Post 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)
User avatar
bluedudex2
Prole
Posts: 11
Joined: Thu Aug 27, 2015 8:56 am

Re: Creating a 2.5d game

Post 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!
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Creating a 2.5d game

Post 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.
User avatar
bluedudex2
Prole
Posts: 11
Joined: Thu Aug 27, 2015 8:56 am

Re: Creating a 2.5d game

Post 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)
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Creating a 2.5d game

Post 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?
User avatar
bluedudex2
Prole
Posts: 11
Joined: Thu Aug 27, 2015 8:56 am

Re: Creating a 2.5d game

Post 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)
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 43 guests