score counter and putting objects to collect

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.
Saltyham
Prole
Posts: 7
Joined: Wed Jul 10, 2013 6:23 pm

score counter and putting objects to collect

Post by Saltyham »

Hello everyone I've just recently started using love2d and being a coding novice how would I put a score counter and what would be the quickest way to put down Items that disappear when the player touches them and add to the score counter any hints or tips would be nice :?
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: score counter and putting objects to collect

Post by micha »

Create a table. Let's say you call it "objectList". Then store all objects that are on screen in this table. Each object itself is a table again, holding data like the coordinates, height, width and the image. In the draw-part you loop over all entries to draw them. In the update-part you have to check for collision with the player. If so, remove the object from objectList.

For a score counter you could create a global variable called score and increase it, whenever a collision with one of the objects happens.

If I remember correctly, you can find some information on collecting items in this tutorial.
Saltyham
Prole
Posts: 7
Joined: Wed Jul 10, 2013 6:23 pm

Re: Didn't help much :/

Post by Saltyham »

Still Having a hard time figuring this out, How would this code look, what would be in it.
User avatar
seanmd
Prole
Posts: 35
Joined: Sat Jun 22, 2013 7:47 am

Re: score counter and putting objects to collect

Post by seanmd »

Is there a piece of your code where powerups are marked as collected or destroyed? In that chunk of code increment a score variable that you initialize to zero upon entering the game state. It all sort of depends on how your game is structured as to how you go about keeping track of things.


an overly simplified example:

Code: Select all

local levelScore = 0

function game:enter()
  ...
  levelScore = 0
  ...
end

local function collect(collectible)
  ...
  levelScore = levelScore + collectible.value
  ...
end
Saltyham
Prole
Posts: 7
Joined: Wed Jul 10, 2013 6:23 pm

Re: score counter and putting objects to collect

Post by Saltyham »

Thanks, but the issue I'm worried about at the moment is making the objects disappear when the player is over them. If you have any code for that I would be most grateful.
:|
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: score counter and putting objects to collect

Post by davisdude »

It would be easier if you posted a .love. Then we could truly help you.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Saltyham
Prole
Posts: 7
Joined: Wed Jul 10, 2013 6:23 pm

Re: score counter and putting objects to collect

Post by Saltyham »

Its a bit bad but here ya go.
Attachments
The adventure of based god.love
My.Love
(1.67 MiB) Downloaded 125 times
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: score counter and putting objects to collect

Post by davisdude »

Your game is not really all that bad (albeit a bit strange)

I chose to make little fruits to eat for your 'based god'
I made it so that about half of you had to be over it in order to be able to eat it.

Notes:
The Title (The adventures of lil B) becomes red when you scroll over 'quit'.
You registered the image 'baseland' twice.
Player movement is rather sluggish.

I fixed some other things too, but you're probably really only interested in the 'fruits.lua' bit.

If you have any questions about the code, feel free to ask!
I mostly did performance related things, although it still loads extremely slowly for me...

The score counter will be homework... :)
Attachments
the adventure of based god.love
(1.67 MiB) Downloaded 131 times
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Saltyham
Prole
Posts: 7
Joined: Wed Jul 10, 2013 6:23 pm

Re: score counter and putting objects to collect

Post by Saltyham »

Thank you very much for the help, I'm gonna reverse engineer the hell out of additions you put in. also instead of making the fruits disappear could i change them into another graphic, also is there a way to get a sound effect for the picking up of the fruits?
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: score counter and putting objects to collect

Post by Plu »

Certainly. Probably the best way is, on pickup, replace the fruit with a new entity with a different image, but the same location. This will also prevent old code from trying to pick the new image up as well (because the code should only respond to collisions with specific objects)

You can play sound using

Code: Select all

soundFile = love.audio.newSource( 'filename.wav' )
to load the sound (give it a filename to the sound and call it ONCE during loading) and you can play the sound fragment by calling

Code: Select all

love.audio.play( soundFile )
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 6 guests