• ### Blog Entries

• entries
29
35
• views
18019

My epic adventure to make a level editor in c# and use this to make a game.

## Pissed (again)

Sorry to be such a ranter, but now these two days I've been working on the project at work (look one post down) I have really come to understand why people complain so much about Internet Explorer. It is really frustrating working with, most common things work as expected(not the box model, but that is a whole chapter by itself, wtf?) but then, when you scratch the surface and so you get completely stunned about the difference between it and Firefox, Opera. Firefox and Opera are pretty much the same, though Opera has surprised me a couple of times. I see now that I look like a Firefox fanboy ranting about "how good Firefox is", but this is not the case. I have no real favorite browser, but Firefox makes the best job giving me what I expect to get when I reload the page. And I don't only talk about cosmetic things though they are the worst to cope with, like not having a disabled option for

## Damn IE!

Did you know that IE doesn't support the text doesn't get gray and the option is very selectable, I found this out today when writing some time based code. Showing the days of the week in an selectbox, but no, it didn't work. Checked firefox to be sure, and yes my code work fine. Began to search the net for a answer. Here I saw that the "feature" was considered to be included in IE7, feature...well it's standard. w3 says that BUTTON, INPUT, OPTGROUP, OPTION, SELECT, and TEXTAREA should support the disabled attribute. Well it all ended with me doing an ugly hack, as usual, I check if the client is using IE (serverside) and then I just don't print the options, but if the client use any other browser I print it out the way it is meant to be. It's a shame though, 99.8 % of the user who are going to use the application is going to use IE.

There, done ranting. Just got a little pissed, not that a gamedeveloper forum is an ideal place to rant about webdevelopment quirks, but had to get it out [smile]

## Undo / Redo done

Done with undo and redo, got the history list up and running to but I have to work some more on that one. And make some proper graphics for it to. And well the only actions really implemented is EntityAdded and EntityRemoved, but gonna make the layer added removed actions when I get to write the code that actually adds and removes layers [smile].

So now I have to come up with what to write next, I think its gonna be the layer form, won't be to hard either, should have it functional the next time I get to code some.

After that there isn't that much more to do, just the polishing, but no major parts. No major parts that I have already decided, but I hope to come up with some more soon. I'll look at some other free leveleditors and perhaps get some inspiration, some suggestions on what to add would also be appreciated.

And well here is a screen of the history list in action.

## Undo and redo part 2

Got a simple application with undo/redo up and running today. Basically each of the buttons registers a ButtonPressAction every time they are pressed, and if you do a undo you register a ButtonPressRemoveAction. And the code to actuallt undo/redo is index based, it manipulates the listbox.items at the current index.
The CircularStack class is made in a couple of seconds so I won't take any responsibility on that it is perfect :)

Try it if you want. Clicky

## Undo/Redo

Hello. Got some progress to show today. Woho. First of all, a thanks to Reiner for making free tile sets to use, I'm currently using one to see what I'm doing.

Here are three screenshots of my progress(click them to see full size):
Screen 1
Here you see the grid, the snap to grid works too. Really easy to make maps fast, will go even faster when I get Undo/Redo up and running, but more about that later.

Screen 2
Here you can see the info box in action, called Navigator in photoshop. Took a while to get it right, but now it works perfectly. The red box follows the what is shown in the form, zoom doesn't work yet but when it does the info box will show that too.

Screen 3
Not much new here, a saved map. We can give the history and layers forms a little attention to then. The names are kind of self-explanatory but well the history form is what is getting the most attention now, it will work so that every action you do can be undone, and also reverted back to in one jump. The layer form will basically show all the layers on the map and enable editing in form of layer order manipulation and such.

