Rhythm game help

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
User avatar
Le_juiceBOX
Citizen
Posts: 71
Joined: Sat Mar 26, 2016 3:07 pm

Rhythm game help

Post by Le_juiceBOX »

im making a rhythm game(like Guitar Hero, Rockband etc.) and when it comes the the white bar it(where the "notes" are detected) only makes the hit counter go down -1 and i scripted a variable that detect whether the note is colliding with the white bar so my script is as follows:

Code: Select all

if collision:detect(note.x, note.y, note.w, note.h, notehit.x, notehit.y, notehit.w, notehit.h) then
      note.TouchingHitter = 1
  else
      note.TouchingHitter = 0
    end
  end


This did have the variable change to 1 when the note was touching the white bar, this is the script that for some reason does not work:

Code: Select all

if note.TouchingHitter == 0 and love.keyboard.isDown("e") then
        note.hits = note.hits - 1
    if note.TouchingHitter == 1 and love.keyboard.isDown("e") then
        note.hits = note.hits + 1
      end
    end
  end
I will provide all my scripts to help find the problem(s), i cant compile them, sorry. If you can, note where i went wrong thanks!
Attachments
notes.lua
(1.28 KiB) Downloaded 262 times
notehit.lua
(197 Bytes) Downloaded 256 times
main.lua
(301 Bytes) Downloaded 249 times
SteamLibrary-like Program For Love2D Games:
take me to the forum thread!
User avatar
Le_juiceBOX
Citizen
Posts: 71
Joined: Sat Mar 26, 2016 3:07 pm

Re: Rhythm game help

Post by Le_juiceBOX »

the rest-
Attachments
conf.lua
(132 Bytes) Downloaded 239 times
collisions.lua
(191 Bytes) Downloaded 257 times
SteamLibrary-like Program For Love2D Games:
take me to the forum thread!
User avatar
Kingdaro
Party member
Posts: 395
Joined: Sun Jul 18, 2010 3:08 am

Re: Rhythm game help

Post by Kingdaro »

First off, a few things:

You can "compile" all of your game scripts by selecting them all, then adding them to a zip file and changing the extension to .love. This'll make your game easier to view and test for us. This is what you're going to want to do, essentially:
Image

Your tabbing's a little off. If you have proper tabbing, bugs are a lot easier to find when you have proper tabbing. The general rule is to tab forward after function/if/while/for/do lines, then tab back on end/else/elseif. Here's a fixed portion of this bit of code:

Code: Select all

function NotCollideNoteHitter()
  if note.TouchingHitter == 0 and love.keyboard.isDown("e") then
    note.hits = note.hits - 1
    if note.TouchingHitter == 1 and love.keyboard.isDown("e") then
      note.hits = note.hits + 1
    end
  end
end
I'd recommend using "true" and "false" instead of 1 and 0, since they work a little more nicely in Lua if statements. You can compress this function pretty easily:

Code: Select all

function AntiSpamHitter()
  note.TouchingHitter = collision:detect(note.x, note.y, note.w, note.h, notehit.x, notehit.y, notehit.w, notehit.h)
end

So then, onto your actual problem, here it seems like a simple matter of responding to a keypress, then checking if the note is colliding with the hitter (which is more technically called a Receptor, fun fact), and "hit" the note if this is true. Add this function to your notes.lua:

Code: Select all

function TapNote()
  if note.TouchingHitter then
    note.x = 0
    note.hits = note.hits + 1
  end
end
Then add this to your main.lua.

Code: Select all

function love.keypressed(key)
  if key == 'e' then
    TapNote()
  end
end
User avatar
Sulunia
Party member
Posts: 203
Joined: Tue Mar 22, 2016 1:10 pm
Location: SRS, Brazil

Re: Rhythm game help

Post by Sulunia »

I'm going to give my bits of advice here!

On rhythm games, as the name say, notes fall down at a very fixed speed. Thing is, normally, the song current playing time is what dictates when the note will hit the bottom of the screen.

For an example, note number one will hit the bottom of the screen when the music is at 0:15 seconds..

Code: Select all

note[1].y = - 15000 --this value should be in milliseconds!
Remember: objects moving down ingame needs to have their Y value added, not subtracted! Otherwise, notes would slide up instead of down.

Then, every frame, you draw the note according to the song time and making sure it hits the bottom of the screen, or your hitBar Y height...

Code: Select all

for i = 1, #notes do --for every note in your list, do
	note[i]:draw(note[i].x, (note[i].y - hitBar.y + screenHeight + currentSongTime)) 
end
So, instead of defining the note will slide down a fixed bit every frame (which is what you're doing), to make sure it stays synchronized with the music you must update it's position using the songTime as basis for this, otherwise, you're gonna have a bad time.

Then later, you can worry about song timer interpolation, relaxed hitInterval, audio delays..

Now, as for the problem you're facing, this is because the interval you have to press the note is quite short i'm afraid. So, i'd start relaxing the precision the user has to have to hit the note correctly, of, say, 30ms ^^
Don't check my github! It contains thousands of lines of spaghetti code in many different languages cool software! :neko:
https://github.com/Sulunia
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest