TBFG (turn based fantasy game)
That is the Code for the 1st Layer.
numberOfBitmaps = how many different 32x32 pixel-Bitmaps will be used
Game.mapBase = Array of integer (2dimensional)
How can I improve permormance in this code?
How can I do this in Direct3d?
Thanks alot,
Roman
//Draw surface (gras, whater..)
using System;
using System.Drawing;
using Microsoft.DirectX;
using Microsoft.DirectX.DirectDraw;
using TBFG;
using TBFG.Global;
namespace TBFG.Drawing
{
public class MapDrawObject
{
public MapDrawObject(Device display, int numberOfBitmaps)
{
_theMapSurfaces = new Surface [numberOfBitmaps];
_description=new SurfaceDescription();
_description.Clear();
_description.Width=32;
_description.Height=32;
for (int i = 0; i<numberOfBitmaps; i++)
{
_theMapSurfaces [i] = new Surface("Bilder\\Base\\" + i.ToString() +".bmp", _description, display);
}
}
private SurfaceDescription _description;
public Surface [] _theMapSurfaces;
public void Draw(int xPos, int yPos, Surface _back)
{
int i = yPos;
Rectangle destination = new Rectangle(0,0,32,32);
for (i = yPos; i<Global.GlobalData.YResSqr +yPos; i++)
{
int j = xPos;
for(j = xPos; j<Global.GlobalData.XResSqr +xPos; j++)
{
try
{
destination.Location=Game.target.PointToScreen(new Point((j-xPos)*GlobalData.SqaureResolution+32,(i-yPos)*GlobalData.SqaureResolution+32));
_back.DrawFast(destination.X, destination.Y, DrawingUtils.MapTile(j,i, Game.mapBase), new Rectangle(0,0,32,32), DrawFastFlags.DoNotWait );
}
catch {}
}
}
}
}
}
//Draw trees, buidungs
using System;
using System.Drawing;
using Microsoft.DirectX;
using Microsoft.DirectX.DirectDraw;
using TBFG;
using TBFG.Global;
namespace TBFG.Drawing
{
/// <summary>
/// Summary description for BuildingDrawObject.
/// </summary>
public class BuildingDrawObject
{
public BuildingDrawObject(Device display, int numberOfBitmaps)
{
_description =new SurfaceDescription();
_buildingsurfaces = new Surface [numberOfBitmaps + 1];
_description.Clear();
ColorKey CC = new ColorKey();
int aColor = Color.FromArgb(148,101,66).ToArgb();
CC.ColorSpaceHighValue = aColor;
CC.ColorSpaceLowValue = aColor;
_buildingsurfaces [1] = new Surface("Bilder\\Advanced\\Dragonhost.bmp", _description, display);
_buildingsurfaces [1].SetColorKey(Microsoft.DirectX.DirectDraw.ColorKeyFlags.SourceDraw, CC);
_description.Clear();
aColor = Color.FromArgb(115,109,181).ToArgb();
CC.ColorSpaceHighValue = aColor;
CC.ColorSpaceLowValue = aColor;
_buildingsurfaces [2] = new Surface("Bilder\\Advanced\\Tree1.bmp", _description, display);
_buildingsurfaces [2].SetColorKey(Microsoft.DirectX.DirectDraw.ColorKeyFlags.SourceDraw, CC);
_description.Clear();
aColor = Color.FromArgb(191,123,199).ToArgb();
CC.ColorSpaceHighValue = aColor;
CC.ColorSpaceLowValue = aColor;
_buildingsurfaces [3] = new Surface("Bilder\\Advanced\\Rock1.bmp", _description, display);
_buildingsurfaces [3].SetColorKey(Microsoft.DirectX.DirectDraw.ColorKeyFlags.SourceDraw, CC);
}
private SurfaceDescription _description;
public Surface [] _buildingsurfaces;
public void Draw(int xPos, int yPos, Surface _back)
{
int i = yPos;
Rectangle destination = new Rectangle(0,0,0,0);
for (i = yPos; i<Global.GlobalData.YResSqr+yPos; i++)
{
int j = xPos;
for(j = xPos; j<Global.GlobalData.XResSqr+xPos; j++)
{
destination.Location=Game.target.PointToScreen(new Point((j-xPos)*GlobalData.SqaureResolution+32,(i-yPos)*GlobalData.SqaureResolution+32));
try
{
if(Game.mapAdvanced.GetMapValue(j, i)!=0)
{
_back.DrawFast(destination.X, destination.Y, DrawingUtils.MapTile(j,i, Game.mapAdvanced), DrawFastFlags.DoNotWait |DrawFastFlags.SourceColorKey );
}
}
catch {}
}
}
}
}
}