Skip to content

Commit

Permalink
Fixed bug with Blinking asteroid in center
Browse files Browse the repository at this point in the history
  • Loading branch information
dimsa committed Aug 6, 2015
1 parent ccfc982 commit 0d92064
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 120 deletions.
Binary file modified Android/Debug/ShadowEngineDemo/assets/internal/res.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Art/res.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
81 changes: 41 additions & 40 deletions DemoCode/uDemoObjects.pas
Original file line number Diff line number Diff line change
Expand Up @@ -12,56 +12,59 @@ interface
TShipFire = class(TSprite)
private
FTip: Byte;
// FShip: TShip;
public
property Tip: Byte read FTip write FTip; // Òèï îãíÿ
// property Ship: TShip read FShip write FShip; // Êîðàáëü, êîîòðó ïðèíàäëåæèò îãîíü
procedure Repaint; override;
constructor Create(newParent: pointer); override;
constructor Create(AParent: pointer); override;
end;

TShip = class(TSprite)
TMovingUnit = class(TSprite)
protected
FDx, FDy, FDA: Double; // Ñäâèãè
public
property DX: Double read FDx write FDx;
property DY: Double read FDy write FDy;
property DA: Double read FDa write FDa;
end;

TShip = class(TMovingUnit)
private
FLeftFire: TShipFire;
FRightFire: TShipFire;
FLeftFireCenter: TShipFire;
FRightFireCenter: TShipFire;
procedure MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single); virtual;
procedure MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Single);
public
property LeftFire: TShipFire read FLeftFire write FLeftFire;
property RightFire: TShipFire read FRightFire write FRightFire;
property LeftFireCenter: TShipFire read FRightFireCenter write FRightFireCenter;
property RightFireCenter: TShipFire read FRightFireCenter write FRightFireCenter;
procedure Repaint; override;
constructor Create(newParent: pointer); override;
constructor Create(AParent: pointer); override;
end;

TAsteroid = class(TSprite)
TAsteroid = class(TMovingUnit)
private
FDx, FDy, FDA: Double; // Ñäâèãè
FNotChange: Integer; // Êîë-âî òèêîâ, êîòîðîå íå áóäåò èçìåíÿòüñÿ íàïðàâëåíèå ïðè êîëëàéäåð
public
property DX: Double read FDx write FDx;
property DY: Double read FDy write FDy;
procedure Repaint; override;
procedure Collide(const AObject: TEngine2DObject);
constructor Create(newParent: pointer); override;
constructor Create(AParent: pointer); override;
end;

TLittleAsteroid = class(TSprite)
TLittleAsteroid = class(TMovingUnit)
private
FTip: Byte;
FDx, FDY: Double; // Ñäâèãè
public
property Tip: Byte read FTip write FTip; // Òèï àñòåðîéäà
procedure Repaint; override;
constructor Create(newParent: pointer); override;
constructor Create(AParent: pointer); override;
end;

TExplosion = class(TSprite)
public
procedure Repaint; override;
constructor Create(newParent: pointer); override;
constructor Create(AParent: pointer); override;
end;

TStar = class(TSprite)
Expand All @@ -77,42 +80,40 @@ implementation

{ TShip }

constructor TShip.Create(newParent: pointer);
constructor TShip.Create(AParent: pointer);
var
vEngine: TEngine2D;
begin
inherited;

vEngine := newParent;
vEngine := AParent;

// Self.Shape.AddFigure(TFigure)

FLeftFire := TShipFire.Create(newParent);
FLeftFire.Parent := newParent;
FLeftFire := TShipFire.Create(AParent);
FLeftFire.Parent := AParent;
FLeftFire.Resources := vEngine.Resources;
FLeftFire.ScaleX := Self.ScaleX;
FLeftFire.ScaleY := Self.ScaleY;
FLeftFire.Opacity := 0.5;
vEngine.AddObject(FLeftFire);

FRightFire := TShipFire.Create(newParent);
FRightFire.Parent := newParent;
FRightFire := TShipFire.Create(AParent);
FRightFire.Parent := AParent;
FRightFire.Resources := vEngine.Resources;
FRightFire.ScaleX := -Self.ScaleX;
FRightFire.ScaleY := Self.ScaleY;
FRightFire.Opacity := 0.5;
vEngine.AddObject(FRightFire);

FLeftFireCenter := TShipFire.Create(newParent);
FLeftFireCenter.Parent := newParent;
FLeftFireCenter := TShipFire.Create(AParent);
FLeftFireCenter.Parent := AParent;
FLeftFireCenter.Resources := vEngine.Resources;
FLeftFireCenter.ScaleX := Self.ScaleX;
FLeftFireCenter.ScaleY := Self.ScaleY;
FLeftFireCenter.Opacity := 0.5;
vEngine.AddObject(FLeftFireCenter);

