⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 powerblaster.dpr

📁 完整的Delphi游戏开发控件
💻 DPR
📖 第 1 页 / 共 3 页
字号:
                end;
                CreateBonus('Money',TAsteroids(Sprite).X, TAsteroids(Sprite).Y);
                TAsteroids(Sprite).Dead;
          end;
     end;
     //
     if Sprite is TEnemy then
     begin
          //MainForm.Music.Songs.Find('Hit').Play;
          Collisioned := False;
          MoveSpeed := 0;
          SetAnim('Explosion3', 0, 12, 0.3, False, False, True);
          if Trunc(AnimPos) < 1 then
             TEnemy(Sprite).BlendMode := Blend_Bright;
          TEnemy(Sprite).Life := TEnemy(Sprite).Life - 1;
          if TEnemy(Sprite).Life <= 0 then
          begin
               TEnemy(Sprite).MoveSpeed := 0;
               TEnemy(Sprite).RotateSpeed := 0;
               TEnemy(Sprite).DestAngle := 0;
               TEnemy(Sprite).LookAt := False;
               TEnemy(Sprite).BlendMode := Blend_Add2X;
               TEnemy(Sprite).ScaleX := 3;
               TEnemy(Sprite).ScaleY := 3;
               TEnemy(Sprite).SetAnim('Explosion2', 0, 16, 0.15, False, False, True);
               CreateBonus('Bonus' + IntToStr(Random(3)), X, Y);
          end;
     end;
     //
     if Sprite is TFort then
     begin
          //MainForm.Music.Songs.Find('Hit').Play;
          Collisioned := False;
          MoveSpeed := 0;
          SetAnim('Explosion3', 0, 12, 0.3, False, False, True);
          if Trunc(AnimPos) < 3 then
             TFort(Sprite).SetColor(255, 0, 0);
          TFort(Sprite).Life := TFort(Sprite).Life - 1;
          if TFort(Sprite).Life <= 0 then
          begin
               TFort(Sprite).BlendMode := Blend_Add;
               TFort(Sprite).ScaleX := 3;
               TFort(Sprite).ScaleY := 3;
               TFort(Sprite).SetAnim('Explosion2', 0, 16, 0.15, False, False, True);
          end;
     end;
end;

procedure  TAsteroids.DoMove(const MoveCount: Single);
begin
     inherited;
     X := PosX + Cos(Step / (30 )) * Range - (Sin(Step / (20 )) * Range);
     Y := PosY + Sin(Step / (30 + Seed )) * Range + (Cos(Step / (20 )) * Range);
     Step := Step + MoveSpeed;
     if ImageName = 'Roids2' then  Angle := Angle + 0.02;
     if ImageName='Roids0' then CollidePos := Point2(X + 32, Y + 32);
     if ImageName='Roids1' then CollidePos := Point2(X + 30, Y + 30);
     if ImageName='Roids2' then CollidePos := Point2(X + 34, Y + 34);
     BlendMode := Blend_Default;
end;

procedure TFort.DoMove(const MoveCount: Single);
begin
     inherited;
     SetColor(255, 255, 255);
     if ImageName = 'Fort' then
     LookAt(Trunc(PlayerShip.X), Trunc(PlayerShip.Y));
     CollidePos := Point2(X + 22, Y + 36);
     if Trunc(AnimPos) >= 15 then Dead;
     if (Trunc(AnimPos) >= 1) and (ImageName = 'Explosion2') then
       Collisioned := False;

     if Random(150) = 50 then
     begin
          if (X > Engine.WorldX + 0)and
          (Y > Engine.WorldY + 0)   and
          (X < Engine.WorldX + 800) and
          (Y < Engine.WorldY + 600) then
          begin
               Bullet := TBullet.Create(SpriteEngine);
               Bullet.ImageName := 'BulletS';
               Bullet.Width := 40;
               Bullet.Height := 40;
               Bullet.BlendMode := Blend_Add;
               Bullet.MoveSpeed := 4;
               Bullet.Z := 4000;
               Bullet.FCounter := 0;
               Bullet.X := Self.X + 5;
               Bullet.Y := Self.Y;
               Bullet.DrawMode := 1;
               Bullet.DestAngle := Angle * 40;
          end;
     end;
end;

