Skip to content

Commit

Permalink
Updated to last Nez version
Browse files Browse the repository at this point in the history
  • Loading branch information
salvadorbs committed Dec 9, 2016
1 parent aeffaa9 commit 329c14f
Show file tree
Hide file tree
Showing 16 changed files with 87 additions and 58 deletions.
36 changes: 20 additions & 16 deletions FlappyNez/Components/PlayerTriggerListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,30 @@ void ITriggerListener.onTriggerEnter(Collider other, Collider self)
{
var _level = (Level)_player.scene;

// Check LevelState
if (_level.State == LevelState.Play)
if (other != self)
{
// Check if other.entity is Star
if (other.entity is Star)

// Check LevelState
if (_level.State == LevelState.Play)
{
// Destroy star and increment score
other.entity.destroy();
if (((Star)(other.entity)).FirstCollision)
// Check if other.entity is Star
if (other.entity is Star)
{
_score.IncrementScore();

// Workaround for double collisions with stars (why!?)
((Star)(other.entity)).FirstCollision = false;
// Destroy star and increment score
other.entity.destroy();
if (((Star)(other.entity)).FirstCollision)
{
_score.IncrementScore();

// Workaround for double collisions with stars (why!?)
((Star)(other.entity)).FirstCollision = false;
}
}
else
{
// Else it is Terrain or Rocks and it is GameOver
_level.State = LevelState.GameOver;
}
}
else
{
// Else it is Terrain or Rocks and it is GameOver
_level.State = LevelState.GameOver;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion FlappyNez/Entities/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ enum Animations
public Player() : base("Plane")
{
// Collider component - isTrigger to true because use of TriggerListeners
addCollider(new CircleCollider())
addComponent<CircleCollider>()
.isTrigger = true;

// Mover component
Expand Down
14 changes: 9 additions & 5 deletions FlappyNez/Entities/Rock.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
using FlappyNez.Scenes;
using FarseerPhysics;
using FarseerPhysics.Dynamics;
using FlappyNez.Scenes;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Nez;
using Nez.Farseer;
using Nez.Sprites;
using Nez.Textures;

namespace FlappyNez.Entities
{
Expand Down Expand Up @@ -44,13 +48,13 @@ public override void onAddedToScene()
var _texture = scene.content.Load<Texture2D>(_spritePath);
_sprite = addComponent(new Sprite(_texture));

// RenderLayer to 1 because monogame must draws rock behind terrain
_sprite.renderLayer = 1;

// Polygon Collider - isTrigger to true because use of TriggerListeners
addCollider(new PolygonCollider(Utils.GetVerticesTexture(_texture)))
addComponent(new PolygonCollider(Utils.GetVerticesTexture(_texture)))
.isTrigger = true;

// RenderLayer to 1 because monogame must draws rock behind terrain
_sprite.renderLayer = 1;

ResetPosition();
}

Expand Down
2 changes: 1 addition & 1 deletion FlappyNez/Entities/Star.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public Star(int offset) : base("Star")
FirstCollision = true;

// Collider component
addCollider(new BoxCollider())
addComponent<BoxCollider>()
.isTrigger = true;

// Mover component
Expand Down
2 changes: 1 addition & 1 deletion FlappyNez/Entities/Terrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public override void onAddedToScene()
for (int i = 0; i < colliderArray.Length; i++)
{
colliderArray[i] = new PolygonCollider(Utils.GetVerticesTexture(_texture));
addCollider(colliderArray[i])
addComponent(colliderArray[i])
.isTrigger = true;
}

Expand Down
6 changes: 3 additions & 3 deletions FlappyNez/Factories/RockFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public RockFactory(Level scene)

public void CreateRocks(object sender, EventArgs e)
{
//if (_level.State == LevelState.Play)
//{
if (_level.State == LevelState.Play)
{
var _offset = Nez.Random.range(Constants.RockRangeMin, Constants.RockRangeMax);

// Rocks
Expand All @@ -25,7 +25,7 @@ public void CreateRocks(object sender, EventArgs e)

// Star (between rocks)
_level.addEntity(new Star(_offset));
//}
}
}
}
}
20 changes: 10 additions & 10 deletions FlappyNez/FlappyNez.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@
<ApplicationIcon>Icon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="FarseerPhysics.Portable, Version=3.5.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\FarseerPhysics.Portable.3.5.1\lib\portable-net4+sl4+wp8+win8\FarseerPhysics.Portable.dll</HintPath>
<Private>True</Private>
</Reference>
<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>
Expand Down Expand Up @@ -123,12 +119,6 @@
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Content.Builder.targets" />
<ItemGroup>
<ProjectReference Include="..\Nez\Nez-PCL\Nez.csproj">
<Project>{60B7197D-D0D5-405C-90A2-A56903E9B039}</Project>
<Name>Nez</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
</ItemGroup>
Expand All @@ -144,4 +134,14 @@
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Nez\Nez.FarseerPhysics\Nez.FarseerPhysics.csproj">
<Project>{cb893b1d-ce04-4492-b957-31ce0dca6c15}</Project>
<Name>Nez.FarseerPhysics</Name>
</ProjectReference>
<ProjectReference Include="..\Nez\Nez.Portable\Nez.csproj">
<Project>{60b7197d-d0d5-405c-90a2-a56903e9b039}</Project>
<Name>Nez</Name>
</ProjectReference>
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion FlappyNez/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected override void Initialize()
#endif

// Load up your initial scene here
scene = Scene.createWithDefaultRenderer<Level>(Color.MonoGameOrange);
scene = new Level();
}
}
}
4 changes: 4 additions & 0 deletions FlappyNez/Scenes/Level.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using FlappyNez.Entities;
using FlappyNez.Factories;
using Nez;
using Nez.Farseer;

