Skip to content

Instantly share code, notes, and snippets.

View Odonno's full-sized avatar
🏠
Working from home

David Bottiau Odonno

🏠
Working from home
View GitHub Profile
@Odonno
Odonno / AppEvent.cs
Last active June 21, 2017 19:21
App Event Store (in C# using Entity Framework)
public class AppEvent
{
public long Id { get; set; }
public string Name { get; set; }
public DateTime CreationDate { get; set; }
public string Data { get; set; }
}
@Odonno
Odonno / Game1.cs
Created September 3, 2017 12:56
Initial code of a MonoGame game in C#
public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
@Odonno
Odonno / LoadContent.cs
Created September 3, 2017 12:59
LoadContent method in C# MonoGame
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
_spriteBatch = new SpriteBatch(GraphicsDevice);
// TODO: use this.Content to load your game content here
_pixeltexture = Content.Load<Texture2D>("pixel.png");
}
@Odonno
Odonno / Update.cs
Created September 3, 2017 13:03
Update method in C# MonoGame
protected override void Update(GameTime gameTime)
{
_player1.Update(gameTime);
_player2.Update(gameTime);
base.Update(gameTime);
}
@Odonno
Odonno / Draw.cs
Created September 3, 2017 13:04
Draw method in C# MonoGame
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
_spriteBatch.Begin();
_player1.Draw(_spriteBatch);
_player2.Draw(_spriteBatch);
_spriteBatch.End();
@Odonno
Odonno / ScoreViewModel.cs
Created September 3, 2017 13:08
Example of a ViewModel used in C#/XAML MonoGame app
public class ScoreViewModel : BaseViewModel, IScoreViewModel
{
#region Properties
private static IScoreViewModel _instance;
public static IScoreViewModel Instance { get { return _instance ?? (_instance = new ScoreViewModel()); } }
private float _distanceMax;
public float DistanceMax
{
@Odonno
Odonno / GamePageWithXaml.cs
Created September 3, 2017 13:45
Initialize ViewModel in GamePage of a C#/XAML MonoGame app
public GamePage(LaunchActivatedEventArgs args)
{
InitializeComponent();
// Add the data context
DataContext = ScoreViewModel.Instance;
// Create the game.
_game = XamlGame<Game1>.Create(args, Window.Current.CoreWindow, this);
}
@Odonno
Odonno / GamePage.xaml
Created September 3, 2017 13:46
Example of a MonoGame page in XAML
<Grid>
<StackPanel Margin="30 30 0 0">
<TextBlock FontSize="42">
<Run Text="Max distance :" />
<Run Text="{Binding Path=DistanceMax, Converter={StaticResource StringToIntegerConverter}}"/>
</TextBlock>
<TextBlock FontSize="42">
<Run Text="Dodging point :" />
<Run Text="{Binding Path=BallPoints, Converter={StaticResource StringToIntegerConverter}}"/>
@Odonno
Odonno / UpdateXaml.cs
Created September 3, 2017 13:47
Example of MonoGame Update method updating ViewModel data
protected override void Update(GameTime gameTime)
{
// add points if a projectile is out of screen
foreach (var activeProjectile in activeProjectiles)
{
if (activeProjectile.Position.Y > ScreenHeight)
{
ScoreViewModel.Instance.BallPoints++;
activeProjectile.Deactivate();
}
@Odonno
Odonno / ScrollingWP.xaml
Created September 10, 2017 13:36
XAML part of the NotificationCenter-like scrolling animation for WIndows Phone
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="60"/>
<RowDefinition Height="Auto" />
<RowDefinition Height="30"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- the title block -->
<Grid Background="#FF5E58C7">