Subversion Repositories spacemission

Rev

Rev 2 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. unit LevMain;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, MMSystem,
  7.   Dialogs, StdCtrls, ExtCtrls, Menus, DIB, DXClass, DXSprite, DXDraws,
  8.   DXSounds, Spin, ComCtrls, PjVersionInfo;
  9.  
  10. type
  11.   TMainForm = class(TDXForm)
  12.     MainMenu: TMainMenu;
  13.     Spiel: TMenuItem;
  14.     Beenden: TMenuItem;
  15.     Hilfe: TMenuItem;
  16.     Mitarbeiter: TMenuItem;
  17.     Leer1: TMenuItem;
  18.     Level: TMenuItem;
  19.     Informationen: TMenuItem;
  20.     Leer2: TMenuItem;
  21.     Enemy1: TRadioButton;
  22.     Enemy2: TRadioButton;
  23.     Enemy3: TRadioButton;
  24.     Enemy4: TRadioButton;
  25.     Enemy5: TRadioButton;
  26.     Enemy6: TRadioButton;
  27.     Enemy7: TRadioButton;
  28.     ScrollBar: TScrollBar;
  29.     Bevel1: TBevel;
  30.     Bevel2: TBevel;
  31.     SelLabel: TLabel;
  32.     SelPanel: TPanel;
  33.     Bevel3: TBevel;
  34.     SLabel1a: TLabel;
  35.     SLabel2a: TLabel;
  36.     SLabel1b: TLabel;
  37.     SLabel2b: TLabel;
  38.     SLabel0: TLabel;
  39.     Neu: TMenuItem;
  40.     Image1: TImage;
  41.     SLabel3a: TLabel;
  42.     SLabel3b: TLabel;
  43.     SLabel4a: TLabel;
  44.     SLabel4b: TLabel;
  45.     LivesLabel: TLabel;
  46.     Quelltext1: TMenuItem;
  47.     StatusBar: TStatusBar;
  48.     N1: TMenuItem;
  49.     Spielfelderweitern1: TMenuItem;
  50.     LivesEdt: TEdit;
  51.     Lives: TUpDown;
  52.     procedure DXDrawFinalize(Sender: TObject);
  53.     procedure DXDrawInitialize(Sender: TObject);
  54.     procedure FormCreate(Sender: TObject);
  55.     procedure DXTimerTimer(Sender: TObject; LagCount: Integer);
  56.     procedure BeendenClick(Sender: TObject);
  57.     procedure FormDestroy(Sender: TObject);
  58.     procedure MitarbeiterClick(Sender: TObject);
  59.     procedure LevelClick(Sender: TObject);
  60.     procedure FormShow(Sender: TObject);
  61.     procedure InformationenClick(Sender: TObject);
  62.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  63.     procedure DXDrawMouseDown(Sender: TObject; Button: TMouseButton;
  64.       Shift: TShiftState; X, Y: Integer);
  65.     procedure EnemyClick(Sender: TObject);
  66.     procedure EnemyAdd(x, y, art, lives: integer);
  67.     procedure NeuClick(Sender: TObject);
  68.     procedure DXDrawMouseMove(Sender: TObject; Shift: TShiftState; X,
  69.       Y: Integer);
  70.     procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  71.     procedure Quelltext1Click(Sender: TObject);
  72.     procedure Spielfelderweitern1Click(Sender: TObject);
  73.     procedure ScrollBarScroll(Sender: TObject; ScrollCode: TScrollCode;
  74.       var ScrollPos: Integer);
  75.     procedure LivesClick(Sender: TObject; Button: TUDBtnType);
  76.     procedure LivesEdtKeyPress(Sender: TObject; var Key: Char);
  77.     procedure LivesEdtChange(Sender: TObject);
  78.   public
  79.     { VCL-Ersatz }
  80.     spriteengine: tdxspriteengine;
  81.     versioninfo: tpjversioninfo;
  82.     dxtimer: tdxtimer;
  83.     imagelist: tdximagelist;
  84.     dxdraw: tdxdraw;
  85.     { Variablen }
  86.     FDirectory: string;
  87.     FEngineVersion: string;
  88.     FMenuItem: integer;
  89.     Enemys: TStrings;
  90.     ArtChecked: integer;
  91.     LiveEdit: integer;
  92.     ScrollP: integer;
  93.     AltScrollPos: integer;
  94.     Boss: boolean;
  95.     LevChanged: boolean;
  96.     NumEnemys: integer;
  97.     { Level-Routinen }
  98.     procedure EnemyCreate(x, y: integer);
  99.     procedure DestroyLevel;
  100.     procedure AnzeigeAct;
  101.     { Initialisiations-Routinen }
  102.     procedure DXInit;
  103.     procedure ProgramInit;
  104.     { Farb-Routinen }
  105.     function ComposeColor(Dest, Src: TRGBQuad; Percent: Integer): TRGBQuad;
  106.     procedure PalleteAnim(Col: TRGBQuad; Time: Integer);
  107.     { Sonstiges }
  108.     procedure LivesChange(newval: integer);
  109.   end;
  110.  
  111. var
  112.   MainForm: TMainForm;
  113.  
  114. const
  115.   FCompVersion = '1.0';
  116.  
  117. implementation
  118.  
  119. uses
  120.   LevSplash, LevSpeicherung, LevText, LevInfo, LevSource, LevOptions;
  121.  
  122. const
  123.   FileError = 'Die Datei kann von SpaceMission nicht geöffnet werden!';
  124.   status_info = ' Zeigen Sie mit dem Mauszeiger auf eine Einheit, um deren Eigenschaften anzuzeigen...';
  125.   status_lives = ' Leben: ';
  126.   status_nolives = ' Einheit hat keine Lebensangabe';
  127.   RasterW = 48;
  128.   RasterH = 32;
  129.  
  130. {$R *.DFM}
  131.  
  132. {$R WindowsXP.res}
  133.  
  134. type
  135.   TBackground = class(TBackgroundSprite)
  136.   protected
  137.     procedure DoMove(MoveCount: Integer); override;
  138.   end;
  139.  
  140.   TEnemy = class(TImageSprite)
  141.   private
  142.     Lives: integer;
  143.     Art: integer;
  144.     XCor: integer;
  145.     CorInit: boolean;
  146.   protected
  147.     procedure DoMove(MoveCount: Integer); override;
  148.   public
  149.     constructor Create(AParent: TSprite); override;
  150.   end;
  151.  
  152. procedure TMainForm.DXInit;
  153. begin
  154.   Imagelist.Items.LoadFromFile(FDirectory+'DirectX\Graphic.dxg');
  155.   ImageList.Items.MakeColorTable;
  156.   DXDraw.ColorTable := ImageList.Items.ColorTable;
  157.   DXDraw.DefColorTable := ImageList.Items.ColorTable;
  158.   DXDraw.UpdatePalette;
  159.   DXDraw.Initialize;
  160. end;
  161.  
  162. procedure TEnemy.DoMove(MoveCount: Integer);
  163. begin
  164.   if not CorInit then
  165.   begin
  166.     XCor := trunc(x) + (MainForm.ScrollP * RasterW);
  167.     CorInit := true;
  168.   end;
  169.   if MainForm.Enemys.IndexOf(floattostr(XCor)+'-'+floattostr(y)+':'+
  170.     inttostr(Art)+'('+inttostr(Lives)+')') = -1 then dead;
  171.   X := XCor - (MainForm.ScrollP * RasterW);
  172. end;
  173.  
  174. procedure TBackground.DoMove(MoveCount: Integer);
  175. begin
  176.   X := -(MainForm.ScrollP * RasterW);
  177. end;
  178.  
  179. constructor TEnemy.Create(AParent: TSprite);
  180. begin
  181.   inherited Create(AParent);
  182.   if MainForm.ArtChecked = 1 then Image := MainForm.ImageList.Items.Find('Enemy-Attacker');
  183.   if MainForm.ArtChecked = 2 then Image := MainForm.ImageList.Items.Find('Enemy-Attacker2');
  184.   if MainForm.ArtChecked = 3 then Image := MainForm.ImageList.Items.Find('Enemy-Attacker3');
  185.   if MainForm.ArtChecked = 4 then Image := MainForm.ImageList.Items.Find('Enemy-Meteor');
  186.   if MainForm.ArtChecked = 5 then Image := MainForm.ImageList.Items.Find('Enemy-Disk');
  187.   if MainForm.ArtChecked = 6 then Image := MainForm.ImageList.Items.Find('Enemy-Disk2');
  188.   if MainForm.ArtChecked = 7 then Image := MainForm.ImageList.Items.Find('Enemy-Boss');
  189.   if MainForm.ArtChecked = 4 then Lives := 0 else Lives := MainForm.LiveEdit;
  190.   Art := MainForm.ArtChecked;
  191.   Width := Image.Width;
  192.   Height := Image.Height;
  193.   PixelCheck := True;
  194. end;
  195.  
  196. procedure TMainForm.FormCreate(Sender: TObject);
  197. var
  198.   Ergebnis: string;
  199.   daten: textfile;
  200.   i: integer;
  201.   punkt: integer;
  202.   ok: boolean;
  203. begin
  204.   { VCL-Ersatz start }
  205.  
  206.   versioninfo := tpjversioninfo.create(self);
  207.  
  208.   dxtimer := tdxtimer.create(self);
  209.   dxtimer.Interval := 100;
  210.   dxtimer.ActiveOnly := false;
  211.   dxtimer.Enabled := false;
  212.   dxtimer.OnTimer := DxTimerTimer;
  213.  
  214.   dxdraw := tdxdraw.Create(self);
  215.   dxdraw.Parent := self;
  216.   dxdraw.Left := 0;
  217.   dxdraw.Top := 0;
  218.   dxdraw.Width := 640;
  219.   dxdraw.Height := 480;
  220.   dxdraw.AutoInitialize := False;
  221.   dxdraw.AutoSize := False;
  222.   dxdraw.Color := clBlack;
  223.   dxdraw.Display.BitCount := 24;
  224.   dxdraw.Display.FixedBitCount := False;
  225.   dxdraw.Display.FixedRatio := False;
  226.   dxdraw.Display.FixedSize := False;
  227.   dxdraw.Display.Height := 600;
  228.   dxdraw.Display.Width := 800;
  229.   dxdraw.Options := [doAllowReboot, doWaitVBlank, doAllowPalette256, doCenter, doRetainedMode, doHardware, doSelectDriver];
  230.   dxdraw.OnFinalize := DXDrawFinalize;
  231.   dxdraw.OnInitialize := DXDrawInitialize;
  232.   dxdraw.ParentShowHint := False;
  233.   dxdraw.ShowHint := False;
  234.   dxdraw.TabOrder := 0;
  235.   dxdraw.OnMouseDown := DXDrawMouseDown;
  236.   dxdraw.OnMouseMove := DXDrawMouseMove;
  237.  
  238.   spriteengine := tdxspriteengine.create(self);
  239.   spriteengine.DXDraw := dxdraw;
  240.  
  241.   imagelist := tdximagelist.create(self);
  242.   imagelist.DXDraw := dxdraw;
  243.  
  244.   { VCL-Ersatz ende }
  245.  
  246.   ArtChecked := 1;
  247.   LiveEdit := 1;
  248.   // Leeres Level am Anfang braucht keine Beenden-Bestätigung.
  249.   // LevChanged := true;
  250.   punkt := 0;
  251.   FDirectory := extractfilepath(paramstr(0));
  252.   versioninfo.filename := paramstr(0);
  253.   for i := 1 to length(versioninfo.ProductVersion) do
  254.   begin
  255.     if copy(versioninfo.ProductVersion, i, 1) = '.' then inc(punkt);
  256.     if punkt < 2 then fengineversion :=
  257.       fengineversion+copy(versioninfo.ProductVersion, i, 1);
  258.   end;
  259.   //Application.Title := 'SpaceMission '+FEngineVersion+' - Leveleditor';
  260.   Caption := 'SpaceMission '+FEngineVersion+' - Leveleditor';
  261.   DXInit;
  262.   if (paramcount > 0) and (fileexists(paramstr(1))) then
  263.   begin
  264.     AssignFile(daten, paramstr(1));
  265.     Reset(daten);
  266.     ok := true;
  267.     ReadLN(daten, Ergebnis);
  268.     if Ergebnis <> '; SpaceMission '+FCompVersion then ok := false;
  269.     ReadLN(daten, Ergebnis);
  270.     if ergebnis <> '; LEV-File' then ok := false;
  271.     if not ok then
  272.     begin
  273.       showmessage(FileError);
  274.       CloseFile(daten);
  275.       ProgramInit;
  276.       exit;
  277.     end;
  278.     { Laden }
  279.     CloseFile(daten);
  280.     exit;
  281.   end;
  282.   if fileexists(fdirectory+'Bilder\Auswahl.bmp') then
  283.     Image1.Picture.LoadFromFile(fdirectory+'Bilder\Auswahl.bmp');
  284.   {else
  285.     SelPanel.visible := false;}
  286.   ProgramInit;
  287. end;
  288.  
  289. procedure TMainForm.FormDestroy(Sender: TObject);
  290. begin
  291.   Enemys.Free;
  292.   //spriteengine.Free;
  293.   versioninfo.free;
  294.   dxtimer.Free;
  295.   imagelist.Free;
  296.   dxdraw.free;
  297. end;
  298.  
  299. procedure TMainForm.BeendenClick(Sender: TObject);
  300. begin
  301.   close;
  302. end;
  303.  
  304. procedure TMainForm.DXDrawInitialize(Sender: TObject);
  305. begin
  306.   DXTimer.Enabled := True;
  307. end;
  308.  
  309. procedure TMainForm.DXDrawFinalize(Sender: TObject);
  310. begin
  311.   DXTimer.Enabled := False;
  312. end;
  313.  
  314. procedure TMainForm.DXTimerTimer(Sender: TObject; LagCount: Integer);
  315. begin
  316.   if not DXDraw.CanDraw then exit;
  317.   LagCount := 1000 div 60;
  318.   SpriteEngine.Move(LagCount);
  319.   SpriteEngine.Dead;
  320.   DxDraw.Surface.Fill(0);
  321.   SpriteEngine.Draw;
  322.   DXDraw.Flip;
  323. end;
  324.  
  325. function TMainForm.ComposeColor(Dest, Src: TRGBQuad; Percent: Integer): TRGBQuad;
  326. begin
  327.   with Result do
  328.   begin
  329.     rgbRed := Src.rgbRed+((Dest.rgbRed-Src.rgbRed)*Percent div 256);
  330.     rgbGreen := Src.rgbGreen+((Dest.rgbGreen-Src.rgbGreen)*Percent div 256);
  331.     rgbBlue := Src.rgbBlue+((Dest.rgbBlue-Src.rgbBlue)*Percent div 256);
  332.     rgbReserved := 0;
  333.   end;
  334. end;
  335.  
  336. procedure TMainForm.PalleteAnim(Col: TRGBQuad; Time: Integer);
  337. var
  338.   i: Integer;
  339.   t, t2: DWORD;
  340.   ChangePalette: Boolean;
  341.   c: Integer;
  342. begin
  343.   if DXDraw.Initialized then
  344.   begin
  345.     c := DXDraw.Surface.ColorMatch(RGB(Col.rgbRed, Col.rgbGreen, Col.rgbBlue));
  346.     ChangePalette := False;
  347.     if DXDraw.CanPaletteAnimation then
  348.     begin
  349.       t := GetTickCount;
  350.       while Abs(GetTickCount-t)<Time do
  351.       begin
  352.         t2 := Trunc(Abs(GetTickCount-t)/Time*255);
  353.         for i := 0 to 255 do
  354.           DXDraw.ColorTable[i] := ComposeColor(Col, DXDraw.DefColorTable[i], t2);
  355.         DXDraw.UpdatePalette;
  356.         ChangePalette := True;
  357.       end;
  358.     end else
  359.       Sleep(Time);
  360.     for i := 0 to 4 do
  361.     begin
  362.       DXDraw.Surface.Fill(c);
  363.       DXDraw.Flip;
  364.     end;
  365.     if ChangePalette then
  366.     begin
  367.       DXDraw.ColorTable := DXDraw.DefColorTable;
  368.       DXDraw.UpdatePalette;
  369.     end;
  370.     DXDraw.Surface.Fill(c);
  371.     DXDraw.Flip;
  372.   end;
  373. end;
  374.  
  375. procedure TMainForm.ProgramInit;
  376. {var
  377.   i, j: Integer;}
  378. begin
  379.   Enemys := TStringList.create;
  380.   sleep(500);
  381.   //PlayerSprite
  382.   with TBackground.Create(SpriteEngine.Engine) do
  383.   begin
  384.     SetMapSize(1, 1);
  385.     Image := mainform.ImageList.Items.Find('Star3');
  386.     Z := -13;
  387.     Y := 40;
  388.     Tile := True;
  389.   end;
  390.   with TBackground.Create(SpriteEngine.Engine) do
  391.   begin
  392.     SetMapSize(1, 1);
  393.     Image := mainform.ImageList.Items.Find('Star2');
  394.     Z := -12;
  395.     Y := 30;
  396.     Tile := True;
  397.   end;
  398.   with TBackground.Create(SpriteEngine.Engine) do
  399.   begin
  400.     SetMapSize(1, 1);
  401.     Image := mainform.ImageList.Items.Find('Star1');
  402.     Z := -11;
  403.     Y := 10;
  404.     Tile := True;
  405.   end;
  406.   with TBackground.Create(SpriteEngine.Engine) do
  407.   begin
  408.     SetMapSize(1, 1);
  409.     Image := mainform.ImageList.Items.Find('Matrix');
  410.     Z := -10;
  411.     Tile := True;
  412.   end;
  413.   {with TBackground.Create(SpriteEngine.Engine) do
  414.   begin
  415.     SetMapSize(200, 10);
  416.     Y := 10;
  417.     Z := -13;
  418.     FSpeed := 1 / 2;
  419.     Tile := True;
  420.     for i := 0 to MapHeight-1 do
  421.     begin
  422.       for j := 0 to MapWidth-1 do
  423.       begin
  424.         Chips[j, i] := Image.PatternCount-Random(Image.PatternCount div 8);
  425.         if Random(100)<95 then Chips[j, i] := -1;
  426.       end;
  427.     end;
  428.   end;
  429.   with TBackground.Create(SpriteEngine.Engine) do
  430.   begin
  431.     SetMapSize(200, 10);
  432.     Y := 30;
  433.     Z := -12;
  434.     FSpeed := 1;
  435.     Tile := True;
  436.     for i := 0 to MapHeight-1 do
  437.     begin
  438.       for j := 0 to MapWidth-1 do
  439.       begin
  440.         Chips[j, i] := Image.PatternCount-Random(Image.PatternCount div 4);
  441.         if Random(100)<95 then Chips[j, i] := -1;
  442.       end;
  443.     end;
  444.   end;
  445.   with TBackground.Create(SpriteEngine.Engine) do
  446.   begin
  447.     SetMapSize(200, 10);
  448.     Y := 40;
  449.     Z := -11;
  450.     FSpeed := 2;
  451.     Tile := True;
  452.     for i := 0 to MapHeight-1 do
  453.     begin
  454.       for j := 0 to MapWidth-1 do
  455.       begin
  456.         Chips[j, i] := Image.PatternCount-Random(Image.PatternCount div 2);
  457.         if Random(100)<95 then Chips[j, i] := -1;
  458.       end;
  459.     end;
  460.   end;}
  461.   PalleteAnim(RGBQuad(0, 0, 0), 300);
  462.   mainform.Visible := true;
  463. end;
  464.  
  465. procedure TMainForm.MitarbeiterClick(Sender: TObject);
  466. begin
  467.   if not fileexists(mainform.fdirectory+'Texte\Mitwirkende.txt') then
  468.   begin
  469.     MessageDLG('Die Datei "Texte\Mitwirkende.txt" ist nicht mehr vorhanden. Die Aktion wird abgebrochen!',
  470.       mtWarning, [mbOK], 0);
  471.   end
  472.   else
  473.   begin
  474.     TextForm.memo1.lines.loadfromfile(mainform.FDirectory+'Texte\Mitwirkende.txt');
  475.     TextForm.showmodal;
  476.   end;
  477. end;
  478.  
  479. procedure TMainForm.LevelClick(Sender: TObject);
  480. begin
  481.   speicherungform.showmodal;
  482. end;
  483.  
  484. procedure TMainForm.FormShow(Sender: TObject);
  485. begin
  486.   SplashForm.Hide;
  487.   SplashForm.Free;
  488.  
  489.   dxtimer.Enabled := true;
  490.   dxtimer.ActiveOnly := true;
  491. end;
  492.  
  493. procedure TMainForm.InformationenClick(Sender: TObject);
  494. begin
  495.   InfoForm.showmodal;
  496. end;
  497.  
  498. procedure TMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
  499. begin
  500.   SpriteEngine.Engine.Clear;
  501.   DXTimer.Enabled := False;
  502. end;
  503.  
  504. procedure TMainForm.DXDrawMouseDown(Sender: TObject; Button: TMouseButton;
  505.   Shift: TShiftState; X, Y: Integer);
  506. var
  507.   i, j, k, l, ex, ey: integer;
  508.   ok, breaked: boolean;
  509. begin
  510.   ex := trunc(x/RasterW) * RasterW;
  511.   ey := trunc(y/RasterH) * RasterH;
  512.   EnemyCreate(ex, ey);
  513.   breaked := false;
  514.   { Setzen }
  515.   if Button = mbLeft then
  516.   begin
  517.     ok := true;
  518.     if (ArtChecked = 7) and boss then ok := false
  519.     else
  520.     begin
  521.       for i := 1 to 7 do
  522.       begin
  523.         for j := 0 to 999 do
  524.         begin
  525.           if boss then
  526.           begin
  527.             for k := 0 to 3 do
  528.             begin
  529.               for l := 0 to 1 do
  530.               begin
  531.                 if Enemys.IndexOf(floattostr(ex + ((ScrollP - k) * RasterW))+'-'+floattostr(ey - (RasterH * l))+':7('+inttostr(j)+')') <> -1 then
  532.                 begin
  533.                   ok := false;
  534.                   break;
  535.                 end;
  536.               end;
  537.               if not ok then break;
  538.             end;
  539.             if not ok then break;
  540.           end;
  541.           if Enemys.IndexOf(floattostr(ex + (ScrollP * RasterW))+'-'+floattostr(ey)+':'+
  542.             inttostr(i)+'('+inttostr(j)+')') <> -1 then
  543.           begin
  544.             ok := false;
  545.             break;
  546.           end;
  547.         end;
  548.         if not ok then break;
  549.       end;
  550.     end;
  551.     if ok then
  552.     begin
  553.       if ArtChecked <> 4 then
  554.         Enemys.Add(floattostr(ex + (ScrollP * RasterW))+'-'+floattostr(ey)+':'+
  555.           inttostr(ArtChecked)+'('+inttostr(LiveEdit)+')')
  556.       else
  557.         Enemys.Add(floattostr(ex + (ScrollP * RasterW))+'-'+floattostr(ey)+':'+
  558.           inttostr(ArtChecked)+'(0)');
  559.       inc(NumEnemys);
  560.       if ArtChecked = 7 then boss := true;
  561.     end
  562.     else beep;
  563.   end
  564.   { Löschen }
  565.   else if Button = mbRight then
  566.   begin
  567.     for i := 1 to 7 do
  568.     begin
  569.       for j := 0 to 999 do
  570.       begin
  571.         if boss and (i = 7) then
  572.         begin
  573.           for k := 0 to 3 do
  574.           begin
  575.             for l := 0 to 1 do
  576.             begin
  577.               if Enemys.IndexOf(floattostr(ex + ((ScrollP - k) * RasterW))+'-'+floattostr(ey - (RasterH * l))+':'+inttostr(i)+'('+inttostr(j)+')') <> -1 then
  578.               begin
  579.                 Enemys.Delete(Enemys.IndexOf(floattostr(ex + ((ScrollP - k) * RasterW))+'-'+floattostr(ey - (RasterH * l))+':'+inttostr(i)+'('+inttostr(j)+')'));
  580.                 Boss := false;
  581.                 dec(NumEnemys);
  582.                 breaked := true;
  583.                 break;
  584.               end;
  585.             end;
  586.             if breaked then break;
  587.           end;
  588.         end;
  589.         if Enemys.IndexOf(floattostr(ex + (ScrollP * RasterW))+'-'+floattostr(ey)+':'+
  590.           inttostr(i)+'('+inttostr(j)+')') <> -1 then
  591.         begin
  592.           Enemys.Delete(Enemys.IndexOf(floattostr(ex + (ScrollP * RasterW))+'-'+floattostr(ey)+
  593.             ':'+inttostr(i)+'('+inttostr(j)+')'));
  594.           if i = 7 then Boss := false;
  595.           dec(NumEnemys);
  596.           breaked := true;
  597.           break;
  598.         end;
  599.       end;
  600.       if breaked then break;
  601.     end;
  602.   end;
  603.   LevChanged := true;
  604.   AnzeigeAct;
  605. end;
  606.  
  607. procedure TMainForm.EnemyClick(Sender: TObject);
  608. begin
  609.   if sender = Enemy1 then ArtChecked := 1;
  610.   if sender = Enemy2 then ArtChecked := 2;
  611.   if sender = Enemy3 then ArtChecked := 3;
  612.   if sender = Enemy4 then ArtChecked := 4;
  613.   if sender = Enemy5 then ArtChecked := 5;
  614.   if sender = Enemy6 then ArtChecked := 6;
  615.   if sender = Enemy7 then ArtChecked := 7;
  616.   Image1.Left := -(87 * (ArtChecked - 1)) + 1;
  617.   Lives.Enabled := sender <> Enemy4;
  618.   LivesLabel.Enabled := sender <> Enemy4;
  619.   if sender = Enemy4 then LivesEdt.Font.Color := clBtnShadow // andere farbe?
  620.     else LivesEdt.Font.Color := clWindowText;
  621. end;
  622.  
  623. procedure TMainForm.EnemyCreate(x, y: integer);
  624. var
  625.   Enemy: TSprite;
  626. begin
  627.   Enemy := TEnemy.Create(SpriteEngine.Engine);
  628.   Enemy.x := x;
  629.   Enemy.y := y;
  630. end;
  631.  
  632. procedure TMainForm.DestroyLevel;
  633. begin
  634.   ScrollBar.Position := 0;
  635.   Enemys.Clear;
  636.   NumEnemys := 0;
  637.   Boss := false;
  638.   LevChanged := true;
  639.   Lives.Position := 1;
  640.   LivesChange(Lives.Position);
  641.   Enemy1.Checked := true;
  642.   EnemyClick(Enemy1);
  643.   AnzeigeAct;
  644. end;
  645.  
  646. procedure TMainForm.AnzeigeAct;
  647. begin
  648.   SLabel1b.Caption := inttostr(NumEnemys);
  649.   if Boss then SLabel2b.Caption := 'Ja' else SLabel2b.Caption := 'Nein';
  650.   SLabel3b.Caption := inttostr(ScrollBar.Max);
  651.   if LevChanged then
  652.   begin
  653.     SLabel4a.Font.Color := $00000096;
  654.     SLabel4b.Font.Color := $00000096;
  655.     SLabel4b.Caption := 'Nein';
  656.   end
  657.   else
  658.   begin
  659.     SLabel4a.Font.Color := $00009600;
  660.     SLabel4b.Font.Color := $00009600;
  661.     SLabel4b.Caption := 'Ja';
  662.   end;
  663. end;
  664.  
  665. procedure TMainForm.EnemyAdd(x, y, art, lives: integer);
  666. begin
  667.   Enemys.Add(inttostr(x)+'-'+inttostr(y)+':'+inttostr(art)+'('+inttostr(lives)+')');
  668. end;
  669.  
  670. procedure TMainForm.NeuClick(Sender: TObject);
  671. begin
  672.   if MessageDlg('Level wirklich löschen?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then
  673.     DestroyLevel;
  674. end;
  675.  
  676. procedure TMainForm.DXDrawMouseMove(Sender: TObject; Shift: TShiftState; X,
  677.   Y: Integer);
  678. var
  679.   ex, ey, i, j, k, l, wert: integer;
  680.   breaked: boolean;
  681. begin
  682.   if sender <> DxDraw then
  683.   begin
  684.     StatusBar.SimpleText := status_info;
  685.     exit;
  686.   end;
  687.   ex := trunc(x/RasterW) * RasterW;
  688.   ey := trunc(y/RasterH) * RasterH;
  689.   wert := -1;
  690.   breaked := false;
  691.   for i := 1 to 7 do
  692.   begin
  693.     for j := 0 to 999 do
  694.     begin
  695.       if boss and (i = 7) then
  696.       begin
  697.         for k := 0 to 3 do
  698.         begin
  699.           for l := 0 to 1 do
  700.           begin
  701.             if Enemys.IndexOf(floattostr(ex + ((ScrollP - k) * RasterW))+'-'+floattostr(ey - (RasterH * l))+':'+inttostr(i)+'('+inttostr(j)+')') <> -1 then
  702.             begin
  703.               wert := j;
  704.               breaked := true;
  705.               break;
  706.             end;
  707.           end;
  708.           if breaked then break;
  709.         end;
  710.       end;
  711.       if (breaked = false) and (Enemys.IndexOf(floattostr(ex + (ScrollP * RasterW))+'-'+floattostr(ey)+':'+
  712.         inttostr(i)+'('+inttostr(j)+')') <> -1) then
  713.       begin
  714.         wert := j;
  715.         breaked := true;
  716.         break;
  717.       end;
  718.     end;
  719.     if breaked then break;
  720.   end;
  721.   if wert <> -1 then
  722.   begin
  723.     if wert > 0 then
  724.       StatusBar.SimpleText := status_lives + inttostr(wert)
  725.     else
  726.       StatusBar.SimpleText := status_nolives;
  727.   end
  728.   else
  729.     StatusBar.SimpleText := status_info;
  730. end;
  731.  
  732. procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
  733. begin
  734.   if LevChanged then
  735.     CanClose := MessageDlg('Beenden ohne abspeichern?', mtConfirmation, [mbYes, mbNo], 0) = mrYes;
  736. end;
  737.  
  738. procedure TMainForm.Quelltext1Click(Sender: TObject);
  739. begin
  740.   SourceForm.Aktualisieren;
  741.   SourceForm.showmodal;
  742. end;
  743.  
  744. procedure TMainForm.Spielfelderweitern1Click(Sender: TObject);
  745. begin
  746.   LevelForm.Aktualisieren;
  747.   LevelForm.showmodal;
  748. end;
  749.  
  750. procedure TMainForm.ScrollBarScroll(Sender: TObject;
  751.   ScrollCode: TScrollCode; var ScrollPos: Integer);
  752. begin
  753.   ScrollP := ScrollPos;
  754. end;
  755.  
  756. procedure TMainForm.LivesChange(newval: integer);
  757. begin
  758.   LiveEdit := newval;
  759.   livesedt.Text := inttostr(LiveEdit);
  760.   lives.Position := newval;
  761. end;
  762.  
  763. procedure TMainForm.LivesClick(Sender: TObject; Button: TUDBtnType);
  764. begin
  765.   LivesChange(lives.Position);
  766. end;
  767.  
  768. procedure TMainForm.LivesEdtKeyPress(Sender: TObject; var Key: Char);
  769. begin
  770.   if not (Key in [#13, #08, '0'..'9']) then
  771.     Key := #0;
  772. end;
  773.  
  774. procedure TMainForm.LivesEdtChange(Sender: TObject);
  775. begin
  776.   LivesChange(strtoint(livesedt.text));
  777. end;
  778.  
  779. end.
  780.  
  781.