/* setTipShape puts a clone of pshape at each vertex of the * pbasepoly(), and then it deletes pshape. So don't use a pshape as argument that you need to save. */ //cSprite overloads /* Overload the standard cSpriteComposite radius() method. */ public override void mutate(int mutationflags, float mutationstrength) { if (BasePoly == null) { add(new cShape()); } BasePoly.mutate(mutationflags, mutationstrength); cSprite ptipshapenew; if (TipShape != null) { ptipshapenew = TipShape.copy(); //Use this as a model } else { ptipshapenew = new cShape(); } ptipshapenew.mutate(mutationflags, mutationstrength); //Make the tip shape have smaller radius than the basepoly. ptipshapenew.Radius = Framework.randomOb.mutate(ptipshapenew.Radius, MIN_TIP_RADIUS_RATIO * BasePoly.Radius, MAX_TIP_RADIUS_RATIO * BasePoly.Radius, mutationstrength); //Randomize the tip rotations. _tipangvelocity = Framework.randomOb.randomSign() * Framework.randomOb.mutate(_tipangvelocity, cPolyPolygon.MINTIPANGLEVELOCITY, cPolyPolygon.MAXTIPANGLEVELOCITY, mutationstrength); //Make all the tips the same. TipShape = ptipshapenew; //This deletes ptipshapenew //More fixup _newgeometryflag = true; //Because you changed the relative positions of the tips. }
public override cSprite copy() { cShape p = new cShape(); p.copy(this); return(p); }
public static readonly float ACCENTRELIEF = 0.1f; //Raise the accent poly this much //Constructors public cSpriteBubble() { cShape pcircle = new cShape(cSpriteCircle.CIRCLESLICES); add(pcircle); setAccentPoly(); }
/* Useful for wrapping * verts in a Shape class to pass to pgraphics->draw. */ //Overloaded cSprite methods public override void copy(cSprite psprite) //Use this in copy constructor and operator= { /* Because our class has some CArray fields, we can't use the default overloaded * copy constructor and operator=. So as to avoid having to maintain similar code * for these two different methods, we write a helper copy function that both * the copy constructor and the operator= can use. */ base.copy(psprite); //does center(), _radius, _angle, _rotationspeed. if (!(psprite is cShape)) { return; //You're done if psprite isn't a cShape*. } cShape pShape = (cShape)(psprite); /* I know it is a cShape * at this point, but I need to do a cast, so the compiler will let me * call a bunch of cShape methods. */ //Arrays _vectorvert.Copy(pShape._vectorvert); //Decoration fields cColorStyle c = new cColorStyle(); c.copy(pShape.pcolorstyle()); ColorStyle = c; cColorStyle c2 = new cColorStyle(); c2.copy(pShape.DotColorStyle); DotColorStyle = c2; _dotted = pShape._dotted; _realdotradiusweight = pShape._realdotradiusweight; //Helper fields _convex = pShape._convex; }
public cCritterArmedPlayer(cGame pownergame = null) : base(pownergame) { _sensitive = false; _collidepriority = cCollider.CP_PLAYER; /* Don't use the setCollidePriority mutator, as that * forces a call to pgame()->buildCollider(); */ // setDensity(cCritter.INFINITEDENSITY); //So it can bull through. But it's wiser to let the individual games do this. AttitudeToMotionLock = false; /* We want the player's * attitude to be controlled by the listner actions and not by bumping into things, * or moving with gravity. */ AimToAttitudeLock = true; /* Normally * we want a player to shoot in the dirction of his attitude. */ cShape ppolygon = new cShape(3); /* Now make it a thin isoceles triangle, with the apex at the 0th vertex. * All that matters at first is the ratios of the numbers, as we will use * seRadius to make the thing the right size. */ ppolygon.setVertex(0, new cVector3(4.0f, 0.0f)); ppolygon.setVertex(1, new cVector3(0.0f, 1.0f)); ppolygon.setVertex(2, new cVector3(0.0f, -1.0f)); ppolygon.Radius = cCritter.PLAYERRADIUS; //Make it to a good size. Sprite = ppolygon; /* Normally the _prismdz will get changed to PLAYERPRISMDZ * by the cGame.setPlayer call */ PrismDz = cSprite.PLAYERPRISMDZ; }
} /* Start out with no basepoly and no tipshape, user must * fix this with a call to mutate or to setBasePoly and setTipShape. */ public cPolyPolygon(int baseverts, int tipverts) { BasePoly = new cShape(baseverts); TipShape = new cShape(tipverts); randomize(cSprite.MF_RADIUS | cShape.MF_COLOR); //Randomize the tip rotations. _tipangvelocity = Framework.randomOb.randomReal(cPolyPolygon.MINTIPANGLEVELOCITY, cPolyPolygon.MAXTIPANGLEVELOCITY); _tipangvelocity *= Framework.randomOb.randomSign(); }
//Mutators public void setEndsThicknessHeight(cVector3 enda, cVector3 endb, float thickness = THICKNESS, float height = WALLPRISMDZ) { _position = (enda + endb) * 0.5f; _wrapposition1.copy(_position); _wrapposition2.copy(_position); _wrapposition3.copy(_position); /* This line is important, as otherwise the * cCritter.draw will thing this thing was wrapped, * and it'll get drawn in two places. */ _tangent = endb - enda; float length = _tangent.Magnitude; _tangent.normalize(); _oldtangent.copy(_tangent); _normal = _tangent.defaultNormal(); /* We orient so that * the normal is oriented to the tangent as the "y-axis" * is to the the "x-axis".*/ _binormal = _tangent.mult(_normal); _attitude = new cMatrix3(_tangent, _normal, _binormal, _position); Skeleton = new cRealBox3(length, thickness, height); Speed = 0.0f; /* Also sets _velocity to ZEROVECTOR, * but doesn't wipe out _direction. */ /*In looking at these settings, think of the wall as aligned horizontally with endb - enda pointing to the right and the normal pointing into the screen*/ cShape ppolygon = new cShape(4); ppolygon.Edged = true; ppolygon.FillColor = Color.Gray; ppolygon.LineWidthWeight = cColorStyle.LW_IGNORELINEWIDTHWEIGHT; ppolygon.LineWidth = 1; //Means draw a one-pixel edge line. ppolygon.setVertex(0, new cVector3(0.5f * length, 0.5f * thickness)); ppolygon.setVertex(1, new cVector3(-0.5f * length, 0.5f * thickness)); ppolygon.setVertex(2, new cVector3(-0.5f * length, -0.5f * thickness)); ppolygon.setVertex(3, new cVector3(0.5f * length, -0.5f * thickness)); ppolygon.fixCenterAndRadius(); /* Use this call after a bunch * of setVertex if points are just where you want. */ ppolygon.SpriteAttitude = cMatrix3.translation(new cVector3(0.0f, 0.0f, -height / 2.0f)); /* This corrects for the fact that we always draw the ppolygon with its * bottom face in the xy plane and its top in the plane z = height. We * shift it down so it's drawn to match the skeleton positon. */ Sprite = ppolygon; /* Also sets cSprite._prismdz to * cCritter._defaultprismdz, which we set to * CritterWall.WALLPRISMDZ in our cCritterWall * constructor. */ }
public virtual void setAccentPoly() { cShape p = AccentPoly; if (p != null) { _childspriteptr.RemoveAt(1); } float side = 0.33f * (CirclePoly.Radius); cVector3[] pverts = new cVector3[] { new cVector3(0.0f, 0.0f, 0.0f), new cVector3(2 * side, 0.0f, 0.0f), new cVector3(2 * side, side, 0.0f), new cVector3(0.0f, side, 0.0f) }; cShape prectpoly = new cShape(4, pverts); prectpoly.SpriteAttitude = cMatrix3.translation(new cVector3(side, 0.5f * side, cSpriteBubble.ACCENTRELIEF)); add(prectpoly); //Decoration rectangle. FillColor = CirclePoly.FillColor; //Make the accent color match the circle. }
{ // Try jumping through this hoop public cCritterTreasure(cGame pownergame) : base(pownergame) { /* The sprites look nice from afar, but bitmap speed is really slow * when you get close to them, so don't use this. */ cShape ppoly = new cShape(24); ppoly.Filled = false; ppoly.LineColor = Color.LightGray; ppoly.LineWidthWeight = 0.5f; Sprite = ppoly; _collidepriority = cCollider.CP_PLAYER + 1; /* Let this guy call collide on the * player, as his method is overloaded in a special way. */ rotate(new cSpin((float)Math.PI / 2.0f, new cVector3(0.0f, 0.0f, 1.0f))); /* Trial and error shows this * rotation works to make it face the z diretion. */ setRadius(cGame3D.TREASURERADIUS); FixedFlag = true; moveTo(new cVector3(_movebox.Midx, _movebox.Midy - 2.0f, _movebox.Loz - 1.5f * cGame3D.TREASURERADIUS)); }
/// <summary> /// A factory method to return one of the various kinds of sprites randomly forned. /// </summary> /// <param name="spritetypeindex">An index for the type of sprite. To select the type of /// sprite, use cGame and select a type that begins with ST_. </param> /// <returns></returns> public cSprite randomSprite(int spritetypeindex) { cShape newpoly; cSpriteBubble newbubble; cPolyPolygon newpolypoly; cSpriteSphere psphere; if (spritetypeindex == cGame.ST_ASSORTED) { spritetypeindex = (int)Framework.randomOb.random((uint)cGame.ST_ASSORTED); } //Select a random index less than cGame.ST_ASSORTED /* This next block should be a switch, but the compiler won't let me use the cGame constants * in a switch. */ if (spritetypeindex == cGame.ST_SIMPLEPOLYGONS) { newpoly = new cShape(Framework.randomOb.random(3, 5)); newpoly.randomize( //cSprite.MF_RADIUS | cShape.MF_COLOR); return(newpoly); } else if (spritetypeindex == cGame.ST_FANCYPOLYGONS) { newpoly = new cShape(); newpoly.randomize( //cSprite.MF_RADIUS | cShape.MF_COLOR | cShape.MF_LINEWIDTH | cShape.MF_DOTS | cShape.MF_VERTCOUNT); return(newpoly); } else if (spritetypeindex == cGame.ST_ASTEROIDPOLYGONS) { newpoly = new cShape(); newpoly.setRandomAsteroidShape(5, 20, Framework.randomOb.randomReal(0.0f, 0.4f)); newpoly.randomize( //cSprite.MF_RADIUS cShape.MF_COLOR); return(newpoly); } else if (spritetypeindex == cGame.ST_BUBBLES) { newbubble = new cSpriteBubble(); newbubble.randomize( //cSprite.MF_RADIUS | cShape.MF_COLOR | cShape.MF_LINEWIDTH); return(newbubble); } else if (spritetypeindex == cGame.ST_SPHERES) { psphere = new cSphere(1.0f, Color.Gray); psphere.randomize(cShape.MF_COLOR); Color fill = psphere.FillColor; return(psphere); } else if (spritetypeindex == cGame.ST_POLYPOLYGONS) { newpolypoly = new cPolyPolygon(); newpolypoly.randomize( //cSprite.MF_RADIUS | cShape.MF_COLOR | cShape.MF_LINEWIDTH | cShape.MF_DOTS | cShape.MF_VERTCOUNT); return(newpolypoly); } else if (spritetypeindex == cGame.ST_TRIPLEPOLYPOLYGONS) { newpolypoly = new cPolyPolygon(); newpolypoly.randomize(cShape.MF_VERTCOUNT); newpolypoly.TipShape = new cPolyPolygon(); newpolypoly.randomize( //cSprite.MF_RADIUS | cShape.MF_COLOR | cShape.MF_LINEWIDTH | cShape.MF_DOTS | cShape.MF_VERTCOUNT); return(newpolypoly); } return(new cSprite()); //Default in the cGame.ST_SPRITETYPENOTUSED case }
public virtual void drawstarShape(cShape pShape, int drawflags) { }
public virtual void drawShape(cShape pShape, int drawflags, bool topPoint = false) { }