The performance isn't too great though (About 10 FPS). And I haven't a C# way to get keyboard input.
My Code:
using System;using System.Collections.Generic;using System.Text;using System.Media;using System.Drawing;using System.Windows.Forms;using Microsoft.DirectX;using Microsoft.DirectX.AudioVideoPlayback;public partial class cMain{ public class ASprite { public Color MyTransparentConst = Color.FromArgb(255, 0, 255); public int TheWidth; public int TheHeight; public Color[] TheColors; public ASprite(int TheWidth, int TheHeight) { this.TheWidth = TheWidth; this.TheHeight = TheHeight; TheColors = new Color[this.TheWidth * this.TheHeight]; for (int TheLoop = 0; TheLoop < this.TheWidth * this.TheHeight; TheLoop++) TheColors[TheLoop] = new Color(); } public ASprite(string TheFileName) { Bitmap TheBitmap = new Bitmap(TheFileName); this.TheWidth = TheBitmap.Width; this.TheHeight = TheBitmap.Height; TheColors = new Color[this.TheWidth * this.TheHeight]; for (int TheLoop = 0; TheLoop < this.TheWidth * this.TheHeight; TheLoop++) TheColors[TheLoop] = new Color(); for (int TheX = 0; TheX < this.TheWidth; TheX++) for (int TheY = 0; TheY < this.TheHeight; TheY++) TheColors[TheX + TheY * this.TheWidth] = TheBitmap.GetPixel(TheX, TheY); } public void sDraw(int TheSrcX, int TheSrcY, int TheSrcWidth, int TheSrcHeight, int TheDestX, int TheDestY, Color[] TheDestination) { for (int TheX = 0; TheX < TheSrcWidth; TheX++) for (int TheY = 0; TheY < TheSrcHeight; TheY++) /* Lets just make sure we are within bounds. */ if (TheX >= 0 && TheX < 80 && TheY >= 0 && TheY < 50) /* And lets make sure its not a transparency color. */ if(this.TheColors[TheSrcX+TheX + (TheSrcY+TheY)*TheWidth] != MyTransparentConst) TheDestination[TheX + TheDestX + (TheY + TheDestY) * 80] = this.TheColors[TheSrcX + TheX + (TheSrcY + TheY) * TheWidth]; } } /* Load the music files needed. */ public Audio MyIntroMusic = new Audio("Resources\\Intro.mid"); /* Load the sources needed. */ public ASprite MyLogo = new ASprite("Resources\\Logo.png"); /* Game variables. */ public enum EGameState { Menu, InGame, Quit } public EGameState MyGameState = EGameState.Menu; /* My render framebuffer. */ public Color[] MyRender = null; public Color[] MyPreviousRender = null; /* Various Animations. */ public int TheLogoAnimation = 0; /* No touch. */ static void Main(string[] args) { cMain TheGame = new cMain(); TheGame.sLoad(); } /* Load procedure; also main game loop. */ public void sLoad() { /* Configure the console window. */ Console.WindowWidth = 80; Console.WindowHeight = 50; Console.Title = "GameDev.Net 3H-GDC (Thevenin Entry)"; /* Build my renderer. */ MyRender = new Color[80*50]; for(int TheLoop=0; TheLoop<80*50; TheLoop++) MyRender[TheLoop] = new Color(); MyPreviousRender = new Color[80 * 50]; for (int TheLoop = 0; TheLoop < 80 * 50; TheLoop++) MyPreviousRender[TheLoop] = new Color(); /* Get the ticks. */ int TheCurrentTickCount = Environment.TickCount; int TheLastTickCount = TheCurrentTickCount; /* Start the music. */ MyIntroMusic.Play(); /* Game loop. */ while(MyGameState == EGameState.InGame || MyGameState == EGameState.Menu) { TheCurrentTickCount = Environment.TickCount; if(TheCurrentTickCount - TheLastTickCount >= 100) { /* Get the graphics thingy ready. */ sPrepareRender(); TheLastTickCount = TheCurrentTickCount; } } /* Finish. */ MessageBox.Show("Thank you for playing~"); } /* Prepare the Render. */ public void sPrepareRender() { TheLogoAnimation++; if (TheLogoAnimation == 10) { MyLogo.sDraw(0, 0, 80, 50, 0, 0, MyRender); sRender(); } else if (TheLogoAnimation == 20) { MyLogo.sDraw(0, 50, 80, 50, 0, 0, MyRender); sRender(); TheLogoAnimation = 0; } } /* Render a frame. */ public void sRender() { for (int TheY = 0; TheY < 50; TheY++) for(int TheX = 0; TheX < 80; TheX++) if(TheY != 49 || TheX != 79) if(MyRender[TheX+TheY*80] != MyPreviousRender[TheX+TheY*80]) { Color TheColor = MyRender[TheX + TheY*80]; if (TheColor == Color.FromArgb(0,0,255)) Console.BackgroundColor = ConsoleColor.Blue; else if (TheColor == Color.FromArgb(0, 0, 128)) Console.BackgroundColor = ConsoleColor.DarkBlue; else if (TheColor == Color.FromArgb(0, 0, 0)) Console.BackgroundColor = ConsoleColor.Black; else if (TheColor == Color.FromArgb(255, 255, 255)) Console.BackgroundColor = ConsoleColor.White; else if (TheColor == Color.FromArgb(0, 255, 0)) Console.BackgroundColor = ConsoleColor.Green; else if (TheColor == Color.FromArgb(0, 128, 0)) Console.BackgroundColor = ConsoleColor.DarkGreen; Console.SetCursorPosition(TheX, TheY); Console.Write(" ");// added in as an optimization instead of putting it below in the commeneted out region.MyPreviousRender[TheX + TheY * 80] = MyRender[TheX + TheY * 80]; } /* Lastly, we'll want to copy the new render onto the old one. */ //for (int TheY = 0; TheY < 50; TheY++) // for (int TheX = 0; TheX < 80; TheX++) // MyPreviousRender[TheX + TheY * 80] = MyRender[TheX + TheY * 80]; }}
I might just use WindowsForms, since I don't want to attempt this in 3 hours in Procedural-C...
[Edited by - Thevenin on February 8, 2006 9:45:49 PM]