eliza
eliza
CC#
Created by eliza on 6/18/2024 in #help
Not increasing Score integer
Hello, I'm creating a rhythm game using XNA. The problem is the Score increasing by value of earned score then to resets to 0. Finally score is 0 too so, i don't have ideas what to do
C#
public void Update(GameTime gameTime)
{
if (!isInitialized) Initialize(game);

List<GameplayObject> objectsToRemove = new List<GameplayObject>();

soundEngine.Update();

Note lastNote = (Note)gameplayObjects.FindLast(gameplayObject =>
{
return gameplayObject is Note note;
});

if ((int)gameTime.TotalGameTime.TotalMilliseconds == lastNote.Time + 2000)
{
game.SwitchToState(RhythmicalState.Score);
}

foreach (GameplayObject gameplayObject in gameplayObjects.ToList())
{
if (gameplayObject is Note note)
{
if (pianoEndRectangle.Intersects(note.rectangle))
{
if (isTouched)
{
objectsToRemove.Add(note);
if (note.rectangle.Y >= 530)
{
Score += 100; // Here is problem
}
else if (note.rectangle.Y <= 530 && note.rectangle.Y >= 510)
{
Score += 50;
}
isTouched = false;
}
}
}
}

foreach (var obj in objectsToRemove.ToList())
{
gameplayObjects.Remove(obj);
}
}
C#
public void Update(GameTime gameTime)
{
if (!isInitialized) Initialize(game);

List<GameplayObject> objectsToRemove = new List<GameplayObject>();

soundEngine.Update();

Note lastNote = (Note)gameplayObjects.FindLast(gameplayObject =>
{
return gameplayObject is Note note;
});

if ((int)gameTime.TotalGameTime.TotalMilliseconds == lastNote.Time + 2000)
{
game.SwitchToState(RhythmicalState.Score);
}

foreach (GameplayObject gameplayObject in gameplayObjects.ToList())
{
if (gameplayObject is Note note)
{
if (pianoEndRectangle.Intersects(note.rectangle))
{
if (isTouched)
{
objectsToRemove.Add(note);
if (note.rectangle.Y >= 530)
{
Score += 100; // Here is problem
}
else if (note.rectangle.Y <= 530 && note.rectangle.Y >= 510)
{
Score += 50;
}
isTouched = false;
}
}
}
}

foreach (var obj in objectsToRemove.ToList())
{
gameplayObjects.Remove(obj);
}
}
12 replies
CC#
Created by eliza on 6/11/2024 in #help
Weird behaviour with SpriteBatch.Draw in MonoGame
No description
3 replies