Undo and Redo
Now this is my mission, I think I will try the memento pattern.
I will make a interface of an action that all action that you can do in the editor will inherit from, and a history class that keeps a undo and a redo stack of actions. When I pop a state from the undo stack I push it onto the redo stack and the other way around if I redo.
The tricky part I think will be representing actions. I could represent a addTile action with a copy of the tile added, but this will skyrocket my memory usage I guess. I will have to think about this for a while before I begin to code. Suggestions are always welcome [smile].

Well that was this for this day, I hope to be able to do these kind of updates a couple of times a week. Bye to then!

## Change of plans

Changed my mind some about the leveleditor. Have been coding some on it, but haven't really come far. I'm modeling it after a well known program that I find easy to use, which the leveleditor hopefully will be too.

But well here is the progress:
The painting selecting and moving tools are functional, the yellow box around one of the green tiles marks that the tile is selected, you can select as many tiles as you want. I will implement a selection box, like in explorer, that selects all the tiles that are within the box, but for now you have to select the tiles one by one.
Once selected you can move the tiles around, using the move tool, right now only by the keyboard but mouse movement should come soon.

Here comes the screenshot:

I will hopefully get some work done on it now that school is done, have my final exam in 12 hours. Got some grand plans for this :)

## Here's the list

In no particular order:

UML 2 Toolkit - Hans-Erik Eriksson, Magnus Penker, Brian Lyons, David Fado.
Mono (kick start) - Hans-Jurgen Schoning, Edwald Geschwinde.
Real-time 3D Terrain Engines using C++ and DirectX 9 - Greg Snook.
Managed DirectX 9 Graphics and Game Programming (kick start) - Tom Miller.
Beginning OpenGL Game Programming - Dave Astle, Kevin Hawkins.
Algorithm Design - Michael T. Goodrich, Roberto Tamassia.
3D Game Engine Design - David H. Eberly.
Core Techniques and Algorihms in Game Programming - Daniel Sanchez, Crespo Dalmau.
C# Step by Step - John Sharp, Jon Jagger.

Any comments on any of the books would be appreciated.

## Books, computers and web dev

Hello, long time since I updated. Haven't done much really, programming vise that is. But I've got a new laptop, a HP with core 2 duo, 2gb ddr2 667mhz ram, a ati x700 gfx card and a 17" screen :)
I also bought a new gfx card for my desktop, replacing my old gf 4 and some ram and silent cpu cooler. I bought a 0db power supply too, but it didn't work, so I guess I'll get it back any day now, or a new one really.
And I have also bought some books, 9 actually. Those cover a lot of subjects, c#, direct x 9, mdx 9, algoritms, engine design, open gl and c++. I'll post a list and ask for comments when I get home to them so I can tell the whole title and authors.
What I have been doing mostly is work on my friends web page, or a page for his band, a metal band. The address is www.winterdawn.com. It is in swedish, and I'm waiting for him to add content, using a neat cms I wrote to the page. What do you think of it?

Well, gonna get back to work on the level editor now, now when I got a svn repository for it.

Cya guys [smile]

## Minor update

I forgot to mention something in the last post, I need some help. In the SlidingControl I slide the control back to the originalSize, but I can't set the originalSize, I want to set this to the size the user sets the Width or Height to, but the propertioes Width and Height isn't overload able. Anyone got any suggestions? In c#.

## Some progress

Hello everyone, I got some progress, not on the toolbox(or well in a way). I just got my SlidingControl to work, it's basically a control just that if you tell it to slide back and it is docked, well yea then it does just that :)
The control is able to slide in any direction you can dock a control, that is any direction Up, Down, Left and Right. If the control is not docked or docked to fill then it does nothing.
Then I just inherit all my controls that I want to be able to slide from this control, in the level editor it will be at least two, one for the tiles, the "toolbox" and another one for the scripting box. I might add one to the right side to, containing map data, name background image etc.

Well I'm under the impression that no journal is popular without images so I'll post a screen shot and better up, I'll post the executable and the code too [smile].

Here is the image:

To the left is a simple SlidingControl it has the delay of 2 seconds, to the right you see my early toolbox, it is click able and so, you can expand the tabs and select the items, but no more.

