Page 1 of 1

Testmap issues, and printing letter by letter???

Posted: Mon Aug 19, 2013 3:58 pm
by FatalMarshmallow
Again entirely followed on from the Gridlocked Player tutorial, it's easy enough to check where the player is moving, but how do you check if they can do something where they are already standing. How would you make it so that if the player is standing in a certain type of tile and a certain key is pressed that it would display a message?
And also on a similar topic, how could I make it print the message letter by letter?
As always, any help is appreciated. :3

Re: Testmap issues, and printing letter by letter???

Posted: Mon Aug 19, 2013 4:03 pm
by raidho36
First question is easy:

Code: Select all

if love.keyboard.isDown ( "escape" ) and tiles[x][y].type == "ThisTileQuitsTheGameOnEscape" then love.event.push ( "quit" ) end
The second one is way too general to even start to explaining. You need to be more specific. For this kind of vague question, I can only give vague answer: send to print function only a part of the string via string.sub:

Code: Select all

love.graphics.print ( textstring:sub ( 1, numberOfCharsToDisplay ), x, y )

Re: Testmap issues, and printing letter by letter???

Posted: Mon Aug 19, 2013 4:22 pm
by FatalMarshmallow
raidho36 wrote:First question is easy:

Code: Select all

if love.keyboard.isDown ( "escape" ) and tiles[x][y].type == "ThisTileQuitsTheGameOnEscape" then love.event.push ( "quit" ) end
The second one is way too general to even start to explaining. You need to be more specific. For this kind of vague question, I can only give vague answer: send to print function only a part of the string via string.sub:

Code: Select all

love.graphics.print ( textstring:sub ( 1, numberOfCharsToDisplay ), x, y )
Where would I put these in MY code? I understand that I need to tell it which tile to stand on, but in which function?

Also, sorry for the vagueness of the second question, when I say print a message letter by letter I mean like in one of those old spy movies, where the date and location appear as if they were being typed.
Thanks for the help anyway. :ultraglee:

Re: Testmap issues, and printing letter by letter???

Posted: Tue Aug 20, 2013 8:46 am
by raidho36
Where would I put these in MY code?
Look, I don't want to be rude (although I will), but how do you expect me to know where do you put it in your code? Just put it wherever it's appropriate. Draw function? Keypress function? Update function? I can't tell. Depends on your code and however you see it.
in one of those old spy movies, where the date and location appear as if they were being typed
If you merely want that, then what I suggested was pretty much spot-on, minus you'd better store mid-animation text somewhere rather than use string:sub every time you render your text, because in Lua strings are immutable and blah blah yadda yadda you better store every single result of stirng operation to a variable if you're gonna reuse it.

Re: Testmap issues, and printing letter by letter???

Posted: Tue Aug 20, 2013 11:23 am
by Robin
FatalMarshmallow wrote:Where would I put these in MY code?
The first goes somewhere in love.update or a function called by love.update. The second goes somewhere in love.draw or in a function called by love.draw.
FatalMarshmallow wrote:I understand that I need to tell it which tile to stand on, but in which function?
Use

Code: Select all

map[player.grid_y / 16][player.grid_x / 16]
and compare it to whatever it needs to be.
FatalMarshmallow wrote:Also, sorry for the vagueness of the second question, when I say print a message letter by letter I mean like in one of those old spy movies, where the date and location appear as if they were being typed.
Thanks for the help anyway. :ultraglee:
After a time, increase numberOfCharsToDisplay. I'll show you a minimal example:

Code: Select all

function love.load()
    textToDisplay = "VICTORY" -- or, you know, whatever
    numberOfCharsToDisplay = 0
    timePassed = 0
    timeForEachChar = 0.2 --seconds
end

function love.update(dt)
    timePassed = timePassed + dt
    if timePassed >= timeForEachChar then
         timePassed = timePassed - timeForEachChar
         numberOfCharsToDisplay = numberOfCharsToDisplay + 1
    end
end

function love.draw()
    love.graphics.print(textToDisplay:sub ( 1, numberOfCharsToDisplay ), 10, 10)
end