view ships/asteroids.d @ 25:2bf818f8b005

fixed asteroids
author zzzzrrr <mason.green@gmail.com>
date Fri, 27 Mar 2009 16:25:17 -0400
parents 441eb7672404
children
line wrap: on
line source

/*
 *  Copyright (c) 2009 Blaze Contributors http://www.dsource.org/projects/blaze
 *  Maintained by Mason Green (zzzzrrr)
 *
 *   This software is provided 'as-is', without any express or implied
 *   warranty. In no event will the authors be held liable for any damages
 *   arising from the use of this software.
 *
 *   Permission is granted to anyone to use this software for any purpose,
 *   including commercial applications, and to alter it and redistribute it
 *   freely, subject to the following restrictions:
 *
 *   1. The origin of this software must not be misrepresented; you must not
 *   claim that you wrote the original software. If you use this software
 *   in a product, an acknowledgment in the product documentation would be
 *   appreciated but is not required.
 *
 *   2. Altered source versions must be plainly marked as such, and must not be
 *   misrepresented as being the original software.
 *
 *   3. This notice may not be removed or altered from any source
 *   distribution.
 */
module openmelee.ships.asteroids;

import blaze.dynamics.bzBody : bzBody;
import blaze.bzWorld: bzWorld;
import blaze.dynamics.bzBodyDef;
import blaze.collision.shapes.bzCircle : bzCircleDef;
import blaze.collision.shapes.bzPolygon : bzPolyDef;
import blaze.collision.shapes.bzShape : bzShapeDef;
import blaze.common.bzMath: bzVec2, bzMul, bzXForm;
import blaze.dynamics.forces.bzAttractor: bzAttractor;

import openmelee.ships.ship: Ship;
import openmelee.ai.utilities;

const PI = 3.141593;

class Asteroid : Ship
{

    bzBodyDef bd;
    bzShapeDef sd;

    this(bzWorld world) {
        super(world);
        init();
        calcRadius();
    }

    void init() {
		{
		    float radius = 0.5f;
            float density = 5.0f;
			auto sd1 = new bzCircleDef(density, radius);
			sd1.localPosition.set(-0.5f, 0.5f);

            density = 0.0f;
			auto sd2 = new bzCircleDef(density, radius);
			sd2.localPosition.set(0.5f, 0.5f);

            float x = randomRange(-100f, 100f);
            float y = randomRange(-100f, 100f);
            bzVec2 position = bzVec2(x , y);
            float angle = randomRange(-PI, PI);
            bd = new bzBodyDef(position, angle);
            bd.allowFreeze = false;
            bd.allowSleep = false;
            rBody = world.createBody(bd);
            rBody.createShape(sd1);
            rBody.createShape(sd2);
            rBody.setMassFromShapes();
            rBody.linearVelocity = bzVec2(x, y);
		}
	}
}