Skip to content

Commit

Permalink
Small changes in pong
Browse files Browse the repository at this point in the history
  • Loading branch information
salvadorbs committed Oct 3, 2016
1 parent 8b928a1 commit d73ecf6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
16 changes: 8 additions & 8 deletions Pong/Entities/Ball.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ public class Ball : Component, ITriggerListener, IUpdatable
{
public Vector2 moveSpeed = new Vector2(300, 300);
Texture2D _ballSprite;
ArcadeRigidbody rigidbody;
ArcadeRigidbody _rigidbody;

public override void onAddedToEntity()
{
//Load ball sprite and add it in entity
_ballSprite = entity.scene.content.Load<Texture2D>(Content.Sprites.ball);
entity.addComponent(new Sprite(_ballSprite));

//Collider and Mover components
//Collider component
entity.colliders.add(new CircleCollider());

//RigidBody
rigidbody = new ArcadeRigidbody()
//RigidBody component
_rigidbody = new ArcadeRigidbody()
.setMass(0.0001f)
.setFriction(0f)
.setElasticity(1f);
rigidbody.shouldUseGravity = false;
entity.addComponent(rigidbody);
_rigidbody.shouldUseGravity = false;
entity.addComponent(_rigidbody);

//Position and
Reset();
Expand All @@ -37,7 +37,7 @@ public override void onAddedToEntity()
public void Reset(bool fromPlayer1 = true)
{
transform.position = new Vector2(Screen.width / 2 + 75 * (fromPlayer1 ? -1 : 1), Screen.height / 2);
rigidbody.setVelocity(moveSpeed * (fromPlayer1 ? 1 : -1));
_rigidbody.setVelocity(moveSpeed * (fromPlayer1 ? 1 : -1));
}

void IUpdatable.update()
Expand All @@ -47,7 +47,7 @@ void IUpdatable.update()

void ITriggerListener.onTriggerEnter(Collider other, Collider self)
{

//TODO: Modifier ball's speed
}


Expand Down
5 changes: 2 additions & 3 deletions Pong/Entities/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Pong_Clone_Nez
{
public class Player : Component, ITriggerListener, IUpdatable
{
VirtualIntegerAxis _yAxisInput;
VirtualIntegerAxis _yAxisInput = new VirtualIntegerAxis();
float _moveSpeed = 300f;
Mover _mover;
Texture2D _paddleSprite;
Expand All @@ -21,11 +21,10 @@ public override void onAddedToEntity()
entity.addComponent(new Sprite(_paddleSprite));

//Collider and Mover components
entity.colliders.add(new BoxCollider());
entity.addCollider(new BoxCollider());
_mover = entity.addComponent(new Mover());

//Vertical input keyboard up/down and position
_yAxisInput = new VirtualIntegerAxis();
if (entity.name == "player")
{
//First player - Up/Down
Expand Down
4 changes: 2 additions & 2 deletions Pong/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ namespace Pong_Clone_Nez
public class Game : Core
{
public Game() : base(width: 800, height: 485, isFullScreen: false, enableEntitySystems: false)
{
}
{}

protected override void Initialize()
{
base.Initialize();

scene = Scene.createWithDefaultRenderer<Level>(Color.Coral);
//TODO: Menu (or StartScreen)
//TODO: Support pause
}
}
}
18 changes: 12 additions & 6 deletions Pong/Pong.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,17 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="OpenTK">
<HintPath>$(MonoGameInstallDirectory)\MonoGame\v3.0\Assemblies\DesktopGL\OpenTK.dll</HintPath>
<Reference Include="MonoGame.Framework, Version=3.5.1.1679, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MonoGame.Framework.DesktopGL.3.5.1.1679\lib\net40\MonoGame.Framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NVorbis">
<HintPath>$(MonoGameInstallDirectory)\MonoGame\v3.0\Assemblies\DesktopGL\NVorbis.dll</HintPath>
<Reference Include="NVorbis, Version=0.8.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MonoGame.Framework.DesktopGL.3.5.1.1679\lib\net40\NVorbis.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="MonoGame.Framework">
<HintPath>$(MonoGameInstallDirectory)\MonoGame\v3.0\Assemblies\DesktopGL\MonoGame.Framework.dll</HintPath>
<Reference Include="OpenTK, Version=1.1.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
<HintPath>..\packages\MonoGame.Framework.DesktopGL.3.5.1.1679\lib\net40\OpenTK.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Xml" />
Expand Down Expand Up @@ -88,6 +91,9 @@
<Name>Nez</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Content.Builder.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
4 changes: 4 additions & 0 deletions Pong/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="MonoGame.Framework.DesktopGL" version="3.5.1.1679" targetFramework="net45" />
</packages>

0 comments on commit d73ecf6

Please sign in to comment.