/// <summary> /// Creates a sprite from an image file. /// </summary> /// <remarks> /// If a sprite from the same image was already loaded /// before it will return a new sprite from the SpriteData /// in the cache. /// </remarks> /// <param name="ImageFile">The image file to create the sprite from</param> /// <param name="offset">Offset, same as <see cref="Sprite.Offset"/>.</param> /// <returns>A <see cref="Sprite"/>.</returns> public static Sprite CreateFromImage(string ImageFile, Vector offset) { if(!SpriteDatas.ContainsKey(ImageFile)) { Surface Surface = new Surface(ImageFile); SpriteData Data = new SpriteData(Surface, offset); SpriteDatas[ImageFile] = Data; return new Sprite(Data); } return new Sprite(SpriteDatas[ImageFile]); }
public SpriteData(Surface Surface, Vector offset) { Action Action = new Action("default", Surface); Action.Offset = offset; Actions.Add(Action.Name, Action); }
public static byte[] Compress(string toCompress) { //then at the end of the function we're going to convert it to an array, and return it. Vector<byte> result = new Vector<byte>(); //make an encoding table out of the huffman tree, out of a frequency table Console.WriteLine("Making Huffman frequency table"); HashTable<char, int> FreqTable = MakeFrequencyTable(toCompress); //copy to memory because we access it multiple times Console.WriteLine("Making Huffman tree"); Node huffmanTree = MakeHuffmanTree(FreqTable); Console.WriteLine("Making Huffman encoding table"); HashTable<char, BitStream> encodingTable = MakeEncodingTable(huffmanTree, new BitStream()); // add to memory because accessed twice //convert the size of the frequency table to bytes. Console.WriteLine("Converting to bytes"); byte[] freqToByte = IntToBytes(FreqTable.Size); //and all four bytes to the resuld linked list Console.WriteLine("Adding bytes bytes"); result.AddRange(freqToByte); //next loop through the frequency table SLinkedList<char> list = FreqTable.Keys; Console.WriteLine("looping through frequency table"); for (int i = 0; i < list.Size; i++) { //convert current key to two bytes byte[] key = CharToBytes(list[i]); //add both bytes to the linked list result.AddRange(key); //convert the current value to foure bytes, byte[] value = IntToBytes(FreqTable[list[i]]); //add alll four bytes to the linked list result.AddRange(value); }//end loop //make new bitstream (datastream) to hold bits BitStream datastream = new BitStream(); //loop through the string Console.WriteLine("Looping through input and adding to datastream"); for (int i = 0; i < toCompress.Length; i++) { //append the bitstream of the encoding table to the newely created bitstream datastream.Append(encodingTable[toCompress[i]]); }//end loop //get the bit streams bit count as an integer int streamBitCount = datastream.BitCount; //convert this integer to bytes and add it to the result list Console.WriteLine("Converting bytes"); byte[] streambitByte = IntToBytes(streamBitCount); result.AddRange(streambitByte); Console.WriteLine("Copying Bytes"); result.AddRange(datastream.Bytes); //finally convert the result list to a byte array. Console.WriteLine("Convert results list to byte array"); byte[] byteResult = result.ToArray(); //return the array return byteResult; }
public void Draw(Vector pos) { gl.BindTexture(gl.TEXTURE_2D, texture.Handle); gl.Begin(gl.QUADS); gl.TexCoord2f(Left, Top); gl.Vertex2f(pos.X, pos.Y); gl.TexCoord2f(Right, Top); gl.Vertex2f(pos.X + Width, pos.Y); gl.TexCoord2f(Right, Bottom); gl.Vertex2f(pos.X + Width, pos.Y + Height); gl.TexCoord2f(Left, Bottom); gl.Vertex2f(pos.X, pos.Y + Height); gl.End(); }
public virtual void Draw(Vector pos) { if(CurrentAction == null || CurrentAction.Frames.Count == 0) return; float AnimationTime = (Timer.CurrentTime - ActionTimeOffset) * CurrentAction.Speed; if(_NextAction != null && AnimationTime > (float) CurrentAction.Frames.Count) { AnimationTime -= CurrentAction.Frames.Count; AnimationTime /= CurrentAction.Speed; CurrentAction = _NextAction; _NextAction = null; AnimationTime *= CurrentAction.Speed; } int AnimationFrame = ((int) AnimationTime) % CurrentAction.Frames.Count; Surface Surface = CurrentAction.Frames[AnimationFrame]; Surface.Draw(pos - CurrentAction.Offset); }
private int[] VectorToIntArray(Vector<double> vector) { return vector.Select(elem => (int)elem).ToArray(); }