Skip to content

Commit

Permalink
Installed package for java style concurrent RNG, reworked cacti AI.
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrickbancan committed Oct 21, 2020
1 parent 8738b81 commit 074b2d3
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 59 deletions.
9 changes: 8 additions & 1 deletion RabbetGameEngine/RabbetGameEngine.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<Reference Include="MedallionRandom, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MedallionRandom.1.1.0\lib\net452\MedallionRandom.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.11.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="OpenTK, Version=3.0.1.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
<HintPath>..\packages\OpenTK.3.0.1\lib\net20\OpenTK.dll</HintPath>
</Reference>
Expand All @@ -73,6 +79,7 @@
<Compile Include="Src\Game\GUIS\MainGUI.cs" />
<Compile Include="Src\Game\MathUtil.cs" />
<Compile Include="Src\Game\TickTimer.cs" />
<Compile Include="Src\Physics\AxisAlignedRay.cs" />
<Compile Include="Src\Physics\Ray.cs" />
<Compile Include="Src\Rendering\GUIComponents\GUICrosshair.cs" />
<Compile Include="Src\Rendering\GUIHandler.cs" />
Expand Down Expand Up @@ -122,7 +129,7 @@
<Compile Include="Src\World\Entity\Projectiles\EntityTankProjectile.cs" />
<Compile Include="Src\World\Entity\Vehicles\EntityTank.cs" />
<Compile Include="Src\World\Entity\Vehicles\EntityVehicle.cs" />
<Compile Include="Src\World\World.cs" />
<Compile Include="Src\World\Planet.cs" />
<Compile Include="Src\Rendering\Camera.cs" />
<Compile Include="Src\Rendering\Models\Model.cs" />
<Compile Include="Src\Rendering\Models\ModelDrawable.cs" />
Expand Down
12 changes: 5 additions & 7 deletions RabbetGameEngine/Src/Game/GameInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class GameInstance : GameWindow
private static int mouseCenterY;//the y position of the center of the game window
private static float dpiY;
public EntityPlayer thePlayer;
public World currentPlanet;
public Planet currentPlanet;