And here is the executable:
The file
You need .net 2.0 to run it. It is in .zip format.

And finally the code:
[source lang=c#]using System;using System.Collections.Generic;using System.Text;using System.Windows.Forms;using System.Drawing;namespace MyToolboxTest{    ///     /// Represents a control that slides back to were it is docked after a delay. Only slides if docked    ///     class SlidingControl : UserControl    {        #region // Enumerators        ///         /// Represents a state the control can be in        ///         enum State        {            Open,            Closed,            Opening,            Closing        };        ///         /// Represents a direction the control can open/clise in, is based on the DockStyle so it can be changed when the docking changes        ///         enum Direction         {            Up = 1,            Down = 2,            Left = 3,            Right = 4        };        #endregion        #region // Private variables        private Timer delayTimer;        private Timer moveTimer;        private State state;        private Direction slideDirection;        private int step;        private Size originalSize;        private bool slide;        #endregion        #region // Constructor        public SlidingControl()        {            delayTimer = new Timer();            delayTimer.Interval = 2000; // wait for 2 seconds before closing            delayTimer.Tick += new EventHandler(delayTimer_Tick);            delayTimer.Start();            moveTimer = new Timer();            moveTimer.Interval = 10;            moveTimer.Tick += new EventHandler(moveTimer_Tick);            state = State.Open;            slideDirection = Direction.Right;            step = 2;            slide = true;            // Windows init            Location = new Point(0, 0);            this.Size = new Size(150, 150);            originalSize = Size;        }        #endregion        #region // Public functions        ///         /// Starts the sliding, either open or close        ///         public void StartMovement()        {            if (slide)            {                if (state == State.Open)                {                    state = State.Closing;                }                else if (state == State.Closed)                {                    state = State.Opening;                }                moveTimer.Start();            }        }        #endregion        #region // Event handlers        ///         /// This happens when the cursor have been outside the control longer than the delay        ///         ///         ///         void delayTimer_Tick(object sender, EventArgs e)        {            if (slide)            {                if (Dock != DockStyle.None && Dock != DockStyle.Fill)                {                    delayTimer.Stop();                    StartMovement();                }            }        }        ///         /// This is what is happening every move tick (every 10 milliseconds when moveTimer is running)        ///         ///         ///         void moveTimer_Tick(object sender, EventArgs e)        {            if (slide)            {                if (state == State.Opening)                {                    if (slideDirection == Direction.Left || slideDirection == Direction.Right)                    {                        this.Width += step;                        if (Width >= originalSize.Width)                        {                            Width = originalSize.Width;                            moveTimer.Stop();                            state = State.Open;                        }                    }                    else if (slideDirection == Direction.Up || slideDirection == Direction.Down)                    {                        this.Height += step;                        if (Height >= originalSize.Height)                        {                            Height = originalSize.Height;                            moveTimer.Stop();                            state = State.Open;                        }                    }                }                else if (state == State.Closing)                {                    if (slideDirection == Direction.Left || slideDirection == Direction.Right)                    {                        this.Width -= step;                        if (Width <= 1)                        {                            Width = 1;                            moveTimer.Stop();                            state = State.Closed;                        }                    }                    else if (slideDirection == Direction.Up || slideDirection == Direction.Down)                    {                        this.Height -= step;                        if (Height <= 1)                        {                            Height = 1;                            moveTimer.Stop();                            state = State.Closed;                        }                    }                }            }        }        #endregion        #region // Properties        ///         /// Gets or sets the delay before the control beginst to slide        ///         public int Delay        {            get { return this.moveTimer.Interval; }            set { this.moveTimer.Interval = value; }        }        ///         /// Gets or sets if the control should slide or not        ///         public bool Slide        {            get { return this.slide; }            set { this.slide = value; }        }        ///         /// Gets or sets the pixels to open/close the control with        ///         public int Step        {            get { return this.step; }            set { this.step = value; }        }        #endregion        #region // Control overrides        protected override void OnMouseEnter(EventArgs e)        {            if (slide)            {                delayTimer.Stop();                moveTimer.Start();                if (state != State.Open) { state = State.Opening; }                base.OnMouseEnter(e);            }        }        protected override void OnMouseLeave(EventArgs e)        {            if (slide)            {                if (Dock != DockStyle.None && Dock != DockStyle.Fill)                {                    delayTimer.Start();                }                base.OnMouseLeave(e);            }        }        public override DockStyle Dock        {            get            {                return base.Dock;            }            set            {                if (value != DockStyle.Fill)                {                    this.slideDirection = (Direction)value; // This is possible because the Direction enum is based on the DockStyle enum                }                base.Dock = value;            }        }        #endregion    }}

I hope the code can be useful to someone.

No one told me otherwise on including the script in the tiles, so I'll go for that. That was about it from me today, I'll post a update when I get my toolbox up and running. Until then, cya m8s. :)

