1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 17:47:29 +08:00

Make the Player class more friendly and add a test case.

This commit is contained in:
Dean Herbert 2016-10-19 18:00:35 +09:00
parent 94968a8b7c
commit a1d961dc87
4 changed files with 70 additions and 23 deletions

View File

@ -0,0 +1,62 @@
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using osu.Framework.GameModes.Testing;
using osu.Framework.MathUtils;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Objects;
using osu.Game.Beatmaps.Objects.Osu;
using System.Collections.Generic;
using osu.Framework.Timing;
using osu.Game.GameModes.Play;
namespace osu.Desktop.Tests
{
class TestCasePlayer : TestCase
{
public override string Name => @"Player";
public override string Description => @"Showing everything to play the game.";
FramedClock localClock;
protected override IFrameBasedClock Clock => localClock;
public override void Reset()
{
base.Reset();
//ensure we are at offset 0
localClock = new FramedClock();
var objects = new List<HitObject>();
int time = 500;
for (int i = 0; i < 1; i++)
{
objects.Add(new Circle()
{
StartTime = time,
Position = new Vector2(RNG.Next(0, 512), RNG.Next(0, 384))
});
time += 500;
}
Add(new Player()
{
Beatmap = new Beatmap
{
HitObjects = objects
}
});
}
protected override void Update()
{
base.Update();
localClock.ProcessFrame();
}
}
}

View File

@ -139,6 +139,7 @@
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Tests\TestCaseChatDisplay.cs" />
<Compile Include="Tests\TestCasePlayer.cs" />
<Compile Include="Tests\TestCaseGamefield.cs" />
<Compile Include="Tests\TestCaseHitObjects.cs" />
<Compile Include="Tests\TestCaseKeyCounter.cs" />

View File

@ -13,8 +13,8 @@ namespace osu.Game.GameModes.Play.Osu
{
public OsuPlayfield()
{
RelativeSizeAxes = Axes.None;
Size = new Vector2(512, 384);
Scale = new Vector2(1.6f);
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
}

View File

@ -24,40 +24,24 @@ using osu.Framework;
namespace osu.Game.GameModes.Play
{
class Player : GameModeWhiteBox
public class Player : OsuGameMode
{
protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg4");
protected override IEnumerable<Type> PossibleChildren => new[] {
typeof(Results)
};
public Beatmap Beatmap;
public PlayMode PlayMode;
public override void Load(BaseGame game)
{
base.Load(game);
List<HitObject> objects = new List<HitObject>();
double time = Time + 1000;
for (int i = 0; i < 100; i++)
{
objects.Add(new Circle()
{
StartTime = time,
Position = new Vector2(RNG.Next(0, 512), RNG.Next(0, 384))
});
time += RNG.Next(50, 500);
}
Beatmap beatmap = new Beatmap
{
HitObjects = objects
HitObjects = Beatmap?.HitObjects ?? new List<HitObject>()
};
OsuGame osu = game as OsuGame;
switch (osu.PlayMode.Value)
switch (PlayMode)
{
case PlayMode.Osu:
Add(new OsuHitRenderer