public static TextureComponent AddTextureComponent(this IGameObject gameObject, string textureName = "", int width = -1, int height = -1) { var component = new TextureComponent(textureName, width, height); gameObject.AddComponent(component); return(component); }
public static Entity NewBlock(Vector3 positionValues, Texture2D texture, string typeName) { Entity block = EntityFactory.NewEntity(typeName); TransformComponent transformComponent = new TransformComponent(block, new Vector3(x: positionValues.X, y: positionValues.Y, z: positionValues.Z)); ModelComponent modelComponent = new ModelComponent(block, AssetManager.Instance.GetContent <Model>("Models/block2")); modelComponent.World = Matrix.CreateWorld(transformComponent.Position, Vector3.Forward, Vector3.Up); TextureComponent textureComponent = new TextureComponent(block, texture); CollisionComponent collisionComponent = new CollisionComponent(block, new BoxVolume(EntityFactory.CreateBoundingBox(modelComponent.Model))); LightComponent lightComponent = new LightComponent(block, new Vector3(0, 7, -5), Color.White.ToVector4(), 10f, Color.Blue.ToVector4(), 0.2f, Color.White.ToVector4(), 1000f); EffectComponent effectComponent = new EffectComponent(block, AssetManager.Instance.GetContent <Effect>("Shading")); BlockComponent blockComponent = new BlockComponent(block); ComponentManager.Instance.AddComponentToEntity(block, transformComponent); ComponentManager.Instance.AddComponentToEntity(block, modelComponent); ComponentManager.Instance.AddComponentToEntity(block, textureComponent); ComponentManager.Instance.AddComponentToEntity(block, collisionComponent, typeof(CollisionComponent)); ComponentManager.Instance.AddComponentToEntity(block, blockComponent); ComponentManager.Instance.AddComponentToEntity(block, effectComponent); ComponentManager.Instance.AddComponentToEntity(block, lightComponent); TransformHelper.SetInitialModelPos(modelComponent, transformComponent); TransformHelper.SetBoundingBoxPos(collisionComponent, transformComponent); //EntityFactory.AddBoundingBoxChildren((BoxVolume)collisionComponent); return(block); }
public static Entity NewBasePlayer(String model, int gamePadIndex, Vector3 transformPos, Texture2D texture, String typeName) { Entity player = EntityFactory.NewEntity(typeName); TransformComponent transformComponent = new TransformComponent(player, transformPos); ModelComponent modelComponent = new ModelComponent(player, AssetManager.Instance.GetContent <Model>(model)); VelocityComponent velocityComponent = new VelocityComponent(player); CollisionComponent collisionComponent = new CollisionComponent(player, new BoxVolume(EntityFactory.CreateBoundingBox(modelComponent.Model))); PlayerComponent playerComponent = new PlayerComponent(player); FrictionComponent frictionComponent = new FrictionComponent(player); TextureComponent textureComponent = new TextureComponent(player, texture); GravityComponent gravityComponent = new GravityComponent(player); EffectComponent effectComponent = new EffectComponent(player, AssetManager.Instance.GetContent <Effect>("Shading")); ComponentManager.Instance.AddComponentToEntity(player, modelComponent); ComponentManager.Instance.AddComponentToEntity(player, transformComponent); ComponentManager.Instance.AddComponentToEntity(player, velocityComponent); ComponentManager.Instance.AddComponentToEntity(player, collisionComponent, typeof(CollisionComponent)); ComponentManager.Instance.AddComponentToEntity(player, playerComponent); ComponentManager.Instance.AddComponentToEntity(player, frictionComponent); ComponentManager.Instance.AddComponentToEntity(player, textureComponent); ComponentManager.Instance.AddComponentToEntity(player, gravityComponent); ComponentManager.Instance.AddComponentToEntity(player, effectComponent); TransformHelper.SetInitialModelPos(modelComponent, transformComponent); TransformHelper.SetBoundingBoxPos(collisionComponent, transformComponent); //TransformHelper.SetInitialModelPos(modelComponent, transformComponent); //TransformHelper.SetInitialBoundingSpherePos(collisionComponent, transformComponent); return(player); }
public override void LoadContent() { Position = _position; if (_sourceRectangles.Count > 0) { var firstRect = _sourceRectangles.First(); var firstRecPosition = new Vector2(firstRect.X, firstRect.Y); foreach (var rectangle in _sourceRectangles) { var offset = firstRecPosition + new Vector2(rectangle.X, rectangle.Y); var textureComponent = new TextureComponent(this, _texture) { Layer = Layer, SpriteEffect = SpriteEffect, }; textureComponent.SourceRectangle = rectangle; AddComponent(textureComponent); } } else { var textureComponent = new TextureComponent(this, _texture) { Layer = Layer, SpriteEffect = SpriteEffect, }; AddComponent(textureComponent); } }
public Enemy(Texture2D body, Texture2D tail, Map map) : base() { _bodyComponent = new TextureComponent(this, body) { GetLayer = () => GetBodyLayer(), PositionOffset = new Vector2(-((body.Width % Map.TileWidth) / 2), Map.TileHeight - (body.Height % Map.TileHeight)) }; _tailComponent = new TextureComponent(this, tail) { GetLayer = () => Direction == Directions.Up ? _bodyComponent.Layer + 0.001f : _bodyComponent.Layer - 0.001f, PositionOffset = new Vector2(0, body.Height - tail.Height), }; _moveComponent = new MoveComponent(this, map, (gameTime) => SetMovementEvent(gameTime)) { CurrentRectangleOffset = new Rectangle(0, 40, 0, 40), Speed = 1, }; _mapComponent = new MapComponent(this, map, GetMapRectangle); _interactComponent = new InteractComponent(this, () => _mapComponent.MapRectangle) { OnInteract = () => OnInteractEvent(), }; Components.Add(_moveComponent); Components.Add(_bodyComponent); Components.Add(_tailComponent); Components.Add(_mapComponent); Components.Add(_interactComponent); }
/* * Draws all Models in ModelComponents. * Requires a CameraComponent to exist on some Entity. */ private void DrawModelsWithEffects(GameTime gameTime) { //Undoes any changes from using the spritebatch graphicsDevice.BlendState = BlendState.Opaque; graphicsDevice.DepthStencilState = DepthStencilState.Default; graphicsDevice.SamplerStates[0] = SamplerState.LinearWrap; ConcurrentDictionary <Entity, Component> modelComponents = ComponentManager.Instance.GetConcurrentDictionary <ModelComponent>(); ConcurrentDictionary <Entity, Component> cameraComponentPairs = ComponentManager.Instance.GetConcurrentDictionary <CameraComponent>(); if (cameraComponentPairs.Count == 0) { return; } CameraComponent cameraComponent = (CameraComponent)cameraComponentPairs.First().Value; //get the cameracomponent for the local player foreach (var modelComponentPair in modelComponents) { ModelComponent model = modelComponentPair.Value as ModelComponent; var collisionComponent = ComponentManager.Instance.ConcurrentGetComponentOfEntity <CollisionComponent>(modelComponentPair.Key); if (cameraComponent.BoundingFrustum.Intersects(collisionComponent.BoundingVolume.BoundingSphere) || cameraComponent.BoundingFrustum.Intersects(collisionComponent.BoundingVolume.BoundingBox)) { TextureComponent textureComponent = ComponentManager.Instance.ConcurrentGetComponentOfEntity <TextureComponent>(modelComponentPair.Key); EffectComponent effectComponent = ComponentManager.Instance.ConcurrentGetComponentOfEntity <EffectComponent>(modelComponentPair.Key); TransformComponent transformcComponent = ComponentManager.Instance.ConcurrentGetComponentOfEntity <TransformComponent>(modelComponentPair.Key); var viewVector = Vector3.Transform(cameraComponent.Target - cameraComponent.Position, Matrix.CreateRotationY(0)); viewVector.Normalize(); model.BoneTransformations[0] = model.World; foreach (var modelMesh in model.Model.Meshes) { foreach (ModelMeshPart part in modelMesh.MeshParts) { part.Effect = effectComponent.Effect; part.Effect.Parameters["DiffuseLightDirection"].SetValue(transformcComponent.Position + Vector3.Up); part.Effect.Parameters["World"].SetValue(model.BoneTransformations[modelMesh.ParentBone.Index] * EngineHelper.Instance().WorldMatrix); part.Effect.Parameters["View"].SetValue(cameraComponent.ViewMatrix); part.Effect.Parameters["Projection"].SetValue(cameraComponent.ProjectionMatrix); part.Effect.Parameters["ViewVector"].SetValue(viewVector); part.Effect.Parameters["CameraPosition"].SetValue(cameraComponent.Position); var worldInverseTransposeMatrix = Matrix.Transpose(Matrix.Invert(modelMesh.ParentBone.Transform * EngineHelper.Instance().WorldMatrix)); part.Effect.Parameters["WorldInverseTranspose"].SetValue(worldInverseTransposeMatrix); if (textureComponent != null) { part.Effect.Parameters["ModelTexture"].SetValue(textureComponent.Texture); } } modelMesh.Draw(); } } } }
private JObject GetTexturePropertyJObject(TextureComponent textureComponent) { return(new JObject(new JProperty("texture_name", GetContentManagerItemJObject(PropertyContentManager, textureComponent.TextureName)), new JProperty("width", GetContentManagerItemJObject(PropertyContentManager, textureComponent.Wight)), new JProperty("height", GetContentManagerItemJObject(PropertyContentManager, textureComponent.Height)))); }
public void Render(RenderHelper renderHelper) { ComponentManager cm = ComponentManager.GetInstance(); Viewport viewport = GetCurrentViewport(renderHelper.graphicsDevice); Rectangle viewportBounds = viewport.Bounds; SpriteBatch spriteBatch = renderHelper.spriteBatch; RenderTiles(renderHelper); //Render all textures foreach (var entity in textures) { TextureComponent textureComponent = entity.Item1; PositionComponent positionComponent = entity.Item2; Point position = positionComponent.Position.ToPoint() - textureComponent.Offset; Rectangle textureBounds = new Rectangle(position.X, position.Y, textureComponent.Texture.Width, textureComponent.Texture.Height); if (viewportBounds.Intersects(textureBounds)) { spriteBatch.Draw(textureComponent.Texture, position.WorldToScreen(ref viewport).ToVector2(), null, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, renderHelper.GetLayerDepth(textureComponent.Layer)); } } //Render all animations foreach (var entity in animations) { AnimationComponent animationComponent = entity.Item1; PositionComponent positionComponent = entity.Item2; Point position = positionComponent.Position.ToPoint() - animationComponent.Offset; Rectangle animationBounds = new Rectangle(position.X, position.Y, animationComponent.FrameSize.X, animationComponent.FrameSize.Y); if (viewportBounds.Intersects(animationBounds)) { spriteBatch.Draw(animationComponent.SpriteSheet, position.WorldToScreen(ref viewport).ToVector2(), animationComponent.SourceRectangle, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, renderHelper.GetLayerDepth(animationComponent.Layer)); } } //Render all animationgroups foreach (var entity in animationGroups) { AnimationGroupComponent animationComponent = entity.Item1; PositionComponent positionComponent = entity.Item2; Point position = positionComponent.Position.ToPoint() - animationComponent.Offset; Rectangle animationBounds = new Rectangle(position.X, position.Y, animationComponent.FrameSize.X, animationComponent.FrameSize.Y); if (viewportBounds.Intersects(animationBounds)) { spriteBatch.Draw(animationComponent.Spritesheet, position.WorldToScreen(ref viewport).ToVector2(), animationComponent.SourceRectangle, Color.White, 0f, Vector2.Zero, 1f, SpriteEffects.None, renderHelper.GetLayerDepth(animationComponent.Layer)); } } }
public BasicEntity(Texture2D texture, Vector2 position) { Position = position; var textureComponent = new TextureComponent(this, texture); var collisionComponent = new CollisionComponent(this, new Rectangle( 0, 0, texture.Width, texture.Height), CollisionTypes.All ); AddComponent(textureComponent); AddComponent(collisionComponent); }
public Canvas(String Background, Vector2 WidthHeight, Vector2 Position = default, bool Draggable = true) { WindowComponent myWindow = AddComponent <WindowComponent>(); TransformComponent myTrans = AddComponent <TransformComponent>(); TextureComponent myBackground = AddComponent <TextureComponent>(); ModelComponent myModel = AddComponent <ModelComponent>(); myModel.PipelineID = "GUIDefault"; GeometryUtility.SetModelVertices(myModel, Shape.Square, WidthHeight); myWindow.CanDrag = Draggable; myTrans.DrawLayer = 0.9f; if (Background != null) { ResourceManager.LoadInto <TextureComponent>(myBackground, Background); myTrans.WorldPosition = new Vector3((int)Position.X, (int)Position.Y, 0); } }
public Building(Texture2D texture, Map map) { _textureComponent = new TextureComponent(this, texture) { GetLayer = () => MathHelper.Clamp((Y + 40) / 1000f, 0, 1), }; _interactComponent = new InteractComponent(this, GetInteractRectangle) { OnInteract = () => Console.WriteLine("Enter me"), }; _mapComponent = new MapComponent(this, map, GetMapRectangle); Components.Add(_interactComponent); Components.Add(_textureComponent); Components.Add(_mapComponent); }
static void RenderGUIs(State currentState) { View view = new View(DisplayManager.View); DisplayManager.View = DisplayManager.Window.DefaultView; List <GUI> guis = currentState.GetGUIs(); foreach (GUI gui in guis) { if (!gui.Visible) { continue; } List <GUIComponent> guiComponents = gui.GetGUIComponents(); foreach (GUIComponent guiComponent in guiComponents) { if (!guiComponent.Visible) { continue; } if (guiComponent is TextComponent) { TextComponent textComponent = (TextComponent)guiComponent; Text text = new Text(textComponent.Text, textComponent.FontInfo.Font, textComponent.FontInfo.CharacterSize); text.Position = textComponent.GetPosition(); text.FillColor = textComponent.FillColor; text.OutlineColor = textComponent.OutlineColor; text.OutlineThickness = textComponent.OutlineThickness; text.Style = textComponent.Style; DisplayManager.Window.Draw(text); } else if (guiComponent is TextureComponent) { TextureComponent textureComponent = (TextureComponent)guiComponent; Sprite sprite = new Sprite(textureComponent.Texture); sprite.Position = textureComponent.GetPosition(); sprite.Scale = new Vector2f(textureComponent.Size.X / (float)textureComponent.Texture.Size.X, textureComponent.Size.Y / (float)textureComponent.Texture.Size.Y); DisplayManager.Window.Draw(sprite); } } } DisplayManager.View = view; }
private void ShowConfig(string command, string[] args) { if (!Context.IsWorldReady) { return; } FrameworkMenu Menu = new FrameworkMenu(new Point(200, 40)); TextComponent label = new TextComponent(new Point(0, 0), "Webhook URL:"); TextboxFormComponent webhookUrlTextbox = new TextboxFormComponent(new Point(0, 8), 175, null); ButtonFormComponent setButton = new ButtonFormComponent(new Point(0, 21), "Set", (t, p, m) => this.SetWebhook(webhookUrlTextbox.Value, Game1.player.farmName)); Texture2D icon = this.Helper.Content.Load <Texture2D>("assets/icon.png"); TextureComponent iconTexture = new TextureComponent(new Rectangle(-16, -16, 16, 16), icon); Menu.AddComponent(label); Menu.AddComponent(webhookUrlTextbox); Menu.AddComponent(setButton); Menu.AddComponent(iconTexture); Game1.activeClickableMenu = Menu; }
public void Draw(TextureComponent myTexture, Rectangle myRectangle) { lock (Lock) { Matrix4x4 projection = Matrix4x4.CreateOrthographic(0.0f, 1.0f, 0.0f, 1.0f); Matrix4x4 modelview = Matrix4x4.CreateRotationZ(30); Gl.UseProgram(ProgramName); // Select the program for drawing Gl.UseProgram(ProgramName); // Set uniform state Gl.UniformMatrix4f(LocationMVP, 1, false, projection * modelview); // Use the vertex array Gl.BindVertexArray(_VertexArray.ArrayName); // Draw triangle // Note: vertex attributes are streamed from GPU memory Gl.DrawArrays(PrimitiveType.Triangles, 0, 3); } }
public override void Process(Entity entity) { TextureComponent tc = entity.GetComponent <TextureComponent>(); PositionComponent pc = entity.GetComponent <PositionComponent>(); RotationComponent rc = (entity.HasComponent <RotationComponent>()) ? entity.GetComponent <RotationComponent>() : new RotationComponent(0, 0, false); ShadowComponent sc = (entity.HasComponent <ShadowComponent>()) ? entity.GetComponent <ShadowComponent>() : null; Rectangle sourceRect = ResourceManager.Instance.GetSpriteSheet(tc.Texture).GetSourceRect(tc.Position.X, tc.Position.Y); Rectangle destRect = new Rectangle((int)pc.Position.X, (int)pc.Position.Y, sourceRect.Width, sourceRect.Height); Texture2D texture = ResourceManager.Instance.GetSpriteSheet(tc.Texture).Texture; ScreenManager.Instance.SpriteBatch.Draw(texture, destRect, sourceRect, Color.White, MathHelper.ToRadians(rc.Angle), tc.Origin, SpriteEffects.None, 0f); //if (sc != null) //{ // Rectangle shadowSourceRect = ResourceManager.Instance.GetSpriteSheet(sc.Texture).GetSourceRect(sc.Position.X, sc.Position.Y); // Texture2D shadowTexture = ResourceManager.Instance.GetSpriteSheet(sc.Texture).Texture; // ScreenManager.Instance.SpriteBatch.Draw(shadowTexture, destRect, shadowSourceRect, Color.White, sc.Angle, sc.Origin, SpriteEffects.None, 0f); //} }
/// <summary> /// Converts the texture swizzle color component enum to the respective Graphics Abstraction Layer enum. /// </summary> /// <param name="component">Texture swizzle color component</param> /// <returns>Converted enum</returns> public static SwizzleComponent Convert(this TextureComponent component) { switch (component) { case TextureComponent.Zero: return(SwizzleComponent.Zero); case TextureComponent.Red: return(SwizzleComponent.Red); case TextureComponent.Green: return(SwizzleComponent.Green); case TextureComponent.Blue: return(SwizzleComponent.Blue); case TextureComponent.Alpha: return(SwizzleComponent.Alpha); case TextureComponent.OneSI: case TextureComponent.OneF: return(SwizzleComponent.One); } return(SwizzleComponent.Zero); }
public GravityBoundEntity(Texture2D texture, Vector2 position) { Position = position; _textureComponent = new TextureComponent(this, texture) { Colour = Color.Green, }; //_moveComponent = new MoveComponent(this, (gameTime, entities) => Move(gameTime, entities)); _collisionComponent = new CollisionComponent(this, new Rectangle( 0, 0, texture.Width, texture.Height), CollisionTypes.All ); AddComponent(_textureComponent); AddComponent(_moveComponent); AddComponent(_collisionComponent); }
public void DrawWorldSpace(uint ID, ModelComponent myModel, TextureComponent myTexture, TransformComponent myTransform) { if (this.ActiveCamera.isInViewingFustrum(myTransform.WorldPosition)) { MVPUniformBuffer areaBuffer = new MVPUniformBuffer(); areaBuffer.View = LookAtMatrix; // areaBuffer.Proj = ProjectionPerspective; // areaBuffer.Model = Matrix4x4.CreateTranslation(myTransform.WorldPosition); ResourceSet myResult; myModelResourceManager.TryGetOrCreate <ModelComponent>(ID, out myResult); myResult.Write("MVPUniform", areaBuffer); if (!myModel.hasTransparency) { GeometryPass.Draw(myResult, myModel.myVertexBuffer, myModel.myIndexBuffer, myModel.PipelineID); } else { //Iterate through the model's submeshes, find the transparency and delay it. throw new Exception("Transparency not supported as of yet!"); } } }
//Create AI Player public static Entity NewAiPlayer(String model, Vector3 transformPos, Texture2D texture) { Entity player = EntityFactory.NewEntity(GameEntityFactory.AI_PLAYER); TransformComponent transformComponent = new TransformComponent(player, transformPos); ModelComponent modelComponent = new ModelComponent(player, AssetManager.Instance.GetContent <Model>(model)); VelocityComponent velocityComponent = new VelocityComponent(player); CollisionComponent collisionComponent = new CollisionComponent(player, new BoxVolume(EntityFactory.CreateBoundingBox(modelComponent.Model))); PlayerComponent playerComponent = new PlayerComponent(player); FrictionComponent frictionComponent = new FrictionComponent(player); TextureComponent textureComponent = new TextureComponent(player, texture); GravityComponent gravityComponent = new GravityComponent(player); AiComponent aiComponent = new AiComponent(player); LightComponent lightComponent = new LightComponent(player, new Vector3(0, 7, -5), Color.White.ToVector4(), 10f, Color.Blue.ToVector4(), 0.2f, Color.White.ToVector4(), 1000f); EffectComponent effectComponent = new EffectComponent(player, AssetManager.Instance.GetContent <Effect>("Shading")); ComponentManager.Instance.AddComponentToEntity(player, modelComponent); ComponentManager.Instance.AddComponentToEntity(player, transformComponent); ComponentManager.Instance.AddComponentToEntity(player, velocityComponent); ComponentManager.Instance.AddComponentToEntity(player, collisionComponent, typeof(CollisionComponent)); ComponentManager.Instance.AddComponentToEntity(player, playerComponent); ComponentManager.Instance.AddComponentToEntity(player, frictionComponent); ComponentManager.Instance.AddComponentToEntity(player, textureComponent); ComponentManager.Instance.AddComponentToEntity(player, gravityComponent); ComponentManager.Instance.AddComponentToEntity(player, aiComponent); ComponentManager.Instance.AddComponentToEntity(player, effectComponent); ComponentManager.Instance.AddComponentToEntity(player, lightComponent); //TransformHelper.SetInitialModelPos(modelComponent, transformComponent); //TransformHelper.SetBoundingBoxPos(collisionComponent, transformComponent); TransformHelper.SetInitialModelPos(modelComponent, transformComponent); TransformHelper.SetBoundingBoxPos(collisionComponent, transformComponent); return(player); }
public static void Init() { for (int i = 0; i < 8; i++) { if (i <= 3) { Bg[i] = new ClickableTextureComponent(new Rectangle(44 * i, 30, 48, 48), Game1.content.Load <Texture2D>("LooseSprites//DialogBoxGreen"), OnContractButton); var temp = new TextureComponent(new Rectangle(44 * i + 8, 30 + 8, 32, 32), Game1.content.Load <Texture2D>("LooseSprites//Cursors").getArea(new Rectangle(268, 470, 16, 16))); temp.Layer = 3; Crosses[i] = temp; } else { Bg[i] = new ClickableTextureComponent(new Rectangle(44 * (i - 4), 75, 48, 48), Game1.content.Load <Texture2D>("LooseSprites//DialogBoxGreen"), OnContractButton); var temp = new TextureComponent(new Rectangle(44 * (i - 4) + 8, 75 + 8, 32, 32), Game1.content.Load <Texture2D>("LooseSprites//Cursors").getArea(new Rectangle(268, 470, 16, 16))); temp.Layer = 3; Crosses[i] = temp; } } if (Menu != null) { Menu.ClearComponents(); } Menu = new FrameworkMenu(new Point(200, 140), false); foreach (var bg in Bg) { Menu.AddComponent(bg); } Menu.AddComponent(HeaderText); Menu.AddComponent(DescText1); Menu.AddComponent(DescText2); Menu.AddComponent(DescText3); Menu.AddComponent(DescText4); Menu.AddComponent(BackButton); }
public void DrawingPriority() { Assert.True(Engine.Initialize("ObjectSystem Test", 800, 600, new Configuration())); var texture = Texture2D.Load(@"../../Core/TestData/IO/AltseedPink.png"); var texture2 = Texture2D.Load(@"../../Core/TestData/IO/AltseedPink.jpg"); Assert.NotNull(texture); var scene = Engine.CurrentScene; var obj1 = new TaggedObject() { DrawingPriority = 1, Tag = "1", }; var tr = new Matrix44F(); tr.SetTranslation(0, 0, 0); var comp1 = new TextureComponent() { Texture = texture, Src = new RectF(200, 0, 200, 200), Transform = tr, }; obj1.AddComponent(comp1); scene.AddObject(obj1); var obj2 = new TaggedObject() { DrawingPriority = 2, Tag = "2", }; tr = new Matrix44F(); tr.SetTranslation(200, 200, 0); var comp2 = new TextureComponent() { Texture = texture2, Src = new RectF(100, 100, 200, 200), Transform = tr, }; obj2.AddComponent(comp2); scene.AddObject(obj2); var obj3 = new TaggedObject() { DrawingPriority = 3, Tag = "3", }; tr = new Matrix44F(); tr.SetTranslation(400, 400, 0); var comp3 = new TextureComponent() { Texture = texture, Src = new RectF(0, 200, 200, 200), Transform = tr, }; obj3.AddComponent(comp3); scene.AddObject(obj3); #if COUNT var count = 0; #endif while (Engine.DoEvents() #if COUNT && count < 300 #endif ) { Assert.True(Engine.Graphics.BeginFrame()); Engine.Update(); var cmdList = Engine.Graphics.CommandList; cmdList.SetRenderTargetWithScreen(); Engine.Renderer.Render(cmdList); Assert.True(Engine.Graphics.EndFrame()); if (Engine.Keyboard.GetKeyState(Keys.Escape) == ButtonState.Push) { break; } #if COUNT count++; #endif } Engine.Terminate(); }
public SceneDefault(SceneManager inSceneManager) : base(inSceneManager) { sceneManager = inSceneManager; sceneManager.updater = update; sceneManager.renderer = render; sceneManager.keyDowner = onKeyDown; GL.ClearColor(Color4.CornflowerBlue); TransformComponent randTrans; TextureComponent randTex; CollisionComponent randColl; RigidBodyComponent randRig; fishHandle = EntityManager.createNewBlankEntity(); randTrans = new TransformComponent(Matrix4.Identity) { Position = new Vector2(-450, 0), Scale = new Vector2(2f, 0.912f) }; randTex = new TextureComponent("Fish1.png"); randRig = new RigidBodyComponent() { Gravity = new Vector2(0.4f, 0f) }; randColl = new CollisionComponent(); EntityManager.Entities[EntityManager.entityRefFromID(fishHandle)].addComponent(randTrans); EntityManager.Entities[EntityManager.entityRefFromID(fishHandle)].addComponent(randTex); EntityManager.Entities[EntityManager.entityRefFromID(fishHandle)].addComponent(randColl); EntityManager.Entities[EntityManager.entityRefFromID(fishHandle)].addComponent(randRig); bubbleHandle = EntityManager.createNewBlankEntity(); randTrans = new TransformComponent(Matrix4.Identity) { Position = new Vector2(250, -375), Scale = new Vector2(0.5f, 0.5f) }; randTex = new TextureComponent("Bubble1.png"); randColl = new CollisionComponent(); randRig = new RigidBodyComponent() { Gravity = new Vector2(0, 0.6f) }; AudioComponent bubblePopSound = new AudioComponent("bubblepop.wav"); int entityRef = EntityManager.entityRefFromID(bubbleHandle); EntityManager.Entities[entityRef].addComponent(randTrans); EntityManager.Entities[entityRef].addComponent(randTex); EntityManager.Entities[entityRef].addComponent(randColl); EntityManager.Entities[entityRef].addComponent(randRig); EntityManager.Entities[entityRef].addComponent(bubblePopSound); plantsHandle = EntityManager.createNewBlankEntity(); randTrans = new TransformComponent(Matrix4.Identity) { Position = new Vector2(0, -265), Scale = new Vector2(11.8f, 1.5f) }; randTex = new TextureComponent("Plants.png"); EntityManager.Entities[EntityManager.entityRefFromID(plantsHandle)].addComponent(randTrans); EntityManager.Entities[EntityManager.entityRefFromID(plantsHandle)].addComponent(randTex); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); camera = new Camera2D(new Vector2(0f, 0f), new Vector2(1f), new Vector2(3f)); this.Services.AddService(typeof(SpriteBatch), spriteBatch); this.Services.AddService(typeof(Camera2D), camera); texture1 = this.Content.Load<Texture2D>("tex"); TileCatalog cat1 = new TileCatalog(texture1, 15, 15); Random rand = new Random(DateTime.Now.Millisecond); TileMap map1 = new TileMap(100, 100); for (int i = 0; i < 100; i++) { for (int j = 0; j < 100; j++) { map1.SetTile(i, j, new Tile(rand.Next(1, cat1.TilePositions.Count))); } } TileLayer layer1 = new TileLayer(cat1, map1, 0.5f, false, new Vector2(0, 0), new Vector2(1f, 1f), new Vector2(3f), false, LayerMovementDirection.None); texture2 = this.Content.Load<Texture2D>("tiles2"); TileCatalog cat2 = new TileCatalog(texture2, 48, 48); TileMap map2 = new TileMap(10, 500); for (int i = 0; i < 10; i++) { for (int j = 0; j < 500; j++) { map2.SetTile(i, j, new Tile(rand.Next(1, cat2.TilePositions.Count))); } } TileLayer layer2 = new TileLayer(cat2, map2, 1.0f, false, new Vector2(0, 0), new Vector2(1f, 1f), new Vector2(3f), true, LayerMovementDirection.Up); scene = new TileScene(); scene.AddLayer(layer2); scene.AddLayer(layer1); TileComponent component = new TileComponent(this, scene, baseScreenSize, resultionIndependent); this.Components.Add(component); TextureLayer tLayer1 = new TextureLayer(this.texture1, 1f, false, new Vector2(20f), Vector2.One, new Vector2(1.5f,1.5f), true, Anchor.LowerRight); TextureLayer tLayer2 = new TextureLayer(this.texture2, 0.5f, false, new Vector2(10f), Vector2.One, new Vector2(5f), true, Anchor.LowerLeft); TextureScene tScene = new TextureScene(); tScene.AddLayer(tLayer1); tScene.AddLayer(tLayer2); TextureComponent tComponent = new TextureComponent(this, tScene, baseScreenSize, resultionIndependent); this.Components.Add(tComponent); texture1 = this.Content.Load<Texture2D>("megax"); SpriteCatalog scatalog = new SpriteCatalog(texture1, 36, 42); SpriteSequence[] spriteSecuences = new SpriteSequence[2]; SpriteSequence spriteSecuence1 = new SpriteSequence(7, 0); spriteSecuence1.StepTime = 400; spriteSecuence1.SetFrame(0,new SpriteFrame(1)); spriteSecuence1.SetFrame(1, new SpriteFrame(1)); spriteSecuence1.SetFrame(2, new SpriteFrame(1)); spriteSecuence1.SetFrame(3, new SpriteFrame(1)); spriteSecuence1.SetFrame(4, new SpriteFrame(2)); spriteSecuence1.SetFrame(5, new SpriteFrame(3)); spriteSecuence1.SetFrame(6, new SpriteFrame(1)); spriteSecuences[0] = spriteSecuence1; SpriteSequence spriteSecuence2 = new SpriteSequence(10, 0); spriteSecuence2.StepTime = 90; spriteSecuence2.SetFrame(0, new SpriteFrame(5)); spriteSecuence2.SetFrame(1, new SpriteFrame(6)); spriteSecuence2.SetFrame(2, new SpriteFrame(7)); spriteSecuence2.SetFrame(3, new SpriteFrame(8)); spriteSecuence2.SetFrame(4, new SpriteFrame(9)); spriteSecuence2.SetFrame(5, new SpriteFrame(10)); spriteSecuence2.SetFrame(6, new SpriteFrame(11)); spriteSecuence2.SetFrame(7, new SpriteFrame(12)); spriteSecuence2.SetFrame(8, new SpriteFrame(13)); spriteSecuence2.SetFrame(9, new SpriteFrame(14)); spriteSecuences[1] = spriteSecuence2; SpriteLayer spLayer = new SpriteLayer(scatalog, spriteSecuences, 1.0f, true, new Vector2(10f), Vector2.One, Vector2.Zero, SpriteEffects.None, true, Anchor.None); spLayer.CurrentSequence = 2; SpriteScene spScene = new SpriteScene(); spScene.AddLayer(spLayer); SpriteComponent spComponent = new SpriteComponent(this, spScene, baseScreenSize, resultionIndependent); this.Components.Add(spComponent); }
public Scene2(SceneManager inSceneManager) : base(inSceneManager) { sceneManager = inSceneManager; sceneManager.updater = update; sceneManager.keyDowner = onKeyDown; sceneManager.renderer = render; GL.ClearColor(Color4.Green); TransformComponent transform; TextureComponent texture; CollisionComponent collision; RigidBodyComponent rigidBody; boxHandle = EntityManager.createNewBlankEntity(); transform = new TransformComponent(Matrix4.Identity) { Position = new Vector2(-450, -250), Scale = new Vector2(1, 1) }; texture = new TextureComponent("box.bmp"); collision = new CollisionComponent(); rigidBody = new RigidBodyComponent(); int boxRef = EntityManager.entityRefFromID(boxHandle); EntityManager.Entities[boxRef].addComponent(transform); EntityManager.Entities[boxRef].addComponent(texture); EntityManager.Entities[boxRef].addComponent(rigidBody); EntityManager.Entities[boxRef].addComponent(collision); box2Handle = EntityManager.createNewBlankEntity(); transform = new TransformComponent(Matrix4.Identity) { Position = new Vector2(-200, 0), Scale = new Vector2(2, 2) }; texture = new TextureComponent("box2.bmp"); collision = new CollisionComponent(); rigidBody = new RigidBodyComponent(); int box2Ref = EntityManager.entityRefFromID(box2Handle); EntityManager.Entities[box2Ref].addComponent(transform); EntityManager.Entities[box2Ref].addComponent(texture); EntityManager.Entities[box2Ref].addComponent(rigidBody); EntityManager.Entities[box2Ref].addComponent(collision); box3Handle = EntityManager.createNewBlankEntity(); transform = new TransformComponent(Matrix4.Identity) { Position = new Vector2(200, 0), Scale = new Vector2(2, 2), Rotation = 45 }; texture = new TextureComponent("notReal.bmp"); collision = new CollisionComponent(); rigidBody = new RigidBodyComponent(); int box3Ref = EntityManager.entityRefFromID(box3Handle); EntityManager.Entities[box3Ref].addComponent(transform); EntityManager.Entities[box3Ref].addComponent(texture); EntityManager.Entities[box3Ref].addComponent(rigidBody); EntityManager.Entities[box3Ref].addComponent(collision); }
public void DrawWorldSpace(uint ID, ModelComponent myModel, TextureComponent myTexture, TransformComponent myTransform) { }
public UIImage(Texture texture, Vector2f position) : base(position) { TextureComponent = AddComponent(new TextureComponent(texture, new Vector2f())); }