## Wohoo

Gamedev is up again, got a real shock when I fired up my browser [smile]
I thought it would be down for a while more.

To continue, maybe it was good gamedev were down, got some work done finally :)
My map format is done, I have a level editor were I can save and load maps now.
Now I'm currently doing some polishing, the data I can fil the maps with now is hard coded into the level editor, I'm making a visual studio like toolbox were I will have my tiles and sprites.
I have some troubles with that, I have zero experiance with custom controls and user controls. But it is going forward.

I got a question, a little bit of design question...my tilemap doesn't support scripting, how should I add it, my first thought were to add the script for a tile in the class Tile. To just have a string that contains the script. I don't know if that is the way to go...

And well, happy to see all of you again, hope you have had a good time without gamedev, if not, I guess this will be the best week of your life. [smile]

## Wishes

I have been looking at both Stompy9999, with Blocky Man and EasilyConfused with Udo and I have been really inspired to make a platformer. This is something that I have wanted for a long time, but never really got that far with, the farthest I ever have been is this. which isn't very good.

So well now I'm gonna make another swing at it. Starting with a good map format and a decent level editor. And this is what I'm gonna describe here. If it sucks, please tell me so, so I don't spend a lot of time(that I don't have) on something worthless.

Basically I want a map format I can use for all tile based games I'm gonna make, and if it's good share with people to make their game making easier. So it have to be quite general. I don't really know how to accomplish this yet. Say if I use a SDL_Surface to store the images it is bound to SDL and so on, the best idea I've come up with is to only use graphics in one class and then if I want to use another API then just change the base class. Or if people want to use their own sprite class, they just change my sprite class with their own. But well I'm gonna make some more looking into it before I make a decision.

Anyone played and looked at SMC (Secret Maryo Chronicles)? They have a level editor thats basically like the one I want to make, you can position every tile diferent, each tile has own coordinates not tile coordinates that are multiplied with the tile width to get the position. This is how I want to make my maps. So I'm gonna make every tile a sprite, basically.

Well here comes the early sketch of my map format:

------------------------

- Entity
The ultimate base class, contains data everything has, mass position and velocity is the first to come to mind, perhaps some more data.

- Sprite : Entity
The sprite class, the one people change to use different API and such, provides drawing, moving, animation, collision and such.

- Image : Entity
Basically a static(non-animated) sprite.

- Tile : Entity // This may be unnecessary
A tile is either a image or a sprite.

- Layer
A layer contains a list of Entities, when you add a Entity you add it to the list of the layer.

- Map
Contains a list of layers to support multiple layers. Contains map data, name background image and such.

- MapHandler
Contains functions to save and load levels.

------------------------

The Entity, Image, Sprite, Tile, Layer and Map classes are gonna be serialization able. And the map file contains a serialized Map. In binary format.

Well that is about how far I've come. Sounds good?

