Skip to content

Commit

Permalink
Merge pull request eesast#120 from Grange007/dev
Browse files Browse the repository at this point in the history
feat: ✨ able to draw ships & bullets
  • Loading branch information
Grange007 authored Mar 9, 2024
2 parents 5557774 + 0bfa3e9 commit a4c66e2
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 5 deletions.
5 changes: 5 additions & 0 deletions logic/Client/UtilFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public static int getIndex(int i, int j)
{
return 50 * i + j;
}

public static PointF getMapCenter(float i, float j)
{
return new PointF(10 * i + 5, 10 * j + 5);
}
}


Expand Down
4 changes: 2 additions & 2 deletions logic/Client/View/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@
<BoxView x:Name="WormHole3HpSlide" Color="Green" HeightRequest="3" WidthRequest="{Binding WormHole3Length}" Grid.Row="7" HorizontalOptions="Start" VerticalOptions="End"/>
</Grid>

<Grid x:Name="MapGrid" x:FieldModifier="public" WidthRequest="500" HeightRequest="500" Grid.Row="0" Grid.RowSpan="2" Grid.Column="2" BackgroundColor="Yellow" VerticalOptions="Center" HorizontalOptions="Center"/>
<Grid x:Name="MapGrid" x:FieldModifier="public" WidthRequest="{Binding MapWidth}" HeightRequest="{Binding MapHeight}" Grid.Row="0" Grid.RowSpan="2" Grid.Column="2" BackgroundColor="Yellow" VerticalOptions="Center" HorizontalOptions="Center"/>
<!--<CollectionView ItemsSource="{Binding MapPatchesList}" Grid.Row="0" Grid.RowSpan="2" Grid.Column="2" >
<CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Vertical" Span="50" />
Expand All @@ -242,7 +242,7 @@
</CollectionView.ItemTemplate>
</CollectionView>-->

<GraphicsView x:Name ="DrawGraphicsView" WidthRequest="530" Drawable="{StaticResource drawable}" HeightRequest="530" Grid.Row="0" Grid.Column="2" Grid.RowSpan="2" BackgroundColor="Blue" />
<GraphicsView x:Name ="DrawGraphicsView" WidthRequest="{Binding MapWidth}" Drawable="{StaticResource drawable}" HeightRequest="{Binding MapHeight}" Grid.Row="0" Grid.Column="2" Grid.RowSpan="2" BackgroundColor="Blue" />

</Grid>

Expand Down
5 changes: 3 additions & 2 deletions logic/Client/View/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public MainPage()
timer.Start();
Application.Current.UserAppTheme = AppTheme.Light; //Light Theme Mode
InitializeComponent();

for (int i = 0; i < 50; i++)
{
for (int j = 0; j < 50; j++)
Expand Down Expand Up @@ -61,8 +62,8 @@ public MainPage()
private Label[,] mapPatches_ = new Label[50, 50];
private readonly IDispatcherTimer timer;
private long counter;
private int unitWidth = 10;
private int unitHeight = 10;
private double unitWidth = 10;
private double unitHeight = 10;
private void TestRefresh(object sender, EventArgs e)
{
counter++;
Expand Down
115 changes: 115 additions & 0 deletions logic/Client/ViewModel/MapViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,37 @@ public void Draw(ICanvas canvas, RectF dirtyRect)

// 绘制小球
canvas.FillEllipse(ballX, ballY, 20, 20);
DrawBullet(new MessageOfBullet
{
X = 10,
Y = 10,
Type = BulletType.NullBulletType,
BombRange = 5
}, canvas);

DrawShip(new MessageOfShip
{
X = 10,
Y = 11,
Hp = 100,
TeamId = 0
}, canvas);

DrawBullet(new MessageOfBullet
{
X = 9,
Y = 11,
Type = BulletType.NullBulletType,
BombRange = 5
}, canvas);

DrawShip(new MessageOfShip
{
X = 10,
Y = 12,
Hp = 100,
TeamId = 1
}, canvas);
}

private Dictionary<MapPatchType, Color> PatchColorDict = new Dictionary<MapPatchType, Color>
Expand Down Expand Up @@ -719,6 +750,62 @@ private void DrawResource(MessageOfResource data)
MapPatchesList[index].TextColor = Colors.White;
}

private void DrawBullet(MessageOfBullet data, ICanvas canvas)
{
PointF point = UtilFunctions.getMapCenter(data.X, data.Y);
float x = point.X;
float y = point.Y;
switch (data.Type)
{
case BulletType.Plasma:
canvas.FillColor = Colors.Red;
break;
case BulletType.Laser:
canvas.FillColor = Colors.Orange;
break;
case BulletType.Missile:
canvas.FillColor = Colors.Yellow;
break;
case BulletType.Arc:
canvas.FillColor = Colors.Green;
break;
case BulletType.Shell:
canvas.FillColor = Colors.Green;
break;
default:
canvas.FillColor = Colors.Black;
break;
}
canvas.FillCircle(x, y, 2);
}

private void DrawShip(MessageOfShip data, ICanvas canvas)
{
PointF point = UtilFunctions.getMapCenter(data.X, data.Y);
float x = point.X;
float y = point.Y;
int hp = data.Hp;
long team_id = data.TeamId;
switch (team_id)
{
case (long)PlayerTeam.Red:
canvas.FillColor = Colors.Red;
break;

case (long)PlayerTeam.Blue:
canvas.FillColor = Colors.Blue;
break;

default:
canvas.FillColor = Colors.Black;
break;
}
canvas.FillCircle(x, y, (float)4.5);
canvas.FontSize = 5.5F;
canvas.FontColor = Colors.White;
canvas.DrawString(Convert.ToString(hp), x - 5, y - 5, 10, 10, HorizontalAlignment.Left, VerticalAlignment.Top);
}

//private void DrawBullet(MessageOfBullet data)
//{
// //Ellipse iconOfBullet = new()
Expand Down Expand Up @@ -877,5 +964,33 @@ public ObservableCollection<MapPatch> MapPatchesList
private readonly double characterRadiusTimes = 400;
private readonly double bulletRadiusTimes = 200;

private int mapHeight = 500;
public int MapHeight
{
get
{
return mapHeight;
}
set
{
mapHeight = value;
OnPropertyChanged();
}
}

private int mapWidth = 500;
public int MapWidth
{
get
{
return mapWidth;
}
set
{
mapWidth = value;
OnPropertyChanged();
}
}

}
}
1 change: 0 additions & 1 deletion logic/Client/ViewModel/PlayerStatusBarViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public Player BluePlayer
}
}


}

}

0 comments on commit a4c66e2

Please sign in to comment.