procedure  TPlayerShip.DoMove(const MoveCount: Single);
begin
      inherited;
      SetColor(255, 255, 255);
      CollidePos := Point2(X + 20, Y + 20);
      Collision;
      if DoAccelerate then Accelerate;
      if DoDeccelerate then Deccelerate;
      if ImageName = 'PlayerShip' then
      begin
           AnimPos:=0;
           UpdatePos(1);
           //LookAt(CursorX, CursorY);
           Angle := Angle256(Trunc(CursorX) - 400, Trunc(CursorY) - 300) * 0.025 ;
           Direction := Trunc(Angle256(Trunc(CursorX) - 400, Trunc(CursorY) - 300));
      end;
      if (Trunc(AnimPos)>=32) and (ImageName = 'Explode') then
      begin
           ImageName :='PlayerShip';
           AnimPos:=0;
           BlendMode := Blend_Default;
           ScaleX := 1.2;
           ScaleY := 1.2;
      end;
      if FReady then
         Inc(FReadyTime);
      if FReadyTime = 350 then
      begin
           FReady := False;
           Collisioned := True;
      end;
      Engine.WorldX := X - 400;
      Engine.WorldY := Y - 300;
end;

procedure TPlayerShip.DoCollision(const Sprite: TSprite);
begin
     if Sprite is TBonus then    
     begin
          //MainForm.Music.Songs.Find('GetBonus').Play;
          if TBonus(Sprite).ImageName =  'Bonus0' then
             Inc(Score, 100);
          if TBonus(Sprite).ImageName =  'Bonus1' then
             Inc(Score, 200);
          if TBonus(Sprite).ImageName =  'Bonus2' then
             Inc(Score, 300);
          if TBonus(Sprite).ImageName =  'Money' then
             Inc(Score, 500);
          CreateSpark(TBonus(Sprite).X, TBonus(Sprite).Y);
          TBonus(Sprite).Dead;
     end;
     if Sprite is TBullet then
     begin
          //MainForm.Music.Songs.Find('Hit').Play;
          PlayerShip.Life :=  PlayerShip.Life - 0.5;
          Self.SetColor(255, 0, 0);
          TBullet(Sprite).Collisioned := False;
          TBullet(Sprite).MoveSpeed := 0;
          TBullet(Sprite).SetAnim('Explosion3', 0, 12, 0.3, False, False, True);
          TBullet(Sprite).Z := 10000;
     end;

     if (Sprite is TAsteroids) or (Sprite is TEnemy) then
     begin
          //MainForm.Music.Songs.Find('Hit').Play;
          FReady := True;
          FReadyTime := 0;
          PlayerShip.Life :=  PlayerShip.Life - 0.25;
          AnimPos := 0;
          SetAnim('Explode', 0, 40, 0.15, False, False, True);
          Collisioned := False;
          BlendMode := Blend_Add;
          ScaleX := 1.5;
          ScaleY := 1.5;
     end;
end;

procedure TTail.DoMove(const MoveCount: Single);
begin
     inherited;
     Alpha := Alpha - 4;
     if PlayerShip.Speed < 1.1 then
     begin
          ScaleX := ScaleX + 0.01;
          ScaleY := ScaleY + 0.01;
     end
     else
     begin
          ScaleX := ScaleX + 0.025;
          ScaleY := ScaleY + 0.025;
     end;
     Angle := Angle + 0.125;
     UpdatePos(1);
     Accelerate;
     Inc(FCounter);
     if FCounter > 25 then Dead;
end;

procedure TExplosion.DoMove(const MoveCount: Single);
begin
     inherited;
     Accelerate;
     UpdatePos(1);
     Alpha := Alpha - 1;
     if Alpha < 1 then Dead;
end;

procedure TSpark.DoMove(const MoveCount: Single);
begin
     inherited;
     Accelerate;
     UpdatePos(1);
     Alpha := Alpha - 1;
     if Alpha < 1 then Dead;
end;

procedure TBonus.DoMove(const MoveCount: Single);
begin
     inherited;
     CollidePos := Point2(X + 24, Y + 24);
     X := PX + Cos(Step / (30)) * 60 - (Sin(Step / (20)) * 150);
     Y := PY + Sin(Step / (90)) * 130 + (Cos(Step / (20)) * 110);
     Step := Step + MoveSpeed;
end;

