Changeset 347

Show
Ignore:
Timestamp:
05/30/08 14:33:00 (6 months ago)
Author:
FeepingCreature
Message:
  • Moved DT into own folder
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/qd/dt/dt.d

    r346 r347  
    1 module dt; // D Tower Defense 
     1module dt.dt; // D Tower Defense 
    22 
    33import tools.base; 
     
    3131 
    3232interface InteractingThing { 
    33   void select(); void unselect(); 
    34   void highlight(); void unhighlight(); 
    35   bool isSelected(); bool isHighlighted(); 
     33  void selected(bool b); void highlighted(bool b); void broken(bool b); 
     34  bool isSelected(); bool isHighlighted(); bool isBroken(); 
     35   
    3636} 
    3737 
    3838template InteractingImpl() { 
    39   bool selected, highlighted; 
    40   void select() { selected = true; highlighted = true; } 
    41   void highlight() { highlighted = true; } 
    42   void unselect() { selected = false; } void unhighlight() { highlighted = false; } 
    43   bool isSelected() { return selected; } bool isHighlighted() { return selected || highlighted; } 
     39  private bool select, highlight, breaks; 
     40  void selected(bool b) { 
     41    select = b; 
     42    if (b) highlight = true; 
     43  } 
     44  void highlighted(bool b) { highlight = b; } 
     45  void broken(bool b) { breaks = b; } 
     46  bool isSelected() { return select; } 
     47  bool isHighlighted() { return select || highlight; } 
     48  bool isBroken() { return breaks; } 
    4449} 
    4550 
     
    4752  vec2f pos; 
    4853  int radius; 
     54  bool collides(WorldThing other) { 
     55    return (pos-other.pos).length <= radius + other.radius; 
     56  } 
    4957  mixin This!("pos, radius"); 
    5058  bool collide(WorldThing other) { return distance(other)<radius+other.radius; } 
     
    330338      circle(ipos.tuple, settings.range-1, White); 
    331339    } 
    332     if (isSelected) bufferedCircle(ipos.tuple, radius, Black, Fill=White~Green~(Blue~White)); 
    333     else bufferedCircle(ipos.tuple, radius, Black, Fill=White~Green); 
     340    rgb col; 
     341    if (isSelected) col = White~Green~(Blue~White); 
     342    else if (isBroken) col = White~Red; 
     343    else col = White~Green; 
     344    bufferedCircle(ipos.tuple, radius, Black, Fill=col); 
    334345    Teh_Ordnance.draw; 
    335346  } 
     
    480491  alias InteractingThing IT; 
    481492  bool[IT] selected, highlighted; 
    482   void cleanHighlights() { foreach (entry; highlighted.keys) entry.unhighlight; highlighted = null; } 
    483   void cleanSelection() { foreach (entry; selected.keys) entry.unselect; selected = null; } 
    484   void rmHighlight(IT it) { it.unhighlight; highlighted.remove(it); } 
    485   void addHighlight(IT it) { highlighted[it] = true; it.highlight; } 
     493  void cleanHighlights() { foreach (entry; highlighted.keys) entry.highlighted = false; highlighted = null; } 
     494  void cleanSelection() { foreach (entry; selected.keys) entry.selected = false; selected = null; } 
     495  void rmHighlight(IT it) { it.selected = false; highlighted.remove(it); } 
     496  void addHighlight(IT it) { highlighted[it] = true; it.highlighted = true; } 
    486497  void mouse_up() { 
    487498    if (!(SDLKey.LCtrl in keystate)) cleanSelection; 
    488499    foreach (entry; highlighted.keys) { 
    489       entry.select
     500      entry.selected = true
    490501      selected[entry] = true; 
    491502    } 
     
    494505} 
    495506 
    496 import test13, tools.functional; 
     507import dt.test13, tools.functional; 
    497508void main() { 
    498509  auto blink_fn = blink(0.5); 
     
    523534      vec2f(440, 30), vec2f(440, 150), vec2f(300, 150), vec2f(300, 300), vec2f(500, 300) 
    524535  ); 
    525    
     536  FatLine fl; 
    526537  auto bg_surf = screen.With(screen.w, screen.h) = { 
    527     FatLine fl; 
    528538    fl = new FatLine(path.points, (float d) { 
    529539      if (abs(d) > fl.width) return Background; 
     
    559569  scope(exit) writefln("Average FPS: ", avg/(cast(float)count)); 
    560570  auto limiter=new FrameLimiter(60, 60); 
    561   bool delegate(WorldThing) shouldHighlight = &underMouse;; 
     571  bool delegate(WorldThing) shouldHighlight = &underMouse; 
     572  auto test_turret = new Turret( 
     573    Turret.Settings(115, 12, false), 
     574    Ammo.Settings(0.5, 0.2, 0.9, 0.9, 1, 128, true, false, false), 
     575    spawner.critters, vec2f(0, 0) 
     576  ); 
    562577  do with (group) { 
    563578    update; 
    564579    // addEffect!(RingEffect)(Blue~Black, mousex, mousey, 50, 50); 
     580    test_turret.pos = vec2f(mouse.pos.x, mouse.pos.y); 
    565581    display.blit(bg_surf); 
    566582    prettyprint(0, 0, Bottom|Right, 
    567583      Format("Score: [b][size -2]", spawner.score, "[/size][/b]")); 
    568584    draw; 
     585    test_turret.broken = fl.circle_collides(test_turret.pos, test_turret.radius) || { 
     586      foreach (t; group) 
     587        if (auto meep = cast(WorldThing) t) 
     588          if (meep.collides(test_turret)) return true; 
     589      return false; 
     590    }(); 
     591    test_turret.draw(); 
     592    auto foo = display.select(pt(100, 40), Bottom|Left); 
     593    line(foo.tl, foo.br, Box=Black, Fill=Background~White); 
     594    .print(foo, Center, Black, "Place turret"); 
    569595    withSet(alpha, 64, { circle(path.points[$-1].to!(int).tuple, 15, Fill=Yellow~Black); }); 
    570596    string formatting = Format(hits_counter); 
  • trunk/qd/dt/test13.d

    r343 r347  
    1 module test13; 
     1module dt.test13; 
    22 
    33import qd, dglut.vector, std.stdio, tools.base, tools.log, std.math; 
     
    7373    if (!isnan(smallest)) return smallest; 
    7474    else return sqrt(smallest_sqr); 
     75  } 
     76  bool circle_collides(vec2f pos, float radius) { 
     77    return normal_dist(pos) <= width + radius; 
    7578  } 
    7679  alias normal_dist opCall;