FRightFireCenter := TShipFire.Create(newParent);
FRightFireCenter.Parent := newParent;
FRightFireCenter := TShipFire.Create(AParent);
FRightFireCenter.Parent := AParent;
FRightFireCenter.Resources := vEngine.Resources;
FRightFireCenter.ScaleX := -Self.ScaleX;
FRightFireCenter.ScaleY := Self.ScaleY;
Expand Down Expand Up @@ -234,7 +235,7 @@ procedure TAsteroid.Collide(const AObject: TEngine2DObject);
tEngine2d(fParent).AnimationList.Add(vAni);
end;

constructor TAsteroid.Create(newParent: pointer);
constructor TAsteroid.Create(AParent: pointer);
begin
inherited;
FDx := 200 * Random;
Expand All @@ -247,34 +248,34 @@ procedure TAsteroid.Repaint;
begin
curRes := 1;

inherited;

Self.x := Self.x + FDx * Game.Speed;
Self.y := Self.y + FDy * Game.Speed;
Self.Rotate := Self.Rotate + FDa * Game.Speed;

if Self.Rotate >= 360 then
Self.Rotate := 0;

if Self.x > tEngine2d(Parent).Width + Self.scW then
if Self.x >= tEngine2d(Parent).Width + Self.scW then
Self.x := -Self.scW
else
if Self.x < 0 - Self.scW then
Self.x := tEngine2d(Parent).Width + Self.scW;
Self.x := tEngine2d(Parent).Width;

if Self.y > tEngine2d(Parent).Height + Self.scH then
if Self.y >= tEngine2d(Parent).Height + Self.scH then
Self.y := -Self.scH
else
if Self.y < 0 - Self.scH then
Self.y := tEngine2d(Parent).Height + Self.scH;
if Self.y < 0 - Self.scH then
Self.y := tEngine2d(Parent).Height;

if FNotChange > 0 then
Dec(FNotChange);

inherited;
end;

{ TLittleAsteroid }

constructor TLittleAsteroid.Create(newParent: pointer);
constructor TLittleAsteroid.Create(AParent: pointer);
begin
inherited;
FTip := Random(6);
Expand All @@ -288,6 +289,8 @@ constructor TLittleAsteroid.Create(newParent: pointer);
procedure TLittleAsteroid.Repaint;
begin
curRes := FTip + 5;
inherited;

Self.x := Self.x + FDx * Game.Speed;
Self.y := Self.y + FDy * Game.Speed;

Expand All @@ -296,8 +299,6 @@ procedure TLittleAsteroid.Repaint;

if Self.y > tEngine2d(Parent).Height then
Self.y := -1;
inherited;

end;

{ TStar }
Expand All @@ -310,7 +311,7 @@ procedure TStar.Repaint;

{ TShipFire }

constructor TShipFire.Create(newParent: pointer);
constructor TShipFire.Create(AParent: pointer);
begin
inherited;
FTip := Random(3);
Expand All @@ -325,7 +326,7 @@ procedure TShipFire.Repaint;

{ TExplosion }

constructor TExplosion.Create(newParent: pointer);
constructor TExplosion.Create(AParent: pointer);
begin
inherited;
end;
Expand Down
3 changes: 1 addition & 2 deletions Engine/uEngine2D.pas
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,6 @@ procedure tEngine2d.repaint;
i, l: integer;
iA, lA: Integer; // Ñ÷åò÷èêè àíèìàöèè è ôîðìàòèðîâàíèÿ
m: tMatrix;
// srcRect, destRect: tRectF;
vAnimation: tAnimation;
begin

Expand All @@ -365,6 +364,7 @@ procedure tEngine2d.repaint;

if fDebug then
fDebug := False;

fCritical.Enter;
if (lA > 0) or (FOptions.ToAnimateForever) then
with fImage do
Expand All @@ -374,7 +374,6 @@ procedure tEngine2d.repaint;
FInBeginPaintBehavior;
FBackgroundBehavior;


l := (fSprites.Count - 1);
for i := 1 to l do
if fSpriteOrder[i] <= l then
Expand Down
12 changes: 8 additions & 4 deletions Engine/uEngine2DThread.pas
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ interface
destructor Destroy; override;
const
{$IFDEF WIN32}
CLeftFPSBorder = 220;
CRightFPSBorder = 260;
CLeftFPSBorder = 180;
CRightFPSBorder = 300;
CMiddleFPS = 240;
{$ENDIF WIN32}
{$IFDEF ANDROID}
CLeftFPSBorder = 50;
CRightFPSBorder = 70;
CLeftFPSBorder = 30;
CRightFPSBorder = 90;
CMiddleFPS = 60;
{$ENDIF ANDROID}
end;
Expand Down Expand Up @@ -81,6 +81,7 @@ procedure tEngineThread.Execute;
Self.Sleep(FSleep);
TickEnd := GetTickCount;
end;

end;

function tEngineThread.GetLastFps: Single;
Expand All @@ -93,6 +94,9 @@ function tEngineThread.GetLastFps: Single;

function TEngineThread.GetSpeed: Single;
begin
if (FPS > CRightFPSBorder) or (FPS < CLeftFPSBorder) then
Exit(1 / CMiddleFPS);

Result := 1 / FPS;
end;

Expand Down
Loading

0 comments on commit 0d92064

Please sign in to comment.