Bay 12 Games Forum

Finally... => Creative Projects => Topic started by: Lightman on January 04, 2010, 04:03:25 am

Title: ASCII Lab
Post by: Lightman on January 04, 2010, 04:03:25 am
Thanks to the Hippoman topic, I decided to post this.

I've written a simple C# .NET library that uses Direct X and handles 2D sprites, TTF text and provides a simple interface for keyboard and mouse input. I have a couple test projects that use it and I can post some examples/more info here.

It could be a quick way to write up an 'ASCII' game (it's all bitmaps, of course). By default, it uses a 16x16 tileset that I got for DF and can render any of the tiles in any colour combination for foreground/background. PNG transparency is supported, of course.

So, I'd like to know if anyone would be interested in this?

I made it because I've been thinking of throwing together an adventure-style game with the library. It might be fun to collaborate, if someone wants to do that.

Why C#?

C# uses C-style syntax, it provides very good performance, and it makes things much easier when compared with C/C++. If you're new to programming, it will definitely be easier and faster to learn.

Limitations
TTF text is experimental and not very useful, at this stage.

Starting out
Starting a project is very simple. Just start Visual Studio Express and click on the template to make a default application.
Important: It seems you'll have to locate the GroboLib.dll, manually. Right-click on references and select 'Add'. Then, Browse and locate the DLL in templates.

Requirements:

DirectX Updates
http://www.microsoft.com/downloads/details.aspx?FamilyID=2da43d38-db71-4c1b-bc6a-9b6652cd92a3&displaylang=en (http://www.microsoft.com/downloads/details.aspx?FamilyID=2da43d38-db71-4c1b-bc6a-9b6652cd92a3&displaylang=en)

Visual C# (Express)
http://www.microsoft.com/express/vcsharp/ (http://www.microsoft.com/express/vcsharp/)

.NET Framework (3.5)
http://www.microsoft.com/downloads/details.aspx?FamilyId=AB99342F-5D1A-413D-8319-81DA479AB0D7&displaylang=en (http://www.microsoft.com/downloads/details.aspx?FamilyId=AB99342F-5D1A-413D-8319-81DA479AB0D7&displaylang=en)

Download
http://www.sendspace.com/file/6zcm9j (http://www.sendspace.com/file/6zcm9j)

Installation
Unzip the file into My documents\Visual Studio 2008\Templates\ProjectTemplates

Example code
For fun, here is some example code. Just create a project and add these files to it. The code demonstrates a little with classes and what-not. The player can be any creature.
http://www.sendspace.com/file/jtqv79 (http://www.sendspace.com/file/jtqv79)

Controls:
U - Add a human at the mouse pointer
D - Add a dwarf at the mouse pointer
G - Add a goblin at the mouse pointer
E - Add an elf at the mouse pointer
K - Kill (remove) the creature at the mouse pointer

Arrow keys move the player.
Mouse-over shows the creature name.

Screenshot
Spoiler (click to show/hide)

Demo
http://www.sendspace.com/file/59n7zq (http://www.sendspace.com/file/59n7zq)
A binary demo game, similar to the above code but with a few changes:

X - Kill (remove) the creature at the mouse pointer
K - Add a kobold at the mouse pointer
C - Cut down tree at the mouse pointer

This version has a simple friend/enemy battle system. Certain races will attack others and defend others.
Title: Re: ASCII Lab
Post by: eerr on January 04, 2010, 04:31:34 am
But, but I just started using game maker!
I've spent about 20 hours trying to make the guy walk and jump, and bump walls smoothly already.

Also, How far different is C# from java?
Is memory managed?
Do you have any ideas in mind?
Download link.
Title: Re: ASCII Lab
Post by: Hippoman on January 04, 2010, 08:20:19 am
Thanks to the Hippoman topic, I decided to post this.

I've written a simple C# .NET library that uses Direct X and handles 2D sprites, TTF text and provides a simple interface for keyboard and mouse input. I have a couple test projects that use it and I can post some examples/more info here.

It could be a quick way to write up an 'ASCII' game (it's all bitmaps, of course). By default, it uses a 16x16 tileset that I got for DF and can render any of the tiles in any colour combination for foreground/background. PNG transparency is supported, of course.

So, I'd like to know if anyone would be interested in this?

I made it because I've been thinking of throwing together an adventure-style game with the library. It might be fun to collaborate, if someone wants to do that.

Why C#?

C# uses C-style syntax, it provides very good performance, and it makes things much easier when compared with C/C++. If you're new to programming, it will definitely be easier and faster to learn.

Starting out
Starting a project is very simple. Just click on the template and it makes a default application:

(http://img5.imageshack.us/img5/1837/asciigame.jpg)
You did this just to piss me off didn't you...
"Thanks to the Hippoman topic...I'll program this in C#."
Title: Re: ASCII Lab
Post by: Willfor on January 04, 2010, 11:19:08 am
Dear Hippoman: Stop seeing insults where there are none. The internet does not revolve around you, as you are but a single step above anonymous. Most people would be content that they started a fad.
Title: Re: ASCII Lab
Post by: Lightman on January 04, 2010, 04:56:16 pm
Hippoman
More like, your thread sparked my interest in posting about a library I had written already. ;)

eerr
Yes, C# is managed and it shares many concepts with Java. I'll post links and more info, soon.

For my ideas, my initial impulse was just to make a 'siege defence' game to try implementing some battle fun. However, it would be cool to make a little adventure game... preferably something open-ended with some exploration. Obviously, nothing near the DF scale but it is tempting to make something so I can add a couple features I'd like to play around with.
Title: Re: ASCII Lab
Post by: eerr on January 04, 2010, 06:20:48 pm
Light->"Hippoman
More like, your thread sparked my interest in posting about a library I had written already. "
Dammit man, you know this stuff makes a great christmas present...

I've got ideas, and Am interested.
but I wouldn't want to start building without you.
Not that I can, considering you haven't posted the link to Mediafire yet.

Actually, What C# Environment do you use?
Title: Re: ASCII Lab
Post by: Hippoman on January 04, 2010, 06:34:48 pm
Hippoman
More like, your thread sparked my interest in posting about a library I had written already. ;)
:C I still wish it was actually in a language I knew...
Title: Re: ASCII Lab
Post by: Willfor on January 04, 2010, 06:37:01 pm
eerr, from the looks of it he uses Visual C#.
Title: Re: ASCII Lab
Post by: eerr on January 04, 2010, 06:48:24 pm
Awhile back, Someone posted bugged code in C++. Debugging that code,(which took me about a week, as I really don't know C++) Taught me with great detail how pointers work. If anyone has a very hard C# sharp debug..
Title: Re: ASCII Lab
Post by: Willfor on January 04, 2010, 07:07:31 pm
Well, the difference between C++ and C# is that everything in C# is a pointer... Well, that's a very general statement, but in general every object you work with is a pointer to an object. There are no hard memory locations that you don't make yourself using unsafe code. I've not had a need to use unsafe code while using the language, but then again, I'm just a hobby programmer.

Also, I have nothing that is hard to debug that I don't actively want to debug myself. Sorry.  :(
Title: Re: ASCII Lab
Post by: Lightman on January 04, 2010, 07:27:38 pm
Hippo
You could always learn. Knowing multiple languages is a good thing. If you're learning C/C++, it will be easy for you to pick up.

eerr
Willfor is correct. I use Visual Studio Express, which is nice and free.

Willfor
Well, yes, the idea of managed code is not to make the user manage memory ;) ... And, a little more accurately, any class-based variable is a pointer. Struct-based variables are not passed by reference.
Title: Re: ASCII Lab
Post by: Hippoman on January 04, 2010, 07:40:52 pm
Well yes, but that'll be in a long while.
Title: Re: ASCII Lab
Post by: eerr on January 04, 2010, 10:03:05 pm
Well yes, but that'll be in a long while.
We're not 7 years old, you don't have to get the last word in every dam time.
Title: Re: ASCII Lab
Post by: eerr on January 04, 2010, 11:20:40 pm
I have an idea I would like to pursue, as you haven't mentioned anything specific. Though I do want to download the engine before I commit to anything.

The idea?
You are a wizard who places boulders, like a tower-defense Dwarf-fortress hybrid.
Lightning and boulders are primary tools, but you will use and gain others.
Title: Re: ASCII Lab
Post by: Alexhans on January 05, 2010, 07:45:30 am
I'm interested... I don't know if I could help much though since I've never tried to jump that from c++ -> c# gap. 

But it might prove useful to open my mind...

maybe we can chat later.  Just add my mail.
Title: Re: ASCII Lab
Post by: Hippoman on January 05, 2010, 08:17:16 am
Well yes, but that'll be in a long while.
We're not 7 years old, you don't have to get the last word in every dam time.

I was simply stating to him that I wont be using his library becuase i wont be learning C# until a long time from now.
Title: Re: ASCII Lab
Post by: sevj on January 05, 2010, 11:41:53 am
I'd certainly be interested in this. Was considering writing my own, but this would make my work a lot easier. Is there any place to download it yet?
Title: Re: ASCII Lab
Post by: eerr on January 05, 2010, 12:10:08 pm
Well yes, but that'll be in a long while.
We're not 7 years old, you don't have to get the last word in every dam time.

I was simply stating to him that I wont be using his library becuase i wont be learning C# until a long time from now.
We know all of that already. We were kinda listening!
Furthermore, you probably know enough programming to handle the ASCII lab, though you might struggle a bit learning c# syntax the first week.
Title: Re: ASCII Lab
Post by: eerr on January 05, 2010, 12:23:34 pm
Still waiting on how detailed that ASCII stuff is.

If I can make a good lightning effect that looks like a nethack wand-zap and regular explosion, then hell yea. I don't look forward to trying to make that sort of game in game maker because there is no space for AI.

Actually, dam, that probably wouldn't work. A defense game needs realtime to add pressure.

Ugh...

Hmmmm.
Title: Re: ASCII Lab
Post by: Lightman on January 05, 2010, 04:56:07 pm
Be patient. I'll have the link ready, today or tomorrow. I've been swamped with work and looking back over this project, I think I might switch out the DirectX code I am using, for performance reasons. However, what I've got right now works and it should be fine to get things started. I don't think I'll change much of anything that's exposed.
Title: Re: ASCII Lab
Post by: Nadaka on January 05, 2010, 05:13:20 pm
C# vs JAVA...
Note: I have used both languages professionally.
C# and java are very similar.

Both are compiled to an intermediate assembly level (java byte codes, .NET CLR).
Both have c++ like syntax.
Both have abstracted most of the fiddly bits of C++ away.
Both have fully managed memory models without pointers, maloc, etc.
Both have fairly large standard libraries including GUI widgets.

Java is open source, c# is not, though for practical purposes that does not matter at all.
Java has a strong philosophy that can seem to impair its functionality, while c# has developed more rapidly and has a lot more "freedom".
Java is faster under most circumstances, however the default garbage collector in java can cause sporadic lag that the c# garbage collector wont.
Title: Re: ASCII Lab
Post by: Hippoman on January 05, 2010, 07:30:28 pm
Well yes, but that'll be in a long while.
We're not 7 years old, you don't have to get the last word in every dam time.

I was simply stating to him that I wont be using his library becuase i wont be learning C# until a long time from now.
We know all of that already. We were kinda listening!
Furthermore, you probably know enough programming to handle the ASCII lab, though you might struggle a bit learning c# syntax the first week.
Plus due to my excessive boredom, I have a tendency to try to continue conversations long after they've ended.
Title: Re: ASCII Lab
Post by: eerr on January 05, 2010, 07:50:40 pm
Well yes, but that'll be in a long while.
We're not 7 years old, you don't have to get the last word in every dam time.

I was simply stating to him that I wont be using his library becuase i wont be learning C# until a long time from now.
We know all of that already. We were kinda listening!
Furthermore, you probably know enough programming to handle the ASCII lab, though you might struggle a bit learning c# syntax the first week.
Plus due to my excessive boredom, I have a tendency to try to continue conversations long after they've ended.
You should try spelunky.
It is awesome. Also made in gamemaker, so I find it a little inspirational.
Title: Re: ASCII Lab
Post by: Outcast Orange on January 05, 2010, 07:54:32 pm
You should try spelunky.
It is awesome. Also made in gamemaker, so I find it a little inspirational.

This. So this.
I play Spelunky like three hours a day.
And when that doesn't work,
 Toribash, FoF, and Cortex Command are there to provide back up vocals.

Also, if you want a major time waster,
 look into "An Untitled Story".
Title: Re: ASCII Lab
Post by: Hippoman on January 05, 2010, 07:58:11 pm
Tried it on my 98. And it wigged out. But I could give it another go on my XP.
Title: Re: ASCII Lab
Post by: Lightman on January 05, 2010, 10:45:36 pm
File uploaded. I added the link to the original post. The default application is a very simple demo. I might post another demo here that is a little more illustrative.
Title: Re: ASCII Lab
Post by: eerr on January 06, 2010, 01:32:13 am
Holy shit, c# is awesome.

Edit: Wait, do I need to write math. everytime I want to use
math.atan2()?
Title: Re: ASCII Lab
Post by: Lightman on January 06, 2010, 05:46:30 pm
Holy shit, c# is awesome.

Edit: Wait, do I need to write math. everytime I want to use
math.atan2()?

Yes ;) and yes. 'Math' is a static class, not a namespace. It's the way things are organised in C# - every function belongs to a class.
Title: Re: ASCII Lab
Post by: Nadaka on January 06, 2010, 05:51:13 pm
c# is pretty awesome, I prefer java for its portability and speed, but c# is very good as well.

