• Content count

  • Joined

  • Last visited

Community Reputation

100 Neutral

About Proudest

  • Rank
  1. I'm interested in creating a small trainer for a single player game I have and want to know how to read/write memory with C# given a specific memory address. I found the memory addresses which hold the score (int '004F19EC') and player x position (float '01150630') and want to use them to produce variables in C# to track them and manipulate them. I couldn't find much info on how to do this. It seems I use the Marshal class but I'm having trouble figuring it out.
  2. I know this thread is a month old, but I'll post my method in case anyone wants to know. I use a finite state machine (FSM) pattern to produce tile based movement seen in many old console RPGS (FF4/5/6). C# using XNA enum State { Idle, MoveUp, MoveRight, MoveDown, MoveLeft } class Player { Vector2 position; Vector2 destination; float speed; State state; public Player() { position = new Vector2(32, 32); destination = position; speed = 128; state = State.Idle; } public void Update(KeyboardState keyState, float elapsed) { switch (state) { #region Idle case State.Idle: if (keyState.IsKeyDown(Keys.Up)) { destination.Y -= 32; state = State.MoveUp; direction = Direction.Up; } else if (keyState.IsKeyDown(Keys.Down)) { destination.Y += 32; state = State.MoveDown; direction = Direction.Down; } else if (keyState.IsKeyDown(Keys.Left)) { destination.X -= 32; state = State.MoveLeft; direction = Direction.Left; } else if (keyState.IsKeyDown(Keys.Right)) { destination.X += 32; state = State.MoveRight; direction = Direction.Right; } break; #endregion #region MoveUp case State.MoveUp: if (position.Y - speed * elapsed < destination.Y) { position.Y = destination.Y; state = State.Idle; } else position.Y -= speed * elapsed; break; #endregion #region MoveDown case State.MoveDown: if (position.Y + speed * elapsed > destination.Y) { position.Y = destination.Y; state = State.Idle; } else position.Y += speed * elapsed; break; #endregion #region MoveLeft case State.MoveLeft: if (position.X - speed * elapsed < destination.X) { position.X = destination.X; state = State.Idle; } else position.X -= speed * elapsed; break; #endregion #region MoveRight case State.MoveRight: if (position.X + speed * elapsed > destination.X) { position.X = destination.X; state = State.Idle; } else position.X += speed * elapsed; break; #endregion } } } The idea is to only accept input when the player is idle. Once the player presses the right arrow key, the state is changed to 'state.MoveRight' and the destination.X is incremented 32 pixels (one tile). The state machine runs the code for state.MoveRight and sets the state to 'state.Idle' once the destination matches with position (once player reaches destination). You also want to make sure not to 'overstep' the destination, so I use pre-emptive movement to detect this. case State.MoveRight: if (position.X + speed * elapsed > destination.X) // if potential movement surpasses destination { position.X = destination.X; // move directly to destination state = State.Idle; } else // otherwise position.X += speed * elapsed; // move normally
  3. Quote: What if the enemy at [0,1] moves to [3,5]? Are you going to try to 'remember' enemy movement so that you can tell if the enemy at [3,5] is the same enemy you attacked last round rather than a new enemy? My example was inadequate. Since this is a tactical rpg, I'll use the curor's position to know where the enemy is. Here you can see what I mean by the cursor (the white tile selector with 4 corners). I'd put the cursor over tile [3, 5] and type "player.Attack(cursor.X, cursor.Y)". As far as remembering my last enemy, I might use that method for AI.
  4. It seems logical for each tile to hold a person because I want to dynamically and anonymously manipulate people in the tilemap based on a tile position. I don't want to keep track of each person and directly manipulate them. For example, suppose the player is at tile [0, 0], and there's an enemy at tile [0, 1]. In order to attack the enemy, I would write player.Attack(0, 1) as opposed to player.Attack(enemy). When I think of decoupling the people from the tilemap, I imagine using an ArrayList instead. It seems easier to directly access the person in an array (tilemap) as opposed to "looking him up" in an ArrayList first. There are probably other methods I'm not considering which you were implying. Maybe an example could help.
  5. I'm working on a 2D tile based tactical rpg similar to Fire Emblem and have some questions. I feel there's room for improvement in the way I store and move people on my tilemap. Here's my current implementation. class Person { // snipped } class Tile { Person person; // current person occupying tile } class Level { Tile[20, 15] tiles; // 2d array of tiles (tilemap) public void Draw() { // loop through each tile in array for (int x = 0; x < 20; x++) { for (int y = 0; y < 15; ++y) { // draw current tile // tileset.Draw(source, x * 32, y * 32); // draw person on current tile (if one exsists) if (tiles[x, y].Person != null) tiles[x, y].Person.Draw(); } } } // creates a new person, places it at x, y on level, and returns the instance for future reference public Person AddPerson(int x, int y) { Person person = new Person(); // create new person person.Level = this; // give person reference to level (needed so person can access tilemap when moving) person.X = x; person.Y = y; tiles[x, y].Person = person; return person; } } Here's an example of how these classes are used. Level town = new Level(); Person player = town.AddPerson(0, 0); // add player to tile [0, 0] on tilemap player.X += 1; // move player right one tile The way I handle movement of people and storage of people in my tilemap seems clunky and hacked together. Does anyone have suggestions for a more elegant and intuitive way to handle this?
  6. I figured out my problem. I changed the texture filter from none to linear. textures.Add(new Texture(device, filePath, 0, 0, 0, 0, Format.A8R8G8B8, Pool.Managed, Filter.None, Filter.None, Color.Magenta.ToArgb(), false, new PaletteEntry[0])); textures.Add(new Texture(device, filePath, 0, 0, 0, 0, Format.A8R8G8B8, Pool.Managed, Filter.Linear, Filter.None, Color.Magenta.ToArgb(), false, new PaletteEntry[0])); Other filters seem to work also, I tried point and box.
  7. 2d vector direction calculation based on angle

    Thanks guys, that worked.
  8. I'm making a small 2D projectile demo in C# + DirectX and need help with my vector calculations. The projectile is a 32x32 pixel arrow image with the following class. class Arrow { Vector3 position; Vector3 velocity; Vector3 direction; float speed; float angle; public Arrow() { position = new Vector3(200, 200, 0); velocity = new Vector3(0, 0, 0); direction = new Vector3(0, 0, 0); speed = 150; // 150 pixels per second angle = 0; } public void Update(float frameTime) { // move forward if (keyboard.GetKey(Keys.Up)) position += velocity * frameTime; // move backward if (keyboard.GetKey(Keys.Down)) position -= velocity * frameTime; // set angle if (keyboard.GetKey(Keys.Left)) angle -= speed * frameTime; if (keyboard.GetKey(Keys.Right)) angle += speed * frameTime; // set direction direction.X = (float)Math.Cos(Geometry.DegreeToRadian(angle)); direction.Y = (float)Math.Sin(Geometry.DegreeToRadian(angle)); // set velocity velocity = direction * speed; } public void Draw(Graphics graphics) { graphics.Sprite.Transform = Matrix.Translation(-position + new Vector3(-16, -16, -16)) * // translate to center (16 = 32/2 = center) Matrix.RotationZ(Geometry.DegreeToRadian(angle)) * // rotate while centered Matrix.Translation(position + new Vector3(16, 16, 16)); // translate back graphics.DrawSprite(textureID, new Rectangle(0, 0, 32, 32), position.X, position.Y, angle); } } My problem is, with the default angle of 0º, the direction is facing right (1, 0) when it seems it should be facing up (0, -1). Since this is my first attempt at vector math, it's probably something silly dealing with calculating direction. Any help is appreciated.
  9. I'm using Direct3DX.Sprite with C# to rotate sprites and have a problem. I have an arrow sprite which rotates clockwise/counter clockwise 30º when the left/right keys are pressed. The shadow is only visible at certain angles, and when scaled to 2x, the shadow doesn't appear at all. In the example below, the shadow gets darker when it gets closer to the red degrees, and lightens when it gets near the black degrees. public Graphics(System.Windows.Forms.Control control) { PresentParameters pp = new PresentParameters(); pp.IsWindowed = true; pp.SwapEffect = SwapEffect.Discard; pp.PresentationInterval = PresentInterval.One; device = new Device(0, DeviceType.Hardware, control.Handle, CreateFlags.HardwareVertexProcessing, pp); sprite = new Sprite(device); } public void BeginRender() { device.Clear(ClearFlags.Target, Color.LightSteelBlue, 1, 0); device.BeginScene(); sprite.Begin(SpriteFlags.AlphaBlend | SpriteFlags.SortDepthFrontToBack); device.SamplerState[0].MinFilter = TextureFilter.None; device.SamplerState[0].MagFilter = TextureFilter.None; } public void EndRender() { sprite.End(); device.EndScene(); device.Present(); } public int LoadTexture(string filePath) { textures.Add(new Texture(device, filePath, 0, 0, 0, 0, Format.A8R8G8B8, Pool.Managed, Filter.None, Filter.None, Color.Magenta.ToArgb(), false, new PaletteEntry[0])); } public void DrawSprite(Texture texture, Rectangle source, float x, float y, float angle) { // translate sprite to origin (16 = center of 32 pixel image) > rotate sprite at origin > translate sprite back to original position > scale sprite to 100% sprite.Transform = Matrix.Translation(-x -16, -y -16, 0) * Matrix.RotationZ(Geometry.DegreeToRadian(angle)) * Matrix.Translation(x + 16, y + 16, 0) * Matrix.Scaling(1, 1, 0); sprite.Draw(texture, source, Vector3.Empty, new Vector3(x, y, 0), Color.White); } Does anyone have an idea on what's causing this?
  10. I want to create a console that will allow me to run methods at runtime based on input from a textBox. For example, suppose I have these functions: public void ShowHello() { MessageBox.Show("hello"); } public void ShowText(string text) { MessageBox.Show(text); } I want to be able to type the following in to the textBox: ShowHello(); // opens MessageBox showing "hello" ShowMessage("test"); // opens MessageBox showing "test"
  11. ajones: The 2nd 3rd and 4th pics are from an open source TRPG called Galaxy Mage. If anyone else has any suggestions, I'd like to hear them.
  12. I'm creating a 3D tactical rpg like Final Fantasy Tactics in DirectX and wonder how I should create the levels. Here are examples of the type of level I'm talking about. I can think of a few methods to use: 1) use an existing 3D modeller like DeleD to create the level and export the mesh. Here's something I made with it. 2) create my own code which plots the vertices for each tile then loads them into a vertex buffer. 3) create my own level editor Any recommendations are welcome. [Edited by - Proudest on May 5, 2006 8:25:27 PM]
  13. I have an assembly named "Engine.dll" which contains a "Root" class and "TextureManager" class. Root contains a TextureManager instance which is accessed externally through a public property. namespace Engine { public class Root { TextureManager textureManager; public Root { textureManager = new TextureManager(); } public TextureManager TextureManager { get { return textureManager; } } } public class TextureManager { internal TextureManager() //internal constructor { // } public void LoadTexture() { // } } } namespace Program { using Engine; static void Main() { Program program = new Program(); } public Program() { Root root = new Root(); //creates TextureManager instance root.TextureManager.LoadTexture(); } } With the internal constructor, I successfully prevent the end user from creating his own TextureManager instance. He has to use the one I provide. Is it possible to hide the TextureManager class from the outside while still allowing access through the public property in Root? namespace Program { using Engine; static void Main() { Program program = new Program(); } public Program() { //I still want this to be possible (visible through root) Root root = new Root(); //creates TextureManager instance root.TextureManager.LoadTexture(); //But not this (invisible without root) TextureManager myTextureManager; } } I want the class to appear private outside of the Engine but still accessible through the root class from the outside. If normal classes don't allow it, is there a way to allow this with interfaces?
  14. I had the same problem a while back and just use an arraylist which keeps track of which keys have been held down. I have the original GetKey function and the additional GetKeyOnce function. //[C# + MDX 2.0] class Keyboard { Device deviceKeyboard; KeyboardState keyState; ArrayList handled; public void Update() { keyState = deviceKeyboard.CurrentKeyboardState; } public bool GetKey(Key key) { return keyState[key]; } public bool GetKeyOnce(Key key) { if (keyState[key]) // if key was pressed { if (handled.Contains(key)) // if key was handled { return false; } else // if key wasnt handled { handled.Add(key); // handle key return true; } } else // if key wasn't pressed { handled.Remove(key); // unhandle key return false; } } } You probably already solved your problem, but I thought it would be useful to someone. I havent tried buffered input yet, that might be a better option.