function FrameFunc: Boolean;
begin
  HGE.Input_GetMousePos(CursorX, CursorY);
  Inc(Counter);

  if (Counter mod 5) =0 then
  if PlayerShip.ImageName = 'PlayerShip' then
     begin
          with  TTail.Create(SpriteEngine) do
          begin
               ImageName := 'Tail';
               Width := PatternWidth;
               Height := PatternHeight;
               BlendMode :=  Blend_Add;
               DrawMode := 1;
               ScaleX := 0.1;
               ScaleY := 0.1;
               X := 398 + Engine.WorldX;
               Y := 298 + Engine.WorldY;
               Z := 4000;
               Acceleration := 2.51;
               MinSpeed := 1;
               if PlayerShip.Speed < 1 then
                  MaxSpeed := 2
               else
                  MaxSpeed := 0.5;
               Direction := -128 + PlayerShip.Direction;
          end;
     end;
  //
    if HGE.Input_KeyDown(HGEK_RBUTTON) then
    begin
   //       CursorX := X;
     //     CursorY := Y;
          PlayerShip.DoAccelerate := True;
          PlayerShip.DoDeccelerate := False;
     end;
     if HGE.Input_KeyDown(HGEK_LBUTTON) and (PlayerShip.ImageName = 'PlayerShip') then
     begin
          //Music.Songs.Find('Shoot').Play;
          PlayerShip.Bullet := TPlayerBullet.Create(SpriteEngine);
          with PlayerShip.Bullet do
          begin
               ImageName := 'Bb';
               Width := PatternWidth;
               Height := PatternHeight;
               ScaleX := 1;
               ScaleY := 1;
               DrawMode := 1;
               BlendMode := Blend_Add;
               DoCenter := True;
               case UserRefreshRate of
                    60: MoveSpeed := 12;
                    75: MoveSpeed := 10;
                    85: MoveSpeed := 8;
               end;

               Angle := PlayerShip.Angle + 0.05;
               X := PlayerShip.X;
               Y := PlayerShip.Y;
               Z := 11000;
               Collisioned := True;
               CollideRadius := 10;
         end;
     end;
     //
   if HGE.Input_KeyUP(HGEK_RBUTTON) then
   begin
          PlayerShip.DoAccelerate := False;
          PlayerShip.DoDeccelerate := True;
   end;
  case HGE.Input_GetKey of
    HGEK_ESCAPE:
    begin
      FreeAndNil(Canvas);
      FreeAndNil(Images);
      FreeAndNil(SpriteEngine);
      FreeAndNil(MistLayer1);
      FreeAndNil(MistLayer2);
      FreeAndNil(SpaceLayer);
      Result := True;
      Exit;
    end;
  end;
  Result := False;
end;

function RenderFunc: Boolean;
var
   Angle: Single;
begin
  HGE.Gfx_BeginScene;
  //HGE.Gfx_Clear(0);
  SpaceLayer.Draw;
  MistLayer1.Draw;
  MistLayer2.Draw;
  SpriteEngine.Draw;
  SpriteEngine.Move(1);
  SpriteEngine.Dead;
  Angle := Angle256(Trunc(CursorX) - 400 , Trunc(CursorY) - 300 ) * 0.025 ;
  Canvas.DrawRotate(Images.Image['Cursor'], 0, Trunc(CursorX) + 5, Trunc(CursorY), 10, 15, Angle, $FFFFFFFF, Blend_Add);
  Canvas.DrawEx(Images.Image['Shield'], -Trunc(PlayerShip.Life), 10, 480, 1,
    False, $FFFFFFFF, Blend_Default);
  SpaceLayer.WorldX := SpriteEngine.WorldX * 0.71;
  SpaceLayer.WorldY := SpriteEngine.WorldY * 0.71;
  MistLayer1.WorldX := SpriteEngine.WorldX * 1.1;
  MistLayer1.WorldY := SpriteEngine.WorldY * 1.1;
  MistLayer2.WorldX := SpriteEngine.WorldX * 1.3;
  MistLayer2.WorldY := SpriteEngine.WorldY * 1.3;
  Fnt.PrintF(320,20, HGETEXT_LEFT, '%d',[Score]);
 // Fnt.PrintF(320,520, HGETEXT_LEFT, '%d',[hge.Timer_GetFPS]);
  if PlayerShip.Life < -16 then
  begin
    Fnt.PrintF(320,320, HGETEXT_LEFT, 'GAME OVER',[]);
    SpriteEngine.Moved := False;
    //Music.Songs.Find('Music1').Stop;
  end;

  HGE.Gfx_EndScene;
  Result := False;
end;

procedure Main;
begin
  HGE := HGECreate(HGE_VERSION);
  HGE.System_SetState(HGE_FRAMEFUNC,FrameFunc);
  HGE.System_SetState(HGE_RENDERFUNC,RenderFunc);
  HGE.System_SetState(HGE_USESOUND, False);
  HGE.System_SetState(HGE_WINDOWED,False);
  HGE.System_SetState(HGE_SCREENWIDTH, 800);
  HGE.System_SetState(HGE_SCREENHEIGHT,600);
  HGE.System_SetState(HGE_SCREENBPP,16);
  HGE.System_SetState(HGE_TEXTUREFILTER,True);
  HGE.System_SetState(HGE_FPS,HGEFPS_VSYNC);
  Canvas := THGECanvas.Create;
  Images := THGEImages.Create;

  if (HGE.System_Initiate) then
  begin
    Fnt := THGEFont.Create('Font1.fnt');
    LoadImages;
    CreateGame;
    HGE.System_Start;
  end
  else
    MessageBox(0,PChar(HGE.System_GetErrorMessage),'Error',MB_OK or MB_ICONERROR or MB_SYSTEMMODAL);

  HGE.System_Shutdown;
  HGE := nil;
end;

begin
  ReportMemoryLeaksOnShutdown := True;
  Main;
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -