raidzero

Member
  • Content count

    71
  • Joined

  • Last visited

Community Reputation

112 Neutral

About raidzero

  • Rank
    Member
  1. I posted my problem over at [url="http://stackoverflow.com/questions/11857819/why-isnt-my-image-loading"]stackoverflow[/url], but haven't found the solution yet. [CODE] private void LoadImageList() { string filepath = Application.StartupPath + @"\Content\Textures\Tiles\PlatformTiles.png"; Bitmap tileSheet = new Bitmap(filepath); int tilecount = 0; for (int y = 0; y < tileSheet.Height / TileGrid.TileHeight; y++) { for (int x = 0; x < tileSheet.Width / TileGrid.TileWidth; x++) { Bitmap newBitmap = tileSheet.Clone( new System.Drawing.Rectangle( x * TileGrid.TileWidth, y * TileGrid.TileHeight, TileGrid.TileWidth, TileGrid.TileHeight), System.Drawing.Imaging.PixelFormat.DontCare); imgListTiles.Images.Add(newBitmap); string itemName = ""; if (tilecount == 0) { itemName = "Empty"; } if (tilecount == 1) { itemName = "White"; } listTiles.Items.Add(new ListViewItem(itemName, tilecount++)); } } } [/CODE] All I did was update PlatformTiles.png with a newer one and the next time I ran the program it doesn't load. I placed a breakpoint at int tilecount = 0; and it doesn't ever reach it. Everything after it doesn't run either. Any ideas? I used the original PlaformTiles.png and it doesn't work either.
  2. Help with isometric tile movement

    [quote name='szecs' timestamp='1341738045' post='4956871'] It's hard to see what's going on. -So how is the coordinate system set up? -How do you handle moving animation? Does moving has some king of moving state with float coordinates? Or the player just pops into the on cell? Your code seems overly complex. Can't you use something like: -snip- ? This means the player will first move diagonally, than in a straight line towards the target. [/quote] I want the sprite to move through the center of each tile. With the code you provided the sprite moves diagonally through each tile. Let me draw up some examples. In the attached image. The thick black line is what I want to achieve, while the purple line is what your code achieves.
  3. I've been trying to move a sprite on a tile map, but I'm having some difficulty working things out. I want the sprite to move from tile to tile. Problems:[list] [*]Sprite moves in a zig-zag manner in-between tiles [*]I can move the sprite on the x or y axis in a straight line, but I can't get it to move on the x axis then on the y axis, ie. moving a tile below would require moving either on the x towards the right or on the y towards the left then move on y towards left or on the x towards the right respectively [/list] Code: [CODE] public void HandleInput(TileGrid grid, SpriteAnimation playerSprite, InputHandler input) { Vector2 selectionLocation = Camera.ScreenToWorld(new Vector2(Mouse.GetState().X, Mouse.GetState().Y)); Point selectionPoint = grid.WorldToMapCell(new Point((int)selectionLocation.X, (int)selectionLocation.Y)); int selectionOffset = 0; if ((selectionPoint.Y) % 2 == 1) selectionOffset = Tile.OddRowOffset; if (input.leftClick() && canMove == true) { desiredPosition.X = (selectionPoint.X * 64) + 32 + selectionOffset; desiredPosition.Y = (selectionPoint.Y * 16) + 48; } if (playerSprite.Position != desiredPosition) { canMove = false; if ((playerSprite.Position.X > desiredPosition.X) && (playerSprite.Position.Y > desiredPosition.Y)) { MoveNorthWest(); } else if ((playerSprite.Position.X > desiredPosition.X) && (playerSprite.Position.Y < desiredPosition.Y)) { MoveSouthWest(); } else if ((playerSprite.Position.X < desiredPosition.X) && (playerSprite.Position.Y > desiredPosition.Y)) { MoveNorthEast(); } else if ((playerSprite.Position.X < desiredPosition.X) && (playerSprite.Position.Y < desiredPosition.Y)) { MoveSouthEast(); } } else { moveDir = Vector2.Zero; } if (grid.GetCellAtWorldPoint(playerSprite.Position + moveDir).Collidable == true) { moveDir = Vector2.Zero; } if (Math.Abs(grid.GetOverallDepth(playerSprite.Position) - grid.GetOverallDepth(playerSprite.Position + moveDir)) > 10) { moveDir = Vector2.Zero; } if (moveDir.Length() != 0) { playerSprite.MoveBy((int)moveDir.X, (int)moveDir.Y); if (playerSprite.CurrentAnimation != animation) playerSprite.CurrentAnimation = animation; } else { playerSprite.CurrentAnimation = "Idle" + playerSprite.CurrentAnimation.Substring(4); canMove = true; } } public void MoveNorthEast() { moveDir = new Vector2(2, -1); animation = "WalkNorthEast"; } public void MoveNorthWest() { moveDir = new Vector2(-2, -1); animation = "WalkNorthWest"; } public void MoveSouthEast() { moveDir = new Vector2(2, 1); animation = "WalkSouthEast"; } public void MoveSouthWest() { moveDir = new Vector2(-2, 1); animation = "WalkSouthWest"; } [/CODE]
  4. Creating a camera class

    [quote name='dAND3h' timestamp='1338842283' post='4946221'] Maybe it is just me, but I don't really understand your question. You are using a Vector2 class with [left][background=rgb(250, 251, 252)]LWJGL and asking what the equivalent is in [/background][/left] [left][color=#282828][font=helvetica, arial, verdana, tahoma, sans-serif][size=3][background=rgb(250, 251, 252)]LWJGL ?[/background][/size][/font][/color][/left] [/quote] I'm asking what is the Java/LWJGL equivalent of a Vector2 from C#
  5. I'm in the process of porting my C#/XNA game to Java/LWJGL, but a few things I can't figure out. I'm using a Vector2f from LWJGL for a Vector2, but what are the equivalents of a Vector2 and the get/set accessors and the keyword value in Java with LWJGL? [CODE] #region Declarations private static Vector2 position = Vector2.Zero; private static Vector2 viewPortSize = Vector2.Zero; private static Rectangle worldBoundary = new Rectangle(0, 0, 0, 0); #endregion #region Properties public static Vector2 Position { get { return position; } set { position = new Vector2( MathHelper.Clamp(value.X, worldBoundary.X, worldBoundary.Width - ViewPortWidth), MathHelper.Clamp(value.Y, worldBoundary.Y, worldBoundary.Height - ViewPortHeight)); } } [/CODE]
  6. I'm attempting to convert my C# project that I have been working on to Java. I'll have more questions as I am converting it, but what is the Java equivalent of a Vector2 in C#? Will it require a framework or API?
  7. [quote name='alnite' timestamp='1333654553' post='4928577'] Reasons why games are not in saved in plain text to prevent cheating, and save bytes (binary format generally takes up less space in disks than text). If saved games are human-readable, then it makes it very easy for anyone to modify it. You can, for example, change your character stats all to 100 if you present them right there in plain text format. You can still do it even in binary, but at least it'd deter enough people. [/quote] I looked into saving data into binary format but I'm not very familiar with it. Is there any way to convert values into binary format through an online application? I get things like ô SOH NUL NUL
  8. I've been doing some research on ways to read and write data but don't know which is the best way to go about it. As for the writing data how do I go about saving? I went and looked through other game's save files. Why are some not in plain text? I assume they're encrypted or need to be opened with an appropriate editor. For loading from a file, I could create some values in a text file and have it read to the game but what if I wanted to add descriptions or commentary to the file so I know what values are which and not have it read by the game? I thought about using Regular Expressions to cut out the stuff I don't need when the game is reading but is that doing more than I really need to? I'm just throwing ideas around and hoping to get some feedback.
  9. I placed a new Game.ico in the path of the old one yet when I run my game the icon is just the default .exe icon Any ideas on why it won't load?
  10. I'm trying to create a menu for game using XNA. I'm using a button to trigger the change of the background to some other image but the new image is drawn then the previous background is drawn again. Main.cs [CODE] using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; using TestGame.Controls; using TestGame.GameStates; namespace TestGame { public class Main : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; InputHandler inputHandler; public SpriteBatch spriteBatch; public SpriteFont spriteFont; MainMenu mainMenu; Vector2 position; public Main() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; inputHandler = new InputHandler(); mainMenu = new MainMenu(this); graphics.PreferredBackBufferWidth = 1280; graphics.PreferredBackBufferHeight = 720; } protected override void Initialize() { this.IsMouseVisible = true; base.Initialize(); mainMenu.MenuInitialize(); } protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); spriteFont = Content.Load<SpriteFont>(@"Fonts\MainFont"); mainMenu.MenuLoadContent(); } protected override void UnloadContent() { } protected override void Update(GameTime gameTime) { inputHandler.Update(); if (inputHandler.currentKeyState.IsKeyDown(Keys.Escape)) this.Exit(); mainMenu.frameTime = gameTime.ElapsedGameTime.Milliseconds / 1000; MouseState mouseState = Mouse.GetState(); mainMenu.mouseX = mouseState.X; mainMenu.mouseY = mouseState.Y; mainMenu.previouslyPressed = mainMenu.mousePressed; mainMenu.mousePressed = mouseState.LeftButton == ButtonState.Pressed; base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Black); spriteBatch.Begin(); mainMenu.MenuDraw(); mainMenu.UpdateButtons(); spriteBatch.End(); base.Draw(gameTime); } } } [/CODE] MainMenu.cs [CODE] using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; namespace TestGame.GameStates { public class MainMenu { enum buttonState { hover, up, released, down } const int numberOfButtons = 4, newGameButtonIndex = 0, loadGameButtonIndex = 1, optionsButtonIndex = 2, quitButtonIndex = 3, buttonHeight = 48, buttonWidth = 80; Color[] buttonColor = new Color[numberOfButtons]; Rectangle[] buttonRect = new Rectangle[numberOfButtons]; buttonState[] buttonSt = new buttonState[numberOfButtons]; Texture2D[] buttonTexture = new Texture2D[numberOfButtons]; double[] buttonTimer = new double[numberOfButtons]; public bool mousePressed, previouslyPressed = false; public int mouseX, mouseY; public double frameTime; int buttonPadding; Main main; Texture2D backgroundImage; Texture2D backgroundImageFade; public MainMenu(Game game) { main = (Main)game; } public void MenuInitialize() { for (int i = 0; i < numberOfButtons; i++) { buttonSt[i] = buttonState.up; buttonColor[i] = Color.White; buttonTimer[i] = 0.0; buttonRect[i] = new Rectangle(0, buttonPadding, buttonWidth, buttonHeight); buttonPadding += buttonHeight; } } public void MenuLoadContent() { backgroundImage = main.Content.Load<Texture2D>(@"Backgrounds\titlescreen"); backgroundImageFade = main.Content.Load<Texture2D>(@"Backgrounds\titlescreenfade"); buttonTexture[newGameButtonIndex] = main.Content.Load<Texture2D>(@"Sprites\desktop"); buttonTexture[loadGameButtonIndex] = main.Content.Load<Texture2D>(@"Sprites\desktop"); buttonTexture[optionsButtonIndex] = main.Content.Load<Texture2D>(@"Sprites\desktop"); buttonTexture[quitButtonIndex] = main.Content.Load<Texture2D>(@"Sprites\desktop"); } public void MenuDraw() { main.spriteBatch.Draw(backgroundImage, new Vector2(0, 0), Color.White); for (int i = 0; i < numberOfButtons; i++) { main.spriteBatch.Draw(buttonTexture[i], buttonRect[i], buttonColor[i]); } } Boolean targetImageAlpha(Rectangle rect, Texture2D texture, int x, int y) { return targetImageAlpha(0, 0, texture, texture.Width * (x - rect.X) / rect.Width, texture.Height * (y - rect.Y) / rect.Height); } Boolean targetImageAlpha(float tx, float ty, Texture2D texture, int x, int y) { if (targetImage(tx, ty, texture, x, y)) { uint[] data = new uint[texture.Width * texture.Height]; texture.GetData<uint>(data); if ((x - (int)tx) + (y - (int)ty) * texture.Width < texture.Width * texture.Height) { return ((data[(x - (int)tx) + (y - (int)ty) * texture.Width] & 0xFF000000) >> 24) > 20; } } return false; } Boolean targetImage(float tx, float ty, Texture2D texture, int x, int y) { return (x >= tx && x <= tx + texture.Width && y >= ty && y <= ty + texture.Height); } public void UpdateButtons() { for (int i = 0; i < numberOfButtons; i++) { if (targetImageAlpha(buttonRect[i], buttonTexture[i], mouseX, mouseY)) { buttonTimer[i] = 0.0; if (mousePressed) { buttonSt[i] = buttonState.down; buttonColor[i] = Color.Blue; } else if (!mousePressed && previouslyPressed) { if (buttonSt[i] == buttonState.down) { buttonSt[i] = buttonState.released; } } else { buttonSt[i] = buttonState.hover; buttonColor[i] = Color.LightBlue; } } else { buttonSt[i] = buttonState.up; if (buttonTimer[i] > 0) { buttonTimer[i] = buttonTimer[i] - frameTime; } else { buttonColor[i] = Color.White; } } if (buttonSt[i] == buttonState.released) { onButtonClick(i); } } } void onButtonClick(int i) { switch (i) { case newGameButtonIndex: //main.spriteBatch.DrawString(main.spriteFont, "Creating new game", new Vector2(100, 200), Color.White); main.spriteBatch.Draw(backgroundImageFade, new Vector2(0, 0), Color.White); break; default: break; } } } } [/CODE]
  11. Nothing appears on screen when running

    [quote name='Mary Thurman' timestamp='1329638132' post='4914457'] I have the same problem, and I tried your suggested change too but it did not fix my problem at all! I am feeling stuck! Any other tips please? [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img] [/quote] I think the reason for my problem is that I was creating a new instance of each object in the constructors. So when Main read mainMenu = new MainMenu(); it would then read MainMenu's constructor which was main = new Main(); which would then go back and read mainMenu = new MainMenu(); creating a loop.
  12. Nothing appears on screen when running

    I managed to get it to run, but I don't understand why it worked. Main.cs [CODE] public class Main : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; InputHandler inputHandler; public SpriteBatch spriteBatch; SpriteFont spriteFont; MainMenu mainMenu; Vector2 position; Texture2D backgroundImage; public Main() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; inputHandler = new InputHandler(); [b]mainMenu = new MainMenu(this);[/b] graphics.PreferredBackBufferWidth = 1280; graphics.PreferredBackBufferHeight = 720; } [/CODE] MainMenu.cs [CODE] public class MainMenu { Main main; public MainMenu([b]Game game[/b]) { [b]main = (Main)game;[/b] } [/CODE] The bold is what I changed. Could anyone explained to me what I did?
  13. I go to debug my program but nothing appears on my screen. I open task manager and I can see the process though. Main.cs [CODE] using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media; using TestGame.Controls; using TestGame.GameStates; namespace TestGame { public class Main : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; InputHandler inputHandler; public SpriteBatch spriteBatch; SpriteFont spriteFont; MainMenu mainMenu; Vector2 position; Texture2D backgroundImage; public Main() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; inputHandler = new InputHandler(); mainMenu = new MainMenu(); graphics.PreferredBackBufferWidth = 1280; graphics.PreferredBackBufferHeight = 720; } protected override void Initialize() { this.IsMouseVisible = true; base.Initialize(); mainMenu.MenuInitialize(); } protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); spriteFont = Content.Load<SpriteFont>(@"Fonts\MainFont"); backgroundImage = Content.Load<Texture2D>(@"Backgrounds\titlescreen"); mainMenu.MenuLoadContent(); } protected override void UnloadContent() { } protected override void Update(GameTime gameTime) { inputHandler.Update(); if (inputHandler.currentKeyState.IsKeyDown(Keys.Escape)) this.Exit(); base.Update(gameTime); } protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Black); spriteBatch.Begin(); spriteBatch.Draw(backgroundImage, new Vector2(0, 0), Color.White); mainMenu.MenuDraw(); spriteBatch.End(); base.Draw(gameTime); } } } [/CODE] MainMenu.cs [CODE] using System; using System.Collections.Generic; using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; namespace TestGame.GameStates { public class MainMenu : Main { enum buttonState { hover, up, released, down } const int numberOfButtons = 4, newGameButtonIndex = 0, loadGameButtonIndex = 1, optionsButtonIndex = 2, quitButtonIndex = 3, buttonHeight = 48, buttonWidth = 80; Color backgroundButtonColor; Color[] buttonColor = new Color[numberOfButtons]; Rectangle[] buttonRect = new Rectangle[numberOfButtons]; buttonState[] buttonSt = new buttonState[numberOfButtons]; Texture2D[] buttonTexture = new Texture2D[numberOfButtons]; double[] buttonTimer = new double[numberOfButtons]; bool mousePressed, previouslyPressed = false; int mouseX, mouseY; double frameTime; int buttonPadding; public void MenuInitialize() { for (int i = 0; i < numberOfButtons; i++) { buttonSt[i] = buttonState.up; buttonColor[i] = Color.White; buttonTimer[i] = 0.0; buttonRect[i] = new Rectangle(0, buttonPadding, buttonWidth, buttonHeight); buttonPadding += buttonHeight; } } public void MenuLoadContent() { buttonTexture[newGameButtonIndex] = Content.Load<Texture2D>(@"Sprites\desktop"); buttonTexture[loadGameButtonIndex] = Content.Load<Texture2D>(@"Sprites\desktop"); buttonTexture[optionsButtonIndex] = Content.Load<Texture2D>(@"Sprites\desktop"); buttonTexture[quitButtonIndex] = Content.Load<Texture2D>(@"Sprites\desktop"); } public void MenuDraw() { for (int i = 0; i < numberOfButtons; i++) { spriteBatch.Draw(buttonTexture[i], buttonRect[i], buttonColor[i]); } } } } [/CODE]
  14. C# Chat Program

    How can I use userInput in my Analyze class so I can see if userInput contains certain text? I have something like this: [code] FormMain main; public void Analysis() { if (main.userInput.Text.Contains("asdf")) { } } [/code] But how can I reference userInput then analyze it and then modify chatOutput?
  15. C# Chat Program

    [quote name='Telastyn' timestamp='1324495949' post='4896271']<br />[quote]<br />I tried debugging it, but I can't figure out what's wrong.<br />[/quote]<br /><br />We don't know either since you didn't say <i>what the actual problem is.</i><br /><br />Well that's not true... The issue is that you're checking a new instance rather than the one with the actual input. But in the future it might not be so obvious.<br />[/quote]<br /><br /><br /> Sorry I'm still a bit new to programming. How can I reference userInput so I can use it instead of creating a new instance of it?