izometrična grafika

Vse kar se tiče programiranja iger.
Odgovori
Silver_War
Prispevkov: 664
Pridružen: 01.06.2004 14:50:41

izometrična grafika

Odgovor Napisal/-a Silver_War » 27.03.2006 14:59:53

Pozdravljeni

Kje bi lahko dobil kakšne dobre primere za izdelavo isometričnega grafičnega pogona.

T
Prispevkov: 95
Pridružen: 02.01.2005 23:18:53

izometrična grafika

Odgovor Napisal/-a T » 28.03.2006 11:48:18

Če ti kaj pomaga, OpenGL podpira, poleg perspektivnega, tudi izometričen 3D pogled.

lp
T

Silver_War
Prispevkov: 664
Pridružen: 01.06.2004 14:50:41

izometrična grafika

Odgovor Napisal/-a Silver_War » 29.03.2006 21:48:02

Žal mi to trenutno nebi prišlo prav, saj hočem, da je ta izometrični pogon čim bol enostaven.

Silver_War
Prispevkov: 664
Pridružen: 01.06.2004 14:50:41

izometrična grafika

Odgovor Napisal/-a Silver_War » 30.03.2006 12:13:15

OK na delphi about sem našel članek, ki opisuje izdelavo izometričnega pogona, vendar pa sem naletel na eno težavo, ki je neznam rešit. In sicer pri izbiranju celic (tilov). Ni mi jasno zakaj mi jih od vrha pa do polovice navzdol izbira lepo, potem pa ne. A mi lahko kdo pomaga?

Koda: Izberi vse

 unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DXDraws, DXClass, DXInput;

type
  TTile = Record
    TileImage: Integer;
    Marked: Boolean;
  end;

type
  TTileMap = Record
    Map: array[1..50,1..50] of TTile;
  end;

type
  TMainForm = class(TDXForm)
    DXDraw: TDXDraw;
    TileMaps: TDXImageList;
    DXTimer: TDXTimer;
    DXInput: TDXInput;
    Markers: TDXImageList;
    procedure DXTimerTimer(Sender: TObject; LagCount: Integer);
    procedure FormCreate(Sender: TObject);
    procedure DXDrawMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
  private
    { Private declarations }
    procedure DrawTiles(StartX, StartY : Integer);
    procedure CheckTiles(X, Y: Integer; var XTile, YTile: Integer);
  public
    { Public declarations }
  end;

var
  MainForm: TMainForm;
  Map: TTileMap;
  StartX, StartY: Integer;
  TileX, TileY: Integer;

implementation

{$R *.dfm}

procedure TMainForm.DrawTiles(StartX, StartY : Integer);
var PosX, PosY, LoopX, LoopY, XTile, YTile, NumOfTilesY,
    TileImage : Integer;
begin
    PosY := 0;
    PosX := 1;
    NumOfTilesY := 1;
    for LoopY := 1 to 50 do
    begin
        XTile := 1;
        YTile := LoopY;
        for LoopX := 1 to NumOfTilesY do
        begin
            TileImage := Map.Map[XTile, YTile].TileImage;
            if Map.Map[XTile, YTile].Marked then
            begin
                Markers.Items[0].Draw(DXDraw. Surface,
                  StartX + PosX + LoopX * 64, StartY + LoopY * 16, 0);
            end
            else
            begin
                TileMaps.Items[TileImage].Draw(DXDraw. Surface,
                  StartX + PosX + LoopX * 64, StartY + LoopY * 16, 0);
            end;
            XTile := XTile + 1;
            YTile := YTile - 1;
        end;
        NumOfTilesY := NumOfTilesY + 1;
        PosX := PosX - 32;
        PosY := PosY + 16;
    end;
    NumOfTilesY := NumOfTilesY - 2;
    PosX := PosX + 64;
    for LoopY := 1 to 49 do
    begin
        XTile := LoopY;
        YTile := 3;
        for LoopX := 1 to NumOfTilesY do
        begin
            TileImage := Map.Map[XTile, YTile].TileImage;
            if Map.Map[XTile, YTile].Marked then
            begin
                Markers.Items[0].Draw(DXDraw. Surface, StartX +
                  PosX + LoopX * 64, StartY + PosY + LoopY * 16, 0);
            end
            else
            begin
                TileMaps.Items[TileImage].Draw(DXDraw. Surface, StartX +
                  PosX + LoopX * 64, StartY + PosY + LoopY * 16, 0);
            end;
            XTile := XTile + 1;
            YTile := YTile - 1;
        end;
        NumOfTilesY := NumOfTilesY - 1;
        PosX := PosX + 32;
    end;
end;

procedure TMainForm.CheckTiles(X, Y: Integer; var XTile, YTile: Integer);
var LoopX, LoopY: Integer;
begin
  for LoopY := 1 to 50 do
  begin
    if (Y - ((0.5) * (X - StartX) + StartY + (LoopY * 32)) < 15) and (Y - ((0.5) * (X - StartX) + StartY + (LoopY * 32)) > (-15)) then
    YTile := LoopY;
  end;
  for LoopX := 1 to 50 do
  begin
    if (-(0.5) * (X - StartX) + StartY + (LoopX * 32) - Y < 15) and ((-0.5) * (X - StartX) + StartY + (LoopX * 32)- Y > (-15)) then
    XTile := LoopX;
  end;
end;

procedure TMainForm.DXTimerTimer(Sender: TObject; LagCount: Integer);
begin
    if not DXDraw.CanDraw then Exit;
    DXDraw.Surface.Fill(0);
    MainForm.Caption := 'FPS:' + InttoStr(DXTimer.FrameRate);
    DrawTiles(StartX, StartY);
    DXDraw.Flip;
    DXInput.Update;
    If isLeft in DXInput.States then StartX := StartX + 16;
    If isRight in DXInput.States then StartX := StartX - 16;
    If isUp in DXInput.States then StartY := StartY + 8;
    If isDown in DXInput.States then StartY := StartY - 8;
end;

procedure TMainForm.FormCreate(Sender: TObject);
begin
    StartX := 1;
    StartY := 1;
    DXTimer.Enabled := True;
end;

procedure TMainForm.DXDrawMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
    Map.Map[TileX, TileY].Marked := False;
    CheckTiles(X - 96, Y, TileX, TileY);
    Map.Map[TileX, TileY].Marked := True;
end;

end. 

Odgovori