public GameInstance(int screenWidth, int screenHeight, int initialWindowWidth, int initialWindowHeight, string title) : base(initialWindowWidth, initialWindowHeight, GraphicsMode.Default, title)
{
Expand All @@ -52,14 +52,14 @@ protected override void OnLoad(EventArgs e)
DebugInfo.init();
HitboxRenderer.init();
//create and spawn player in new world
thePlayer = new EntityPlayer("Steve", new Vector3(0, 3, 2));
currentPlanet = new World();
thePlayer = new EntityPlayer(currentPlanet, "Steve", new Vector3(0, 3, 2));
currentPlanet = new Planet(0xdeadbeef);
for (int i = 0; i < 35; i++)
{
currentPlanet.spawnEntityInWorld(new EntityCactus(new Vector3(0, 10, 0)));
currentPlanet.spawnEntityInWorld(new EntityCactus(currentPlanet, new Vector3(0, 10, 0)));
}
currentPlanet.spawnEntityInWorld(thePlayer);
currentPlanet.spawnEntityInWorld(new EntityTank(new Vector3(5, 10, -5)));
// currentPlanet.spawnEntityInWorld(new EntityTank(currentPlanet, new Vector3(5, 10, -5)));

//center mouse in preperation for first person
Input.centerMouse();
Expand Down Expand Up @@ -101,13 +101,11 @@ protected override void OnFocusedChanged(EventArgs e)
/*Each itteration of game logic is done here*/
private void onTick()
{
Profiler.beginEndProfile(Profiler.gameLoopName);
mouseCenterX = this.X + this.Width / 2;
mouseCenterY = this.Y + this.Height / 2;
GUIHandler.onTick();
MainGUI.onTick();
currentPlanet.onTick();
Profiler.beginEndProfile(Profiler.gameLoopName);
}


Expand Down
2 changes: 0 additions & 2 deletions RabbetGameEngine/Src/Rendering/Renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,10 @@ public static void onFrame()

public static void renderAll()
{
Profiler.beginEndProfile(Profiler.renderingName);
preRender();
renderWorld();
GUIHandler.drawCurrentGUIScreen();
postRender();
Profiler.beginEndProfile(Profiler.renderingName);
}

/*Called before all draw calls*/
Expand Down
6 changes: 3 additions & 3 deletions RabbetGameEngine/Src/Rendering/VFX/VFXUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace RabbetGameEngine.VFX
change certain VFX*/
public static class VFXUtil
{
public static void doExplosionEffect(World planet, Vector3 location, float radius, float pitch = 0, float yaw = -90, float roll = 0)
public static void doExplosionEffect(Planet planet, Vector3 location, float radius, float pitch = 0, float yaw = -90, float roll = 0)
{
VFXBase smoke = new VFXPointParticles(location, CustomColor.darkGrey, (25 - (int)radius / 2) + (int)(radius / 2 * radius / 2), radius / 15, 0.15F, true, false, 2F, 0.8F);

Expand Down Expand Up @@ -36,7 +36,7 @@ public static void doExplosionEffect(World planet, Vector3 location, float radiu
planet.spawnVFXInWorld(explosion2);
}

public static void doSmallSmokePuffEffect(World planet, Vector3 location, float pitch = 0, float yaw = -90, float roll = 0)
public static void doSmallSmokePuffEffect(Planet planet, Vector3 location, float pitch = 0, float yaw = -90, float roll = 0)
{
VFXBase smoke = new VFXPointParticles(location, CustomColor.darkGrey, 7, 0.05F, 0.05F, true, false, .5F, 0.8F);

Expand All @@ -52,7 +52,7 @@ public static void doSmallSmokePuffEffect(World planet, Vector3 location, float
planet.spawnVFXInWorld(smoke);
}

public static void doDebugSmokeEffect(World planet)
public static void doDebugSmokeEffect(Planet planet)
{
VFXBase smoke = new VFXPointParticles(new Vector3(0, 2F, 0), new CustomColor(Color.DarkGray), 5, 0.5F, 0.5F, true, false, 2F, 0.5F);
smoke.setExpansionResistance(0.05F);
Expand Down
10 changes: 6 additions & 4 deletions RabbetGameEngine/Src/World/Entity/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@ namespace RabbetGameEngine

public class Entity : PositionalObject
{
protected World currentPlanet;
protected Planet currentPlanet;
protected EntityModel entityModel;
protected bool hasModel = false;
protected bool isFlying = false;
private bool removalFlag = false;// true if this entity should be removed in the next tick
protected int existedTicks = 0;//number of ticks this entity has existed for
protected bool isPlayer = false;
public Entity() : base()
public Entity(Planet planet) : base()
{
currentPlanet = planet;
setYAccel(-gravity);
}

public Entity(Vector3 spawnPosition) : base(spawnPosition)
public Entity(Planet planet, Vector3 spawnPosition) : base(spawnPosition)
{
currentPlanet = planet;
setYAccel(-gravity);
}

Expand Down Expand Up @@ -78,7 +80,7 @@ public virtual void onTick()
}
}

public virtual void setCurrentPlanet(World p)
public virtual void setCurrentPlanet(Planet p)
{
this.currentPlanet = p;
}
Expand Down
70 changes: 52 additions & 18 deletions RabbetGameEngine/Src/World/Entity/EntityCactus.cs
Original file line number Diff line number Diff line change
@@ -1,50 +1,84 @@
using OpenTK;
using RabbetGameEngine.Models;
using RabbetGameEngine.Physics;
using System;
namespace RabbetGameEngine
{
public class EntityCactus : EntityLiving
{
private bool turn = true;
private static Random rand = new Random();
public EntityCactus() : base()
private bool turningRight = false;
private bool turningLeft = false;
private bool walkingFowards = false;
private float rotationSpeed = 2.5F;
public EntityCactus(Planet planet) : base(planet)
{
this.walkSpeed = 0.025F;
this.entityModel = new EntityCactusModel(this);
this.hasModel = true;
this.collider = new AABB(new Vector3(-0.5F, -0.5F, -0.5F), new Vector3(0.5F, 0.5F, 0.5F), this);
this.hasCollider = true;
yaw = (float)rand.NextDouble() * 360;
yaw = (float)currentPlanet.rand.NextDouble() * 360;
walkFowards();
}
public EntityCactus(Vector3 pos) : base(pos)
public EntityCactus(Planet planet, Vector3 pos) : base(planet, pos)
{
this.walkSpeed = 0.025F;
this.entityModel = new EntityCactusModel(this);
this.hasModel = true;
this.collider = new AABB(new Vector3(-0.5F, -0.5F, -0.5F), new Vector3(0.5F, 0.5F, 0.5F), this);
this.hasCollider = true;
yaw = (float)rand.NextDouble() * 360;
yaw = (float)currentPlanet.rand.NextDouble() * 360;
walkFowards();
}

public override void onTick()
{
if(rand.Next(0, 25) == 1)
{
turn = !turn;
}
if (currentPlanet.rand.Next() % 100 == 0)
{
walkingFowards = true;
}

if (turn) rotateYaw(-3.0F); else rotateYaw(3.0F);
if (walkingFowards && currentPlanet.rand.Next() % 20 == 0)
{
walkingFowards = false;
}
if (walkingFowards)
{
turningLeft = turningRight = false;
}
else
{
if (currentPlanet.rand.Next() % 100 == 0)
{
turningLeft = true;
}
if (turningLeft && currentPlanet.rand.Next() % 10 == 0)
{
turningLeft = false;
}
if (currentPlanet.rand.Next() % 100 == 0)
{
turningRight = true;
}
if (turningRight && currentPlanet.rand.Next() % 10 == 0)
{
turningRight = false;
}
}
if (walkingFowards)
{
walkFowards();
}

walkFowards();
if (turningLeft)
{
yaw -= rotationSpeed;
}

if (rand.Next(0, 50) == 1)
{
jump();
}
base.onTick();//do last
if (turningRight)
{
yaw += rotationSpeed;
}
base.onTick();//do last
}
}
}
4 changes: 2 additions & 2 deletions RabbetGameEngine/Src/World/Entity/EntityLiving.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ public class EntityLiving : Entity
is set to true. To detect if an action is requested, check the index. e.g: if(actions[Action.attack])*/
protected bool[] actions = new bool[EntityLiving.actionsCount];

public EntityLiving() : base()
public EntityLiving(Planet planet) : base(planet)
{
frontVector = new Vector3(0.0F, 0.0F, -1.0F);
upVector = new Vector3(0.0F, 1.0F, 0.0F);
interactTimer = new TickTimer(interactIntervalSeconds);
}

public EntityLiving(Vector3 pos) : base(pos)
public EntityLiving(Planet planet, Vector3 pos) : base(planet, pos)
{
frontVector = new Vector3(0.0F, 0.0F, -1.0F);
upVector = new Vector3(0.0F, 1.0F, 0.0F);
Expand Down
4 changes: 2 additions & 2 deletions RabbetGameEngine/Src/World/Entity/EntityPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ public class EntityPlayer : EntityLiving
public bool debugScreenOn = false;

public static readonly Vector3 eyeOffset = new Vector3(0.0F, 0.62F, 0.0F);
public EntityPlayer(string name) : base()
public EntityPlayer(Planet planet, string name) : base(planet)
{
isPlayer = true;
this.playerName = name;
camera = new Camera(this);
this.collider = new AABB(new Vector3(-0.5F, -1, -0.5F), new Vector3(0.5F, 1, 0.5F), this);
this.hasCollider = true;
}
public EntityPlayer(string name, Vector3 spawnPosition) : base(spawnPosition)
public EntityPlayer(Planet planet, string name, Vector3 spawnPosition) : base(planet, spawnPosition)
{
isPlayer = true;
this.playerName = name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class EntityProjectile : Entity, IDisposable
{
protected float maxExistedTicks;

public EntityProjectile(Vector3 pos, Vector3 direction, float initialVelocity = 2.5F, float maxLivingSeconds = 20) : base(pos)
public EntityProjectile(Planet p, Vector3 pos, Vector3 direction, float initialVelocity = 2.5F, float maxLivingSeconds = 20) : base(p, pos)
{
airResistance = 0.001F;
velocity += direction * initialVelocity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace RabbetGameEngine
{
class EntityTankProjectile : EntityProjectile
{
public EntityTankProjectile(Vector3 pos, Vector3 direction, float barrelPitch, float initialYaw) : base(pos, direction)
public EntityTankProjectile(Planet p, Vector3 pos, Vector3 direction, float barrelPitch, float initialYaw) : base(p, pos, direction)
{
this.yaw = initialYaw - 90;
this.pitch = barrelPitch;
Expand Down
6 changes: 3 additions & 3 deletions RabbetGameEngine/Src/World/Entity/Vehicles/EntityTank.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ public class EntityTank : EntityVehicle
private float barrelPitch;
public static readonly float barrelLength = 6.75F;
private TickTimer fireTimer;
public EntityTank() : base()
public EntityTank(Planet p) : base(p)
{
this.entityModel = new EntityTankModel(this);
this.hasModel = true;
this.collider = new AABB(new Vector3(-2.5F, -1.25F, -2.5F), new Vector3(2.5F, 1.25F, 2.5F), this);
this.hasCollider = true;
fireTimer = new TickTimer(1F / roundsPerSecond);
}
public EntityTank(Vector3 initialPos) : base(initialPos)
public EntityTank(Planet p, Vector3 initialPos) : base(p, initialPos)
{
this.entityModel = new EntityTankModel(this);
this.hasModel = true;
Expand Down Expand Up @@ -93,7 +93,7 @@ protected override void moveByMovementVector()
public void onDriverAttack()
{
Vector3 muzzleLocation = getMuzzleLocation();
currentPlanet.spawnEntityInWorld(new EntityTankProjectile(muzzleLocation, getMuzzleFrontVector(), barrelPitch, bodyYaw));
currentPlanet.spawnEntityInWorld(new EntityTankProjectile(currentPlanet, muzzleLocation, getMuzzleFrontVector(), barrelPitch, bodyYaw));
VFXUtil.doSmallSmokePuffEffect(currentPlanet, muzzleLocation, (float)barrelPitch, (float)bodyYaw);
}

Expand Down
4 changes: 2 additions & 2 deletions RabbetGameEngine/Src/World/Entity/Vehicles/EntityVehicle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ public class EntityVehicle : Entity
protected float driveSpeed = defaultDriveSpeed;
protected float turnRate = defaultTurnRate;
protected bool playerDriving = false;
public EntityVehicle() : base()
public EntityVehicle(Planet p) : base(p)
{
frontVector = new Vector3(0.0F, 0.0F, -1.0F);
upVector = new Vector3(0.0F, 1.0F, 0.0F);
movementVector = new Vector3(0.0F, 0.0F, 0.0F);
mountingOffset = new Vector3(0.0F, 1.9F, 0.0F);
}

public EntityVehicle(Vector3 pos) : base(pos)
public EntityVehicle(Planet p, Vector3 pos) : base(p, pos)
{
frontVector = new Vector3(0.0F, 0.0F, -1.0F);
upVector = new Vector3(0.0F, 1.0F, 0.0F);
Expand Down
Loading

0 comments on commit 074b2d3

Please sign in to comment.