Archive

Archive for the ‘.net’ Category

Scorched Earth clone

November 6th, 2009 Sune Rievers No comments

I’ve just finished a tutorial from www.riemers.net. The tutorial was about learning 2D programming in XNA, by creating a (very simplified) clone of Scorched Earth (a long time favorite of mine from a distant time :) ).

I’ve added a few features, namely:

  • Menu screen with number of players selection
  • Restart game by pressing escape
  • Xbox360 version :D
  • Vibration in Xbox360 mode
  • Optimized collision detection by checking X-values of objects before creating matrices
  • Original Scorch death/win messages
  • Computer players with multiple types of AI
  • Numerous small tweaks, including kill count, stats and support for multiple rockets

Download is available here: rievers.dk

Categories: .net, c#, xna Tags: , , , , ,

LinkButton madness

May 13th, 2009 Sune Rievers 1 comment

When you have an <asp:repeater> with an embedded LinkButton, in some cases the OnClick event does not fire for some reason. Even when using LinkButton as Command instead, does absolutely nothing…

This code works, however:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        if (!Page.IsPostBack)
        {
            var s = from s1 in HttpContext.Current.Request.ServerVariables.AllKeys
                    select new { name = s1.ToString() };

            this.rep.DataSource = s;
            this.rep.DataBind();
        }

    }

    protected void Hello(object sender, EventArgs e)
    {
        LinkButton l = (LinkButton)sender;

        l.Enabled = false;
        l.Text = String.Format("<b>{0}</b> Clicked", l.CommandArgument);
    }

}

The page for the codebehind is here:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="NestedLinkButton.aspx.cs" MasterPageFile="~/Master/default.master" Inherits="_Default" %>
<asp:Content ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <ul>
    <asp:Repeater ID="rep" runat="server">

        <ItemTemplate>

            <li><%# Eval("name") %> <asp:LinkButton ID="hello" runat="server" CommandArgument='<%# Eval("name") %>' Text="hej" OnClick="Hello"></asp:LinkButton></li>

        </ItemTemplate>            

    </asp:Repeater>
    </ul>

  </asp:Content>

Masterpage here:

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="default.master.cs" Inherits="Master_default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div>       

        <asp:ScriptManager ID="ScriptManager1" runat="server" />

        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>

            <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">

            </asp:ContentPlaceHolder>

        </ContentTemplate>
        </asp:UpdatePanel>

    </div>
    </form>
</body>
</html>
Categories: .net, c# Tags: