Some newbie questions...

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
c00ld00d
Prole
Posts: 5
Joined: Wed Jan 18, 2012 6:56 am

Some newbie questions...

Post by c00ld00d »

Hi, I'm new to this forum ( and also to LÖVE ) but I've been programming a form of Lua for 2 years. I have a few questions before I can continue making my game..

Q1: What is the LÖVE cnosole and how do I get it?

Q2: How do I make a .love file(I know it's a renamed .zip file, I don't know how to change the classfile, I'm on Windows XP)

Q3: How would I sprite my characters and objects?

Q4: How do I loop my background music? ( I don't want the player to push P again when the music is finished... )

Q5: How would I change the resolution? (I've already tried this in the conf.lua:

function love.conf(a)
a.title = "Some platformer"
a.height = 640
a.width = 480
end

but that didn't work, as it stayed on 800x600 )

Q6: How to make a message appear and dissappear by pushing a key/clicking a button? (I know how to make one appear: love.graphics.print("msg",x,y) )

And that was all. Thanks for helping in advance!
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Some newbie questions...

Post by Robin »

c00ld00d wrote:Q1: What is the LÖVE cnosole and how do I get it?
I'm not sure what you mean, but I think you're talking about the terminal (cmd.exe, pretty much). In love.conf(), put a.console = true. Use print() in your game to print out some things to the console window.
c00ld00d wrote:Q2: How do I make a .love file(I know it's a renamed .zip file, I don't know how to change the classfile, I'm on Windows XP)
There is a setting in Windows XP called "hide file name extensions". You need to disable that. It's in the settings for Windows Explorer somewhere, I think.
c00ld00d wrote:Q3: How would I sprite my characters and objects?
love.graphics.newImage
love.graphics.draw
c00ld00d wrote:Q4: How do I loop my background music? ( I don't want the player to push P again when the music is finished... )
Source:setLooping
c00ld00d wrote:Q5: How would I change the resolution? (I've already tried this in the conf.lua:
Almost, but you should use:

Code: Select all

function love.conf(a)
  a.title = "Some platformer"
  a.screen.height = 640
  a.screen.width = 480
end
Trips me up all the time.
c00ld00d wrote:Q6: How to make a message appear and dissappear by pushing a key/clicking a button? (I know how to make one appear: love.graphics.print("msg",x,y) )
Wrap it in an if statement:

Code: Select all

if something then
   love.graphics.print("msg",x,y) )
end
And see love.keypressed, love.keyreleased, love.mousepressed, love.mousereleased

Hope this helps.
Help us help you: attach a .love.
c00ld00d
Prole
Posts: 5
Joined: Wed Jan 18, 2012 6:56 am

Re: Some newbie questions...

Post by c00ld00d »

@Robin

Wow, thanks a lot! But still a problem with how to make a message appear and dissappear. What you showed me is if something equals true or false(in an if statement to check the condition), it'll print my message. But my question was; how would I remove my message after it was printed on the screen?

EDIT:

Oh and, I tried spriting but it doesn't draw the image on the screen? And it lags horribly. How would I create an image as background or as sprite for a character/object? If it's possible: can you show me a piece of code showing how to create an image?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Some newbie questions...

Post by Robin »

c00ld00d wrote:Wow, thanks a lot! But still a problem with how to make a message appear and dissappear. What you showed me is if something equals true or false(in an if statement to check the condition), it'll print my message. But my question was; how would I remove my message after it was printed on the screen?
That happens automatically: the screen is cleared each frame.
c00ld00d wrote:Oh and, I tried spriting but it doesn't draw the image on the screen? And it lags horribly. How would I create an image as background or as sprite for a character/object? If it's possible: can you show me a piece of code showing how to create an image?
Don't create an image each frame, only in love.load():

Code: Select all

function love.load()
   someImage = love.graphics.newImage('image.png') -- or what the name of your image is
end

function love.draw()
  love.graphics.draw(someImage, 0, 0) --draws the image in the top-left corner
end
Help us help you: attach a .love.
c00ld00d
Prole
Posts: 5
Joined: Wed Jan 18, 2012 6:56 am

Re: Some newbie questions...

Post by c00ld00d »

@Robin

I don't understand what you said that the print message dissappears in a new frame. This is the code I have:

Code: Select all


function love.draw()
 -- bgi = love.graphics.newImage("Background.png") where I tried to make a background, I'll fix it later.
  love.graphics.setBackgroundColor(0,170,200)
  love.graphics.setColor(0,255,20) -- block color
  for y=1,#map do
    for x=1,#map[y] do
      if map[y][x] == 1 then
        love.graphics.rectangle("fill",x*CELLSIZE,y*CELLSIZE,CELLSIZE,CELLSIZE)
      else
        if DEBUG then
          love.graphics.rectangle("line",x*CELLSIZE,y*CELLSIZE,CELLSIZE,CELLSIZE)
        end
      end
    end
  end
  love.graphics.setColor(255,255,255) -- 255,0,0,128 = red
  love.graphics.rectangle("fill",Player.x,Player.y,PLAYERSIZE, PLAYERSIZE)
---NOTE TO SELF: Make message dissappear when spacebar is pressed
  love.graphics.print("Press Space bar to begin!",200,200) ----------------------------HERE
  if DEBUG then
    love.graphics.setColor(0,255,0)
    love.graphics.print(string.format("Player at (%06.2f , %06.2f) jumping = %s falling = ", Player.x, Player.y, tostring(Player.jumping), tostring(Player.falling)), 50,0)
    love.graphics.print(string.format("Player occupies cells(%d): %s", #Player.Cells, table.concat(Player.Cells, ' | ')), 450,0)
  end
end
And here's the jump section(when spacebar is pressed):

Code: Select all

local isDown = love.keyboard.isDown
function playermove(dt)

  local newX, newY
  if isDown("a") then
    newX=Player.x-Player.S*dt
  end
  if isDown("d") then 
    newX=Player.x+Player.S*dt
  end
  if newX then 
    local offmap=isOffMap(newX, Player.y)
    local colliding=isColliding(playerOnCells(newX, Player.y))
    if not offmap and not colliding then
      Player.x=newX
    end
  end


  Player.G = Player.G + Player.S*dt

  if not Player.jumping and isDown(" ") and not Player.falling then -- JUMPING PART
	jmps = love.audio.newSource("Jump.wav") 
    love.audio.play(jmps,"stream",true)
    Player.jumping = true
    Player.G = -120 -- note to self: originally -100
  end

    
  newY= Player.y + Player.G*dt 

  local coll=isColliding(playerOnCells(Player.x, newY))
  if coll then
    if Player.G>=0 then 
      Player.jumping=false
      Player.falling=false
    end
    Player.G=0
  else
    Player.falling=true 
  end

  if not isOffMap(Player.x, newY) and not coll then
    Player.y=newY
  end
  if DEBUG then
    Player.Cells=playerOnCells(Player.x, Player.y) 
  end
end
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Some newbie questions...

Post by Robin »

Make it say:

Code: Select all

if not Player.jumping then
    love.graphics.print("Press Space bar to begin!",200,200)
end
Also, when the player presses space, you create a new source. That is bad. Create the source in love.load() (where you also need to load the background image) and only play it when the player presses space.
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: No registered users and 230 guests