unit _var;

interface

uses eXgine,Classes;

type
  TGameState=(gsIntro, gsMenu, gsGame, gsPause);

  TEnemyProgram=(epVagabond, epMutter, epGateKeeper, epBouncer, epHound);

  TScr = record
    wl,wr,wt,wd:integer;
    l,r,t,d:integer;
    dx,dy:integer;
    plX,plY:integer;
  end;

  TFood=record
    colR,colB,colG:byte;
    x,y,fx,fy:single;//integer;
    active:boolean;
    place:byte;
    delay:integer;
  end;

  TLevel = record
    pass: byte;
    wall: byte;
    tube: byte;
    contain:byte;
    ret:byte;
    food: array [0..29] of TFood;
  end;

  TInput=record
    Up, Down, Left, Right, UpR, UpL, DownR, DwnL, B1, B2, Esc, Ent, Pause:boolean;
    lastkey:integer;
    delay_u,delay_d,delay_l,delay_r:integer;
    _Up, _Down, _Left, _Right:boolean
  end;

  TPlayer=record
    x,y:integer;
    _x,_y:single;
    direction:integer;
    angle:integer;
    speed:single;
    shellangle:single;
    seq: array[0..5] of byte;
    frame:byte;
    oral:byte;
    delay:integer;
    consum:byte;
    energy:integer;
    max_energy:integer;
    ready:integer;
    mut:integer;
    hit:byte;
    tba,tbn:integer;
    Charged:integer;
    lvl:integer;
    dead:integer;
  end;

  TEnemy=record
    x,y:integer;
    _x,_y:single;
    direction:byte;
    angle:integer;
    frame:integer;
    delay:integer;
    colR,colG,colB:byte;
    frz:integer;
    speed:single;
//    dspeed:single;
    turned:integer;
    hp:integer;
    hit:byte;
    tgt_x, tgt_y:integer;
    base_prog: TEnemyProgram;
    curr_prog: TEnemyProgram;
    spr: byte;
  end;

  TLevelData=record
    Keys:integer;
    colR,colG,colB:byte;
    precolR,precolG,precolBL:byte;
    enemyseq:string;
    repenemy:integer;
  end;

  TBonus=record
    x,y:integer;
    TTL:integer;
    active:boolean;
    direction:byte;
    speed:integer;
    tp:byte;
    turned:byte;
  end;

  TMut=record
    x,y:integer;
    _x,_y:single;
    dx,dy:single;
    angle:single;
    speed:single;
  end;

  TTech=record
    x,y:integer;
    _x,_y:integer;
    angle:integer;
    direction:integer;
    delay: integer;
    frame:integer;
    state:integer;
  end;

  TSparker=record
    x,y:integer;
    sparkFr:integer;
    sparkW, sparkH:integer;
    delay:integer;
    tp:integer;
  end;

  THUD=record
    x,y:integer;
    energy_x, energy_y :integer;
    DNA_x, DNA_y :integer;
  end;




const
// --- Textures ---
Max_Textures=145;
tube=0; //15]
wall=16;
mut=17;
enter=18;
exit=19; //20]
replicator=21;
faketube=22;
pass=23;
core=24;
pg=25;
oral=26; //29]
sparker=30; //31]
spark=32; //34]
t_hud=35;
t_energy=36;
t_dna0=37;
t_dna1=38;
bbox=39;
coreinv=40;
//bonuser=41; //42]
t_bonus=41;
thunder=43; //47]
repliflash=48;
replilight=49;

enemy0=50; //57]
enemy1=60; //67]
enemy2=70; //77]
enemy3=80; //87]
enemy4=90; //97]

t_logo=100;
t_copyr=101;

//food=100; //debug

// --- Sounds ---
Max_Sounds=12;
s_oral=0;
s_mut=1;
s_amb=2;
s_spark=3;
s_exit_open=4;
s_hit=5;
s_replicator=6;
s_energy=7;
s_enter_replicator=8;
s_bonusend=9;
s_bonusend1=10;
s_enemyD=11;
s_bonus_enter=12;


// --- Constants ---
pi180=0.01745329251;
ClickWait=300;
Shot_Speed=6;
hit_margin=18;
FRate=100;
fpf=FRate div 15;
dfood=0.5;
bonustime=frate*10;
replicator_time=frate*3;


//tracks: array [0..3] of integer = (94,249,169,248);

var
  t:array[0..Max_Textures] of TTexture;
  sn:array[0..Max_Sounds] of TSound;
  level: array of array of TLevel;
  Fnt8, Fnt10, Fnt12, Fnt16, FntL:cardinal;
  GameState:TGameState;
  ms:Tmemorystream;
  tsl:tstringlist;
  Input:TInput;
  Control:TInput;
  delay:integer;
  lasttick:longint;
  Player:TPlayer;
  pause:boolean;
  F:file of longword;
  levelW:integer;
  levelH:integer;
  Scr:Tscr;
  debugX,debugY:integer;
  LevelData:Tleveldata;
  Bonus:TBonus;
  Tech_enter:TTech;
  Tech_exit:TTech;
  Tech_replica:TTech;
  Tech_bonuser:TTech;
  HUD:THUD;


  a_mut: array of TMut;
  a_ret: array of TTech;
  a_sparker: array of TSparker;
  a_enemy: array of TEnemy;
  {
  a_explosions: array of TExpl;
  a_enemy: array of TEnemy;
  a_rally: array of array of TRally;
  a_score: array of TScore;
  a_DelayAction: array of TDelayAction;
  a_bonus: array of TScore;
 }
procedure Init_player(New:boolean=false);
function get_angle (d:integer):integer;
function onscreen(x,y:integer):boolean;

implementation

//----------------------------------------------------------------------------------------------------------------------------------------------------

function onscreen(x,y:integer):boolean;
begin
  result:=(x>scr.l) and (x<scr.r) and (y>scr.t) and (y<scr.d);
end;

//----------------------------------------------------------------------------------------------------------------------------------------------------

procedure Init_player(New:boolean=false);
begin
  player.x:=scr.plX;
  player.y:=scr.plY;
  player._x:=player.x;
  player._y:=player.y;
  player.ready:=0;
  player.hit:=0;
  player.dead:=0;
  player.direction:=tech_enter.direction;
  player.angle:=tech_enter.angle;
  player.speed:=1.5;
  player.Charged:=0;
  if new then
    begin
      player.mut:=0;
      player.speed:=1.5;
      player.consum:=8;
      player.energy:=200;
      player.max_energy:=2000;
      player.lvl:=0;
    end;
end;

//----------------------------------------------------------------------------------------------------------------------------------------------------

function get_angle (d:integer):integer;
begin
  result:=0;
  case d of
    8: result:=0;
    6: result:=90;
    4: result:=-90;
    2: result:=180;
  end;
end;
//----------------------------------------------------------------------------------------------------------------------------------------------------


end.