Re: math c# does not have an analog to the with command from vb, so yep always have to specify the class/object name for methods. Its pretty much the only thing I want c# to import from vb.
Title: Re: ASCII Lab
Post by: eerr on January 06, 2010, 07:55:31 pm
But it's fine because I can use operator overloading to write out math.atan2 wrapped up into a function called "atan" , and use it like a "+" "-", or moreso a "/" operator?
Title: Re: ASCII Lab
Post by: Normandy on January 06, 2010, 07:59:31 pm
Operating overloading is only for basic operators such as +, -, ==, !=, etc...

If you did not know that, I'm pretty sure you shouldn't be worrying about that.

Just deal with it, mostly. It's five characters more, surely no impediment on productivity.

Also, it should be noted that you shouldn't do operating overloading on primitives like numbers in the first place, if it's actually possible.
Title: Re: ASCII Lab
Post by: eerr on January 06, 2010, 08:10:55 pm
someone write me a gui with a goddam macro.
We're doing this, we can make c# absolutely better than Java.
When it is time to write code.

Ok, compromise, I can get java style with commonly used functions
by wrapping them up in a shorter function, and supposedly the compiler optimises to the same result as if I just typed out the dam thing by hand. Supposedly.
Title: Re: ASCII Lab
Post by: Lightman on January 07, 2010, 12:49:09 am
...by wrapping them up in a shorter function, and supposedly the compiler optimises to the same result as if I just typed out the dam thing by hand. Supposedly.

