Jumat, 30 April 2021

Cara menggunakan box2D pada delphi console

uses
  System.SysUtils, Box2D.Collision, Box2D.Common,
  Box2D.Dynamics,
  Box2D.Rope, Box2DTypes;

var
  gravity: b2Vec2;
  world: b2WorldWrapper;
  groundBodyDef: b2BodyDef;
  groundBody: b2BodyWrapper;
  groundBox: b2PolygonShapeWrapper;
  bodyDef: b2BodyDef;
  body: b2BodyWrapper;
  dynamicBox: b2PolygonShapeWrapper;
  fixtureDef: b2FixtureDef;
  timeStep, angle: Single;
  velocityIterations, positionIterations, i: Integer;
  position: b2Vec2;
begin
  try
    // Define the gravity vector.
    gravity := b2Vec2.Create(0.0, -10.0);

    // Construct a world object, which will hold and simulate the rigid bodies.
    world := b2WorldWrapper.Create(gravity);

    // Define the ground body.
    groundBodyDef := b2BodyDef.Create;
    groundBodyDef.position.&Set(0.0, -10.0);

    // Call the body factory which allocates memory for the ground body
    // from a pool and creates the ground box shape (also from a pool).
    // The body is also added to the world.
    groundBody := world.CreateBody(@groundBodyDef);

    // Define the ground box shape.
    groundBox := b2PolygonShapeWrapper.Create;

    // The extents are the half-widths of the box.
    groundBox.SetAsBox(50.0, 10.0);

    // Add the ground fixture to the ground body.
    groundBody.CreateFixture(groundBox, 0.0);

    // Define the dynamic body. We set its position and call the body factory.
    bodyDef := b2BodyDef.Create;
    bodyDef.&type := b2_dynamicBody;
    bodyDef.position.&Set(0.0, 4.0);
    body := world.CreateBody(@bodyDef);

    // Define another box shape for our dynamic body.
    dynamicBox := b2PolygonShapeWrapper.Create;
    dynamicBox.SetAsBox(1.0, 1.0);

    // Define the dynamic body fixture.
    fixtureDef := b2FixtureDef.Create;
    fixtureDef.shape := dynamicBox;

    // Set the box density to be non-zero, so it will be dynamic.
    fixtureDef.density := 1.0;

    // Override the default friction.
    fixtureDef.friction := 0.3;

    // Add the shape to the body.
    body.CreateFixture(@fixtureDef);

    // Prepare for simulation. Typically we use a time step of 1/60 of a
    // second (60Hz) and 10 iterations. This provides a high quality simulation
    // in most game scenarios.
    timeStep := 1.0 / 60.0;
    velocityIterations := 6;
    positionIterations := 2;

    // This is our little game loop.
    for I := 0 to 59 do
    begin
      // Instruct the world to perform a single step of simulation.
      // It is generally best to keep the time step and iterations fixed.
      world.Step(timeStep, velocityIterations, positionIterations);

      // Now print the position and angle of the body.
      position := body.GetPosition^;
      angle := body.GetAngle;

      WriteLn(Format('%4.2f %4.2f %4.2f', [position.x, position.y, angle]));
    end;

    // When the world destructor is called, all bodies and joints are freed.
    // This can create orphaned pointers, so be careful about your world
    // management.
    world.Destroy;

    ReadLn;
    
    

Belajar mengisi tipe Trect fungsi bound pada Delphi Console

tambahkan code pada proect anda seperti ini
uses
  System.SysUtils,
  System.Types;

var
  aRectangle:TRect;

begin
  try
    aRectangle := Bounds(4,5,16,25);
    {
    equivalent to:
      aRectangle.Left := 4;
      aRectangle.Top := 5;
      aRectangle.Width := 16;
      aRectangle.Height := 25;
    }

    WriteLn('batas kiri ',aRectangle.Left,' batas atas ', aRectangle.Top,
     ' batas kanan ',aRectangle.Right,' batas bawah ',aRectangle.Bottom);

    readln; 

Menampilkan Hello World di Delphi 10 console

Buka Delphi buat project baru tipe aplikasi console tampilan akan seperti ini :

kemudian ketik dua baris code dibawah perintah try seperti ini :
    writeln('Hello world');
    readln;
    

Kemudian Jalankan maka tampilan klo berhasil harus seperti ini

Belajar bahasa pascal Mode Console di Delphi 10

Tahun 2017 ini saya menginstal delphi vwersi 10, lumayanlah untuk berjalan di laptop Core_i3 ku.

Kamis, 30 Juni 2016

whats up in 2016

long time ago since 2013 not post any. learn some code.. lazy dizzy era. 2014 still busy with workhour... but i took course of programming using pascal. 2015 i move from central office to branch office. i never create code again. poor me. 2016 well in this year.. statring nu life.. still doing some cool code.. micro controller with C. omg.. i dont' using pascal anymore ??? sorry to read that..

Senin, 01 April 2013

Joystick code

var regs:registers; bit:integer; ... // get joystick button values via DOS interupt request 15h regs.ah:=$84; regs.dx:=$00; // notes sub-function 0 : read the buttons intr($15,regs); gotoxy(1,8); if (regs.al and 16) <> 16 then write (' ON':6) else write('off':6); if (regs.al and 32) <> 32 then write (' ON':13) else write('off':13); if (regs.al and 64) <> 64 then write (' ON':16) else write('off':16); if (regs.al and 128) <> 128 then write (' ON':11) else write('off':11); // get joystick position via DOS interupt request 15h regs.ah:=$84; regs.dx:=$01; // notes sub-function 1 : read the positions intr($15,regs); gotoxy(1,10); writeln(regs.AX:6); writeln(regs.BX:6); writeln(regs.CX:6); writeln(regs.DX:6);

Minggu, 09 Desember 2012

Rewind Jan -des 2012

ah.. the end of year 2012 How do you do ? I'm busy in administrative at office. so i cannot explore at the weekend to create software, anyway each month i try to report sometng like this :

Januari : umm..
Feruari : eh..?
Maret : almost..done
April : tik tok tik tok
Mei : ???
Juni : Creating Library Online, web based huh ?
Juli : PXE boot, try to bring my old laptop back to life
Agustus : Independen Day
September: Miku Miku Dance Software Research
Oktober : Trip other city
November : Rain.. time to check equipment.
December : Oh my GOD, my Electronc stuff getting wet. rusty. :(

bobo