Mercurial > projects > openmelee
view melee.d @ 14:af1e8620f027
fixed steering
author | zzzzrrr <mason.green@gmail.com> |
---|---|
date | Mon, 23 Mar 2009 14:06:47 -0400 |
parents | e1004697cae1 |
children | 8e6a9e390cba |
line wrap: on
line source
/* * Copyright (c) 2009, Mason Green (zzzzrrr) * http://www.dsource.org/projects/openmelee * * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of the polygonal nor the names of its contributors may be * used to endorse or promote products derived from this software without specific * prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ module openmelee.melee; import tango.io.Stdout: Stdout; import Integer = tango.text.convert.Integer; import tango.math.Math; import xf.hybrid.Event; import xf.input.KeySym; import xf.omg.core.LinearAlgebra; public import blaze.all; import openmelee.boundaryListener; import openmelee.contactListener; import openmelee.ship; import openmelee.urQuan; import openmelee.orz; import openmelee.planet; // Cursor scale factor const CURSORSIZE = 0.05f; const INIT_SPAWN_SIZE = 0.5f; // Dragging stuffs const BUNGEE_K = 1.5f; // Damping factor for dragging const DRAGDAMP = 20.0f; // Size of hinges const HINGE_RADIUS = 0.05f; // Smallest allowed dimension const MIN_DIMENSION = 0.1; const k_maxContactPoints = 2048; enum ContactState { e_contactAdded, e_contactPersisted, e_contactRemoved } struct ContactPoint { bzShape shape1; bzShape shape2; bzVec2 normal; bzVec2 position; bzVec2 velocity; bzContactID id; ContactState state; } // Melee settings. Some can be controlled in the GUI. struct Settings { float hz = 60; int velocityIterations = 5; int positionIterations = 1; bool drawShapes = true; bool drawJoints = true; bool drawControllers; bool drawCoreShapes; bool drawAABBs; bool drawOBBs; bool drawPairs; bool drawContactPoints; bool drawContactNormals; bool drawContactForces; bool drawFrictionForces; bool drawCOMs; bool drawStats; bool enableWarmStarting; bool enableTOI; } // Dirty, dirty hack for communicating config changes to Main // TODO: Harass h3 to add .changed to hybrid so this isn't necessary struct ConfigChange (T) { protected { bool _pending = false; T _value; } T value() { _pending = false; return _value; } void value(T change) { _value = change; _pending = true; } bool pending() { return _pending; } T opAssign(T change) { value(change); return _value; } bool opEquals(T other) { return _value == other; } } class Melee { this(Settings *settings) { this.settings = settings; spawnRect = vec2(INIT_SPAWN_SIZE, INIT_SPAWN_SIZE); // bzWorld boundary callback m_boundaryListener = new BoundaryListener(this); // bzContact callback m_contactListener = new ContactListener(this); init(); } void init() { // Define world boundaries worldAABB.lowerBound.set(-400.0f, -250.0f); worldAABB.upperBound.set(400.0f, 250.0f); world = new bzWorld(worldAABB, gravity, allowSleep); world.boundaryListener = m_boundaryListener; world.contactListener = m_contactListener; viewCenter = vec2(10, 10); ship1 = new UrQuan(world); ship2 = new Orz(world); ship2.rBody.angle = 3.14159265/4; auto planet = new Planet(world); } void drag() { } EventHandling onClick(MouseButtonEvent e) { return EventHandling.Stop; } EventHandling onKey(KeyboardEvent e) { // Key pressed if (e.down) { switch (e.keySym) { case KeySym.space: settings.drawAABBs = !settings.drawAABBs; break; case KeySym.Escape: quit = true; break; case KeySym.Up: thrust = true; break; case KeySym.Left: ship1.turnLeft(); break; case KeySym.Right: ship1.turnRight(); break; case KeySym.Down: break; default: break; } // Key released } else { if(e.keySym == KeySym.Up) { thrust = false; } else if (e.keySym == KeySym.Left || e.keySym == KeySym.Right) { ship1.rBody.angularVelocity = 0.0f; } } return EventHandling.Stop; } // Mouse move EventHandling onMove(MouseMoveEvent e) { return EventHandling.Stop; } EventHandling onDT(TimeUpdateEvent e) { return EventHandling.Continue; } EventHandling onMouseEnter(MouseEnterEvent e) { return EventHandling.Continue; } EventHandling onMouseLeave(MouseLeaveEvent e) { return EventHandling.Continue; } protected { const bzVec2 gravity = bzVec2(0.0f, 0.0f); bool allowSleep = false; vec2 spawnRect; vec2[] drawing; vec2i screenSize = vec2i.zero; vec2 mousePos = vec2.zero; bool scaling = false; bool full = false; vec2 spawnStart; bool preserveBullet = false; float waterDelta = 0; } void boundaryViolated(bzBody rBody) { float x,y; if(rBody.position.x > worldAABB.upperBound.x) { x = worldAABB.lowerBound.x + 5; rBody.position = bzVec2(x, rBody.position.y); } else if (rBody.position.x < worldAABB.lowerBound.x) { x = worldAABB.upperBound.x - 5; rBody.position = bzVec2(x, rBody.position.y); } else if (rBody.position.y > worldAABB.upperBound.y) { y = worldAABB.lowerBound.y + 5; rBody.position = bzVec2(rBody.position.x, y); } else if(rBody.position.y < worldAABB.lowerBound.y) { y = worldAABB.upperBound.y - 5; rBody.position = bzVec2(rBody.position.x, y); } } bool quit; // Ortho view zoom float zoom = 40; int pointCount; vec2 viewCenter; bzWorld world; Settings *settings; // bzWorld boundary listener. Destroy bodies that leave world bzAABB bzBoundaryListener m_boundaryListener; bzContactListener m_contactListener; ContactPoint[k_maxContactPoints] points; ConfigChange!(vec2) editChange; bool thrust; bzAABB worldAABB; Ship ship1; Ship ship2; } // Utility functions bzVec2 toBlaze(vec2 vec) { auto ret = bzVec2(vec.x, vec.y); return ret; } vec2 rotate(vec2 point, float rad) { return vec2(cos(rad) * point.x - sin(rad) * point.y, sin(rad) * point.x + cos(rad) * point.y); } class Select { bool select; }