UPyramid.pas
上传用户:zkjn0718
上传日期:2021-01-01
资源大小:776k
文件大小:3k
- unit UPyramid;
- interface
- {$I ......SourcePhysics2D.inc}
- uses
- UMain, UPhysics2DTypes, UPhysics2D, SysUtils;
- type
- TPyramid = class(TTester)
- private
- m_bodyCount: Integer;
- public
- constructor Create; override;
- procedure Step(var settings: TSettings; timeStep: Float); override;
- procedure Keyboard(key: Byte); override;
- procedure LaunchBomb(velocity_factor: Float = 1.0); override;
- end;
- implementation
- var
- m_level: Integer;
- { TPyramid }
- constructor TPyramid.Create;
- const
- deltaX: TVector2 = (X: 0.5625; Y: 2.0);
- deltaY: TVector2 = (X: 1.125; Y: 0.0);
- var
- i, j: Integer;
- sd: Tb2PolygonDef;
- bd: Tb2BodyDef;
- ground: Tb2Body;
- body: Tb2Body;
- x, y: TVector2;
- begin
- inherited;
- begin
- sd := Tb2PolygonDef.Create;
- sd.SetAsBox(50.0, 10.0);
- bd := Tb2BodyDef.Create;
- {$IFDEF OP_OVERLOAD}
- bd.position.SetValue(0.0, -10.0);
- {$ELSE}
- SetValue(bd.position, 0.0, -10.0);
- {$ENDIF}
- ground := m_world.CreateBody(bd);
- ground.CreateShape(sd);
- end;
- begin
- sd := Tb2PolygonDef.Create;
- sd.SetAsBox(0.5, 0.5);
- sd.density := 5.0;
- sd.friction := 0.7;
- bd := Tb2BodyDef.Create;
- {$IFDEF OP_OVERLOAD}
- x.SetValue(-10.0, 0.75);
- {$ELSE}
- SetValue(x, -10.0, 0.75);
- {$ENDIF}
- m_bodyCount := 0;
- for i := 0 to m_level do
- begin
- y := x;
- for j := i to m_level do
- begin
- bd.position := y;
- body := m_world.CreateBody(bd, False);
- body.CreateShape(sd, False);
- body.SetMassFromShapes;
- Inc(m_bodyCount);
- {$IFDEF OP_OVERLOAD}
- y.AddBy(deltaY);
- {$ELSE}
- AddBy(y, deltaY);
- {$ENDIF}
- end;
- {$IFDEF OP_OVERLOAD}
- x.AddBy(deltaX);
- {$ELSE}
- AddBy(x, deltaX);
- {$ENDIF}
- end;
- sd.Free;
- bd.Free;
- end;
- end;
- procedure TPyramid.Step(var settings: TSettings; timeStep: Float);
- begin
- inherited;
- DrawText(Format('Use +/- to change box count. Box Count: %d', [m_bodyCount]));
- end;
- procedure TPyramid.Keyboard(key: Byte);
- begin
- inherited;
- case key of
- 187{+}:
- if m_level < 30 then
- Inc(m_level);
- 189{-}:
- if m_level > 1 then
- Dec(m_level);
- else
- Exit;
- end;
- frmMain.btnResetClick(nil);
- end;
- procedure TPyramid.LaunchBomb(velocity_factor: Float);
- begin
- inherited LaunchBomb(15.0);
- end;
- initialization
- m_level := 25;
- RegisterTestEntry('Pyramid', TPyramid);
- end.