Showing posts with label source code. Show all posts
Showing posts with label source code. Show all posts

Tuesday, July 12, 2016

WinForms C# ctrl-z for undo and redo

I have a personal application I built to help sort pictures. It works really well for me, but no where near commercial quality. Every so often I add a new little feature to it.  This time I'm adding undo and redo.  The control key for handling was a little different than I expected and I had to look it up so I thought I would add it for my own future reference.

        bool bUndoDown = false;

        // checking for ctrl key
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {

            switch (e.KeyCode)
            {

                case Keys.Z:
                    if (bUndoDown)
                        break;

                    if (e.Modifiers == (Keys.Control | Keys.Shift))
                    {
                        bUndoDown = true;
                        Console.WriteLine("redo pressed");
                    }
                    else if (Control.ModifierKeys == Keys.Control)
                    {
                        bUndoDown = true;
                        undodebugcnt++;
                        Console.WriteLine("undo pressed "+undodebugcnt);
                    }
                    break;
            }
        }


    private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            if (bUndoDown)
            {
                if (e.KeyCode==Keys.Z)
                {
                    bUndoDown = false;
                }
            }
        }

I originally thought I could get this to work with just the KeyPressed event, but had to do it a little deeper in the KeyDown and KeyUp events.

Wednesday, April 1, 2009

Balance Air Game

This is the best one so far. Didn't have a lot of time again so I went 2D and wished I had enough time to add a little sound (like a hair dryer sound) and do some more complex goals (like a bucket), but I think it's probably the most fun so far. It's not super pretty, but good luck, it's really really hard.


The game is called Balance Air. You have a hair dryer at the bottom of the screen and you need to balance the ball on air and force it into the goal. You move the blower left or right to change the direction of the ball. There are 7 levels which are basically just different locations for the goal. The score for each goal is dropping over time.

As I did last time you can download a free executable of the game. It is available here: http://www.woodsgoods.com/gawxna/02balanceair.

The complete source and Visual Studio project is available for $5 at http://store.payloadz.com/go?id=246205 .

Enjoy and please give me some feedback.

Wednesday, March 25, 2009

Skeet Slider game

I didn't even think I was going to be able to get a game done this week. I was spending a bunch of time on HLSL (the XNA shader language) and not getting where I needed to get. I decided I still needed to get a game done this week and I have yet to do a 2D game using XNA so I decided (yesterday) that would be the best way to complete the project in the time left.

The game is called Skeet Slider. Not my best by far, but much better than the past few weeks while I've been learning the XNA framework. You slide a puck across the bottom of the screen trying to avoid bouncing blocks. It's all about timing. I wanted to add a feature to change the velocity of the puck, but I'm out of time. Here is a screen shot of the game on level 4, the highest level. I spent a little time at the end to add better art for the game so it is cleaner that what I've written in XNA so far.



I also messed with the publish system in XNA Game Studio 3.0 and created an installer you can use to run the game. It is available here: http://www.woodsgoods.com/gawxna/01skeetslider.

I have also been considering offering the source code to some of these games to try and cover some of my time. It's a minimal $5 to purchase the C# source code to the Skeet Slider XNA Game. Please tell me if you think this is reasonable or not? I could really use some feedback.