public Meteor(Scene scene, Vector2 position) { meteorBroken = false; sizeX = 160.0f; sizeY = 333.0f; frameTime = 0; animationDelay = 3; widthCount = 0; //Line sprite initialise lineTextureInfo = new TextureInfo("/Application/textures/meteorLine.png"); lineSprite = new SpriteUV(lineTextureInfo); lineSprite.Position = new Vector2(position.X, position.Y - 544.0f); //Meteor sprite initialise meteorTextureInfo = new TextureInfo("/Application/textures/meteorSprite.png"); noOnSpritesheetWidth = 4; meteorSprite = new SpriteUV(meteorTextureInfo); meteorSprite.UV.S = new Vector2(1.0f / noOnSpritesheetWidth, 1.0f); meteorSprite.Position = position; meteorSprite.Quad.S = new Vector2(160, 333); Bounds2 meteorBounds = meteorSprite.Quad.Bounds2(); // Add sprites to scene scene.AddChild(meteorSprite); scene.AddChild(lineSprite); }
public OrthographicCamera(Transform cameraToWorld, Bounds2 <float> screenWindow, float shutterOpen, float shutterClose, Film film) : base(cameraToWorld, Orthographic(0, 1), screenWindow, shutterOpen, shutterClose, film) { dxCamera = RasterToCamera * new Vector3 <float>(1, 0, 0); dyCamera = RasterToCamera * new Vector3 <float>(0, 1, 0); }
public bool pressBtn(SpriteUV btn, float x, float y) { Bounds2 boxb = btn.Quad.Bounds2(); float width = boxb.Point11.X; float height = boxb.Point11.Y; if ((btn.Position.X) > x) { return(false); } else if (btn.Position.X + width < x) { return(false); } else if ((btn.Position.Y) > y) { return(false); } else if (btn.Position.Y + height < y) { return(false); } else { return(true); } }
//Public functions. public Background(Scene scene) { sea = new SpriteUV[3]; sand = new SpriteUV[2]; sandInfo = new TextureInfo[2]; seaInfo = new TextureInfo("/Application/textures/underwater.png"); sandInfo[0] = new TextureInfo("/Application/textures/sand.png"); sandInfo[1] = new TextureInfo("/Application/textures/sand2.png"); //Left sea[0] = new SpriteUV(seaInfo); sea[0].Quad.S = seaInfo.TextureSizef; //Middle sea[1] = new SpriteUV(seaInfo); sea[1].Quad.S = seaInfo.TextureSizef; //Right sea[2] = new SpriteUV(seaInfo); sea[2].Quad.S = seaInfo.TextureSizef; //Left sand[0] = new SpriteUV(sandInfo[0]); sand[0].Quad.S = sandInfo[0].TextureSizef; //Right sand[1] = new SpriteUV(sandInfo[1]); sand[1].Quad.S = sandInfo[1].TextureSizef; //Colour Blending //sprites.BlendMode.BlendFunc.Set(BlendFuncMode.Add, BlendFuncFactor.SrcColor, BlendFuncFactor.DstColor); //Get sprite bounds. Bounds2 b = sand[0].Quad.Bounds2(); sandWidth = b.Point10.X; Bounds2 bSea = sea[0].Quad.Bounds2(); seaWidth = bSea.Point10.X; //Position background. sea[0].Position = new Vector2(0.0f, 0.0f); sea[1].Position = new Vector2(sea[0].Position.X + seaWidth, 0.0f); sea[2].Position = new Vector2(sea[1].Position.X + seaWidth, 0.0f); sand[0].Position = new Vector2(0.0f, 0.0f); sand[1].Position = new Vector2(Director.Instance.GL.Context.GetViewport().Width, 0.0f); //Add to the current scene. foreach (SpriteUV s in sea) { scene.AddChild(s); } foreach (SpriteUV sa in sand) { scene.AddChild(sa); } }
//Accessors. //public SpriteUV SpriteTop { get{return sprites[0];} } //public SpriteUV SpriteBottom { get{return sprites[1];} } //Public functions. public Obstacle(float startX, Scene scene) { textureInfoTop = new TextureInfo("/Application/textures/toppipe.png"); textureInfoBottom = new TextureInfo("/Application/textures/bottompipe.png"); sprites = new SpriteUV[2]; //Top sprites[0] = new SpriteUV(textureInfoTop); sprites[0].Quad.S = textureInfoTop.TextureSizef; //Add to the current scene. scene.AddChild(sprites[0]); //Bottom sprites[1] = new SpriteUV(textureInfoBottom); sprites[1].Quad.S = textureInfoBottom.TextureSizef; //Add to the current scene. scene.AddChild(sprites[1]); //Get sprite bounds. Bounds2 b = sprites[0].Quad.Bounds2(); width = b.Point10.X; height = b.Point01.Y; //Position pipes. sprites[0].Position = new Vector2(startX, Director.Instance.GL.Context.GetViewport().Height *RandomPosition()); sprites[1].Position = new Vector2(startX, sprites[0].Position.Y - height - kGap); }
//Public functions. public SpinObstacle(Scene scene, Vector2 position) { textureSpinObstacle = new TextureInfo("/Application/textures/firebeam.png"); textureSpinPiv = new TextureInfo("/Application/textures/piv.png"); pivSprite = new SpriteUV[numberOfObstacles]; spinSprite = new SpriteUV[numberOfObstacles]; for (int i = 0; i < numberOfObstacles; i++) { pivSprite[i] = new SpriteUV(textureSpinPiv); pivSprite[i].Quad.S = textureSpinPiv.TextureSizef; pivSprite[i].CenterSprite(); pivSprite[i].Position = new Vector2(position.X + (100 + i * 200.0f), Director.Instance.GL.Context.GetViewport().Height *0.45f); spinSprite[i] = new SpriteUV(textureSpinObstacle); spinSprite[i].Quad.S = textureSpinObstacle.TextureSizef; spinBounds = spinSprite[i].Quad.Bounds2(); spinSprite[i].CenterSprite(); spinSprite[i].Position = pivSprite[i].Position; //scene.AddChild(pivSprite[i]); scene.AddChild(spinSprite[i]); } spinSprite[0].Angle = 2.12f; spinSprite[1].Angle = 1.02f; spinSprite[2].Angle = 2.12f; }
// Crop window specific in normalized coordinates public Film(Point2 <int> resolution, Bounds2 <float> cropWindow, Filter filter /*, float diagonal*/) { Resolution = resolution; Filter = filter; //Diagonal = diagonal * 0.001f; // Millimeters to meters croppedPixelsBounds = new Bounds2 <int>( new Point2 <int>( (int)Math.Ceiling(resolution.X * cropWindow.Min.X), (int)Math.Ceiling(resolution.Y * cropWindow.Min.Y)), new Point2 <int>( (int)Math.Ceiling(resolution.X * cropWindow.Max.X), (int)Math.Ceiling(resolution.Y * cropWindow.Max.Y))); pixels = new Pixel[Resolution.X * Resolution.Y]; // Precompute filter weights var offset = 0; for (var y = 0; y < filterTableSize; ++y) { for (var x = 0; x < filterTableSize; ++x, ++offset) { var p = new Point2 <float>( (x + 0.5f) * filter.Radius.X / filterTableSize, (y + 0.5f) * filter.Radius.Y / filterTableSize); filterTable[offset] = filter.Evaluate(p); } } }
public void Render() { //Animation StandingIndex = (StandingIndex + Engine.TimeDelta * AnimationRate) % 2.0f; RightIndex = (RightIndex + Engine.TimeDelta * AnimationRate) % 2.0f; LeftIndex = (LeftIndex + Engine.TimeDelta * AnimationRate) % 2.0f; Bounds2 AnimationBounds = new Bounds2(0, 0, 64, 64); if (WalkState == WSTATE.STANDING) { AnimationBounds = new Bounds2(((int)StandingIndex) * 64, 0, 64, 64); Current = Standing; } else if (WalkState == WSTATE.RIGHT) { AnimationBounds = new Bounds2(((int)RightIndex) * 48, 0, 48, 64); Current = Right; } else if (WalkState == WSTATE.LEFT) { AnimationBounds = new Bounds2(((int)LeftIndex) * 48, 0, 48, 64); Current = Left; } Engine.DrawTexture(Current, new Vector2(ScreenX, ScreenY), source: AnimationBounds); }
public void RefreshCameraBounds() { if (Camera.main) { cameraBounds = Camera.main.GetOrthographicBounds2(); } }
public Trap(Scene scene, Vector2 position) { _textureInfo = new TextureInfo("/Application/textures/TrapSpriteSheet.png"); _noOnSpritesheetWidth = 4; _noOnSpritesheetHeight = 3; _noOnSpritesheet = 11; _widthCount = 0; _heightCount = _noOnSpritesheetHeight - 1; _animationDelay = 4; _counter = 1; //Create Sprite _sprite = new SpriteUV(); _sprite = new SpriteUV(_textureInfo); _sprite.UV.S = new Vector2(1.0f / _noOnSpritesheetWidth, 1.0f / _noOnSpritesheetHeight); //_sprite.Quad.S = new Vector2(_size, _size); //_sprite.Scale = new Vector2(_scale, _scale); _sprite.Quad.S = new Vector2(_textureInfo.TextureSizef.X / _noOnSpritesheetWidth, _textureInfo.TextureSizef.Y / _noOnSpritesheetHeight); _sprite.Position = position; _box = _sprite.Quad.Bounds2(); scene.AddChild(_sprite); }
//Public functions. public Background(Scene scene) { sprites = new SpriteUV[3]; textureInfo = new TextureInfo("/Application/textures/background.png"); //Left sprites[0] = new SpriteUV(textureInfo); sprites[0].Quad.S = textureInfo.TextureSizef; //Middle sprites[1] = new SpriteUV(textureInfo); sprites[1].Quad.S = textureInfo.TextureSizef; //Right sprites[2] = new SpriteUV(textureInfo); sprites[2].Quad.S = textureInfo.TextureSizef; //Get sprite bounds. Bounds2 b = sprites[0].Quad.Bounds2(); width = b.Point10.X; //Position pipes. sprites[0].Position = new Vector2(0.0f, 0.0f); sprites[1].Position = new Vector2(sprites[0].Position.X + width, 0.0f); sprites[2].Position = new Vector2(sprites[1].Position.X + width, 0.0f); //Add to the current scene. foreach (SpriteUV sprite in sprites) { scene.AddChild(sprite); } }
public bool Collision(Vector2 ePos, Vector2 eSize) { //Console.WriteLine(ePos.X); //Console.WriteLine(eSize); Bounds2 box = sprite.Quad.Bounds2(); float width = box.Point11.X; float height = box.Point11.Y; if ((position.X + width) < ePos.X - eSize.X) { return(false); } else if (position.X - width > (ePos.X + eSize.X)) { return(false); } else if ((position.Y + height) < ePos.Y - eSize.Y) { return(false); } else if (position.Y - height > (ePos.Y + eSize.Y)) { return(false); } else { return(true); } }
public PerspectiveCamera(Transform cameraToWorld, Bounds2 <float> screenWindow, float shutterOpen, float shutterClose, float fov, Film film) : base(cameraToWorld, Perspective(fov, 0.001f, 1000f), screenWindow, shutterOpen, shutterClose, film) { dxCamera = RasterToCamera * new Vector3 <float>(1, 0, 0) - RasterToCamera * Vector3 <float> .Zero; dyCamera = RasterToCamera * new Vector3 <float>(0, 1, 0) - RasterToCamera * Vector3 <float> .Zero; }
public void CheckInput() { var touches = Touch.GetData(0); var touchPos = Input2.Touch00.Pos; Bounds2 touchBox = new Bounds2(); touchBox.Min.X = (touchPos.X * (Director.Instance.GL.Context.GetViewport().Width / 2)) + (Director.Instance.GL.Context.GetViewport().Width / 2); touchBox.Max.X = (touchPos.X * (Director.Instance.GL.Context.GetViewport().Width / 2)) + (Director.Instance.GL.Context.GetViewport().Width / 2); touchBox.Min.Y = (touchPos.Y * (Director.Instance.GL.Context.GetViewport().Height / 2)) + (Director.Instance.GL.Context.GetViewport().Height / 2); touchBox.Max.Y = (touchPos.Y * (Director.Instance.GL.Context.GetViewport().Height / 2)) + (Director.Instance.GL.Context.GetViewport().Height / 2); if (touchBox.Overlaps(restartBox) && touches.Count != 0) { restart = true; } if (Input2.GamePad0.Square.Release) { restart = true; } if (touches.Count > 0) { restart = true; } }
public static Scene MakeManySpritesScene() { var tex1 = new TextureInfo(new Texture2D("/Application/Sample/GameEngine2D/FeatureCatalog/data/slime_green_frames.png", false) , new Vector2i(4, 4)); var scene = new Scene() { Name = "many SpriteUV scene" }; Bounds2 bounds = scene.Camera.CalcBounds(); Vector2i num_cells = new Vector2i(8, 8); Vector2 cell_size = bounds.Size / num_cells.Vector2(); Math.RandGenerator rgen = new Math.RandGenerator(); System.Random random = new System.Random(); for (int y = 0; y < num_cells.Y; ++y) { for (int x = 0; x < num_cells.X; ++x) { Vector2 uv = new Vector2((float)x, (float)y) / num_cells.Vector2(); var sprite = new SpriteTile() { TextureInfo = tex1 , Color = Math.SetAlpha(new Vector4(0.5f) + rgen.NextVector4(Math._0000, Math._1111) * 0.5f, 0.75f) //, Color = Math.SetAlpha( new Vector4(0.5f), 1f/*0.75f*/ ) , BlendMode = BlendMode.None , TileIndex2D = new Vector2i(random.Next(0, 4), random.Next(0, 4)) }; Vector2 p = bounds.Min + bounds.Size * uv; // init position/size sprite.Position = p; sprite.Quad.S = cell_size; // note: we don't want to touch the Node.Scale here sprite.Pivot = sprite.Quad.S * 0.5f; sprite.Schedule((dt) => { sprite.Rotation = sprite.Rotation.Rotate(Math.Deg2Rad(1.0f)); sprite.Rotation = sprite.Rotation.Normalize(); if (Common.FrameCount % 8 == 0) { sprite.TileIndex1D = (sprite.TileIndex1D + 1) % 16; } }); scene.AddChild(sprite); } } scene.RegisterDisposeOnExit((System.IDisposable)tex1); return(scene); }
public Player() { //load the player's sprite var tex1 = new TextureInfo(new Texture2D("/Application/data/tiles/machinegun_fire.png", false) , new Vector2i(14, 1)); tex1.Texture.SetFilter(TextureFilterMode.Disabled); playerBodySprite = new SpriteTile(); playerBodySprite.TextureInfo = tex1; playerBodySprite.TileIndex2D = new Vector2i(0, 0); //playerBodySprite.BlendMode = BlendMode.None; //testing only //set up scale,position ect playerBodySprite.CenterSprite(new Vector2(0.2f, 0.1f)); playerBodySprite.Pivot = new Vector2(0.08f, 0.0f); playerBodySprite.Scale = new Vector2(0.75f, 1.5f); this.AddChild(playerBodySprite); //Position = new Vector2 (MapManager.Instance.currentMap.width/2.0f, MapManager.Instance.currentMap.height/2.0f); var list = MapManager.Instance.currentMap.returnTilesOfType(MapTile.Types.floor); Position = list[Support.random.Next(0, list.Count - 1)].position; //get the local bounds of the sprite bounds = new Bounds2(); playerBodySprite.GetlContentLocalBounds(ref bounds); bounds = new Bounds2(bounds.Min * 0.5f, bounds.Max * 0.5f); }
public new bool HasCollidedWithPlayer(SpriteUV player) //Check if the a sprite has hit a part of the maze { if (tileIndex > 5 && tileIndex < 15) { laserOn = true; } else { laserOn = false; } Bounds2 playerBounds = player.GetlContentLocalBounds(); player.GetContentWorldBounds(ref playerBounds); //Get sprite bounds (player bounds) Bounds2 laserBounds = sprite.GetlContentLocalBounds(); sprite.GetContentWorldBounds(ref laserBounds); //Get all of the maze bounds laserBounds.Max = laserBounds.Max - 15.0f; laserBounds.Min = laserBounds.Min + 15.0f; if (playerBounds.Overlaps(laserBounds) && laserOn) { return(true); } return(false); }
public bool isInsideGap(SpriteBase sprite) { Bounds2 spriteBounds = sprite.GetlContentLocalBounds(); sprite.GetContentWorldBounds(ref spriteBounds); return(pipeGap.Overlaps(spriteBounds)); }
public FilmTile(Bounds2 <int> pixelBounds, Filter filter, float[] filterTable) { this.pixelBounds = pixelBounds; this.filter = filter; this.filterTable = filterTable; pixels = new Pixel[(int)pixelBounds.Width() * (int)pixelBounds.Height()]; }
public virtual void DebugDrawContentLocalBounds() { Bounds2 bounds = default(Bounds2); this.GetlContentLocalBounds(ref bounds); Director.Instance.DrawHelpers.SetColor(Colors.Yellow); Director.Instance.DrawHelpers.DrawBounds2(bounds); }
/* * Simple collision check between two entities * */ public static bool checkCollisionBetweenEntities(GameEntity ge1, GameEntity ge2) { Bounds2 tempBounds1 = new Bounds2(ge1.Position + ge1.bounds.Min, ge1.Position + ge1.bounds.Max); Bounds2 tempBounds2 = new Bounds2(ge2.Position + ge2.bounds.Min, ge2.Position + ge2.bounds.Max); return(tempBounds1.Overlaps(tempBounds2)); }
public void Fit() { var bounds = Bounds2.MinMax(3.2, 4.1, 10.6, 12); var rect = new Area(); var scale = 0.5; rect.Fit(bounds, scale); Assert.AreEqual(new Area(6, 8, 21, 24), rect); }
public Bounds2 CalculateBounds() { Bounds2 bounds = new Bounds2(); foreach (OsmNode node in nodes.Values) { bounds.ExtendToCover(node.Longitude, node.Latitude); } return(bounds); }
/// <summary> /// Draws a solid rectangle. /// </summary> /// <param name="bounds">The bounds of the rectangle.</param> /// <param name="color">The color of the rectangle.</param> public static void DrawRectSolid(Bounds2 bounds, Color color) { DrawPrimitiveSetup(color); SDL.SDL_Rect rect = new SDL.SDL_Rect(); rect.x = (int)bounds.Position.X; rect.y = (int)bounds.Position.Y; rect.w = (int)bounds.Size.X; rect.h = (int)bounds.Size.Y; SDL.SDL_RenderFillRect(Renderer, ref rect); }
public void UpdateBounds(Vector2 dr) { Bounds2 cameraBounds = Camera.main.GetOrthographicBounds2WithOffset(0.1f); cameraBounds.Center += dr; bounds.Center = transform.position = cameraBounds.Center; for (int j = 0; j < threadCells.Length; j++) { threadCells[j].UpdateBounds(cameraBounds); } }
public FilmTile GetTile(Bounds2 <int> sampleBounds) { // Account for the radius of the filter var halfPixel = Vector2 <float> .One * 0.5f; var p0 = (sampleBounds.Min.ToFloat() - halfPixel - Filter.Radius).Ceiling().ToInt(); var p1 = (sampleBounds.Max.ToFloat() - halfPixel + Filter.Radius).Floor().ToInt() + Vector2 <int> .One; // Account for the overall image bounds var tilePixelBounds = Bounds2 <int> .Intersect(new Bounds2 <int>(p0, p1), croppedPixelsBounds); return(new FilmTile(tilePixelBounds, Filter, filterTable)); }
public Enemy(Vector2 Pos, String FileName) { texInfo = new TextureInfo("/Application/textures/" + FileName + ".png"); sprite = new SpriteUV(texInfo); sprite.Quad.S = texInfo.TextureSizef; sprite.Position = new Vector2(Pos.X, Pos.Y); moveSpeed = 2.0f; RmoveSpeed = 5.0f; min = new Vector2(sprite.Position.X, sprite.Position.Y); max = new Vector2(sprite.Position.X + 44.0f, sprite.Position.Y + 50.0f); box = new Bounds2(min, max); }
// Mark tile as being rendered public void MarkTile(Bounds2 <int> tileBounds) { for (var y = tileBounds.Min.Y; y < tileBounds.Max.Y; ++y) { for (var x = tileBounds.Min.X; x < tileBounds.Max.X; ++x) { if (x >= 0 && x < Program.Width && y >= 0 && y < Program.Height) { bitmap[(y * Width + x) * 4 + 1] = 0xFF; } } } }
public Button(Bounds2 bounds, Texture tNormal, Texture tHovered, Texture tPressed) { hovered = false; pressed = false; clicked = false; this.bounds = bounds; this.tNormal = tNormal; this.tHovered = tHovered; this.tPressed = tPressed; }
public Pit(Scene scene, Vector2 position) { _textureInfo = new TextureInfo("/Application/textures/Pit.png"); //Create Sprite _sprite = new SpriteUV(_textureInfo); _sprite.Quad.S = _textureInfo.TextureSizef; _sprite.Position = position; _box = _sprite.Quad.Bounds2(); scene.AddChild(_sprite); }
public Bounds2 GetBounds() { Bounds2 bounds = new Bounds2 (new Vector2 (this.Position.X, 544 - this.Position.Y), new Vector2 (this.Position.X + this.Quad.S.X, this.Quad.S.Y + 544 - this.Position.Y)); return bounds; }