Changeset 248
- Timestamp:
- 11/26/07 15:40:00 (1 year ago)
- Files:
-
- trunk/samples/simple.md (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/samples/simple.md
r240 r248 1 1 module simple; 2 2 3 /*{3 { 4 4 import arc.draw.color : Color; 5 5 import arc.draw.image : drawImage, drawImageTopLeft; 6 import arc.draw.shape : drawCircle, drawRectangle ;6 import arc.draw.shape : drawCircle, drawRectangle, drawLine, drawPixel; 7 7 import arc.font : Font; 8 8 import arc.input : key, mouse; … … 14 14 import arc.window; 15 15 16 class ParticleGen 17 { 18 mParticles = null; 19 mFreeParticles = null; 20 mRate; 21 mGravity; 22 mLife; 23 mLast; 24 25 this(rate, gravity = 0.05, life = 2.5) 26 { 27 mRate = toFloat(rate); 28 mGravity = toFloat(gravity); 29 mLife = toInt(life * 1_000_000); 30 mLast = os.microTime(); 31 } 32 33 function generate(pos) 34 { 35 local time = os.microTime(); 36 37 if((time - mLast) < mRate) 38 return; 39 40 local ang = math.rand(360); 41 42 local part; 43 44 if(mFreeParticles is null) 45 part = { color = Color(1.0, 1.0, 1.0) }; 46 else 47 { 48 part = mFreeParticles; 49 mFreeParticles = part.next; 50 } 51 52 part.pos = pos; 53 part.vx = math.sin(ang) * math.frand(1.5); 54 part.vy = math.cos(ang) * math.frand(1.5); 55 part.color.setR(1.0); 56 part.color.setG(0.0); 57 part.color.setB(0.0); 58 part.color.setA(1.0); 59 part.start = time; 60 part.next = mParticles; 61 mParticles = part; 62 63 mLast = time; 64 } 65 66 function process() 67 { 68 if(mParticles is null) 69 return; 70 71 local time = os.microTime(); 72 73 for(local v = mParticles, local old = null; v !is null; ) 74 { 75 local t = time - v.start; 76 77 if((time - v.start) > mLife) 78 { 79 if(old is null) 80 mParticles = v.next; 81 else 82 old.next = v.next; 83 84 local temp = v.next; 85 v.next = mFreeParticles; 86 mFreeParticles = v; 87 v = temp; 88 continue; 89 } 90 91 v.color.setA(1.0 - (t / toFloat(mLife))); 92 93 v.vy -= mGravity; 94 v.pos.y -= v.vy; 95 v.pos.x += v.vx; 96 97 if(v.pos.x < 0 || v.pos.x > arc.window.getWidth() || v.pos.y > arc.window.getHeight()) 98 { 99 if(old is null) 100 mParticles = v.next; 101 else 102 old.next = v.next; 103 104 local temp = v.next; 105 v.next = mFreeParticles; 106 mFreeParticles = v; 107 v = temp; 108 continue; 109 } 110 111 drawCircle(v.pos, 2, 8, v.color, true); 112 113 old = v; 114 v = v.next; 115 } 116 } 117 } 118 16 119 arc.window.open("Hello world", 800, 600, false); 17 120 arc.input.open(); … … 24 127 local origin = Point(0.0, 0.0); 25 128 local white = Color(255, 255, 255); 26 27 // local sound = Sound(SoundFile("LASERTW.WAV")); 28 // local music = Sound(SoundFile("title choir.ogg")); 29 // music.setLoop(true); 30 // music.play(); 31 129 130 local pg = ParticleGen(1000); 131 132 arc.input.defaultCursorVisible(false); 133 32 134 while(!arc.input.keyDown(key.Quit) && !arc.input.keyDown(key.Esc)) 33 135 { … … 36 138 arc.time.process(); 37 139 arc.sound.process(); 38 // sound.process(); 39 // music.process(); 40 41 // if(arc.input.mouseButtonPressed(mouse.Left)) 42 // { 43 // sound.seek(0.0); 44 // sound.play(); 45 // } 140 141 if(arc.input.mouseButtonDown(mouse.Left)) 142 pg.generate(arc.input.mousePos()); 143 144 pg.process(); 145 146 drawCircle(arc.input.mousePos(), 6, 10, white, false); 46 147 47 148 font.draw(toString(arc.time.fps()), origin, white); 48 149 font.draw(toString(pg.mParticles is null), Point(0.0, 16.0), white); 49 150 arc.time.limitFPS(60); 50 151 arc.window.swap(); … … 58 159 59 160 return; 60 } */161 } 61 162 62 163 /* … … 591 692 592 693 for(i : 0 .. 10) 593 prioQ.insert(math.rand( 0,20));694 prioQ.insert(math.rand(20)); 594 695 595 696 while(prioQ.hasData())
