Skip to content

Instantly share code, notes, and snippets.

View codesmith-fi's full-sized avatar
💭
Live long and prosper

Erno Pakarinen codesmith-fi

💭
Live long and prosper
View GitHub Profile
@codesmith-fi
codesmith-fi / deltaengine_particledraw.cs
Last active December 16, 2015 19:51
Bit optimized version of particle draw loop for delta engine
private VertexPositionColorTextured[] _vertices = new VertexPositionColorTextured[4 * 1000];
private short[] _indices = new short[6 * 1000];
public virtual void Draw(Time gameTime, Drawing drawing)
{
int pc = particles.Count;
if (_vertices.Length < (4 * pc) || _indices.Length < (6 * pc))
{
_vertices = new VertexPositionColorTextured[4 * pc];
_indices = new short[6 * pc];
@codesmith-fi
codesmith-fi / AtlasSpriteSample.cs
Last active December 16, 2015 17:59
Small sample of SmithNgine and AtlasSprite/TextureAtlas classes
// TextureAtlas
// This will use a texture having 5 columns
// and 1 rows. And makes a sprite for frame 1
// (yeah, it's the second frame :)
atlas = new TextureAtlas(
StateManager.Content.Load<Texture2D>(
"Images/joukahainen"), 5, 1);
atlasSprite = atlas.MakeSprite(1);
atlasSprite.Position = new Vector2(42f, 42f);
@codesmith-fi
codesmith-fi / particleinvoke.cs
Last active December 16, 2015 01:09
Invoking particles from effect
// Invoke new particles from the effect for 1 seconds if mouse right is pressed
if (StateManager.Input.IsMouseButtonPressed(SmithNgine.Input.MouseButton.Right))
{
particleEffect.Generate(TimeSpan.FromSeconds(1.0f));
}
// OR... Generate 10 new particles on each frame whenever Right mouse button is held down
if (StateManager.Input.IsMouseButtonPressed(SmithNgine.Input.MouseButton.Right))
{
particleEffect.AddParticles( emitter.Generate(10) );
@codesmith-fi
codesmith-fi / lineemitter.cs
Created April 10, 2013 08:20
Example emitter (lineemitter.cs)
public class LineEmitter : ParticleEmitter
{
private Vector2 startVector;
private Vector2 endVector;
public LineEmitter(Vector2 lineStart, Vector2 lineEnd)
: base(lineStart)
{
startVector = lineStart;
endVector = lineEnd;
@codesmith-fi
codesmith-fi / particle1.cs
Created April 10, 2013 08:15
Particle System example - smithNgine
// Create a new particle system
particleSystem = new ParticleSystem();
// Create a new particle Effect
particleEffect = new ParticleEffect();
particleEffect.GravityVector = new Vector2(0.0f, 0.04f);
// Create new emitter for the Effect, with 2 textures that are randomly used in generation
emitter = new PointEmitter(animSprite.Position);
emitter.AddTexture(StateManager.Content.Load<Texture2D>("Images/flower"));
@codesmith-fi
codesmith-fi / MainMenuCanvas.cs
Created April 5, 2013 04:53
Example of smithNgine game canvas class
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Codesmith.SmithNgine.GameState;
namespace Codesmith.SmithTest
{
class MenuCanvas : GameCanvas
@codesmith-fi
codesmith-fi / MainMenuState.cs
Last active December 15, 2015 20:09
smithNgine GameState example
using System;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Codesmith.SmithNgine.GameState;
namespace Codesmith.SmithTest
{
public class MainMenuState : GameState
{
private Texture2D image;