Changeset 347
- Timestamp:
- 05/30/08 14:33:00 (6 months ago)
- Files:
-
- trunk/qd/dt (added)
- trunk/qd/dt/dt.d (copied) (copied from trunk/qd/dt.d) (8 diffs)
- trunk/qd/dt/test13.d (copied) (copied from trunk/qd/test13.d) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/qd/dt/dt.d
r346 r347 1 module dt ; // D Tower Defense1 module dt.dt; // D Tower Defense 2 2 3 3 import tools.base; … … 31 31 32 32 interface 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 36 36 } 37 37 38 38 template 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; } 44 49 } 45 50 … … 47 52 vec2f pos; 48 53 int radius; 54 bool collides(WorldThing other) { 55 return (pos-other.pos).length <= radius + other.radius; 56 } 49 57 mixin This!("pos, radius"); 50 58 bool collide(WorldThing other) { return distance(other)<radius+other.radius; } … … 330 338 circle(ipos.tuple, settings.range-1, White); 331 339 } 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); 334 345 Teh_Ordnance.draw; 335 346 } … … 480 491 alias InteractingThing IT; 481 492 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; } 486 497 void mouse_up() { 487 498 if (!(SDLKey.LCtrl in keystate)) cleanSelection; 488 499 foreach (entry; highlighted.keys) { 489 entry.select ;500 entry.selected = true; 490 501 selected[entry] = true; 491 502 } … … 494 505 } 495 506 496 import test13, tools.functional;507 import dt.test13, tools.functional; 497 508 void main() { 498 509 auto blink_fn = blink(0.5); … … 523 534 vec2f(440, 30), vec2f(440, 150), vec2f(300, 150), vec2f(300, 300), vec2f(500, 300) 524 535 ); 525 536 FatLine fl; 526 537 auto bg_surf = screen.With(screen.w, screen.h) = { 527 FatLine fl;528 538 fl = new FatLine(path.points, (float d) { 529 539 if (abs(d) > fl.width) return Background; … … 559 569 scope(exit) writefln("Average FPS: ", avg/(cast(float)count)); 560 570 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 ); 562 577 do with (group) { 563 578 update; 564 579 // addEffect!(RingEffect)(Blue~Black, mousex, mousey, 50, 50); 580 test_turret.pos = vec2f(mouse.pos.x, mouse.pos.y); 565 581 display.blit(bg_surf); 566 582 prettyprint(0, 0, Bottom|Right, 567 583 Format("Score: [b][size -2]", spawner.score, "[/size][/b]")); 568 584 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"); 569 595 withSet(alpha, 64, { circle(path.points[$-1].to!(int).tuple, 15, Fill=Yellow~Black); }); 570 596 string formatting = Format(hits_counter); trunk/qd/dt/test13.d
r343 r347 1 module test13;1 module dt.test13; 2 2 3 3 import qd, dglut.vector, std.stdio, tools.base, tools.log, std.math; … … 73 73 if (!isnan(smallest)) return smallest; 74 74 else return sqrt(smallest_sqr); 75 } 76 bool circle_collides(vec2f pos, float radius) { 77 return normal_dist(pos) <= width + radius; 75 78 } 76 79 alias normal_dist opCall;
