protected override void RenderSelf(GXPEngine.Core.GLContext glContext) { // NB: After you insert your own extended Vec2 struct here, // it's a lot easier and clearer to implement the next lines using // methods such as Add, Scale, Length, Normalize, Rotate, etc.! Vec2 endPoint = new Vec2( startPoint.x + vector.x * drawScale, startPoint.y + vector.y * drawScale ); LineSegment.RenderLine(startPoint, endPoint, color, lineWidth, true); float length = Mathf.Sqrt(vector.x * vector.x + vector.y * vector.y); // length of vector Vec2 smallVec = new Vec2(-10 * vector.x / length, -10 * vector.y / length); // constant length 10, opposite direction of vector Vec2 left = new Vec2(-smallVec.y, smallVec.x); // rotate 90 degrees Vec2 right = new Vec2(smallVec.y, -smallVec.x); // rotate -90 degrees left.Add(smallVec); left.Add(endPoint); right.Add(smallVec); right.Add(endPoint); LineSegment.RenderLine(endPoint, left, color, lineWidth, true); LineSegment.RenderLine(endPoint, right, color, lineWidth, true); }
public void Update() { updatePosition(); _velocity.Add(_gravity); TimerProjectile(); ProjectileCollision(); enemyCollision(); }
protected override void RenderSelf (GXPEngine.Core.GLContext glContext) { if (_startPoint == null || _vector == null) return; Vec2 endPoint = _startPoint.Clone().Add (_vector.Clone().Scale (scale)); LineSegment.RenderLine (_startPoint, endPoint, color, lineWidth, true); Vec2 smallVec = endPoint.Clone().Sub(_startPoint).Normalize ().Scale (-10); Vec2 left = new Vec2 (-smallVec.y, smallVec.x); Vec2 right = new Vec2 (smallVec.y, -smallVec.x); left.Add (smallVec).Add (endPoint); right.Add (smallVec).Add (endPoint); LineSegment.RenderLine (endPoint, left, color, lineWidth, true); LineSegment.RenderLine (endPoint, right, color, lineWidth, true); }
private void ProjectileCollision() { GameObject TiledObject; int directionY; this.x = _position.x + _velocity.x; TiledObject = Level.Return().CheckCollision(this); if (TiledObject != null) { _velocity.x *= -1; _velocity.x *= _bouncinessX; } x = _position.x - _velocity.x; //Y-Collision this.y = _position.y + _velocity.y; TiledObject = Level.Return().CheckCollision(this); if (TiledObject != null) { directionY = _velocity.y > 0 ? 1 : -1; if (directionY == 1) { _velocity.y *= -1; _velocity.y *= _bouncinessY; } if (directionY == -1) { _velocity.y = 0; } } y = _position.y - _velocity.y; _position.Add(_velocity); }
protected override void RenderSelf(GXPEngine.Core.GLContext glContext) { if (_startPoint == null || _vector == null) { return; } Vec2 endPoint = _startPoint.Clone().Add(_vector.Clone().Scale(scale)); LineSegment.RenderLine(_startPoint, endPoint, color, lineWidth, true); Vec2 smallVec = endPoint.Clone().Sub(_startPoint).Normalize().Scale(-10); Vec2 left = new Vec2(-smallVec.y, smallVec.x); Vec2 right = new Vec2(smallVec.y, -smallVec.x); left.Add(smallVec).Add(endPoint); right.Add(smallVec).Add(endPoint); LineSegment.RenderLine(endPoint, left, color, lineWidth, true); LineSegment.RenderLine(endPoint, right, color, lineWidth, true); }