You can do it that way, if it really matters. I'd suggest some simple, static wrapper. When you get towards 'release' code you could always just do a search/replace and add 'Math.' to everything. By the way, I think the non-Express version of Visual Studio supports macros.

I uploaded some sample code for people to try (classes for you, Hippoman? :)). See the original post (http://www.bay12games.com/forum/index.php?topic=47370.0).
Title: Re: ASCII Lab
Post by: eerr on January 07, 2010, 02:07:25 am
It complains about importing Grobo,

"GraphicsManager" does not exist in this context.

There is also a GroboLib that has a little exclamation point.
Title: Re: ASCII Lab
Post by: Lightman on January 07, 2010, 04:11:13 am
It complains about importing Grobo,

"GraphicsManager" does not exist in this context.

There is also a GroboLib that has a little exclamation point.

That means it can't find the DLL. It's in the zip file. Did you follow the installation instructions? To use the demo code, you start a new ASCII Game project and add those files (replace Program.cs).
Title: Re: ASCII Lab
Post by: eerr on January 07, 2010, 05:00:10 am
Read to me the exact files you have in that directory.

I have tried both just extracting the first zip, and extracting both.
No diffrence.
Title: Re: ASCII Lab
Post by: Alexhans on January 07, 2010, 12:05:37 pm
I haven't downloaded and installed last SP of .NET yet but I'm already checking out C#'s features.

So far... I like it very much.

Small details like not having to care about argument order made my day:
Code: [Select]
System.Console.WriteLine("What do you know? {1} contains {0}",sss,eee);sss and eee are strings, btw.
Title: Re: ASCII Lab
Post by: Berserker on January 07, 2010, 12:10:14 pm
Also, if you want a major time waster,
 look into "An Untitled Story".

I tried this yesterday, and it messed up my computer totally. I had to reinstall my computer's operating system.
Title: Re: ASCII Lab
Post by: Lightman on January 07, 2010, 12:13:22 pm
Read to me the exact files you have in that directory.

I have tried both just extracting the first zip, and extracting both.
No diffrence.

I must have missed something for the template. Annoying. Anyway, just expand the references, remove Grobo and then add it manually: right-click on references, choose add, select the browse tab and locate the DLL. That should do it.
Title: Re: ASCII Lab
Post by: Berserker on January 07, 2010, 12:48:04 pm
This is kind of hard to explain, but is there a function that prints text in the same way the BlitASCII prints a character?
BlitASCII uses the 16x16 characters and DrawText uses it's own font.

So I'm looking for a function that prints the text with the 16x16 characters.


Edit: Nevermind, I made my own function:

Code: [Select]
public static void DrawASCIIText(int x, int y, string txt, Color col) {
    x *= 16; y *= 16;
    int drawPos = 0;
    foreach(char c in txt) {
        GraphicsManager.BlitASCII(x+drawPos, y, (byte)c, col);
        drawPos += 16;
    }
}

Title: Re: ASCII Lab
Post by: Lightman on January 07, 2010, 04:35:08 pm
This is kind of hard to explain, but is there a function that prints text in the same way the BlitASCII prints a character?
BlitASCII uses the 16x16 characters and DrawText uses it's own font.

I understand. The point is that BlitASCII is just using a set of bitmap tiles and DrawText is using a true-type font. Ie. the former is intended to create game graphics and the latter is for text output. However, you can obviously use the ASCII table for text, too, as per the function you wrote ;)
Title: Re: ASCII Lab
Post by: eerr on January 07, 2010, 11:59:41 pm
My first challenge shall be:
Implementation of g's that march on the player.
The player can only kill one per turn, and any goblin can kill the player.

