Daily update on 20221030

This commit is contained in:
Youmu Konpaku
2022-10-31 01:57:33 +08:00
parent 0d744b064b
commit db39aff487
24 changed files with 305 additions and 155 deletions
@@ -11,16 +11,25 @@ namespace StgSharp.Control
{ {
public static class Pool public static class Pool
{ {
internal static IPool topCollector; internal static Collector topCollector
=new Collector(side.top,1000);
internal static Collector bottomCollector
=new Collector(side.bottom,-1000);
internal static Collector leftCollector
= new Collector(side.left, -600);
internal static Collector rightCollector
= new Collector(side.right,600);
internal static IPool pointPool internal static IPool pointPool
= new PointPool(); = new PointPool(topCollector,bottomCollector,leftCollector,rightCollector) ;
internal static IPool bulletPool internal static IPool bulletPool
= new BulletPool(); = new BulletPool(topCollector, bottomCollector, leftCollector, rightCollector);
static Pool() static Pool()
{ {
} }
public static void Creat() public static void Creat()
@@ -28,20 +28,20 @@ namespace StgSharp.Entity
get { return _velocityLow; } get { return _velocityLow; }
} }
private float _xLocation; private float _x;
public float XLocation public float X
{ {
get { return _xLocation; } get { return _x; }
set { _xLocation = value; } set { _x = value; }
} }
public float _yLocation; public float _y;
public float YLocation public float Y
{ {
get { return _yLocation; } get { return _y; }
set { _yLocation = value; } set { _y = value; }
} }
private KeyboardState _keyboardState; private KeyboardState _keyboardState;
@@ -71,13 +71,25 @@ namespace StgSharp.Entity
private Launcher _launcherAtLow; private Launcher _launcherAtLow;
public void Action() public void OnRender()
{ {
//进行各种碰撞判定
//先进行中弹判定
//进行移动和射击
if (_keyboardState.IsKeyDown(Key.ShiftLeft)) if (_keyboardState.IsKeyDown(Key.ShiftLeft))
{ {
FastShoot(); FastShoot();
FastMove(); FastMove();
} }
else
{
SlowMove();
SlowSoot();
}
} }
/// <summary> /// <summary>
@@ -89,34 +101,34 @@ namespace StgSharp.Entity
{ {
if (_keyboardState.IsKeyDown(Key.Left)) if (_keyboardState.IsKeyDown(Key.Left))
{ {
this._yLocation += _vLowCorner; this._y += _vLowCorner;
this._xLocation -= _vLowCorner; this._x -= _vLowCorner;
} }
else if (_keyboardState.IsKeyDown(Key.Right)) else if (_keyboardState.IsKeyDown(Key.Right))
{ {
this._yLocation += _vLowCorner; this._y += _vLowCorner;
this._xLocation += _vLowCorner; this._x += _vLowCorner;
} }
else else
{ {
this._yLocation += _velocityLow; this._y += _velocityLow;
} }
} }
else if (_keyboardState.IsKeyDown(Key.Down)) else if (_keyboardState.IsKeyDown(Key.Down))
{ {
if (_keyboardState.IsKeyDown(Key.Left)) if (_keyboardState.IsKeyDown(Key.Left))
{ {
this._yLocation -= _vLowCorner; this._y -= _vLowCorner;
this._xLocation -= _vLowCorner; this._x -= _vLowCorner;
} }
else if (_keyboardState.IsKeyDown(Key.Right)) else if (_keyboardState.IsKeyDown(Key.Right))
{ {
this._yLocation -= _vLowCorner; this._y -= _vLowCorner;
this._xLocation += _vLowCorner; this._x += _vLowCorner;
} }
else else
{ {
this._yLocation -= _velocityLow; this._y -= _velocityLow;
} }
} }
@@ -132,34 +144,34 @@ namespace StgSharp.Entity
{ {
if (_keyboardState.IsKeyDown(Key.Left)) if (_keyboardState.IsKeyDown(Key.Left))
{ {
this._yLocation += _vHighCorner; this._y += _vHighCorner;
this._xLocation -= _vHighCorner; this._x -= _vHighCorner;
} }
else if (_keyboardState.IsKeyDown(Key.Right)) else if (_keyboardState.IsKeyDown(Key.Right))
{ {
this._yLocation += _vHighCorner; this._y += _vHighCorner;
this._xLocation += _vHighCorner; this._x += _vHighCorner;
} }
else else
{ {
this._yLocation += _velocityHigh; this._y += _velocityHigh;
} }
} }
else if (_keyboardState.IsKeyDown(Key.Down)) else if (_keyboardState.IsKeyDown(Key.Down))
{ {
if (_keyboardState.IsKeyDown(Key.Left)) if (_keyboardState.IsKeyDown(Key.Left))
{ {
this._yLocation -= _vHighCorner; this._y -= _vHighCorner;
this._xLocation -= _vHighCorner; this._x -= _vHighCorner;
} }
else if (_keyboardState.IsKeyDown(Key.Right)) else if (_keyboardState.IsKeyDown(Key.Right))
{ {
this._yLocation -= _vHighCorner; this._y -= _vHighCorner;
this._xLocation += _vHighCorner; this._x += _vHighCorner;
} }
else else
{ {
this._yLocation -= _velocityHigh; this._y -= _velocityHigh;
} }
} }
@@ -0,0 +1,83 @@
using StgSharp.Logic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Entity
{
internal class Reward:LinkedObject
{
private float _x;
private float _y;
private float _v;
private bool _isBeingCollected;
private Player _player;
public float X
{
get { return _x; }
set { _x = value; }
}
public float Y
{
get { return _y; }
set { _y = value; }
}
public float Velo
{
get { return _v; }
set { _v = value; }
}
public bool IsBeingCollected
{
get { return _isBeingCollected; }
set { _isBeingCollected = value; }
}
public Player Player
{
get { return _player; }
set { _player = value; }
}
public Reward(float x,float y,float v)
{
_x = x;
_y = y;
_v = v;
this._isBeingCollected=false;
}
private float distance;
public void OnRender()
{
if (_isBeingCollected)
{
distance = (float)Math.Sqrt
((_x-_player.X)* (_x - _player.X)
+(_y-_player.Y)* (_y - _player.Y));
_x += (_player.X-_x)*_v/distance;
_y += (_player.Y-_y) * _v / distance;
}
else
{
_y -= _v;
}
}
public void Collet(Player player)
{
_player = player;
_v *= 2.0f;
}
}
}
@@ -1,7 +1,9 @@
using StgSharp.Logic; using StgSharp.Entity;
using StgSharp.Logic;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net.Http.Headers;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -35,111 +37,40 @@ namespace StgSharp.Pool
get { return _rightCollector; } get { return _rightCollector; }
} }
static IContainer mainContainer00;
static IContainer mainContainer01; //用一个实体容器存放各种各样的实体,太不安全了,
static IContainer mainContainer02; //写这种代码的人是个大SB。
static IContainer mainContainer10; static EntityContainer mainContainer;
static IContainer mainContainer11; static EntityContainer grazeContainer;
static IContainer mainContainer12;
static IContainer mainContainer20;
static IContainer mainContainer21;
static IContainer mainContainer22;
static IContainer mainContainer30;
static IContainer mainContainer31;
static IContainer mainContainer32;
static BulletPool() public BulletPool(Collector t, Collector b, Collector l, Collector r)
{ {
mainContainer00 = new EntityContainer(1000,400,-600,-150); mainContainer = new EntityContainer(1000,-1000,-600,600);
mainContainer01 = new EntityContainer(1000,400,-150,150); grazeContainer = new EntityContainer(1000,400,-150,150);
mainContainer02 = new EntityContainer(1000,400,150,600); mainContainer.Top = _topCollector;
mainContainer.Bottom = _bottomCollector;
mainContainer.Left = _leftCollector;
mainContainer.Right = _rightCollector;
mainContainer10 = new EntityContainer(400,0,-600,-150); grazeContainer.Top = mainContainer;
grazeContainer.Bottom = mainContainer;
mainContainer11 = new EntityContainer(400,0,-150,150); grazeContainer.Left = mainContainer;
grazeContainer.Right = mainContainer;
mainContainer12 = new EntityContainer(400,0,150,600);
mainContainer20 = new EntityContainer(0,-400,-600,-150);
mainContainer21 = new EntityContainer(0,-400,-150,150);
mainContainer22 = new EntityContainer(0,-400,150,600);
mainContainer30 = new EntityContainer(-400,-1000,-600,-150);
mainContainer31 = new EntityContainer(-400,-1000,-150,150);
mainContainer32 = new EntityContainer(-400,-1000,150,600);
mainContainer00.Top = _topCollector;
mainContainer00.Bottom = mainContainer10;
mainContainer00.Left = _leftCollector;
mainContainer00.Right = mainContainer01;
mainContainer01.Top = _topCollector;
mainContainer01.Bottom = mainContainer11;
mainContainer01.Left = mainContainer00;
mainContainer01.Right = mainContainer02;
mainContainer02.Top = _topCollector;
mainContainer02.Bottom = mainContainer12;
mainContainer02.Left = mainContainer01;
mainContainer02.Right = _rightCollector;
mainContainer10.Top = mainContainer00;
mainContainer10.Bottom = mainContainer20;
mainContainer10.Left = _leftCollector;
mainContainer10.Right = mainContainer11;
mainContainer11.Top = mainContainer01;
mainContainer11.Bottom = mainContainer21;
mainContainer11.Left = mainContainer10;
mainContainer11.Right = mainContainer12;
mainContainer12.Top = mainContainer02;
mainContainer12.Bottom = mainContainer22;
mainContainer12.Left = mainContainer11;
mainContainer12.Right = _rightCollector;
mainContainer20.Top = mainContainer10;
mainContainer20.Bottom = mainContainer30;
mainContainer20.Left=_leftCollector;
mainContainer20.Right = mainContainer21;
mainContainer21.Top = mainContainer11;
mainContainer21.Bottom = mainContainer31;
mainContainer21.Left = mainContainer20;
mainContainer21.Right = mainContainer22;
mainContainer22.Top = mainContainer12;
mainContainer22.Bottom = mainContainer32;
mainContainer22.Left = mainContainer21;
mainContainer22.Right = _rightCollector;
mainContainer30.Top = mainContainer20;
mainContainer30.Bottom = _bottomCollector;
mainContainer30.Left = _leftCollector;
mainContainer30.Right = mainContainer31;
mainContainer31.Top = mainContainer21;
mainContainer31.Bottom = _bottomCollector;
mainContainer31.Left = mainContainer30;
mainContainer31.Right = mainContainer32;
mainContainer32.Top = mainContainer22;
mainContainer32.Bottom = _bottomCollector;
mainContainer32.Left = mainContainer31;
mainContainer32.Right=_rightCollector;
_topCollector = t;
_bottomCollector = b;
_leftCollector = l;
_rightCollector = r;
} }
private static Bullet cache;
public static void OnRender() public static void OnRender()
{ {
cache = mainContainer.Heading;
} }
} }
} }
@@ -0,0 +1,121 @@
using StgSharp.Logic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Pool
{
public class Collector : LinkedList, IContainer
{
private readonly float _topBorder;
private readonly float _bottomBorder;
private readonly float _leftBorder;
private readonly float _rightBorder;
private readonly IContainer _top;
private readonly IContainer _bottom;
private readonly IContainer _left;
private readonly IContainer _right;
private readonly Counter<int> _counter;
private readonly int _limit;
public float TopBorder
{
get { return _topBorder; }
set { }
}
public float BottomBorder
{
get { return _bottomBorder; }
set { }
}
public float LeftBorder
{
get { return _leftBorder; }
set { }
}
public float RightBorder
{
get { return _rightBorder; }
set { }
}
public IContainer Top
{
get { return _top; }
set { }
}
public IContainer Bottom
{
get { return _bottom; }
set { }
}
public IContainer Left
{
get { return _left; }
set { }
}
public IContainer Right
{
get { return _right; }
set { }
}
public Counter<int> Counter
{
get;
set;
}
public int Limit
{
get { return _limit; }
set { }
}
public Collector(side s,float b)
{
switch (s)
{
case side.top:
_bottomBorder = b;
break;
case side.bottom:
_topBorder = b;
break;
case side.left:
_rightBorder = b;
break;
case side.right:
_leftBorder = b;
break;
default:
break;
}
}
}
public enum side
{
top,
bottom,
left,
right,
}
}
@@ -1,4 +1,5 @@
using System; using StgSharp.Pool;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
@@ -79,33 +80,20 @@ namespace StgSharp.Logic
_amountCounter.Value = 0; _amountCounter.Value = 0;
_heading = null; _heading = null;
} }
public void MoveLeft(LinkedObject target)
{
target.Previous = target.Next;
target.Next = target.Previous;
_left.Add(target);
}
public void MoveRight(LinkedObject target) public EntityContainer(IContainer t, IContainer b, IContainer l, IContainer r)
{ {
target.Previous = target.Next; _top = t;
target.Next = target.Previous; _topBorder = t.BottomBorder;
_right.Add(target);
}
public void MoveUp(LinkedObject target) _bottom = b;
{ _bottomBorder = b.TopBorder;
target.Previous = target.Next;
target.Next = target.Previous;
_top.Add(target);
}
public void Movebottom(LinkedObject target) _left= l;
{ _leftBorder = l.RightBorder;
target.Previous = target.Next;
target.Next = target.Previous; _right = r;
_bottom.Add(target); _rightBorder = r.LeftBorder;
} }
//What should a container do on each rendering frame //What should a container do on each rendering frame
@@ -37,8 +37,12 @@ namespace StgSharp.Pool
public static EntityContainer mainCotainer public static EntityContainer mainCotainer
= new EntityContainer(1000,-1000,-600,600); = new EntityContainer(1000,-1000,-600,600);
public PointPool() public PointPool(Collector t, Collector b, Collector l, Collector r)
{ {
_topContainer= t;
_bottomContainer= b;
_leftContainer= l;
_rightContainer= r;
} }
} }
} }
@@ -48,6 +48,7 @@
<Compile Include="Control\Bind.cs" /> <Compile Include="Control\Bind.cs" />
<Compile Include="Control\Pool.cs" /> <Compile Include="Control\Pool.cs" />
<Compile Include="Control\Create.cs" /> <Compile Include="Control\Create.cs" />
<Compile Include="Entity\Reward.cs" />
<Compile Include="Entity\Enemy.cs" /> <Compile Include="Entity\Enemy.cs" />
<Compile Include="Game\CoreInfo.cs" /> <Compile Include="Game\CoreInfo.cs" />
<Compile Include="Control\ComplexOperationHandler.cs" /> <Compile Include="Control\ComplexOperationHandler.cs" />
@@ -55,6 +56,7 @@
<Compile Include="Geometry\IPoint.cs" /> <Compile Include="Geometry\IPoint.cs" />
<Compile Include="Geometry\PointCommon.cs" /> <Compile Include="Geometry\PointCommon.cs" />
<Compile Include="Logic\IContainer.cs" /> <Compile Include="Logic\IContainer.cs" />
<Compile Include="Pool\Collector.cs" />
<Compile Include="Pool\PointContainer.cs" /> <Compile Include="Pool\PointContainer.cs" />
<Compile Include="Pool\PointPool.cs" /> <Compile Include="Pool\PointPool.cs" />
<Compile Include="Logic\IPool.cs" /> <Compile Include="Logic\IPool.cs" />
@@ -1,4 +1,4 @@
20221030 20221029
重大算法bug,为减少运算量创建的子弹池结构由多个块构成,块边界附近的子弹 重大算法bug,为减少运算量创建的子弹池结构由多个块构成,块边界附近的子弹
不一定会参加碰撞判定运算,使不一定触发player中弹事件 不一定会参加碰撞判定运算,使不一定触发player中弹事件