Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


3H-GDC m.V: Something Special (winner: BeanDog)


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
214 replies to this topic

#61 Thevenin   Members   -  Reputation: 270

Posted 08 February 2006 - 01:45 PM

Well, I spent an hour and made a neat intro with MDX playing a few MIDIs in C#.

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]

Sponsor:

#62 d000hg   Members   -  Reputation: 939

Posted 08 February 2006 - 08:42 PM

d000hg's D3D Console Emulator v1.0


I thought I'd make all the base code I plan to use available to you all, in case anyone thought of entering but couldn't be arsed to find out how to do text-mode coding.
It uses D3D8.1 and supports the following:
  • Set character, with foreground & background colour.

  • Set character without changing colours at that location

  • Set colours without changing the character at that location

  • Draw dithered blocks

  • Draw dithered rectangles

  • Draw a frame/border, or a dual-panel frame (see screenshot)

  • Draw a string, which wraps around if required


  • You can get it here:
    http://www.sendmefile.com/00274115, including the .dds font file and a VS6 workspace. A sample app is present including D3D initialisation. Check D3DConsoleEmulator.h for a list of special characters like those in the screenshot.
    You may use any of this code for any purpose as long as you let me know and give me a mention somewhere.
    It's not meant to be especially good, it's just thrown together for fun! But suggest improvements or report bugs and I'll address them.
    If I make any fixes or add new stuff before Saturday I'll try to release the updated version.
    I threw in a few comments and it should be fairly self explanatory especially from the sample app but feel free to ask me any questions.


    #63 Sean T. McBeth   Crossbones+   -  Reputation: 1683

    Posted 09 February 2006 - 02:50 AM

    Quote:
    Original post by paulecoyote
    another question - anyone know of any good .Net 2 console input examples suitable for controlling a game?

    Trying to get my head around DllImporting GetKeyState and GetKeyboardState and don't seem to be getting very far.

    It's odd cos I could do this keyboard control in C++ no troubles, but I kind of want to do this in C# 2 [smile]


    Here is the .NET 2.0 Class Library Reference
    here is the System.Console class
    bool System.Console.KeyAvailable is a boolean property that returns true if a key is on the input stream
    System.ConsoleKeyInfo System.Console.ReadKey([bool suppresDisplay]) blocks and returns a ConsoleKeyInfo struct when a key is available on the input stream. It also has an optional boolean parameter that setting to true causes the key to not echo to the screen
    System.ConsoleKeyInfo primarily holds flags for the ctrl, shift, and alt key, as well as a value for the System.ConsoleKey that was pressed
    System.ConsoleKey is an enumeration of virtual keys, including definitions for the arrow keys.

    [Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]


    #64 paulecoyote   Members   -  Reputation: 1060

    Posted 09 February 2006 - 03:58 AM

    Quote:
    Original post by capn_midnight
    Quote:
    Original post by paulecoyote
    another question - anyone know of any good .Net 2 console input examples suitable for controlling a game?

    Trying to get my head around DllImporting GetKeyState and GetKeyboardState and don't seem to be getting very far.

    It's odd cos I could do this keyboard control in C++ no troubles, but I kind of want to do this in C# 2 [smile]


    Here is the .NET 2.0 Class Library Reference
    here is the System.Console class
    bool System.Console.KeyAvailable is a boolean property that returns true if a key is on the input stream
    System.ConsoleKeyInfo System.Console.ReadKey([bool suppresDisplay]) blocks and returns a ConsoleKeyInfo struct when a key is available on the input stream. It also has an optional boolean parameter that setting to true causes the key to not echo to the screen
    System.ConsoleKeyInfo primarily holds flags for the ctrl, shift, and alt key, as well as a value for the System.ConsoleKey that was pressed
    System.ConsoleKey is an enumeration of virtual keys, including definitions for the arrow keys.


    Hey thanks for that. I did see some of that stuff but I was looking to figure out keydown and keyup events. In the end I managed to wrap win32 ReadConsoleInput and some over pinvoked functions to do that. I expect I'll post the code with my entry - I want to comment it some more and hammer it before inflicting it on the world. I'm determined to get an entry in for one of these competitions!

    So can I use my friends music with his permission then?

    #65 Sean T. McBeth   Crossbones+   -  Reputation: 1683

    Posted 09 February 2006 - 05:33 AM

    Yeah, you can use it. I'll consider you as a team. *only one copy of prizes per team*

    [Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]


    #66 paulecoyote   Members   -  Reputation: 1060

    Posted 09 February 2006 - 10:46 AM

    Quote:
    Original post by capn_midnight
    Yeah, you can use it. I'll consider you as a team. *only one copy of prizes per team*


    awesome.

    #67 matt_j   Members   -  Reputation: 106

    Posted 09 February 2006 - 05:09 PM

    Is 80x50 or 80x43 allowed?

    #68 scgrn   Members   -  Reputation: 168

    Posted 09 February 2006 - 05:20 PM

    Quote:
    Original post by matt_j
    Is 80x50 or 80x43 allowed?

    This question has already been fielded. I believe the answers was "yeeeeup".

    #69 Thevenin   Members   -  Reputation: 270

    Posted 09 February 2006 - 05:37 PM

    Quote:
    Original post by matt_j
    Is 80x50 or 80x43 allowed?


    They are both allowed. Be warned though, as the screensize increases, the framerate descreases.

    Us C# Console coders (Without using the Win32API) have some solid restraints on what we can do due the bad performance....

    Here's a quicky on what I'm working on (it glows! [grin]). Less than 10 FPS though, and the only redraws are done on parts that have changed.


    #70 d000hg   Members   -  Reputation: 939

    Posted 09 February 2006 - 08:09 PM

    Cool. Are the glow effects actually a special effect, or does the original 'artwork' include those glows in the first place?

    #71 paulecoyote   Members   -  Reputation: 1060

    Posted 09 February 2006 - 09:04 PM

    I think mine is gonna look a little crude compared to you guys!

    Does any know of any tutorials for making scalable fonts like in the picture above?

    #72 d000hg   Members   -  Reputation: 939

    Posted 09 February 2006 - 09:58 PM

    You mean instead of setting a character, set several characters to a solid block to make a larger image of a font? If you have a 2D bool array (say 8x8) for each character then just set which 'bits' are on or off and then use this to draw your character on screen... of course it is a pain to generate those masks. You could get an image of all characters (look at the .dds file in my example) and then write a function to use that, or maybe there is a DOS function to get you the mask for each character.

    #73 ToohrVyk   Members   -  Reputation: 1591

    Posted 09 February 2006 - 10:06 PM

    Ph34r my pretty-printing text-wrapper! With ascii borders!

    Pretty!

    Yeah, I know, it sucks.


    #74 d000hg   Members   -  Reputation: 939

    Posted 09 February 2006 - 11:19 PM

    Why not use the special border characters (see my screenshot a few posts up) instead of those characters?

    #75 ToohrVyk   Members   -  Reputation: 1591

    Posted 10 February 2006 - 02:23 AM

    Genius, you deserve more rating!

    Now, my application uses non-alphanumeric character shaders! And a zero-bit depth buffer!

    #76 d000hg   Members   -  Reputation: 939

    Posted 10 February 2006 - 02:49 AM

    Let's see a new shot then?

    #77 ToohrVyk   Members   -  Reputation: 1591

    Posted 10 February 2006 - 09:29 AM

    Character shaders!

    #78 DrPetter   Members   -  Reputation: 132

    Posted 10 February 2006 - 10:57 AM

    I'll see if I can whip something up... 3 hours should be enough for cool things to happen.
    If I do enter I will use my recently hacked-together OpenGL text renderer (made for the purpose of this compo). It features a low resolution two-color font grabbed from a console window screenshot as well as some blippy sounds courtesy of bass lib.
    From what I've read in this thread that should be well within spec.

    Prototype screenshot:


    #79 ToohrVyk   Members   -  Reputation: 1591

    Posted 11 February 2006 - 03:44 AM

    I found out I can play music as well. Behold:


    let badadee = [ (800,100); (850,100); (900,200) ];;
    let badodum = [ (800,100); (700,100); (600,300) ];;
    let badibadidaa = [ (800,100); (850,100); (800,100); (850,100); (750,200) ];;
    let tudidadodaa = [ (800,60); (850,60); (750,60); (700,60); (750,200) ];;
    let todidotodido = [ (750,100); (800,100); (750,100); (700,100); (750,100); (700,400) ];;
    let blip = [ (900,60); (800,80) ];;


    #80 Endurion   Crossbones+   -  Reputation: 4099

    Posted 11 February 2006 - 06:55 AM

    Just to be on the safe side. Here's a link to fixed worldtime. I'd like to have a link to this added everytime for a competition.

    This makes my questions regarding timezones obsolete :)

    Clicky




    Old topic!
    Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



    PARTNERS