In the process, I will use structs and such.


Edit: or maybe I will be simple and use objects...
Title: Re: ASCII Lab
Post by: Lightman on January 08, 2010, 12:00:44 pm
Edit: or maybe I will be simple and use objects...

Classes (that's what you mean by 'objects', right?) would make more sense, probably, for what you are doing.
Title: Re: ASCII Lab
Post by: eerr on January 08, 2010, 01:26:23 pm
Edit: or maybe I will be simple and use objects...

Classes (that's what you mean by 'objects', right?) would make more sense, probably, for what you are doing.
Classes, because objects are much more convenient than goblin structures.
Title: Re: ASCII Lab
Post by: Berserker on January 08, 2010, 02:43:15 pm
Now I have goblins running around and a dwarf that you can control, next I am going to do combat things and consider adding body parts.
Title: Re: ASCII Lab
Post by: eerr on January 08, 2010, 04:28:02 pm
Don't forget the Arm_Ok variable.
Title: Re: ASCII Lab
Post by: eerr on January 10, 2010, 03:01:32 am
Cancer of the colon has spread to become cancer of the indents
>.<

namespace, class,if, ifelse, for, if, if.
I count 7 there.
Code: [Select]
        static void ProcessInput()
        {
            int previousx=player.X;
            int previousy=player.Y;
            int dx=0;
            int dy=0;
            int dother = 0;


            // Is the player moving?
            if (gamestate >= 0) // changed to operate when key is
            {                   // released, bug, player can still hold more than one
                if (InputManager.IsPressed(Keys.Up))
                    keypressed_updown = 1;         
                else if (keypressed_updown == 1)
                { dy -= 1; keypressed_updown = 0; }

                if (InputManager.IsPressed(Keys.Down))
                    keypressed_updown = -1;
                else if (keypressed_updown == -1)
                { dy += 1; keypressed_updown = 0; }

                if (InputManager.IsPressed(Keys.Left))
                    keypressed_leftright = -1;
                else if (keypressed_leftright == -1)
                { dx -= 1; keypressed_leftright = 0; }

                if (InputManager.IsPressed(Keys.Right))
                    keypressed_leftright = 1;
                else if (keypressed_leftright == 1)
                { dx += 1; keypressed_leftright = 0; }
                if (InputManager.IsPressed(Keys.Enter))
                {
                    keypressed_leftright = 0;
                    keypressed_updown = 0;
                    keypressed_enter = 1;

                }
                else
                {
                    if (keypressed_enter > 0) { }

                    keypressed_enter = 0;
                    dother = 1;
                }





                if (dy == 0 & dx == 0 & dother == 0)
                {

                }
                else
                {


                    player.X += dx;
                    player.Y += dy;

                    goblin h;
                    for (int i = 0; i < goblins.Length; i++)// player kills goblins
                    {
                        h = goblins[i];

                       
                            if ((h.loc.X == player.X) & (h.loc.Y == player.Y))
                            {
                                h.setx(-1);
                                h.sety(-1);
                                h.alive = -1;
                                score++;
                            }
                       

                    }
                    //if ((x == playerx) & (y == playery))



                    // Keep the player on the screen
                    if (player.X < 0) player.X = 0;
                    else if (player.X * 16 > Video.width - 16) player.X = Video.width / 16 - 1;

                    if (player.Y < 0) player.Y = 0;
                    else if (player.Y * 16 > Video.height - 16) player.Y = Video.height / 16 - 1;


                    if (!(previousx - player.X == 0) || !(previousy - player.Y == 0))
                        gamestate = goblin.update(player.X, player.Y, goblins);
                }
            }

        }
     
    }/*

But anyway, All of the goblins now path towards the player. If the player moves onto the goblin, the goblin is killed.
If the goblin moves onto the player, the player dies.

Of course, the goblins can move diagonally while the player can't, so it's kinda unfair and impossible to win. But it works! god dam that was alot more work than I thought, but it works!
Title: Re: ASCII Lab
Post by: Willfor on January 10, 2010, 12:02:58 pm

Cancer of the colon has spread to become cancer of the indents
>.<
I'm not even sure where the indents are in my body. :(



 ;)
Title: Re: ASCII Lab
Post by: eerr on January 10, 2010, 07:05:03 pm
So lightman, you mentioned something about cooperating on a game?

I'ma go ahead and pursue that defense game right now.
Title: Re: ASCII Lab
Post by: Lightman on January 11, 2010, 11:51:26 pm
So lightman, you mentioned something about cooperating on a game?

Yeah, I started up a sourceforge repository. That might be the best way to organise it. We need a small group interested in the same idea and willing/able to contribute. The first thing to do would be to hash out the major goals and what-not. Right now, I'm just playing around with the code and trying some things. I think the siege game would be fun but I'd probably rather make an open-ended adventure/exploration game.
Title: Re: ASCII Lab
Post by: eerr on January 12, 2010, 05:51:19 pm
Why do you keep using the players location in terms of x +- 16?
I mean, I know it draws that directly to the screen at those positions, but is it really necessary?

Also, You won't be sharing code directly with me, which blows. Repurposing/reusing code is slow and barely worth it. Though as examples they work pretty well.


Though you seem intent on making code bits, so for suggestions:

Some code which moves the player with the numpad.
Some code which moves a purple worm around a screen.(nethack style)
An name input menu, both an example and something we can experiment with ourselves.
A snake that shoots venom( perhaps color-changing?) randomly
Creatures walk randomly, but are blocked by terrain features(trees and boulders) and other creatures.
The ability to make a line of terrain features from point x to point y.(walls and such)

Title: Re: ASCII Lab
Post by: Willfor on January 12, 2010, 07:15:21 pm
Why do you keep using the players location in terms of x +- 16?
I mean, I know it draws that directly to the screen at those positions, but is it really necessary?
Because it's a test/show project, and doesn't need a complicated tile setup. :P
Title: Re: ASCII Lab
Post by: eerr on January 12, 2010, 09:39:49 pm
Ugh, It was a typo.

creature vs
Creature

I also have a duplicate entry or something.
Title: Re: ASCII Lab
Post by: Lightman on January 13, 2010, 12:41:31 am
Because it's a test/show project, and doesn't need a complicated tile setup. :P

What Willfor said.

Also, You won't be sharing code directly with me, which blows. Repurposing/reusing code is slow and barely worth it. Though as examples they work pretty well.

Though you seem intent on making code bits, so for suggestions:

I don't understand what you mean, here?
Title: Re: ASCII Lab
Post by: eerr on January 13, 2010, 12:56:23 am
Ehhh, Forget it.
I'm in ur library, usin ur code.
Title: Re: ASCII Lab
Post by: Lightman on January 13, 2010, 10:37:43 pm
Ehhh, Forget it.
I'm in ur library, usin ur code.

Mah lib iz n ur cpuz... stealin' ur cyclz
Title: Re: ASCII Lab
Post by: eerr on January 13, 2010, 11:55:26 pm
I still don't know what game I'm making.

Or what you are making.


I also feel obsessive with almost half the posts in the thread.

We need to chat on msn or something.
Title: Re: ASCII Lab
Post by: Willfor on January 14, 2010, 10:30:15 pm
And then ASCII Lab became an easily modifiable high-end console emulator.

Spoiler (click to show/hide)

My mouse doesn't show up, but it's there.
Title: Re: ASCII Lab
Post by: eerr on January 15, 2010, 12:10:29 am
I've got code that draws a wall between two points.

With the hours of debugging it took to make that work, I'm not inclined to make the line shaped nicer, or avoid tacking on the end pts.

It works as long as the points aren't equal.
Title: Re: ASCII Lab
Post by: Lightman on January 15, 2010, 12:11:39 am
And then ASCII Lab became an easily modifiable high-end console emulator.

My mouse doesn't show up, but it's there.

You need the background black and green text.

eerr
Yes, we'll chat.
Title: Re: ASCII Lab
Post by: Willfor on January 15, 2010, 12:23:49 am
You need the background black and green text.

That's what I'm trying to move away from.  ;)
Title: Re: ASCII Lab
Post by: Bricks on January 15, 2010, 01:09:40 pm
Eerr, you may already know of it, and I might not understand what your issue is, but have you looked at Bresenham's line algorithm (http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm)?  It seems to be the standard raster line drawing algorithm, although it doesn't naturally allow for the double-width walls that most roguelikes require.
Title: Re: ASCII Lab
Post by: eerr on January 15, 2010, 02:13:25 pm
Eerr, you may already know of it, and I might not understand what your issue is, but have you looked at Bresenham's line algorithm (http://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm)?  It seems to be the standard raster line drawing algorithm, although it doesn't naturally allow for the double-width walls that most roguelikes require.
I think I just implemented my version by hand.
Code: [Select]
public static loc[] makeline(loc l, loc V)
        {
           

            double slope = ((double)l.X-V.X) / ((double)l.Y-V.Y);

            //int x =             
            int dx = (l.X - V.X);
            int absdx = Math.Abs(dx);
            int dy = (l.Y - V.Y);
            int absdy = Math.Abs(dy);
            int i;
            loc[] array;
            slope = (((double)dy) / ((double)dx));//dx/dy
            double altslope = (((double)dx) / ((double)dy));//dx/dy

            if (absdx > absdy)
            {
                array = new loc[absdx+1];

                if (dx <= 0)
                {
                    //i = dx;

                    for (i = dx; i <= 0; i++)
                    {
                        loc G;
                        G.X = i;
                        G.Y = (int)((double)i * slope -.5);

                        array[Math.Abs(i)] = G+V;

                    }
                    array[0] = V;
                    array[array.Length-1] = l;
               
                }
                else
                {
                    //absdx = dx;
                    for (i = 0; i <= absdx; i++)
                    {
                        loc G;
                        G.X = i;
                        G.Y = (int)((double)i * slope +.5);
                        array[i] = G+V;

                    }
                    array[0] = V;
                    array[array.Length - 1] = l;
                }
            }


            else
            {
                array = new loc[absdy+1];
                if (dy <= 0)
                {


                    for (i = dy; i <= 0; i++)
                    {
                        loc G;
                        G.Y = i;
                        G.X = (int)((double)i * altslope -.5);

                        array[Math.Abs(i)] = G+V;

                    }
                    array[0] = V;
                    array[array.Length - 1] = l;
                }
                else
                {
                    for (i = 0; i < absdy; i++)
                    {
                        loc G;
                        G.Y = i;
                        G.X = (int)((double)i * altslope +.5 );
                        array[i] = G+V;

                    }
                    array[0] = V;
                    array[array.Length - 1] = l;

                }

                //return Math.Abs(l.X - V.X);
            }

            return array;
        }

You can substitute point for loc without any changes if you sub
Code: [Select]
array[i] = G+V; for array[i].X = G.X+V.X; and array[i].Y = G.Y+V.Y;. I slowed down the algorithm further by operator overloading loc+loc. The last two points are copied over by hand. I am currently in fear of using mouse.x and mouse.y because I screwed up something which hung the computer. And then later the IDE crashed.


Actually, Bresenham's algorithm looks really good for making thick walls. Whenever the y increases, you either need an extra wall next to that point or at the point before.

Edit 2: Algorithm fixed for center-ness.
Edit 3: Algorithm fixed for further center-ness.
Title: Re: ASCII Lab
Post by: Bricks on January 15, 2010, 06:52:28 pm
Actually, Bresenham's algorithm looks really good for making thick walls. Whenever the y increases, you either need an extra wall next to that point or at the point before.

Good call, I didn't consider that.
Title: Re: ASCII Lab
Post by: eerr on January 15, 2010, 08:28:20 pm
Spoiler (click to show/hide)
Just my imagination. I failed to see the full black tip of the mouse properly against that rainbow background.
I changed it to dwarves and saw it fine.
Title: Re: ASCII Lab
Post by: Lightman on January 17, 2010, 05:51:26 pm
That's what I'm trying to move away from.  ;)

Fair enough :)

Binary demo added to the original post. It adds a few things.
Title: Re: ASCII Lab
Post by: eerr on January 18, 2010, 06:47:54 pm
Ok, I figured out what I want to make, finally.
Title: Re: ASCII Lab
Post by: eerr on January 20, 2010, 11:29:08 pm
And it has nothing to do with Dwarf fortress.
Title: Re: ASCII Lab
Post by: Alexhans on February 21, 2010, 10:37:13 pm
how's this going, lightman?

I never actually made myself the time to try it properly because I figured I didn't have time to fiddle with c# but that may change soon enough in april depending on the bosses in my chain of command :P

So... If this is still alive by then I might get involved for learning purposes.
Title: Re: ASCII Lab
Post by: eerr on February 22, 2010, 01:44:14 pm
Lightman has no time, nor does he have any time in the near future.

Though features for the lab like something new to do with images wouldn't be out of the question, I think.

The lab for drawing ASCII text is sufficiently completed to draw most every symbol in dwarf fortress, in a DIY manner.

I'm surprised more people haven't posted about using it actually.

Title: Re: ASCII Lab
Post by: Willfor on February 22, 2010, 02:20:05 pm
This game itself is mostly meant to be a private project for friends based on the world and characters we've developed together, but I guess posting screens wouldn't be too egregious.


Spoiler (click to show/hide)

I'm planning to use elements of the source later in a more public project.
Title: Re: ASCII Lab
Post by: Outcast Orange on February 23, 2010, 12:51:04 am
That looks really nice.

I would like to see more of this.