Mercurial > projects > openmelee
comparison main.d @ 17:82efafc87d54
fixed camera zoom
author | zzzzrrr <mason.green@gmail.com> |
---|---|
date | Tue, 24 Mar 2009 16:47:42 -0400 |
parents | 8e6a9e390cba |
children |
comparison
equal
deleted
inserted
replaced
16:cc494b8f8710 | 17:82efafc87d54 |
---|---|
47 | 47 |
48 import openmelee.melee; | 48 import openmelee.melee; |
49 import openmelee.render; | 49 import openmelee.render; |
50 import openmelee.ai; | 50 import openmelee.ai; |
51 | 51 |
52 const ITERS_PER_SECOND = 60; | 52 const ITERS_PER_SECOND = 100; |
53 | 53 |
54 void main() { | 54 void main() { |
55 | 55 |
56 Settings settings; | 56 Settings settings; |
57 float timeStep = settings.hz > 0.0f ? 1.0f / settings.hz : 0.0f; | 57 float timeStep = settings.hz > 0.0f ? 1.0f / settings.hz : 0.0f; |
75 gui.immediate.end; | 75 gui.immediate.end; |
76 | 76 |
77 StopWatch timer; | 77 StopWatch timer; |
78 | 78 |
79 jobHub.addRepeatableJob( { | 79 jobHub.addRepeatableJob( { |
80 | |
81 // Update AI | |
82 ai.move(whut.ship1); | |
83 | |
84 // Update physics | 80 // Update physics |
85 whut.world.step(timeStep, settings.velocityIterations, | 81 whut.world.step(timeStep, settings.velocityIterations, |
86 settings.positionIterations); | 82 settings.positionIterations); |
83 }, ITERS_PER_SECOND); | |
84 | |
85 bool running = true; | |
86 | |
87 jobHub.addPreFrameJob( { | |
88 // Update AI | |
89 ai.move(whut.ship1); | |
90 }); | |
91 | |
92 jobHub.addPostFrameJob( { | |
87 | 93 |
88 // Limit velocity | 94 // Limit velocity |
89 whut.ship1.limitVelocity(); | 95 whut.ship1.limitVelocity(); |
90 whut.ship2.limitVelocity(); | 96 whut.ship2.limitVelocity(); |
91 whut.ship1.updateState(); | 97 whut.ship1.updateState(); |
92 whut.ship2.updateState(); | 98 whut.ship2.updateState(); |
93 | |
94 }, ITERS_PER_SECOND); | |
95 | |
96 bool running = true; | |
97 | |
98 jobHub.addPreFrameJob( { | |
99 }); | |
100 | |
101 jobHub.addPostFrameJob( { | |
102 | 99 |
103 gui.begin(cfg); | 100 gui.begin(cfg); |
104 gui.push(`main`); | 101 gui.push(`main`); |
105 if (gui().getProperty!(bool)("frame.closeClicked")) { | 102 if (gui().getProperty!(bool)("frame.closeClicked")) { |
106 running = false; | 103 running = false; |
114 gui().setProperty!(bool)("showCursor", true); | 111 gui().setProperty!(bool)("showCursor", true); |
115 gui.pop(); | 112 gui.pop(); |
116 gui.end; | 113 gui.end; |
117 gui.render(renderer); | 114 gui.render(renderer); |
118 | 115 |
119 { | |
120 vec2 p1 = vec2.from(whut.ship1.rBody.position); | |
121 vec2 p2 = vec2.from(whut.ship2.rBody.position); | |
122 vec2 distance = p1 - p2; | |
123 float d = distance.length; | |
124 whut.zoom = bzClamp(1/d*1000, 2, 50); | |
125 whut.viewCenter = p1 - (distance * 0.5f); | |
126 } | |
127 | |
128 }); | 116 }); |
129 | 117 |
130 while (running && !whut.quit) { | 118 while (running && !whut.quit) { |
131 float delta = timer.stop; | 119 float delta = timer.stop; |
132 timer.start; | 120 timer.start; |