/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { screenWidth = graphics.PreferredBackBufferWidth; screenHeight = graphics.PreferredBackBufferHeight; mainTarget = DefaultTarget; tileTarget = DefaultTarget; entityTarget = DefaultTarget; postTileTarget = DefaultTarget; screenTarget = DefaultTarget; drawingTarget = DefaultTarget; random = new Random(); cameraPosition = Point.Zero; mousePos = new Point(); TextureHandler.Initialize(); GameID.Initialize(); NpcHandler.Initialize(); LevelHandler.Initialize(); TileHandler.Initialize(); base.Initialize(); }
protected override void Initialize() { textureHandler = new TextureHandler(); base.Initialize(); currentScene = new Scene(this); mouseInputHandler = new MouseInputHandler(this); }
public TileQuadTexture(Tile tile, TextureHandler texture, float scale) { _enabled = true; GetTile = tile; _cache = tile.GetQuad(scale); Texture = texture; }
public static void LoadContent(ContentManager content, GameWindow window) { TextureHandler.LoadContent(content); //Deserialize all earlier games gameHandlers = GameHandler.DeserializeOnStartup(); store.Load(graphicsDevice); //Menu load stuff menu = new Menu((int)States.Menu); menu.LoadContent(graphicsDevice, window, content); menu.AddItem(content.Load <Texture2D>("Menu/Play"), (int)States.GameStart, window, content.Load <Texture2D>("Menu/MenuIcons/PlayNew")); menu.AddItem(content.Load <Texture2D>("Menu/Store"), (int)States.Saves, window, content.Load <Texture2D>("Menu/MenuIcons/Saves")); menu.AddItem(content.Load <Texture2D>("Menu/Store"), (int)States.Store, window, content.Load <Texture2D>("Menu/MenuIcons/Collection")); menu.AddItem(content.Load <Texture2D>("Menu/Exit"), (int)States.Quit, window, content.Load <Texture2D>("Menu/MenuIcons/Exit")); //check progress on eg. dog unlock etc CheckProgress(); //Add previous games to the save manager displayGames.LoadContent(window, graphicsDevice); foreach (GameHandler gh in gameHandlers) { displayGames.AddGameItem(gh); } }
public void TextureHandler_Bmp_CombineFailed() { TextureHandler target = new TextureHandler(32, 32); Bitmap input1 = new Bitmap(Path.Combine(localFolder, image_bmp_1_big_red)); Bitmap input2 = new Bitmap(Path.Combine(localFolder, image_bmp_1_big_black)); Bitmap input3 = new Bitmap(Path.Combine(localFolder, image_bmp_1_big_red)); Bitmap input4 = new Bitmap(Path.Combine(localFolder, image_bmp_1_big_green)); Bitmap[][] inputArray = new Bitmap[2][]; inputArray[0] = new Bitmap[2] { input1, input2 }; inputArray[1] = new Bitmap[2] { input3, input4 }; target.Combine(inputArray, 32, 32, true); target.Save(Path.Combine(localFolder, image_bmp_1_combineFail_out), ImageFormat.Bmp); target.Dispose(); Bitmap original = new Bitmap(Path.Combine(localFolder, image_bmp_1_big)); Bitmap output = new Bitmap(Path.Combine(localFolder, image_bmp_1_combineFail_out)); BitmapAssert.AreNotEqual(original, output, 10, "Written image should not be like the reference."); // cleanup - dispose of the bitmaps original.Dispose(); output.Dispose(); input1.Dispose(); input2.Dispose(); input3.Dispose(); input4.Dispose(); }
protected override void LoadContent() { // Load any game content // ================ TextureHandler.LoadContent(); AudioHandler.LoadContent(); }
public override void Draw(ref Particle particle, int pidx, float lasttime, float globaltime, NodeReference reference, ResourceManager res, ParticleEffectInstance instance, ref Matrix4x4 transform, float sparam) { var time = particle.TimeAlive / particle.LifeSpan; var node_tr = GetAttachment(reference, transform); Vector3 deltap; Quaternion deltaq; if (DoTransform(reference, sparam, lasttime, globaltime, out deltap, out deltaq)) { particle.Position += deltap; particle.Orientation *= deltaq; } var p = Vector3.Transform(Vector3.Transform(particle.Position, particle.Orientation), node_tr); TextureHandler.Update(Texture, res); var c = Color.GetValue(sparam, time); var a = Alpha.GetValue(sparam, time); instance.Pool.DrawBasic( particle.Instance, this, TextureHandler, p, new Vector2(Size.GetValue(sparam, time)) * 2, new Color4(c, a), GetFrame(globaltime, sparam, ref particle), Rotate == null ? 0f : MathHelper.DegreesToRadians(Rotate.GetValue(sparam, time)), reference.Index ); }
public TileQuadTexture(Tile tile, TextureHandler texture, float scale) { this.enabled = true; this.tile = tile; this.cache = tile.GetQuad(scale); this.texture = texture; }
public void ImageChanged() { if (Input.GetKey(KeyCode.E)) { if (Input.mouseScrollDelta.y > 0) { TextureHandler.ActualIndex++; if (TextureHandler.ActualIndex <= indexes) { MainImage.mainTexture = TextureHandler.TexturetoRender(TextureHandler.SerieOf2DImages[TextureHandler.ActualIndex]); } else { TextureHandler.ActualIndex--; } } if (Input.mouseScrollDelta.y < 0) { TextureHandler.ActualIndex--; if (TextureHandler.ActualIndex >= 0) { MainImage.mainTexture = TextureHandler.TexturetoRender(TextureHandler.SerieOf2DImages[TextureHandler.ActualIndex]); } else { TextureHandler.ActualIndex++; } } } }
public override void Draw(ref Particle particle, int pidx, float lasttime, float globaltime, NodeReference reference, ResourceManager res, ParticleEffectInstance instance, ref Matrix4x4 transform, float sparam) { var time = particle.TimeAlive / particle.LifeSpan; var node_tr = GetAttachment(reference, transform); TextureHandler.Update(Texture, res); var c = Color.GetValue(sparam, time); var a = Alpha.GetValue(sparam, time); var q = particle.Orientation * Transform.GetDeltaRotation(sparam, lasttime, globaltime); particle.Orientation = q; var mat = Matrix4x4.CreateFromQuaternion(q); var p = Vector3.Transform(particle.Position, transform); var p2 = Vector3.Transform(particle.Position + particle.Normal, transform); var n = (p - p2).Normalized(); instance.Pool.DrawPerspective( particle.Instance, this, TextureHandler, Vector3.Transform(particle.Position, transform), mat, new Vector2(Size.GetValue(sparam, time)), new Color4(c, a), GetFrame(globaltime, sparam, ref particle), n, Rotate == null ? 0f : MathHelper.DegreesToRadians(Rotate.GetValue(sparam, time)), reference.Index ); if (DrawNormals) { Debug.DrawLine(p - (n * 100), p + (n * 100)); } }
public static void LoadPreContent(ContentManager content, GameWindow window, GraphicsDevice graphics) { graphicsDevice = graphics; //Load Pre textures and assets FontHandler.LoadContent(content); TextureHandler.LoadPreContent(content); background = new Background(TextureHandler.Sprites["Backgrounds/background1"], window); }
public LoadScreen(Game1 game, TextureHandler textureHandler) { this.textureHandler = textureHandler; this.game = game; loading = textureHandler.getLoadingImage(); fadeIn = true; finished = fadeOut = false; }
public Texture2D SetupTextureAtlas(GraphicsDevice graphicsDevice) { var triangles = Models.SelectMany(m => m.ModelTriangles).ToList(); var dict = new Dictionary <KeyValuePair <string, Rectangle>, TrianglesWithCroppedTexture>(); foreach (var triangle in triangles) { if (!dict.ContainsKey(triangle.TextureKey)) { if (!TextureHandler.HasCroppedTexture(triangle.TextureKey)) { TextureHandler.AddCroppedTexture(triangle.TextureKey, TextureHandler.CropTexture(triangle.OriginalTexture, triangle.OriginalTextureRectangle)); } dict.Add(triangle.TextureKey, new TrianglesWithCroppedTexture() { CroppedTexture = TextureHandler.GetCroppedTexture(triangle.TextureKey).Key, HasTransparentPixels = TextureHandler.GetCroppedTexture(triangle.TextureKey).Value }); } dict[triangle.TextureKey].ModelTriangles.Add(triangle); } var packer = new RectanglePacker(4096, 4096); foreach (var pair in dict) { var rect = pair.Value.CroppedTexture.Bounds; if (!packer.Pack(rect.Width, rect.Height, out rect.X, out rect.Y)) { throw new Exception("Uh oh, we couldn't pack the rectangles"); } pair.Value.AtlasRectangle = rect; } foreach (var pair in dict) { foreach (var triangle in pair.Value.ModelTriangles) { triangle.AtlasTextureRectangle = pair.Value.AtlasRectangle; triangle.HasTransparentPixels = pair.Value.HasTransparentPixels; } } var atlas = new Texture2D(graphicsDevice, 4096, 4096); foreach (var pair in dict) { var data = new Color[pair.Value.CroppedTexture.Width * pair.Value.CroppedTexture.Height]; pair.Value.CroppedTexture.GetData(0, pair.Value.CroppedTexture.Bounds, data, 0, data.Length); atlas.SetData(0, pair.Value.AtlasRectangle, data, 0, data.Length); pair.Value.CroppedTexture = null; } return(atlas); }
public RenderTexture[] AllImagesToRender(Texture2D[] images) { RenderTexture[] rt = new RenderTexture[images.Length]; for (int i = 0; i < images.Length; i++) { rt[i] = TextureHandler.TexturetoRender(images[i]); } return(rt); }
void Start() { audioSource = GetComponent <AudioSource>(); rend = GetComponent <Renderer>(); textureHandler = FindObjectOfType <TextureHandler>(); loadAssets = FindObjectOfType <LoadAssets>(); StartCoroutine(CoRecordingRestarter()); }
public void DrawTileSides(SpriteBatch spriteBatch, int i, int j) { if (DrawSides(spriteBatch, i, j)) { Rectangle rect1 = DrawRect();//gets the draw rect Texture2D texture = TextureHandler.GetTexture(sideTexture); Point drawPos = (rect1.Location + new Point(i, j).MultBy(TileHandler.tileSize)); Point drawSize = (texture.Size() * GameMain.spriteScaling).ToPoint(); spriteBatch.Draw(texture, new Rectangle(drawPos, drawSize).WorldToScreenCoords(), null, Color.White, default, new Vector2(texture.Width, 0), default, default);
public void OnLeftButtonClick() { TextureHandler.LeftMask = TextureHandler.RenderTo2D(MaskTexture); var clones = GameObject.FindGameObjectsWithTag("clone"); foreach (var clone in clones) { Destroy(clone); } }
public void DrawTileBottom(SpriteBatch spriteBatch, int i, int j) { if (DrawBottom(spriteBatch, i, j)) { Rectangle rect1 = DrawRect();//gets the draw rect Texture2D texture = TextureHandler.GetTexture(bottomTexture); Point drawPos = ((rect1.Location + new Point(0, rect1.Size.Y)) + (new Point(i, j).MultBy(TileHandler.tileSize))); Point drawSize = new Point(rect1.Size.X, (int)(texture.Height * GameMain.spriteScaling)); spriteBatch.Draw(texture, new Rectangle(drawPos, drawSize).WorldToScreenCoords(), Color.White); } }
public void OnRightButton() { TextureHandler.ActualIndex++; if (TextureHandler.ActualIndex <= indexes) { MainImage.mainTexture = TextureHandler.TexturetoRender(TextureHandler.SerieOf2DImages[TextureHandler.ActualIndex]); } else { TextureHandler.ActualIndex--; } }
public void OnLeftButton() { TextureHandler.ActualIndex--; if (TextureHandler.ActualIndex >= 0) { MainImage.mainTexture = TextureHandler.TexturetoRender(TextureHandler.SerieOf2DImages[TextureHandler.ActualIndex]); } else { TextureHandler.ActualIndex++; } }
public Level(LevelInfo levelInfo, GraphicsDevice graphicsDevice) { LevelInfo = levelInfo; LevelRenderer = new LevelRenderer(); DayCycleTexture = TextureHandler.LoadTexture(graphicsDevice, "C:\\GitHub\\Maps\\YourRoom\\textures\\daycycle.png"); SetLastColor(); var entities = new List <EntityInfo>(); foreach (var structure in LevelInfo.Structures) { var directory = LevelInfo.DirectoryLocation; if (!Path.HasExtension(structure.Map)) { structure.Map += ".dat"; } var structurePath = Path.Combine(directory, structure.Map); var file = File.ReadAllText(structurePath); // Little hack var structureData = LevelLoader.Load(file, structurePath); foreach (var entityInfo in structureData.Entities) { entityInfo.Parent = levelInfo; entityInfo.Position += structure.Offset; var rot = Entity.GetRotationFromVector(entityInfo.Rotation) + (structure.Rotation == -1 ? 0 : structure.Rotation); while (rot > 3) { rot -= 4; } entityInfo.Rotation = Entity.GetRotationFromInteger(rot); } entities.AddRange(structureData.Entities); } var combined = LevelInfo.Entities.Concat(entities).ToList(); foreach (var entity in combined) { entity.Shader = GetDaytimeColor(true); Models.Add(BaseModel.GetModelByEntityInfo(entity, graphicsDevice)); } LevelRenderer.HandleModels(Models); LevelRenderer.Setup(graphicsDevice); //BaseModel.SetupStatic(graphicsDevice); }
public Main() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; Window.Title = "Sandboxin 4 days"; Window.AllowUserResizing = true; Window.ClientSizeChanged += OnResize; Window.TextInput += TextInputHandler; graphics.PreferredBackBufferHeight = 450; textureHandler = new TextureHandler(); fontHandler = new FontHandler(); }
//public Animation(int width, int height, byte clut, byte texturePage, byte cols, byte rows, ModelGroups _mg, int count = 0, int x = 0, int y = 0, int skip = 1) public TextureAnimation(TextureHandler tex, int width, int height, int texturePage, int cols, int rows, int count = 0, int x = 0, int y = 0, int skip = 1) { this.tex = tex; this.width = width; this.height = height; this.texturePage = texturePage; this.cols = cols; this.rows = rows; this.skip = skip; FrameNumber = skip; this.x = x; this.y = y; Frames = count > 0 ? count : rows * cols; }
protected override void LoadContent() { this.IsMouseVisible = true; // Create a new SpriteBatch, which can be used to draw textures. this.spriteBatch = new SpriteBatch(this.GraphicsDevice); this.player.LoadContent(this.Content); this.shadow.LoadContent(this.Content); this.skeleton.LoadContent(this.Content); this.goblin.LoadContent(this.Content); this.gargoyle.LoadContent(this.Content); this.death.LoadContent(this.Content); this.sorceror.LoadContent(this.Content); TextureHandler.Load(this.Content); }
/// <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. this.spriteBatch = new SpriteBatch(this.GraphicsDevice); //// this.graphicsEngine = new GraphicsEngine(this.spriteBatch); this.controller = new ControllerUserInput(); ITextureHandler textureHandler = new TextureHandler(this.Content); IPaintInterface painter = new PaintBrush(textureHandler, this.graphicsEngine); this.engine = new Engine(this.controller, painter); //// this.gameLoader = new GameLoader(new UnitOfWork(), this.engine); this.consoleHandler = new ConsoleHandler(this.console, this.gameLoader); }
public void TextureHandler_Bmp_ReadWrite() { TextureHandler t1 = new TextureHandler(Path.Combine(localFolder, image_bmp_1)); t1.Save(Path.Combine(localFolder, image_bmp_1_out), ImageFormat.Bmp); t1.Dispose(); Bitmap original = new Bitmap(Path.Combine(localFolder, image_bmp_1)); Bitmap output = new Bitmap(Path.Combine(localFolder, image_bmp_1_out)); BitmapAssert.AreEqual(original, output, 2, "Written image should be as the original."); // cleanup - dispose of the bitmaps original.Dispose(); output.Dispose(); }
public void TextureHandler_Bmp_ResizeDown() { TextureHandler t1 = new TextureHandler(Path.Combine(localFolder, image_bmp_1)); t1.Resize(8, 8, true); t1.Save(Path.Combine(localFolder, image_bmp_1_small_out), ImageFormat.Bmp); t1.Dispose(); Bitmap original = new Bitmap(Path.Combine(localFolder, image_bmp_1_small)); Bitmap output = new Bitmap(Path.Combine(localFolder, image_bmp_1_small_out)); BitmapAssert.AreEqual(original, output, 128, "Written image should be like the reference."); // cleanup - dispose of the bitmaps original.Dispose(); output.Dispose(); }
public texl(byte[] texlBuffer) { textures = new TextureHandler[20][]; using (MemoryStream ms = new MemoryStream(texlBuffer)) using (BinaryReader br = new BinaryReader(ms)) for (int i = 0; i < TEX_COUNT; i++) { int timOffset = i * TEX_SIZE; TIM2 tim = new TIM2(texlBuffer, (uint)timOffset); textures[i] = new TextureHandler[tim.GetClutCount]; for (ushort k = 0; k < textures[i].Length; k++) { textures[i][k] = TextureHandler.Create($"texl_tim{(i + 1).ToString("D2")}.tim", tim, k, null); } //todo detect if mods aren't using palettes. } }
//Initialization and content loading public static void Initialize() { //Creates folder structure if nescessary CreateFolderStructure(); frameCounter = new FrameCounter(); random = new Random(); TextureHandler.Initialize(); InputHandler.Initialize(); FontHandler.Initialize(); displayGames = new DisplayGames(); playerInformationHandler = PlayerInformationHandler.Initialize(); Tick = 0; MouseHandler.Initialize(); store = new Store(playerInformationHandler, (int)States.Store); }
/// <summary> /// Reads chara.one buffer -> chara one is a file packed with MCH files and TIM textures /// without pointers. File needs to be scanned /// </summary> /// <param name="buffer">Full chara.one file</param> public CharaOne(byte[] buffer) { this.buffer = buffer; List <Debug_MCH> mchs = new List <Debug_MCH>(); List <TextureHandler> texturesList = new List <TextureHandler>(); int i = 0; MemoryStream ms = null; using (BinaryReader br = new BinaryReader(ms = new MemoryStream(this.buffer))) { uint eof = br.ReadUInt32(); TIM2 tim; while (ms.CanRead) { if (ms.Position >= ms.Length) { break; } else if (BitConverter.ToUInt16(this.buffer, (int)ms.Position) == 0) { ms.Seek(2, SeekOrigin.Current); } else if (br.ReadUInt64() == 0x0000000800000010) { ms.Seek(-8, SeekOrigin.Current); tim = new TIM2(this.buffer, (uint)ms.Position); ms.Seek(tim.GetHeight * tim.GetWidth / 2 + 64, SeekOrigin.Current); //i.e. 64*20=1280/2=640 + 64= 704 + eof texturesList.Add(TextureHandler.Create($"chara_tim{(i++).ToString("D2")}", tim, 0, null)); } else //is geometry structure { ms.Seek(-8, SeekOrigin.Current); Debug_MCH mch = new Debug_MCH(ms, br); if (mch.bValid()) { mchs.Add(mch); } } } ms = null; } mchInstances = mchs.ToArray(); textures = texturesList.ToArray(); }
//return an editor tile layer data object, which will hold the necessary data for processing on the handler / manager layers public static EditorTileLayerDO OpenEditorLayer(string fileName, TextureHandler textureHandler, TexturePreviewHandler texturePreviewHandler) { try { EditorTileLayerDO openedTileLayerDO = EngineFileHandler.OpenEditorLayer(fileName); //loop through each texture name, load the texture and add it to the layer. //We need to decide what to do when textures have been deleted / no longer exist in that directory.. should we not load the level at all? //Or maybe have each tile hold a reference to the texture file, and just not draw the textures who's files have not been loaded in List<string> modifiedTextureFileNames = new List<string>(); foreach (string textureFile in openedTileLayerDO.LayerTextureNameList) { string trimmedTextureFile = FileUtility.GetFileNameWithParentFolder(textureFile); if (textureHandler.HandleFile(textureFile)) { texturePreviewHandler.HandleFile(textureFile); //we just successfully handled that texture, it should be stored in memory now openedTileLayerDO.EditorTileLayer.AddNewTexture(textureHandler.GetTexture(trimmedTextureFile)); //now add it to our modified texture file names, so we can pass it back to the client for display modifiedTextureFileNames.Add(trimmedTextureFile); } else { //The texture still exists in memory, just add it to the tile layers texture list. It will be added in the correct index //just make sure the texture handler contains it... if (textureHandler.ContainsTexture(trimmedTextureFile)) openedTileLayerDO.EditorTileLayer.AddNewTexture(textureHandler.GetTexture(trimmedTextureFile)); } } openedTileLayerDO.LayerTextureNameList.Clear(); foreach (string modifiedFile in modifiedTextureFileNames) { openedTileLayerDO.LayerTextureNameList.Add(modifiedFile); } //return new Tuple with all texture that are handled correctly, and have had their file names modified return openedTileLayerDO; } catch (Exception e) { throw e; } }
public TutorialScreen(Game1 game, TextureHandler textureHandler) { this.textureHandler = textureHandler; this.game = game; }
public GameOverScreen(Game1 game, TextureHandler textureHandler) { this.textureHandler = textureHandler; this.game = game; }
public PauseScreen(Game1 game, TextureHandler textureHandler) { this.textureHandler = textureHandler; this.game = game; }
public MainMenuScreen(Game1 game, TextureHandler textureHandler) { this.textureHandler = textureHandler; this.game = game; }
public void setTextureHandler(TextureHandler textureHandler) { this.textureHandler = textureHandler; }