locked
Scoring Behavior RRS feed

  • Question

  • I am attempting to write a behavior for a hockey game that we are creating.  We are having trouble figuring out how to write this behavior as we are new to c#.  We need to be able to tell the program to add to a certain score depending on which side the puck goes through.  We also do not know how to tell it to reset the game with the updated score after the puck goes off screen.  Any ideas?  We are using physics helper 4 for the motion.  I'm not sure if it helps, but I have attached the xaml code for the program.  Also, the coding has to be in c#.  Thank you
    <UserControl
    	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    	xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:BeeHive="clr-namespace:BeeHive;assembly=BeeHive" xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" xmlns:local="clr-namespace:SilverlightApplication4"
    	xmlns:pb="clr-namespace:Spritehand.PhysicsBehaviors;assembly=Spritehand.PhysicsBehaviors"
    	xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
    	x:Class="SilverlightApplication4.MainPage"
    	Width="640" Height="480">
    
    	<Canvas x:Name="LayoutRoot" Background="White">
    		<i:Interaction.Behaviors>
    			<pb:PhysicsControllerBehavior GravityVertical="0" MousePickEnabled="True"/>
    		</i:Interaction.Behaviors>
    		<i:Interaction.Triggers>
    			<i:EventTrigger>
    				<ei:GoToStateAction StateName="Start"/>
    			</i:EventTrigger>
    		</i:Interaction.Triggers>
    		<VisualStateManager.VisualStateGroups>
    			<VisualStateGroup x:Name="Game">
    				<VisualState x:Name="Start">
    					<Storyboard>
    						<ColorAnimation Duration="0" To="#FF1111DE" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="paddle" d:IsOptimized="True"/>
    						<ColorAnimation Duration="0" To="#FFF31B10" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="paddle_Copy" d:IsOptimized="True"/>
    						<DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="textBlock" d:IsOptimized="True"/>
    						<DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="textBlock1" d:IsOptimized="True"/>
    						<ColorAnimation Duration="0" To="#FFD81212" Storyboard.TargetProperty="(UIElement.OpacityMask).(SolidColorBrush.Color)" Storyboard.TargetName="textBlock1" d:IsOptimized="True"/>
    					</Storyboard>
    				</VisualState>
    			</VisualStateGroup>
    		</VisualStateManager.VisualStateGroups>
    		<ed:Arc x:Name="paddle" ArcThickness="20" ArcThicknessUnit="Pixel" EndAngle="360" Fill="#FFF4F4F5" Height="59" Canvas.Left="42" Stretch="None" Stroke="#FF1111DE" StartAngle="0" Canvas.Top="211" UseLayoutRounding="False" Width="59">
    			<i:Interaction.Behaviors>
    				<pb:PhysicsObjectBehavior RestitutionCoefficient="1"/>
    			</i:Interaction.Behaviors>
    		</ed:Arc>
    		<Ellipse x:Name="puck" Fill="#FF080810" Height="32" Canvas.Left="264" Stroke="Black" Canvas.Top="211" Width="33">
    			<i:Interaction.Behaviors>
    				<pb:PhysicsObjectBehavior RestitutionCoefficient="1"/>
    				<local:MotionBehavior Direction="-20" Speed="10"/>
    			</i:Interaction.Behaviors>
    		</Ellipse>
    		<Path Data="M76,35 L550,35" Height="1" Canvas.Left="34" Stretch="Fill" Stroke="#FF29AF16" Canvas.Top="35" UseLayoutRounding="False" Width="576" Fill="#FF29AF16">
    			<i:Interaction.Behaviors>
    				<pb:PhysicsObjectBehavior IsStatic="True"/>
    			</i:Interaction.Behaviors>
    		</Path>
    		<Path Data="M76,35 L550,35" Height="1" Canvas.Left="34" Stretch="Fill" Stroke="#FF29AF16" Canvas.Top="442" UseLayoutRounding="False" Width="585" Fill="Black">
    			<i:Interaction.Behaviors>
    				<pb:PhysicsObjectBehavior IsStatic="True"/>
    			</i:Interaction.Behaviors>
    		</Path>
    		<Path Data="M24,383 L22,290" Fill="#FFF4F4F5" Height="144" Canvas.Left="31" Stretch="Fill" Stroke="#FF29AF16" Canvas.Top="299" UseLayoutRounding="False" Width="3">
    			<i:Interaction.Behaviors>
    				<pb:PhysicsObjectBehavior IsStatic="True"/>
    			</i:Interaction.Behaviors>
    		</Path>
    		<Path Data="M24,383 L22,290" Fill="#FFF4F4F5" Height="156" Canvas.Left="31" Stretch="Fill" Stroke="#FF29AF16" Canvas.Top="35" UseLayoutRounding="False" Width="3">
    			<i:Interaction.Behaviors>
    				<pb:PhysicsObjectBehavior IsStatic="True"/>
    			</i:Interaction.Behaviors>
    		</Path>
    		<Path Data="M24,383 L22,290" Fill="#FFF4F4F5" Height="156" Canvas.Left="607" Stretch="Fill" Stroke="#FF29AF16" Canvas.Top="35" UseLayoutRounding="False" Width="3">
    			<i:Interaction.Behaviors>
    				<pb:PhysicsObjectBehavior IsStatic="True"/>
    			</i:Interaction.Behaviors>
    		</Path>
    		<Path Data="M24,383 L22,290" Fill="#FFF4F4F5" Height="144" Canvas.Left="616" Stretch="Fill" Stroke="#FF29AF16" Canvas.Top="299" UseLayoutRounding="False" Width="3">
    			<i:Interaction.Behaviors>
    				<pb:PhysicsObjectBehavior IsStatic="True"/>
    			</i:Interaction.Behaviors>
    		</Path>
    		<ed:Arc x:Name="paddle_Copy" ArcThickness="20" ArcThicknessUnit="Pixel" EndAngle="360" Fill="#FFF4F4F5" Height="59" Canvas.Left="551" Stretch="None" Stroke="#FFF31B10" StartAngle="0" Canvas.Top="201" UseLayoutRounding="False" Width="59">
    			<i:Interaction.Behaviors>
    				<pb:PhysicsObjectBehavior RestitutionCoefficient="1"/>
    			</i:Interaction.Behaviors>
    		</ed:Arc>
    		<TextBlock x:Name="textBlock" Height="16" Canvas.Left="53" Opacity="0" TextWrapping="Wrap" Text="Blue Score: 0" Canvas.Top="2" Width="169"/>
    		<TextBlock x:Name="textBlock1" Height="15" Canvas.Left="441" Opacity="0" TextWrapping="Wrap" Text="Red Score: 0" Canvas.Top="1" Width="143" OpacityMask="Black"/>
    	</Canvas>
    </UserControl>
    

    Wednesday, October 5, 2011 5:42 PM