namespace FlappyNez.Scenes
{
Expand All @@ -18,6 +19,9 @@ class Level : Scene

public override void initialize()
{
base.initialize();
addRenderer(new DefaultRenderer());

_rockManager = new RockFactory(this);

// TimedEvent to create rocks and star every tot seconds
Expand Down
2 changes: 1 addition & 1 deletion FlappyNez/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static Vector2[] GetVerticesTexture(Texture2D texture)
// Get vertices of Texture
uint[] texData = new uint[texture.Width * texture.Height];
texture.GetData<uint>(texData);
Vertices verticesList = TextureConverter.DetectVertices(texData, texture.Width);
Vertices verticesList = TextureConverter.detectVertices(texData, texture.Width);
Vector2[] verticesArray = verticesList.ToArray();

// PolygonCollider has offset in center, so vertices does too
Expand Down
2 changes: 0 additions & 2 deletions FlappyNez/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="FarseerPhysics" version="3.5.0" targetFramework="net45" />
<package id="FarseerPhysics.Portable" version="3.5.1" targetFramework="net45" />
<package id="MonoGame.Framework.DesktopGL" version="3.5.1.1679" targetFramework="net45" />
</packages>
32 changes: 23 additions & 9 deletions Nez4Fun.sln
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pong", "Pong\Pong.csproj",
{60B7197D-D0D5-405C-90A2-A56903E9B039} = {60B7197D-D0D5-405C-90A2-A56903E9B039}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nez", "Nez\Nez-PCL\Nez.csproj", "{60B7197D-D0D5-405C-90A2-A56903E9B039}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlappyNez", "FlappyNez\FlappyNez.csproj", "{AF7D4E7B-804A-476A-8CF9-DA21521F1827}"
ProjectSection(ProjectDependencies) = postProject
{CB893B1D-CE04-4492-B957-31CE0DCA6C15} = {CB893B1D-CE04-4492-B957-31CE0DCA6C15}
{60B7197D-D0D5-405C-90A2-A56903E9B039} = {60B7197D-D0D5-405C-90A2-A56903E9B039}
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nez.FarseerPhysics", "Nez\Nez.FarseerPhysics\Nez.FarseerPhysics.csproj", "{CB893B1D-CE04-4492-B957-31CE0DCA6C15}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nez", "Nez\Nez.Portable\Nez.csproj", "{60B7197D-D0D5-405C-90A2-A56903E9B039}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -27,6 +33,21 @@ Global
{A50D929A-7EB1-4ABD-AD99-04E47F2E9BA9}.Release|Any CPU.ActiveCfg = Release|x86
{A50D929A-7EB1-4ABD-AD99-04E47F2E9BA9}.Release|x86.ActiveCfg = Release|x86
{A50D929A-7EB1-4ABD-AD99-04E47F2E9BA9}.Release|x86.Build.0 = Release|x86
{AF7D4E7B-804A-476A-8CF9-DA21521F1827}.Debug|Any CPU.ActiveCfg = Debug|x86
{AF7D4E7B-804A-476A-8CF9-DA21521F1827}.Debug|Any CPU.Build.0 = Debug|x86
{AF7D4E7B-804A-476A-8CF9-DA21521F1827}.Debug|x86.ActiveCfg = Debug|x86
{AF7D4E7B-804A-476A-8CF9-DA21521F1827}.Debug|x86.Build.0 = Debug|x86
{AF7D4E7B-804A-476A-8CF9-DA21521F1827}.Release|Any CPU.ActiveCfg = Release|x86
{AF7D4E7B-804A-476A-8CF9-DA21521F1827}.Release|x86.ActiveCfg = Release|x86
{AF7D4E7B-804A-476A-8CF9-DA21521F1827}.Release|x86.Build.0 = Release|x86
{CB893B1D-CE04-4492-B957-31CE0DCA6C15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CB893B1D-CE04-4492-B957-31CE0DCA6C15}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CB893B1D-CE04-4492-B957-31CE0DCA6C15}.Debug|x86.ActiveCfg = Debug|Any CPU
{CB893B1D-CE04-4492-B957-31CE0DCA6C15}.Debug|x86.Build.0 = Debug|Any CPU
{CB893B1D-CE04-4492-B957-31CE0DCA6C15}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CB893B1D-CE04-4492-B957-31CE0DCA6C15}.Release|Any CPU.Build.0 = Release|Any CPU
{CB893B1D-CE04-4492-B957-31CE0DCA6C15}.Release|x86.ActiveCfg = Release|Any CPU
{CB893B1D-CE04-4492-B957-31CE0DCA6C15}.Release|x86.Build.0 = Release|Any CPU
{60B7197D-D0D5-405C-90A2-A56903E9B039}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{60B7197D-D0D5-405C-90A2-A56903E9B039}.Debug|Any CPU.Build.0 = Debug|Any CPU
{60B7197D-D0D5-405C-90A2-A56903E9B039}.Debug|x86.ActiveCfg = Debug|Any CPU
Expand All @@ -35,13 +56,6 @@ Global
{60B7197D-D0D5-405C-90A2-A56903E9B039}.Release|Any CPU.Build.0 = Release|Any CPU
{60B7197D-D0D5-405C-90A2-A56903E9B039}.Release|x86.ActiveCfg = Release|Any CPU
{60B7197D-D0D5-405C-90A2-A56903E9B039}.Release|x86.Build.0 = Release|Any CPU
{AF7D4E7B-804A-476A-8CF9-DA21521F1827}.Debug|Any CPU.ActiveCfg = Debug|x86
{AF7D4E7B-804A-476A-8CF9-DA21521F1827}.Debug|Any CPU.Build.0 = Debug|x86
{AF7D4E7B-804A-476A-8CF9-DA21521F1827}.Debug|x86.ActiveCfg = Debug|x86
{AF7D4E7B-804A-476A-8CF9-DA21521F1827}.Debug|x86.Build.0 = Debug|x86
{AF7D4E7B-804A-476A-8CF9-DA21521F1827}.Release|Any CPU.ActiveCfg = Release|x86
{AF7D4E7B-804A-476A-8CF9-DA21521F1827}.Release|x86.ActiveCfg = Release|x86
{AF7D4E7B-804A-476A-8CF9-DA21521F1827}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
2 changes: 1 addition & 1 deletion Pong/Entities/Ball.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Ball : Entity
public Ball() : base("Ball")
{
// Collider component
colliders.add(new CircleCollider());
addComponent<CircleCollider>();

// RigidBody component
_rigidbody = new ArcadeRigidbody()
Expand Down
2 changes: 1 addition & 1 deletion Pong/Entities/Border.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public Border(TypeBorder border) : base()
}

