some basic tips.

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.
Post Reply
User avatar
baconhawka7x
Party member
Posts: 491
Joined: Mon Nov 21, 2011 7:05 am
Location: Oregon, USA
Contact:

some basic tips.

Post by baconhawka7x »

Me AGAIN i know.."This baconhawka7x is such a bastard for posting so many questions on the support forums!" well im sorry! hehe, i just have a few questions.
I am making a 2d game, you start out on a flat grass plane (ITS tiles) and theres a store to your left and a cave to your right, on the first level it is mandatory to go into the store first. You walk in and recieve a wooden sword and pickaxe(for free). You leave the store and enter the cave. The cave is a dungeon, full of goblins evil skelotons and zombies. It is mainly vertical and you goal is to reach the bottom. As you go down through the 48 x 48 stone blocks you may see some diamond in the wall, you can mine it with your wooden pickaxe, and with that diamond you can buy stuff at the store!

So my idea is that there is a survival mode; You go through as many randomly generated dungeons as possible.
and an arcade mode; You go through 20-30 premade levels with an amazing surprise boss.

so far i have a flat grass tile map, character animations, and all the player can do is move left or right

I have a few questions..
I have been having trouble trying to make the character jump. I know how to make a timer, but I couldn't quite get it right. I tried saying..

Code: Select all

if lovekeyboard.isDown("w") then
               gravity = false
               timer_jumping = timer_jumping + dt
blah blah blah
i also tried instead of gravity = false, jumping = true, still i just cant quite get the timers right. So if someone could please help me with that i would love you for ever!

Another thing is collisions with my tilemaps. Ive tried everything. But then i looked at a forum post where someone said something like.
"set the property list for tiles,with a bolean being ''solid = true or solid = false''" and stuff like that. I also saw someone talk about
"check if the block is occupied" but im unsure of how to set the properties for either of those. But if i could im sure i could figure out the rest on my own.
Although i don't mind detailed advice ^.^

Some bits of code are...

Tile map layout...

Code: Select all

tiletable1={
	{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
	{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
	{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
	{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
	{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
	{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
	{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
	{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
	{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
	{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
	{ 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
	{ 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
	{ 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
	{ 2,2,2,2,2,2,2,2,2,2,3,2,2,2,2,2,2,2,2,2},
	{ 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
	{ 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2}
Tilemap display...

Code: Select all

for rowIndex=1, #tiletable1 do
		local row = tiletable1[rowIndex]
			for columnIndex=1, #row do
				local number = row[columnIndex]
				love.graphics.draw(tiles[number], (columnIndex-1)*48, (rowIndex-1)*48)
			end
	end
and player movement is basically..

Code: Select all

if love.keyboard.isDown("(whatever)") then
        steve.x = steve.x + steve.speed * dt
and then theres some other stuff inside of love.update(dt) for the animations!

please help me i will love you forever!
Last edited by baconhawka7x on Thu Dec 15, 2011 2:52 pm, edited 2 times in total.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: 2d tile dungeon taker!(help please!)

Post by Robin »

baconhawka7x wrote:I have been having trouble trying to make the character jump. I know how to make a timer, but I couldn't quite get it right. I tried saying..

Code: Select all

if lovekeyboard.isDown("w") then
               gravity = false
               timer_jumping = timer_jumping + dt
blah blah blah
i also tried instead of gravity = false, jumping = true, still i just cant quite get the timers right. So if someone could please help me with that i would love you for ever!
What works really depends on the rest of your code, so it would be really hard to say. How I usually do things like that is:

Code: Select all

love.update(dt)
    ... other things
    if love.keyboard.isDown "w" and not jumping then
        jumping  = true
        timer_jumping = 0
    end
    if jumping then
        timer_jumping = timer_jumping + dt
        if timer_jumping > TIME_JUMP then
             jumping = false
        end
    end
   ... other things
end
You would handle the jumping itself somewhere else then.
baconhawka7x wrote:Another thing is collisions with my tilemaps. Ive tried everything. But then i looked at a forum post where someone said something like.
"set the property list for tiles,with a bolean being ''solid = true or solid = false''" and stuff like that. I also saw someone talk about
"check if the block is occupied" but im unsure of how to set the properties for either of those. But if i could im sure i could figure out the rest on my own.
Although i don't mind detailed advice ^.^
Ehm, what is the question here?
Help us help you: attach a .love.
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: 2d tile dungeon taker!(help please!)

Post by Taehl »

For jumping, you really need to track your player's velocity. Instead of changing their position each frame based on what key is pressed, you move them based on their velocity. Then you have a few simple rules, such as "y velocity constantly increases" and "x value constantly slows", to account for gravity and friction. Lastly, to jump, you just set the y velocity to a relatively high negative number. You'll go up, and as the y velocity gets more and more positive, you'll slow and then fall.

For colliding with tiles... Well, there's a lot of ways to do it. In my game Underlife, I'm using a pretty sophisticated technique. It goes like this:
All tiles are stored in a map table, which contains tables for all rows with tiles. Tiles themselves can be a table or a number, whatever you need. The point is, you express it in form of map[x][y] = tile. The coordinates work best if you use integers (-1, 0, 1, 2...). If there's no tile there, then make sure the tile is nil. For collision, you just see if map[x][y] is true or not. So to check for collisions downward (i.e., standing on a tile), you say something like "if map[math.round(player.x)][math.ceil(player.y)] then -- whatever, presumably push the player up if needed and set y velocity to 0".

Sorry I can't walk you through it more and give a full code example, I'm in a bit of a rush. Good luck! If you don't understand, I'll try to explain it more later.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
baconhawka7x
Party member
Posts: 491
Joined: Mon Nov 21, 2011 7:05 am
Location: Oregon, USA
Contact:

Re: 2d tile dungeon taker!(help please!)

Post by baconhawka7x »

Ehm, what is the question here?
i just dont want the player to be able to walk through blocks
User avatar
baconhawka7x
Party member
Posts: 491
Joined: Mon Nov 21, 2011 7:05 am
Location: Oregon, USA
Contact:

Re: 2d tile dungeon taker!(help please!)

Post by baconhawka7x »

What works really depends on the rest of your code, so it would be really hard to say. How I usually do things like that is:

Code: Select all

love.update(dt)
    ... other things
    if love.keyboard.isDown "w" and not jumping then
        jumping  = true
        timer_jumping = 0
    end
    if jumping then
        timer_jumping = timer_jumping + dt
        if timer_jumping > TIME_JUMP then
             jumping = false
        end
    end
   ... other things
end
You would handle the jumping itself somewhere else then.[/quote]
The only reason that wont work is because if they hold down "w" then they will just keep going up. And im guessing thats what you ment by "other stuff", but im unsure how to do that
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: 2d tile dungeon taker!(help please!)

Post by Robin »

baconhawka7x wrote:i just dont want the player to be able to walk through blocks
The only answer I have now is: check the positions of the blocks and the player's position and check if they overlap. What you need to do exactly depends on your code. (How do you store the blocks? What kind of movement does the player have? etc.)
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], rabbitboots and 85 guests