Jump to content
  • Advertisement

DominicBridge

Member
  • Content Count

    5
  • Joined

  • Last visited

Community Reputation

123 Neutral

About DominicBridge

  • Rank
    Newbie

Personal Information

  • Interests
    |programmer|
  1. DominicBridge

    Seamless map Integration

    Hey guys, Definitely going to be a regular here... Anyway, for my game I'm looking into seamless maps. Not sure if its the correct term but it basically means I don't have any loading screens or map transitions. I'm wondering on different theories to get this working.   My first thought would be to load nine maps, 1 2 3  4 5 6 7 8 9   Assuming the player is always in 5, when it moves to 6 it will be done like this 2 3 10 5 6 11 8 9 12   But drawing this code would mean accessing different variables and be a ballache.   Would it be better to made load them, but just replacing number 5s end lines with the next map?   Any reading or theory on this would be much appreciated, any language is fine but C# is preferred.   Thanks guys, I feel like I'm really over thinking this.   Should mention that this is also a 2d Tile Map
  2. DominicBridge

    Advice for writing good code

    Things you NEED to know: - All of the features of your debugger. - All of the features of your profiler. - Everything related to unit testing. - Everything related to integration testing. Programming guidelines: - Do the simplest thing that could possibly work. - Don't write code that you aren't going to use NOW. - Delete code which is not being used. - Delete code which is not covered by a unit test. - If you KNOW something will perform terribly, optimize it now. Otherwise, profile it later. - Keep variables as short-lived (or encapsulated) as possible (locals > parameters > closures > private members >>>> public members >>>>>> thread statics >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> globals) - Keep variables in valid states at all times (don't leave things null, set them to invalid values, or use types which even allow invalid values in the first place). - Avoid keeping variables which mean the same thing in multiple places. - Use immutable variables until you're *sure* you need mutable ones. - Make constants for your magic numbers now, not later. - Keep your functions as short as possible. If you find yourself writing a big function, split it up. - Avoid inheritance until you are absolutely sure you need it. - Prefer simple functions and functional style over classes. Don't use classes until you need them. - When you have classes, ensure that their instances are always in a valid state. - Refactor frequently, and use unit tests to catch refactoring mistakes. - Don't use threads until you ABSOLUTELY know what you're doing. - Never use linked lists. - Never concatenate strings using the + operator in .NET.   Some of these are fantastic, especially magic numbers, it's so easy to make a rectangle draw at 32,32 but if you ever change that, Going through all the code is a ballache.   However can you explain the last one? Not sure why that would  be an issue.
  3. DominicBridge

    Event based Menu System

    Aye you're correct I have this now Menu.cs if (OldKS.IsKeyDown(Keys.Enter) && KS.IsKeyUp(Keys.Enter)) { MenuItems[SelectedMenuItem].ButtonChose(); } MenuItem.cs public void ButtonChose() { this.ButtonChosen(); } I can't call menuItems[SelectedMenuItem].ButtonChosen(); Directly from another class, but this works.   Thank you very much for the help and pointers :)
  4. DominicBridge

    Event based Menu System

    I only read your first sentence and immediately released. Sometime it just takes a a fresh set off eyes!   I changed the menu.cs to for (int i = 0; i < MenuItems.Count; i++) { if(i == SelectedMenuItem) MenuItems[i].Update(KS, OldKS); } All works now. Thank you kindly sir!
  5. DominicBridge

    Event based Menu System

         Hey guys,   First of all I'm using MonoGame (I miss you XNA).   I've always done menus quite badly, but for my new game that require a lot of menus I'd like it to be a bit better.   So its still fairly skeleton at the moment. but it looks like this public class Menu { List<MenuItem> MenuItems; private SpriteFont Font; private string FontName; private Vector2 Position; private int SelectedMenuItem = 0; public Menu(ContentManager content, Vector2 Position, string fontName = "Arial36") { MenuItems = new List<MenuItem>(); FontName = fontName; this.Position = Position; this.LoadContent(content); } private void LoadContent(ContentManager content) { Font = content.Load<SpriteFont>("Fonts/" + FontName); } public void AddItems(MenuItem menuItem) { MenuItems.Add(menuItem); } public void Update(GameTime gameTime, KeyboardState KS, KeyboardState OldKS) { if(OldKS.IsKeyDown(Keys.Up) && KS.IsKeyUp(Keys.Up)) { SelectedMenuItem--; } if (OldKS.IsKeyDown(Keys.Down) && KS.IsKeyUp(Keys.Down)) { SelectedMenuItem++; } foreach (MenuItem menuItem in MenuItems) menuItem.Update(KS, OldKS); if (SelectedMenuItem <= -1) SelectedMenuItem = MenuItems.Count - 1; else if (SelectedMenuItem >= MenuItems.Count) SelectedMenuItem = 0; } And MenuItems public class MenuItem { public string Text { get; set; } public delegate void OnChose(); public event OnChose ButtonChosen; public MenuItem(string text) { this.Text = text; } public void Update(KeyboardState KS, KeyboardState OldKS) { if (OldKS.IsKeyDown(Keys.Enter) && KS.IsKeyUp(Keys.Enter)) { ButtonChosen(); } } } Now finally to use this code I use            MenuItem LoadGame = new MenuItem("Load Game"); LoadGame.ButtonChosen += LoadGame_ButtonChosen; MainMenu.AddItems(LoadGame); MenuItem NewGame = new MenuItem("NewGame"); NewGame.ButtonChosen += NewGame_ButtonChosen; ; MainMenu.AddItems(NewGame);               private void NewGame_ButtonChosen()         {             throw new NotImplementedException();         }           private void LoadGame_ButtonChosen()         {             throw new NotImplementedException();         }     However, even when New Game is selected, LoadGame_ButtonChosen() Is always selected.   Can't quite work out where to go from here. Any advice would be fantastic  
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!