// Collider
colliders.add(new BoxCollider());
addComponent<BoxCollider>();
}

public override void onAddedToScene()
Expand Down
4 changes: 2 additions & 2 deletions Pong/Entities/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public class Player : Entity
{
public Player(bool isPlayer1 = true) : base(isPlayer1 ? "player" : "player2")
{
addComponent(new PlayerController());
addCollider(new BoxCollider());
addComponent<PlayerController>();
addComponent<BoxCollider>();
}

public override void onAddedToScene()
Expand Down
13 changes: 9 additions & 4 deletions Pong/Pong.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<DefineConstants>DEBUG;TRACE;LINUX</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<UseVSHostingProcess>true</UseVSHostingProcess>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x86</PlatformTarget>
Expand Down Expand Up @@ -88,14 +89,18 @@
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Nez\Nez-PCL\Nez.csproj">
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Nez\Nez.FarseerPhysics\Nez.FarseerPhysics.csproj">
<Project>{cb893b1d-ce04-4492-b957-31ce0dca6c15}</Project>
<Name>Nez.FarseerPhysics</Name>
</ProjectReference>
<ProjectReference Include="..\Nez\Nez.Portable\Nez.csproj">
<Project>{60b7197d-d0d5-405c-90a2-a56903e9b039}</Project>
<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

0 comments on commit 329c14f

Please sign in to comment.