Results 1 to 10 of 25

Thread: Proceural Programming vs. Object Oriented Programming

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #13
    Hmm, that looks way more complicated than i had in mind. Also pay attention to memory usage! Do you have 2 billion different terrain types, or could you decide texture by just that terrain type instead of separate variable? Is the collision list required?
    Code:
      terraintile_t = record
        texture: integer;
        terraintype: integer; // 0(unpassable), 1(land), 2(water), 3(sub) - Also could be set as a compination of FLG_xxx flags with 0 as unpassable for easier checking using bitwise or
        blocklist: unit_p;    // colision list linked with unit_t.nextsamatile
      end;
    I would plan something like this:
    Code:
    const
      MAX_UNIT_TYPES = 10;
      MaxLandW = 256;
      MaxLandH = 256;
    
    type
      TUnitType = (utLand, utAir, utNaval, utSub);
      
      TUnitInfo = record
        ut: TUnitType;
        attLand, attAir, attNaval, attSub: boolean;
        maxHP, movespeed, acceleration: single;
      end;
      PUnitInfo = ^TUnitInfo;
    
      TUnit = record
        info: PUnitInfo;
        position, movement: TVector2f;
        HP, rotation: single;
        target: integer; // Target index from unit-array
      end;
    
    var
      land: array[0..MaxLandW-1, 0..MaxLandH-1] of byte;
      unitTypes: array[0..MAX_UNIT_TYPES-1] of TUnitInfo;
      unit: array of TUnit;
      uCount: integer;
    ...
    Then just initialize by filling details to unitTypes for 10 ship types. Give pointer to needed unitType when adding a new unit. And i'm missing guns and stuff for now...
    Last edited by User137; 30-03-2012 at 10:53 AM.

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
  •