//Overloads /// <summary> /// Makes sure the gun is pionted in the right direction (aim is realigned with the tangent). Shoots /// the gun if the _waitshoot interval has elapsed. Override this for other features. /// </summary> /// <param name="pactiveview">Might be useful if the mouse cursor is used.</param> /// <param name="dt">The change in time since the last update.</param> public override void update(ACView pactiveview, float dt) { //(1) Call base class update to apply force. base.update(pactiveview, dt); //(2) Align gun with move direction if necessary. if (_aimtoattitudelock) { AimVector = AttitudeTangent; /* Keep the gun pointed in the right direction. */ } //(3) Shoot if possible. if (!_armed || !_bshooting) { return; } /* If _age has been reset to 0.0, you need to get ageshoot back in synch. */ if (_age < _ageshoot) { _ageshoot = _age; } if ((_age - _ageshoot > _waitshoot)) //A shoot key is down { shoot(); _ageshoot = _age; } }
} /* Don't bother doing anything as this is only * used in copy and serialize. */ public cCritterViewer(ACView pview) { _pownerview = pview; _proportionofworldtoshow = PROPORTIONOFWORLDTOSHOW; _aspect = (4.0f / 3.0f); //Start with standard screen aspect. _fieldofviewangle = STARTFIELDOFVIEWANGLE; _trackplayer = false; /* Depending on the game, you might want to start with either FALSE * or TRUE for _trackplayer. In general the place where your game can make adjustments * to the critterviewer is in the cGame.initializeView method. */ _perspective = false; //Will be reset by setViewer, _foveaproportion = FOVEAPROPORTION; _movebox = new cRealBox3(Game.Border.Center, MOVEBOXTOGAMEBORDERRATIO * Game.Border.MaxSize); /* Put the * viewer in a cube (or square in the 2D case) whose edge is a multiple * of the world's largest dimension. */ _dragbox = new cRealBox3(); _dragbox.copy(_movebox); _wrapflag = cCritter.CLAMP; /* I had WRAP, which was a big mistake, * as sometimes I'd back way up above the world and then suddenly be * under it. */ //We will set _znear and _zfar in the cCritterViewer.setZClipPlanes call. setViewpoint(); /* Default viewpoint is up the z axis looking down at the origin. * This call also initializes some of the remaining vairables. */ /* Don't bother to set a listener, as the various cGame.initializeView will do * that indirectly via a setGraphicsClass call, and then possibly with a * direct call to change the listener again. */ Density = 0.0f; //so you don't move things you bump into. AbsorberFlag = true; //So you don't bounce when you bump things. Sprite.Radius = 0.1f; /* Although this guy is invisible, it seems to be * good to have a radius of 1.0 for use in the COLLIDEVIEWER code. */ _lastgoodplayeroffset = new cVector3(); }
public void stepDoc(float dt, ACView pactiveview) //Called by Framework. It calls // _pgame.step and ACView.OnDraw { _dt = dt; _pgame.step(dt, pactiveview); /* Move the critters and maybe add or * delete some. Critters possibly use the pview to sniff out the pixel color at some locations. */ pactiveview.OnDraw(); // sets up drawings for everything in the game //Possibly wait for user to start or restart game. bool didareset = false; if (_pgame.NewGame) { string msg = "*Objective: Defeat all bosses to win." + "\n *Controls:" + "\n - W = jump" + "\n - A = move left" + "\n - S = crouch" + "\n - D = move right" + "\n - L = toggle invincibility" + "\n - [SpaceBar] , click = shoot" + "\n*Hint: Remember to pick up the medpacks!" + "\nPress Enter\nTo Start Game"; MessageBox.Show(msg); //MessageBox.Show("PRESS ENTER\nTo Start Game."); RESTART = true; _pgame.start(); didareset = true; } if (didareset && _pgame.Player.Listener.IsKindOf("cListenerCursor")) { pactiveview.setCursorPosToCritter(_pgame.Player); // Match cursor to player pos. } }
public virtual void onMouseMove(ACView pview, Point point) { if (GameOver) { return; //Don't use mouse or keyborad messages until game starts. } if (PlayerListenerClass == "cListenerCursor") { return; } /* We pass this on, but ordinarily the critters don't do anything with it. */ //The _cursorpos gets set in CView.OnMouseMove if you're dragging. // Drag Hand Case, with (_hcursor == ((CpopApp*).AfxGetApp())->_hCursorDragger) if ((pFocus() != null) && _bDragging) { cVector3 cursorforcritter = pview.pixelToCritterPlaneVector(point.X, point.Y, pFocus()); /* It's going to easier, at least to start with, to drag only within the focus critter * plane. */ pFocus().dragTo(cursorforcritter, _pcontroller.dt()); /* Feed the current _dt to dragTo * so as to set the critter's velocity to match the speed of the drag; this way you * can "throw" a critter by dragging it. */ _pbiota.processServiceRequests(); /* In case critter reacts. * If you wait for the timer to trigger CpopDoc.stepDoc * to call the processServiceRequest, you might possibly manage to * click or drag the same critter again. The reason is that you may * have several OnMouseMove messages in the message queue, and when they * are processed you will get several calls to onMouseMove. */ } }
/// <summary> /// Calls the base update and aims at the _ptarget (does nothing if Armed is set to false or if /// the _ptarget is null) /// </summary> /// <param name="pactiveview">Might be useful if the mouse cursor is being used.</param> /// <param name="dt">The interval of time that has elapsed since the last update.</param> public override void update(ACView pactiveview, float dt) { base.update(pactiveview, dt); /* Do the basic cCritterArmed update to apply the forces, * in _forcearray, which might include a cForceObjectSeek to approach the player * and a cForceClassEvade to avoid the bullets. */ aimAt(_ptarget); }
public override void update(ACView pactiveview, float dt) { base.update(pactiveview, dt); totalTime = totalTime + dt; float newRadius = (float)(Math.Abs((maxRadius - minRadius) * Math.Sin(pulseRate * totalTime)) + minRadius); setRadius(newRadius); }
public override void update(ACView pactiveview, float dt) { base.update(pactiveview, dt); //Always call this first if ((_outcode & cRealBox3.BOX_HIZ) != 0) /* use bitwise AND to check if a flag is set. */ { delete_me(); //tell the game to remove yourself if you fall up to the hiz. } }
public override void update(ACView pactiveview, float dt) { base.update(pactiveview, dt); if (closingFrame < 100) { closingFrame++; roll((float)Math.PI / 2 / 100); } }
public override void update(ACView pactiveview, float dt) { base.update(pactiveview, dt); // keep the boss a certain distance from the player if (distanceTo(Player) < 6) { if (Player.Position.Z > this.Position.Z) { clearForcelist(); addForce(new cForceGravity(25.0f, new cVector3(0.0f, -1, 0.00f))); addForce(new cForceDrag(20.0f)); // default friction strength 0.5 addForce(new CenteringForce()); addForce(new KnockbackForce(new cVector3(0, 0, -10.0f))); //if boss facing right, rotate to face player if (facing) { rotate(); } } else { clearForcelist(); addForce(new cForceGravity(25.0f, new cVector3(0.0f, -1, 0.00f))); addForce(new cForceDrag(20.0f)); // default friction strength 0.5 addForce(new CenteringForce()); addForce(new KnockbackForce(new cVector3(0, 0, 10.0f))); //if boss facing left, rotate to face player if (!facing) { rotate(); } } } else { if (Player.Position.Z > this.Position.Z) { // rotate boss to face player if (facing) { rotate(); } } else { // rotate boss to face player if (!facing) { rotate(); } } } }
public override void update(ACView pactiveview, float dt) { base.update(pactiveview, dt); //Always call this first if (!warningGiven && distanceTo(new cVector3(Game.Border.Lox, Game.Border.Loy, Game.Border.Midz)) < 3.0f) { warningGiven = true; MessageBox.Show("DON'T GO THROUGH THAT DOOR!!! DON'T EVEN THINK ABOUT IT!!!"); } }
public override void update(ACView pactiveview, float dt) { if (Health < 5) { BulletClass = new cCritterBulletKamehameha(); } base.update(pactiveview, dt); //Always call this first rotateAttitude(Tangent.rotationAngle(AttitudeTangent)); _waitshoot = (float)rand.NextDouble(); }
//Overloaded methods /// <summary> /// Override to update the bullet the way that you want to. /// </summary> /// <param name="pactiveview">This argument could be useful if you are using cListenerCursor.</param> /// <param name="dt">The change in time between frame updates. Might be useful if an update should not occur until a specified /// amount of time has elapsed.</param> public override void update(ACView pactiveview, float dt) { base.update(pactiveview, dt); /* Feels force, also checks _age against _lifetime. */ if (_baseAccessControl == 1) { return; } if ((_outcode != 0) && _dieatedges) /* _outcode nonzero means near an edge. This keeps bullets * from bouncing or wrapping, but it also makes the critters unable tofire when they are * really near an edge. */ { delete_me(); return; } }
public override void update(ACView pactiveview, float dt) { //base.update(pactiveview, dt); float varX; float varY; float varZ; Framework.randomOb.randomUnitTriple(out varX, out varY, out varZ); cVector3 aimingVariance = new cVector3(varX, varY, varZ); aimingVariance.multassign(8); aimAt(Target.Position.add(aimingVariance)); shoot(); feelforce(); }
//Calls each critter's move(dt). public void update(ACView pactiveview, float dt) { // necessary to make a copy in case someone wants to call a list-walking function // from other code executed in foreach LinkedList <cCritter> clist = new LinkedList <cCritter>( delegate(out cCritter c1, cCritter c2) { c1 = c2; } ); clist.Copy(this); foreach (cCritter c in clist) { clist.ElementAt().update(pactiveview, dt); } }
public override void update(ACView pactiveview, float dt) { base.update(pactiveview, dt); //Always call this first //Player.Sprite.setstate( ); //Here's where I added my chosen frame animation for step (6) **************** //allows character to return to Running ( now idle on step (7) ) after getting knocked down if (CountingFrames) { frameCount++; } if (frameCount > 300) { CountingFrames = false; frameCount = 0; Sprite.ModelState = State.Run; } }
public void stepDoc(float dt, ACView pactiveview) //Called by Framework. It calls // _pgame.step and ACView.OnDraw { _dt = dt; _pgame.step(dt, pactiveview); /* Move the critters and maybe add or * delete some. Critters possibly use the pview to sniff out the pixel color at some locations. */ pactiveview.OnDraw(); // sets up drawings for everything in the game //Possibly wait for user to start or restart game. bool didareset = false; if (_pgame.NewGame) { MessageBox.Show("PRESS ENTER To Start Game\nWASD to move\nSpacebar to jump\nAlt to shoot\nCtrl to punch\nThe powerup at the start is the cheat\nThere are additional powerups throughout the levels"); RESTART = true; _pgame.start(); didareset = true; } if (didareset && _pgame.Player.Listener.IsKindOf("cListenerCursor")) { pactiveview.setCursorPosToCritter(_pgame.Player); // Match cursor to player pos. } }
public void stepDoc(float dt, ACView pactiveview) //Called by Framework. It calls // _pgame.step and ACView.OnDraw { _dt = dt; _pgame.step(dt, pactiveview); /* Move the critters and maybe add or * delete some. Critters possibly use the pview to sniff out the pixel color at some locations. */ pactiveview.OnDraw(); // sets up drawings for everything in the game //Possibly wait for user to start or restart game. bool didareset = false; if (_pgame.NewGame) { MessageBox.Show("PRESS ENTER\nTo Start Game."); RESTART = true; _pgame.start(); didareset = true; } if (didareset && _pgame.Player.Listener is cListenerCursor) { pactiveview.setCursorPosToCritter(_pgame.Player); // Match cursor to player pos. } }
public virtual void step(float dt, ACView pactiveview) { float runspeed = Framework.Runspeed; float realdt = dt / runspeed; _pcontroller.update(realdt); /* Do controller update first, when you're fresh from the OnIdle * call that did the checking of messages as this, too, checks user input. The mouse * click handling code of cController expects you to do the update right after the * standard mouse processing of OnIdle, so don't move this call. This call also stores * the current dt value inside the controller. And don't use the dt = 0.0.*/ if (_gameover) //Meaning you haven't pressed ENTER for the first time. { dt = 0.0f; /* Prevents the lurch at startup when I turn _gameover off, also * prevents anything from happening in the move or update methods when _gameover. */ } adjustGameParameters(); _pbiota.feellistener(dt); /* Critters listen to the _pcontroller data, * possibly using _cursorpos. The cCritterArmedPlayer, in particular, will * look at the _cursorpos if left button is down. Use the dt to adjust velocity if you have a * cListenerCursor, */ _pbiota.move(dt); /* Critters save current position as _oldposition, use * their _velocity and _acceleration to compute a new position, possibly wrap or bounce * this position off the _border and then set the new _position. */ _pbiota.update(pactiveview, dt); /* Feel any forces acting on the critter, possibly call sniff * on pview to check some pixel colors in the world to maybe back off from something * or kill something. We don't presently use the dt argument, but could use it for * shrinking critter radius. */ if (dt > 0.0f) //Prevent constant readjustment when paused // pause is not implemented yet -- JC { collideStep(); //Critter may abruptly change _position and _velocity in here. } _pbiota.processServiceRequests(); _pbiota.animate(dt); }
public override void update(ACView pactiveview, float dt) { base.update(pactiveview, dt); addForce(new CenteringForce()); }
/* Uses _foveaproportion which lies between 0.0 and 1.0. We say something is visible if it * appears on the inner _foveaproportion central box of the viewer's image screen, * which is what you see in the view window. */ //overloads //Use _pownerview to get the CpopDoc and get the cGame from that. public override void update(ACView pactiveview, float dt) { base.update(pactiveview, dt); ZClipPlanes = Game.Border.outerBox(cSprite.MAXPRISMDZ); if (_trackplayer && !((Listener != null) && Listener.RuntimeClass == "cListenerViewerRide")) /* The meaning of the visibleplayer() condition is that it doesn't make sense * to track the player if it's not an onscreen player. The reason for the * listener condition is that you don't want to stare at the player when * riding it. */ /* I should explain that the goal here is to not bother turning when the player * is moving around in the middle of the veiw area, and only to turn when he's near * the edge, but to have the turning when he's near the edge be smoooth. * The use of the 0.85 foveaproportion parameter means that you react before the player * gets right up to the edge. The reactproportion factor in lookAtProportional and * moveToProportional is delicate and should probably be adjusted according to the * current player speed relative to the visible window. The issue is that (a) if I make * reactproportion too small, like 0.01, then the viewer doesn't turn (or move) fast * enough to catch up with the player and keep it in view, but (b) if I make reactpropotion * too big, like 0.5, then the turning or moving is such an abrupt jump that the visual * effect is jerky. The goal is to do turns that are just big enough to not look jerky, * but to have the turns be big enough so you aren't turning more often than you really * have to. Another downside of a toosmall reactproportion, by the way, is that it can be * computationally expensive to react. * The way we finally solved this is to do a while loop to turn just * far enough, moving just a little at a time so as to not overshoot. */ { if (isVisible(Game.Player.Position)) // Uses _foveaproportion { _lastgoodplayeroffset = Position - Game.Player.Position; } /*I'm not sure about constantly changing _lastgoodplayeroffset. On the * one hand, the offset I set in setViewpoint was a standard good one, so why * not keep it. On the other, if I want to move my viewpoint around then I * do want to be able to get a new value here. It seems ok for now.*/ else //not visible, so do somehting about it. { int loopcount = 0; /* Never have a while loop without a loopcount * to make sure you don't spin inside the while forever under some * unexpected situation like at startup. */ cVector3 lookat = Game.Player.Position; cVector3 viewerpos = lookat + _lastgoodplayeroffset; if (Game.worldShape() == cGame.SHAPE_XSCROLLER) { lookat = new cVector3(Game.Player.Position.X, Game.Border.Midy, Game.Player.Position.Z); viewerpos = new cVector3(lookat.X, Position.Y, Position.Z); } if (Game.worldShape() == cGame.SHAPE_YSCROLLER) { lookat = new cVector3(Game.Border.Midx, Game.Player.Position.Y, Game.Player.Position.Z); viewerpos = new cVector3(Position.X, lookat.Y, Position.Z); } if (_perspective) { while (!isVisible(lookat) && loopcount < 100) // Uses _foveaproportion { moveToProportional(viewerpos, cCritterViewer.TURNPROPORTION); loopcount++; } } else //ortho case { while (!isVisible(lookat) && loopcount < 100) // Uses _foveaproportion { moveToProportional(lookat + Game.Player.Binormal * 10.0f, cCritterViewer.TURNPROPORTION); loopcount++; } } } } //Possibly ride the player. if (Listener is cListenerViewerRide) { cCritter pplayer = Game.Player; cVector3 offset = ((cListenerViewerRide)Listener).Offset; moveTo(pplayer.Position + pplayer.AttitudeTangent * offset.X + pplayer.AttitudeNormal * offset.Y + pplayer.AttitudeBinormal * offset.Z); cRealBox3 skeleton = pplayer.MoveBox; if (skeleton.ZSize < 0.5f) { skeleton.setZRange(0.0f, offset.Z); } if (skeleton.YSize < 0.5f) { skeleton.setYRange(0.0f, offset.Z); } skeleton.clamp(_position); for (int i = 0; i < Game.Biota.count(); i++) { cCritter pother = Game.Biota.GetAt(i); if (pother is cCritterWall) { pother.collide(this); } } /* colliding with the wall may have twisted the viwer's orientation, * so align it once again. */ Attitude = pplayer.Attitude; /* Before we call lookAt, * make sure your attitude matches the player. For one thing, * you may have gotten twisted around in the COLLIDEVIEWER code. */ lookAt(pplayer.Position + pplayer.AttitudeTangent * cListenerViewerRide.PLAYERLOOKAHEAD * pplayer.Radius); /* This has the effect that as offset gets large you change your * looking direction see right in front of the player. The multiplier * cCritterViewer.PLAYERLOOKAHEAD is tweaked to work well * with the default cCritterViewer.OFFSET. */ } }
public override void update(ACView pactiveview, float dt) { base.update(pactiveview, dt); //Always call this first //Console.WriteLine(" Player x: " + Player.Position.X + " Boss x: " + Position.X); }
// In this function, I initialize the objects that I declared above, and // also initialize the OpenGL settings -- I used the same initial OpenGL // settings that are used in the Pop framework, and Rucker's comments are // included about these initial settings public override void OnLoad(EventArgs e) { DateTime currentDate = new DateTime(); currentDate = DateTime.Now; savetime = currentDate.Ticks; _mindt = MIN_DT; Keydev = new cKeyInfo(); dthistory = new LinkedList <float>( delegate(out float f1, float f2) { f1 = f2; } ); pdoc = new ACDoc(); view = new ACView(); GL.ClearColor(Color.SteelBlue); GL.Enable(EnableCap.DepthTest); GL.ClearDepth(1.0); // enable depth testing GL.Enable(EnableCap.Normalize); /* By default DepthTest is off. We normally need it so that nearer things cover * further things. Don't need it, though, in the two dimensional case. */ GL.DepthFunc(DepthFunction.Less); /* This is the default depth test, but we make it explicity. Skips drawing any pixel with * a smaller depth than the zbuffer depth value at that spot. */ // ::glShadeModel(GL_SMOOTH); //The default shading model, instead we prefer GL_FLAT GL.ShadeModel(ShadingModel.Flat); /* Smooth interpolates from the vertices across a polygon, while * Flat picks one vertex (the first of the poly) and uses that color across * the polygon. Default is Smooth. Runs about 75% as fast as Flat, and there's * no point to it for polyhedra, as all verts of a polyhedron face have the same * normal anyway (Unless you tilt the vert normals to make the polyhedron resemble * a curved surface, in which case you do want Smooth and should temporarily * turn it on for that object with a glShadeModel call). */ // ::glEnable(GL_LINE_SMOOTH); //Anti-alias lines. Makes lines a bit more solid looking, but costs a lot of speed. // ::glEnable(GL_POLYGON_SMOOTH); /* To make the polygon edges smoother. Don't even THINK of using this one, it cuts your speed * to almost nothing. */ //::glEnable(GL_CULL_FACE); /* Don't draw back-facing polygons to save speed? Better not. First of all, we need to * draw them in demo mode, as the teapot seems to have clockwise polygons. Second of all, * the cSpriteIcon doesn't work if we cull faces. */ // GL.Enable(EnableCap.Lighting); /* Default is lighting ON. We do in fact * always want to use lighting with OpenGL, as, surprisingly, OpenGL is FASTER with lighting * turned on! Do be aware that if have lighting on, you MUST install some lights * or everything is black. So we MUST have a call to installLightingModel here as well. * To be safe, we turn the light on with a call to our installLightingModel with * a NULL argument to give a default behavior that turns lighting on and adds some * lights. */ GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1); //We're not padding at ends of lines when we write textures. GL.PixelStore(PixelStoreParameter.PackAlignment, 1); //We're not padding at ends of lines when we read textures. }
} // Don't blow up anyone. /// <summary> /// Override to update the bullet the way that you want to. /// </summary> /// <param name="pactiveview">This argument could be useful if you are using cListenerCursor.</param> /// <param name="dt">The change in time between frame updates. Might be useful if an update should not occur until a specified /// amount of time has elapsed.</param> public override void update(ACView pactiveview, float dt) //Don't use the cCritterBullet update. { _baseAccessControl = 1; base.update(pactiveview, dt); //Don't do the bullet stuff. _baseAccessControl = 0; }
public override void update(ACView pactiveview, float dt) { base.update(pactiveview, dt); //Always call this first }
public override void update(ACView pactiveview, float dt) { base.update(pactiveview, dt); //aimAt(Game.Player); }
public override void update(ACView pactiveview, float dt) { base.update(pactiveview, dt); moveGate(_startPosition, _moveToPosition, _moveSpeed); }