If you got this far: Thanks for reading [smile]!

## ...

Yay, made a christmas theme for my journal instead of studying for my final exam this year...smart move... [grin]

## salary

How much should a programmer make? I know there are many threads like this one, but I'm looking for a specific answer for me :)

I make \$11.7/h (according to google) 80 sek per hour at my part-time work as a programmer, doing PHP scripting for a company that has 3-5 large websites.
I'm doing everything the other programmers are doing, but I don't have any education, in programming. I just graduated from upper secondary school, and are now attending collage, that is why I'm working part-time.

Any suggestions, does it sound fare, should I be lucky to get that much?

## swecoders.se is online

Hello, I've made a little community/forum called swecoders.se and it's targeted to Swedish programmers. So if you are Swedish, or know Swedish check out swecoders.se and make an account. If you don't know Swedish, check out the page and tell me it is ugly :)

## Well, if this isn't awesome I don't know what is

Well you all know those "key cards" you have at school, work and so to get inside. You slide the card in the machine and it let you go in. Yes?
Well, we had these to get to work on my current workplace, but last week they changed this.
Any one wanna guess what we use now?

Well I can tell you. We use our fingerprints, stick your finger in the machine and it'll let you through.

How cool isn't that! :)

## Bored

I have been looking for a simple "notes" program to store notes and schedual my time a little. But I havn't found any good ones. So with my new c# skills I made my one my self. Not good in any way...but all I wanted. A textbox that loads a file on startup and saves the file when the program terminates.
Works really well, and I'm falling more and more in love with c#. I will probably soon test XNA too. Or at the wery least DX...

Be good!

## Hello again

No, I'm not dead...just been starting out at university =)
I just wanted to pop in and say that I like c#. I've been doing some windows form programming now, and that resulted in SimpleTextEditor.exe. Guess what it is [smile]
It's around 700 lines total, and it works about the same as notepad. I'm stunned =)

Bye, take care!

## Last day

Today is my last day at work, the work at the crappy gas station...so wohoo! But a sad thing, yesterday were my last day as a programmer, the great job. That's really sad, but I talked a little with the people I worked with, and I will probably work there at the same time as I go to school(collage). And that my friends were the good news I wanted to inform you all about.
And yes, school starts on monday...I'm exited about that to, the beginning of y 4 years(at least) as a collage student [smile].

Bye, sorry about the text, I start my shift in 18 minutes, and I have to eat something and walk down to the work because my stupid car is dead, or the breakes anyway(it's a funny story, I'll tell it if you ask me :))

## c#

Are there any "Programmers guide to c#" or even better "c++ and php programmers guide to c#" books? Tired in reading about declaring variables and so forth, but still to closed minded(scared also works [smile]) to skip the chapters...

## I am so proud

I have made a particle engine, that allocates and deallocates memory on it own, newer done it before...and I made it without looking at any tutorials.

I'm so proud! [smile]

Test it

## I whish...

I whish that I had the programmer art skills of stompy!

## Some revision...

Have had some party here this weekend...but when I waved goodbye to my guests I took uot my computer and looked at the code I had produced a couple of days ago...

I had forgot to convert from polar coordinates ro rectangular...I had done it the other way around...but in my code I used angles instead of xy values on my particles =)

So here is the revision nr.1.
I'm quite proud of my self, because I have made a little particle simulation without even looking at a piece of code or reading anything about it, just using my common sense...
I'll make some improvments on it...but for now its just a "big bang" simulation. One pixel in the center that explodes and sent of 360 particles in each degree, just that they bounce of the walls.

Well just dont sit there...test it!

## Oups smile

Were a little tired and didn't bother to count and such last night...well I want to show you all what could happen then...remember...this is a particle system...and it is suposed to be a circle of particles that go in each degree of an circle 360 particles...added the collisions just to see what happened to my particles when they left the screen =) well looks cool anyway =)

The .rar file

Take a look =)