Skip to content

Instantly share code, notes, and snippets.

View demonixis's full-sized avatar

Yannick Comte demonixis

View GitHub Profile
@demonixis
demonixis / Animation sample
Created May 19, 2012 20:45
Yna Framework Animations
public SpriteState()
{
sonicSprite = new Sprite(new Vector2(50, 50), "2d//soniclg4");
sonicSprite.LoadContent();
sonicSprite.PrepareAnimation(50, 41);
sonicSprite.AddAnimation("down", new int[] { 0, 1, 2, 3 }, 25, false);
sonicSprite.AddAnimation("left", new int[] { 4, 5, 6, 7 }, 25, false);
sonicSprite.AddAnimation("right", new int[] { 8, 9, 10, 11 }, 25, false);
sonicSprite.AddAnimation("up", new int[] { 12, 13, 14, 15 }, 25, false);
@demonixis
demonixis / SpriteState.cs
Created May 20, 2012 20:49
PlayState example with YNA Framework
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Yna.Display;
using Yna.Input;
namespace Yna.Test
{
@demonixis
demonixis / Game2.cs
Created May 21, 2012 06:09
YNA Framework - Game and engine initialization
using System;
using System.Collections.Generic;
using Yna;
using Yna.Display;
namespace Yna.Test
{
public class Game2 : Yna.YnGame
{
@demonixis
demonixis / RawSprite.cs
Created May 21, 2012 06:12
YNA Framework - Create custom Sprite with no texture
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Yna;
using Yna.Display;
namespace Yna.Test
{
@demonixis
demonixis / SpriteState.cs
Created May 23, 2012 20:40
New SpriteState implementation for YNA Framework
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Yna.Display;
using Yna.Input;
namespace Yna.Test
@demonixis
demonixis / LambdaSample.cs
Created August 5, 2012 19:26
Expression Lambda with C#
public void AddExplosion(int x, int y)
{
Sprite explode = new Sprite("SFX/explosion2");
explode.LoadContent();
explode.Position = new Vector2(x, y);
explode.PrepareAnimation(94, 94);
explode.AddAnimation("0", new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }, 25, false);
// Expression Lambda
// equivalent à explode.GetAnimation("0").AnimationComplete += onAnimationComplete;
@demonixis
demonixis / AdaptScale.cs
Created August 6, 2012 20:03
Code for adapt scale with a reference resolution
/* Le rectangle jouable a une résolution réel de 1000x760
* La texture d'origine fait 1280x800
* 1 et 2 : Il y a un décallage de 20px entre le debut de la texture (x ,y)
* et la surface de jeu
* 1280 / 64 = 20 --> adaptation à chaque résulutions
* 3 et 4 : 1280 / (1280 / 1000) = 1280 / 1.28 = 1000 soit la largeur max de la surface jouable
* pour avoir la surface jouable relative complète il faut ajouter les 20px de décalage calculé au début
* prenant en compte l'échelle
*/
this.playableSurface = new Rectangle (
@demonixis
demonixis / TranslateAndRotate.cs
Created August 7, 2012 09:08
Translation and rotation on a spriteBatch
protected SpriteSortMode _spriteSortMode;
protected BlendState _blendState;
protected SamplerState _samplerState;
protected DepthStencilState _depthStencilState;
protected RasterizerState _rasterizerState;
protected Effect _effect;
protected Matrix _transformMatrix;
protected float _rotation;
protected float _zoom;
@demonixis
demonixis / WiimoteHelper.cs
Created August 14, 2012 11:57
A basic input helper for testing LibWiimote
using System;
using System.Collections.Generic;
using System.Drawing;
using WiimoteLib;
namespace SpaceGame
{
public class WiimoteHelper
{
private Wiimote wiimote;
@demonixis
demonixis / StackList.cs
Created August 17, 2012 13:50
An hybrid collection who work like a Stack with the advantages of a List
using System;
using System.Collections.Generic;
namespace Yna.Utils
{
/// <summary>
/// An hybrid collection who work like a Stack with the advantages
/// of a List. It's a List object with 3 extension methods who simulates a Stack
/// </summary>
/// <typeparam name="T"></typeparam>