Testmap issues, and printing letter by letter???

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
FatalMarshmallow
Prole
Posts: 17
Joined: Mon Jul 30, 2012 9:15 pm

Testmap issues, and printing letter by letter???

Post 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
Attachments
Example.love
(1.61 KiB) Downloaded 127 times
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

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

Post 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 )
FatalMarshmallow
Prole
Posts: 17
Joined: Mon Jul 30, 2012 9:15 pm

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

Post 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:
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

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

Post 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.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

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

Post 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
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 3 guests