This commit is contained in:
Royce551 2022-08-06 09:29:28 -05:00
parent 4b952fa998
commit 634b08c6ac
7 changed files with 178 additions and 5 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

View file

@ -65,6 +65,9 @@
<None Update="Assets\Gameplay\gameplayday.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Assets\Gameplay\Items\placeholder.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Assets\indulge.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>

View file

@ -1,4 +1,5 @@
using FrivoloCo.Screens.Menu;
using FrivoloCo.Screens.Play.Items;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Media;
@ -24,7 +25,7 @@ namespace FrivoloCo.Screens.Play
public override void Deinitialize()
{
Game.Input.KeyDown -= Input_KeyDown;
}
public override void Draw(GameTime gameTime, SpriteBatch spriteBatch, GraphicsDevice graphicsDevice)
@ -37,11 +38,13 @@ namespace FrivoloCo.Screens.Play
public override void Initialize()
{
Game.Input.KeyDown += Input_KeyDown;
MediaPlayer.Play(Song.FromUri("gameplay-1", new("Assets/Music/gameplay-1.ogg", UriKind.Relative)));
// Playfield
var rc = new RenderContainer(Game.GraphicsDevice)
{
Layout = Water.Graphics.Layout.Fill
Layout = Layout.Fill
};
var sp = new Sprite("Assets/Gameplay/gameplayday.png")
{
@ -53,11 +56,18 @@ namespace FrivoloCo.Screens.Play
RelativePosition = new(0, 0, 1920, 1080),
Layout = Layout.Center
};
co.AddChild(Game.AddObject(sp));
rc.AddChild(co);
AddChild(rc);
co.AddChild(Game.AddObject(new ItemDispenser(ItemType.Placeholder)
{
Layout = Layout.AnchorBottom,
RelativePosition = new(50, 0, 120, 230)
}));
// HUD
var moneyBox = new Box()
{
@ -94,6 +104,17 @@ namespace FrivoloCo.Screens.Play
statusBox.AddChild(Game.AddObject(statusTb));
}
private void Input_KeyDown(object sender, Water.Input.KeyEventArgs e)
{
if (e.Key == Microsoft.Xna.Framework.Input.Keys.Escape)
{
MediaPlayer.Stop();
ScreenManager.ChangeScreen(new MenuScreen());
}
else if (e.Key == Microsoft.Xna.Framework.Input.Keys.F5)
ScreenManager.ChangeScreen(new GameScreen(new GameState()));
}
private double timeLeft = 120000; // 2 minutes in milliseconds
public override void Update(GameTime gameTime)

View file

@ -0,0 +1,68 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Water.Graphics;
using Water.Graphics.Controls;
namespace FrivoloCo.Screens.Play.Items
{
public class Item : Sprite
{
public bool IsBeingDragged { get; private set; } = false;
public virtual string Name => "Placeholder";
public Item(string texturePath, bool isBeingDragged) : base(texturePath)
{
IsBeingDragged = isBeingDragged;
}
public override void Initialize()
{
if (Layout != Layout.Manual)
throw new Exception("Kyaa >.< !, The only valid layout for me is manual!");
Game.Input.PrimaryMouseButtonDown += Input_PrimaryMouseButtonDown;
Game.Input.PrimaryMouseButtonUp += Input_PrimaryMouseButtonUp;
base.Initialize();
}
private void Input_PrimaryMouseButtonDown(object sender, Water.Input.MousePressEventArgs e)
{
if (Game.Input.IsMouseWithin(this))
IsBeingDragged = true;
}
private void Input_PrimaryMouseButtonUp(object sender, Water.Input.MousePressEventArgs e)
{
if (Game.Input.IsMouseWithin(this))
IsBeingDragged = false;
}
public override void Deinitialize()
{
Game.Input.PrimaryMouseButtonDown -= Input_PrimaryMouseButtonDown;
Game.Input.PrimaryMouseButtonUp -= Input_PrimaryMouseButtonUp;
base.Deinitialize();
}
public override void Update(GameTime gameTime)
{
if (IsBeingDragged)
{
var pos = Game.Input.GetMousePositionRelativeTo(Parent);
RelativePosition = new(pos.X - 60, pos.Y - 115, 120, 230);
}
else
{
if (Parent is not null)
if (RelativePosition.Y <= Parent.ActualPosition.Height - 230)
RelativePosition = new(RelativePosition.X, RelativePosition.Y + 1, 120, 230);
}
base.Update(gameTime);
}
}
}

View file

@ -0,0 +1,82 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Water.Graphics;
using Water.Graphics.Controls;
namespace FrivoloCo.Screens.Play.Items
{
public class ItemDispenser : GameObject
{
private ItemType type;
public ItemDispenser(ItemType type)
{
this.type = type;
}
public override void Deinitialize()
{
Game.Input.PrimaryMouseButtonDown -= Input_PrimaryMouseButtonDown;
}
public override void Draw(GameTime gameTime, SpriteBatch spriteBatch, GraphicsDevice graphicsDevice)
{
}
public override void Initialize()
{
Game.Input.PrimaryMouseButtonDown += Input_PrimaryMouseButtonDown;
var x = GetItemForItemType(type);
var sp = new Sprite(x.Path)
{
Layout = Layout.Fill,
RelativePosition = new(0, 0, 0, 0)
};
AddChild(Game.AddObject(sp));
var labelBox = new Box()
{
Color = Color.Black * 0.5f,
RelativePosition = new(0, 0, 0, 100),
Layout = Layout.DockBottom
};
var tb = new TextBlock(new(0, 0, 0, 0), Game.Fonts.Get("Assets/Fonts/parisienne-regular.ttf", 30), x.Name, Color.White)
{
Layout = Layout.Fill,
HorizontalTextAlignment = HorizontalTextAlignment.Center,
VerticalTextAlignment = VerticalTextAlignment.Center
};
labelBox.AddChild(Game.AddObject(tb));
AddChild(Game.AddObject(labelBox));
}
private void Input_PrimaryMouseButtonDown(object sender, Water.Input.MousePressEventArgs e)
{
if (Game.Input.IsMouseWithin(this))
Parent.AddChild(Game.AddObject(GetItemForItemType(type)));
}
public override void Update(GameTime gameTime)
{
}
private Item GetItemForItemType(ItemType type) => type switch
{
ItemType.Placeholder or _ => new Item("Assets/Gameplay/Items/placeholder.png", true)
};
}
public enum ItemType
{
Placeholder
}
}

View file

@ -133,6 +133,8 @@ namespace Water.Input
currentMouseState.Y >= container.ActualPosition.Y && currentMouseState.Y <= (container.ActualPosition.Y + container.ActualPosition.Height);
}
public bool IsPrimaryMouseButtonHeld() => currentMouseState.LeftButton == ButtonState.Pressed;
public bool IsKeyHeld(Keys key) => currentKbState.GetPressedKeys().Contains(key);
}

View file

@ -50,9 +50,6 @@ namespace Water
{
switch (e.Key)
{
case Keys.Escape:
Exit();
break;
case Keys.F11:
Graphics.PreferredBackBufferWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
Graphics.PreferredBackBufferHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;