shooflenet/articles/dynamic_systems_in_games.article.html

60 lines
4.2 KiB
HTML
Raw Normal View History

2013-09-01 21:06:36 -04:00
<article>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script type="text/javascript" src="/static/flot/jquery.flot.js"></script>
<script type="text/javascript" src="/static/flot/jquery.flot.resize.js"></script>
<script type="text/javascript" src="engine.js"></script>
2013-09-01 21:06:36 -04:00
<h1>Dynamic Systems in Games</h1>
<p>Here, take a look at this simple game I coded up. Your task is to keep an engine's temperature as high as possible, to maximize power output, without dmaaging the engine. The threshhold for damage is at <span data-var="damage_threshhold">10</span> degrees, and the engine will stop burning and deignite if it goes under <span data-var="ignition_threshhold">2</span> degrees.</p>
<div class="row-fluid">
<div id="fuel-management-1" class="span4 offset4">
<script type="text/javascript">
2013-09-04 13:54:38 -04:00
function heyo(sq) {
if (sq.temperature.value < sq.ignition_threshhold.value) {
return -0.5*sq.temperature.value;
}
2013-09-04 13:54:38 -04:00
return sq.temperature.value*sq.fuel_flow_rate.value - 0.5*sq.temperature.value;
}
2013-09-04 13:54:38 -04:00
var e1=engine($('#fuel-management-1'), heyo);
2013-09-01 21:06:36 -04:00
</script>
<div class="flow_rate">
2013-09-01 21:06:36 -04:00
<label for="fuel">Fuel Flow Rate</label>
<input type="range" name="fuel" min=0 max=2 step=0.01 value=.8>
2013-09-01 21:06:36 -04:00
</div>
<input type="button" name="ignition" value="Ignite!">
<span><span class="temp-out">0</span> degrees</span>
<span class="noignition label label-info">No ignition</span>
<span class="damage label label-warning">DAMAGE!</span>
2013-09-04 13:54:38 -04:00
<div class="potential_plot" style="width:100%;height:300px"></div>
2013-09-01 21:06:36 -04:00
</div>
2013-09-04 13:54:38 -04:00
<span class="sidenote span4">The dotted lines indicate what the curve will look like if you adjust the fuel flow rate up or down a little bit.</span>
2013-09-01 21:06:36 -04:00
</div>
<p>It's interesting! Or maybe it's not. I threw this together trying to think of what an interesting way for an engine to work might be. The fundamental relationship here is:</p>
\[\frac{\partial T}{\partial t} = c_F T F - c_T (T - T_0)\]
<p>That is, at any given moment, the temperature is changing (\(\frac{\partial T}{\partial t}\)) by increasing proportional to the temperature times the fuel flow rate (\(c_F T F\)) and decreasing proportional to the difference between the chamber temperature and the ambient temperature (\(c_T (T - T_0)\)). The deignition isn't described in this formula, but it's pretty simple - the \(c_F T F\) factor becomes zero when the temperature is less than <span data-var="ignition_threshhold">2</span> degrees.</p>
2013-09-04 13:54:38 -04:00
<p>As it turns out, (surprise of surprises!) that description in a formula is pretty useless for actually understanding how this feels. The key was to look at it as a function of the temperature. See, the player changes \(F\), and I want to get a feel for how the temperature's going to change. So I made a graph with respect to \(T\) where the slope is given by \(\frac{\partial T}{\partial t}\). <span class="sidenote span4">Note that this is not just going to undo the partial derivative. In this graph, we're integrating against \(T\), not \(t\). Roughly, this graph should be thought of as one where the temperature would slide down hills. Anyway.</span></p>
<p>You can feel free to slide around the fuel flow rate slider to play with this. When the graph is flat, that temperature is stable. (Remember: temperature is on the x-axis.)</p>
<p>Well. This is <em>terrible</em>. There aren't any stable points!
<div class="row-fluid">
<div id="fuel-management-2" class="span4 offset4">
<script type="text/javascript">
2013-09-04 13:54:38 -04:00
function heyo2(sq) {
if (sq.temperature.value < sq.ignition_threshhold.value) {
return -0.5;
}
2013-09-04 13:54:38 -04:00
return sq.temperature.value*sq.fuel_flow_rate.value - 0.5;
}
2013-09-04 13:54:38 -04:00
var e2=engine($('#fuel-management-2'), heyo2);
</script>
<div class="flow_rate">
<label for="fuel">Fuel Flow Rate</label>
<input type="range" name="fuel" min=0 max=0.5 step=0.01 value=.8>
</div>
<input type="button" name="ignition" value="Ignite!">
<span><span class="temp-out">0</span> degrees</span>
<span class="noignition label label-info">No ignition</span>
<span class="damage label label-warning">DAMAGE!</span>
2013-09-04 13:54:38 -04:00
<div class="potential_plot" style="width:100%;height:300px"></div>
</div>
</div>
</article>