Page 1 of 1

Rhythm game help

Posted: Sat May 21, 2016 1:35 am
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!

Re: Rhythm game help

Posted: Sat May 21, 2016 1:36 am
by Le_juiceBOX
the rest-

Re: Rhythm game help

Posted: Sat May 21, 2016 2:15 am
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

Re: Rhythm game help

Posted: Sat May 21, 2016 3:04 am
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 ^^