BrownBot Logo BrownBot Head

Dispell Magazine Review

4:18 pm Filed under: Uncategorized

PascalGamer_Banner_110x80 A month or so ago I got an enquiry through the website asking for some details about Dispell, it particular whether it was written in Pascal.

Turns out it was a guy starting an online magazine about Pascal game development, and wanted some games to review.

The first issue is out now and he gave Dispell a pretty good review, he completely missed the fact that it is actually a kids game, but I think that was the problem with Dispell all along, it wasn’t really all that clear… and a bit hardcore in the game-play… I think my testers (wife and nephews) played it too much and got too good.

Ghost Dirchie

2:29 am Filed under: Dirchie Kart,XNA

I achieved one more step along the path to Dirchie AI nirvana this afternoon by implementing a time trial mode with a recorded ghost of your last best lap.

image

I was having all sorts of trouble getting the ghost to sync with the lap time, he was always a bit faster than you even if you beat his lap time. The solution was to put the game back into fixed time step mode (so your update method always runs at 60fps).

Good ole Shawny Hargreaves has a great article explaining how XNA handles it.

What does the ghost have to do with the AI? I’m planning on using the best ghost data as the optimum racing line for the AI drivers. How exactly I do this… I don’t know…. yet.

Stacking DataTemplates – Code Reuse in WPF

11:10 pm Filed under: WPF

Today I was working on the UI for our Product business objects which use a bit of inheritance, it turned into a nice concise example of a DataTemplate stacking technique that I use.

First have a quick look at the class diagram, you’ll see some basic inheritance and a few fields added at each level Product – Ingredient – Drug.

ProductsDiag Now check out the UI, you’ll see the fields added at each inheritance level correspond to a Blue expander.

ProductUI To achieve this effect I use a series of ContentControls, DataTemplates and a TemplateSelector to handle the splitting of the object types.

The main DataTemlpate for all Products looks like this:

<DataTemplate x:Key="ItemReadOnlyTemplate">
    <StackPanel>
        <Expander Header="Product Detail" IsExpanded="{Binding Path=ROExpanderStates[0], Source={StaticResource ViewModelODP}}">
            <Grid >
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="0.3*" />
                    <ColumnDefinition Width="0.7*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <TextBlock Grid.Column="0" Grid.Row="0" Text="Code:" Style="{StaticResource LabelTBStyle}"/>
                <TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding Path=Code}" Style="{StaticResource ValueTBStyle}"/>

                <Border Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2" Style="{StaticResource AlternateGridTextBorderStyle}" />
                <TextBlock Grid.Column="0" Grid.Row="1" Text="Name:" Style="{StaticResource LabelTBStyle}"/>
                <TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding Path=Name}"  Style="{StaticResource ValueTBStyle}"/>

                <TextBlock Grid.Column="0" Grid.Row="2" Text="Type:" Style="{StaticResource LabelTBStyle}"/>
                <TextBlock Grid.Column="1" Grid.Row="2" Text="{Binding Path=Type.Name}" Style="{StaticResource ValueTBStyle}"/>
            </Grid>
        </Expander>
        <ContentControl Content="{Binding}" ContentTemplateSelector="{StaticResource ROTempateSelector}" />
    </StackPanel>
</DataTemplate>

Expander displays all the fields from the base “Product” object, the ContentControl at the bottom is hooked up to a TemplateSelector to feed in any additional DataTemplates based on the object type.

The TemplateSelector definition look like this:

<Qaf_Local:ProductTemplateSelector x:Key="ROTempateSelector"
    DefaultTemplate="{StaticResource ItemRODefaultTemplate}"
    IngredientTemplate="{StaticResource ItemROIngredientTemplate}"
    DrugTemplate="{StaticResource ItemRODrugTemplate}"
    FinishedProductTemplate="{StaticResource ItemROFinishedProductTemplate}"
                                   />

Fairly self explanatory, the only DataTemlpate that does anything tricky is the ItemRODrugTemplate which uses a similar technique as above to stack the ItemROIngredientTemplate in it’s own DataTemplate, which looks like:

<DataTemplate x:Key="ItemRODrugTemplate">
    <StackPanel>
        <ContentControl Content="{Binding}" ContentTemplate="{StaticResource ItemROIngredientTemplate}" />
        <Expander Header="Drug Details" IsExpanded="{Binding Path=ROExpanderStates[2], Source={StaticResource ViewModelODP}}">
            <Grid >
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="0.3*" />
                    <ColumnDefinition Width="0.7*" />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition />
                </Grid.RowDefinitions>
                <TextBlock Grid.Column="0" Grid.Row="0" Text="Is S4:" Style="{StaticResource LabelTBStyle}"/>
                <TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding Path=IsS4}" Style="{StaticResource ValueTBStyle}"/>
            </Grid>
        </Expander>
    </StackPanel>
</DataTemplate>

The one trick you need to look out for when stacking the DataTemplates like this is the weird binding with no path:

<ContentControl Content="{Binding}" ContentTemplate="{StaticResource ItemROIngredientTemplate}" />

This passes the current DataContext (the Product object) through to the ContentControl, without it you’ll get blank fields.

Name Generator

12:51 am Filed under: Uncategorized

I’ve been chipping away at this one for a little while, with a renewed push I finished it off over the last couple of days.

image

Basically it’s an N tier random name generator and ranking system with a 3D UI, I’m betting most of you just went WTF!

Here goes (this is all in the context of finding a name for my new feedmill administration application):

  1. Client reads in a list of name parts (letters a through to z plus any interesting letter combinations you might like to see in the name, in this case, “feed”, “admin”).
  2. Client generates a name from a random sequence of name parts (must be between 3 and 10 letters long).
  3. User either accepts (left arrow) or rejects (down arrow) the random name (most of them are illegible so you down arrow a lot).
  4. Any accepted names are saved to the DB and ranked with a plus vote against them, the list on the left hand side are all ranked names with a rank > 0.
  5. Next time any other client refreshes (goes to generate a name) they have to rank the saved name before they can continue with the random names.
  6. The user can back space and re-key any part of a generated name, this is very handy as the random names are usually better at giving you ideas for names than the actual names themselves.
  7. A client can also re-vote on all items at any time by pressing F12. All existing votes remain so this is a way of weeding out the really crap ones as well as re-shuffling the list over time.

I’m going to try in out with the work peeps tomorrow, should be interesting to see what we come up with across 3 or 4 clients.

I also planning on using it to try and come up with an original name for our new born, only got a few weeks to go.

Powered by WordPress