First time with LÖVE

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
IronCrab
Prole
Posts: 2
Joined: Tue Jul 14, 2015 10:36 pm

First time with LÖVE

Post by IronCrab »

New to the forum here, so hello everyone. I've been coding for awhile (year perhaps, just a hobby, nothing serious) in C++, and I've decided to create a game using SDL library, resulting in a enormous mess, and loads of unexplainable errors :? . Instead of giving up I moved into LUA because of it's simplicity and usage in scripts, with "LÖVE" framework just yesterday ago, since a simple 2d platformer does not need to be this complex. I've read some of the tutorials, got that hamster one working fine, but mine attempts of "juicing" it up kind of failed, and I was wondering if I would find some help on this forum.

For instance, a trace of the .png whenever hamster is moving at any direction, in random colors then disappearing in a short time. I made a variable in love.load() called:

Code: Select all

rand = math.rand(1,255)
put the setColor command, in the update function in every input:

Code: Select all

	if love.keyboard.isDown("direction") then
	love.graphics.setColor(rand,rand,rand,255)
	love.graphics.draw(ham, x, y)
	x or y = x or y + (speed*dt)
	end
and it just doesn't work. Should it create a new png file instead and delete it if the alpha hits zero? If yes then how do I implement that? Complete newbie here, i just have no idea. I was thinking about setting up boundaries too, by detecting if upper, lower, left or right side of the screen is either at 0 or maximum, but I just don't know how.
Yes, English is my second language, in case I messes up some grammar or didn't made any sense.
I would be very thankful if anyone could help.
User avatar
Crossing
Prole
Posts: 42
Joined: Sat Mar 21, 2015 3:37 pm

Re: First time with LÖVE

Post by Crossing »

First, welcome to LÖVE.

Second, whenever you need help it better to upload a .love file so we can look through your code.

To create boundarys is pretty simple, a picture is a square.
Squares have 4 points.

Top left point - x,y
Top right - x+width,y
Bottom left - x,y+height
Bottom right - x+width,y+height

So lets say you have a window thats 500px by 500px, meaning 500 wide 500 tall.
Now lets say our picture is 32x32
Lets set those into variables.

Code: Select all

picture = {} --setting picture to a table to hold values
picture.x = 250 -- setting player x value to middle of screen
picture.y = 250 -- setting player y value to middle of screen
picture.width = 32 -- setting width
picture.height = 32-- setting height
That should go in you love.load or your player file

Now we have the begining to a simple collision system, however checking boundarys is alot easier.

First lets see where this x is, if its less then 0 its gone to far!

Put this in your update.love

Code: Select all

 
if picture.x < 0 then picture.x = 0 end -- so if picture tries to go to far left it cant!
Now lets do the same for the other side and the top and bottom.

Code: Select all

if picture.x < 0 then picture.x = 0 end
if picture.y < 0 then picture.y =  0 end
if picture.x + picture.width > 500 then picture.x = 500 - picture.width end
if picture.y + picture.height > 500 then picture.y = 500 - picture.height end
Remember that goes in update.

So whats left? Drawing your picture and making it move.
Make sure when drawing you use picture.x and picture.y as the x and y of the image.
Put the picture under picture.pic like this.

Code: Select all

picture.pic = love.graphics.newImage("whatever.png")
Also put that in love.load after you set picture to a table.

Then just create your movement using love.keyboard.isDown("") and make it update the picture.x and picture.y

Hope this helped i probs should have changed name of the var picture but was im at work not much time to think of var names.
User avatar
Linkpy
Party member
Posts: 102
Joined: Fri Aug 29, 2014 6:05 pm
Location: France
Contact:

Re: First time with LÖVE

Post by Linkpy »

Code: Select all

    local rand = math.rand(1,255) --Place this line in the same function.

   if love.keyboard.isDown("direction") then
   love.graphics.setColor(rand,rand,rand,255)
   love.graphics.draw(ham, x, y)
   x or y = x or y + (speed*dt)
   end
And...

Code: Select all

x or y = x or y + (speed*dt)
What ? :crazy:

Did you mean :

Code: Select all

x, y = x, y + (speed*dt)
? :?
Founder of NeoShadow Studio. Currently working on the project "Sirami".
github / linkpy
IronCrab
Prole
Posts: 2
Joined: Tue Jul 14, 2015 10:36 pm

Re: First time with LÖVE

Post by IronCrab »

Linkpy wrote:

Code: Select all

    local rand = math.rand(1,255) --Place this line in the same function.

   if love.keyboard.isDown("direction") then
   love.graphics.setColor(rand,rand,rand,255)
   love.graphics.draw(ham, x, y)
   x or y = x or y + (speed*dt)
   end
And...

Code: Select all

x or y = x or y + (speed*dt)
What ? :crazy:

Did you mean :

Code: Select all

x, y = x, y + (speed*dt)
? :?

Yeah, my whole experience with programming feels more like a month rather than a year. :| But thank you Crossing for your help :awesome:. Guess I just have to experiment more with this framework :o:.

I tried to create a particle effect, that would let me print out six stars falling down at the same spot whenever I pressed LMB, but it didn't went well. They just stacked up, and I can't use the delta time to update the values. I looked up at source codes of some games from wiki, tried the tutorials, and i don't know, maybe I'm just a terrible programmer :?. Are there any demos (not as unfinished games) that show up some of the features of LÖVE? Here's the .love file, tho.
Attachments
wha.love
(15.64 KiB) Downloaded 102 times
User avatar
Crossing
Prole
Posts: 42
Joined: Sat Mar 21, 2015 3:37 pm

Re: First time with LÖVE

Post by Crossing »

Whenever i get off from work ill try to find some of mine. It will be 4-5 hours though.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 4 guests