Results 1 to 9 of 9

Thread: Shooting Bullets

  1. #1

    Shooting Bullets

    I've been trying to make a remake of the gamemaker "scrolling shooter" tutorial(http://www.yoyogames.com/make/tutorials).
    Everything's been going pretty well except when my plane has to shoot. You see, there's a
    'create instance of bullet at point [X, Y]' in gamemaker but in delphi(particularly DelphiX) I have no idea where to start. Do I use an array of some type? I'll post up the source soon to give a better idea.

  2. #2
    Legendary Member NecroDOME's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands, Eindhoven
    Posts
    1,059

    Re: Shooting Bullets

    Yes, you can have some array or list that holds the projectiles.

    Code:
    procedure Update projecttiles();
    begin
     for each projectile do
     begin
      Projectile[ index ].Move;
      Projectile[ index ].CheckHitWithEnemy;
     end;
    end;
    NecroSOFT - End of line -

  3. #3

    Re: Shooting Bullets

    Thanks!!
    I'll try it out

  4. #4

    Re: Shooting Bullets

    I've found an easier way without the need for another procedure or an array, create one on the spot!
    Without further ado:
    Code:
     If (GetKeyState(32) and 128 = 128) And (Shot_Counter < 0)
      Then
      Begin
       Shot_Counter := 10;
       with THBullet.Create(Engine.Engine) Do // <--This Here's The Important line :)
        Begin
         Image := Sprites.Items.Find('Bullet');
         X := Hero.X + (Hero.Width DIV 2);
         Y := Hero.Y;
         Z := 13;
         Width := Image.Width;
         Height := Image.Height;
        End;//With
      End;//If
    Of course all the movement is handled in the DoMove Procedure.

  5. #5

    Re: Shooting Bullets

    Image := Sprites.Items.Find('Bullet');
    Instead of using 'find', rather use an index i.e.

    [pascal]Image := FormGame.DXImageList.Items[20];[/pascal]

    It's faster
    Wake up from the dream and live your life to the full

  6. #6

    Re: Shooting Bullets

    Hey. Why not better:

    Proyectiles:array[0..10] of TBitmap;

    //if you nedd more so use a function to Increase the array


    if theKey=VK_SPACE then
    inc(i);
    Proyectiles[i].Create;
    Proyectiles[i].LoadFromFile('missile.bmp');
    initx:=Hero.X;
    for j:=initx to ClientWidth do
    begin
    inc(j,10);
    Hero.x:=j;
    end;


    That is what I would do it.. i suppose its right
    Live programming, eat programming, breath programming and die programming

  7. #7
    Legendary Member NecroDOME's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands, Eindhoven
    Posts
    1,059

    Re: Shooting Bullets

    an other approach.

    [pascal]TPojectile = record
    x, y : single;
    Image : TBitmap;
    SpeedX, SpeedY : single;
    end;[/pascal]

    ...or...

    [pascal]TPojectile = class
    Image: TBitmap;
    SpeedX, SpeedY : single;
    end;[/pascal]

    ...or...

    [pascal]TPojectile = class(TBitmap)
    SpeedX, SpeedY : single;
    end;[/pascal]

    ...and...

    I'm not really a fan of using fixed-arrays, but if you are sure you maximum have 10 projectiles (or a fixed maximum amount), that you can indeed use a fixed array. Here is dynamic a more dynamic approach with a TList object. (Would be nicer if pascal has generics, than you could declare it like TList<TProjectile>.
    [pascal]Projectiles : TList;

    procedure InitGame()
    begin
    Projectiles := TList.Create;
    end;

    procedure Shoot()
    begin
    Projectiles.Add(Projectile.Create(x, y, speed, etc...));
    end;

    procedure UpdateProjectiles()
    var i : integer;
    p : TProjectile;
    begin
    for i := 0 to Projectiles.Count-1 do
    begin
    p := TProjectile(Projectiles.Items[i]);
    p.x := p.x + p.speedx;
    p.y := p.y + p.speedy;
    end;
    end;

    procedure OnProjectilehitSomething(ProjectileInstance : TProjectile)
    begin
    SpawnMagicalEffectThingy(ProjectileInstance .x, ProjectileInstance .y);
    Projectiles.Remove(ProjectileInstance);
    end;
    [/pascal]
    NecroSOFT - End of line -

  8. #8

    Re: Shooting Bullets

    Quote Originally Posted by NecroDOME
    I'm not really a fan of using fixed-arrays, but if you are sure you maximum have 10 projectiles (or a fixed maximum amount), that you can indeed use a fixed array. Here is dynamic a more dynamic approach with a TList object. (Would be nicer if pascal has generics, than you could declare it like TList<TProjectile>.
    Actually, since Delphi 2009 pascal has generics, I love em, TList<TProjectile>, TDictionary<TProjectile>, TQueue<TProjectile> etc!
    Amnoxx

    Oh, and this code appears to be an approximate replacement for return(random() & 0x01);

    Phoenix Wiki
    http://www.phoenixlib.net/

    Phoenix Forum
    http://www.pascalgamedevelopment.com/viewforum.php?f=71

  9. #9
    Legendary Member NecroDOME's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands, Eindhoven
    Posts
    1,059

    Re: Shooting Bullets

    Yes I know, but I didn't get that thing working... yet...
    NecroSOFT - End of line -

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Comodo SSL