kostile

Members
  • Content count

    9
  • Joined

  • Last visited

Community Reputation

102 Neutral

About kostile

  • Rank
    Newbie

Personal Information

  • Interests
    Design
    Programming
  1. Just wanted to update you guys that I was able to get an understanding of using a generic set of parameters as an object. I ended up with this. public struct GenerericShapeAttributes { public int Amount; public float Delay; public float Radius; public Vector2 P1; public Vector2 P2; public bool IsCircle; public bool IsLine; public bool IsRandom; public bool IsSpiral; public int MaxIteration { get { return Amount - 1; } } } I moved the SpawnPolyGroup and SpawnGroup to the static class. They both now return arrays of Vector2 and are called GeneratePolygonVectors and GenerateBasicShapeVectors. The static class is now called ShapeBuilder. Only the GenerateBasicShapeVectors function takes the struct as a parameter and depending on which bool is flagged, it will determine which parameters to pass to which function. This will make it much easier to extend in the future with more patterns and logic. Thanks for the help guys and though I know it may not be perfect or pleasing to everyone, I would agree this structure is better and more pleasing to most people than my previous code. I did fix this issue and it took some thinking to get it done. The Line function wasn't the issue, but it was the parameters being passed to it. It did not return the end point but it will now that I have fixed my other functions that call Line. I also realized that I did not have the SpawnPolyGroup functioning correctly either. It "looked" like it was working as I was testing, but I had to change up the loop and the math to get it to account for the extra points that weren't being assigned in the array which would cause an exception if the array was only large enough to hold the amount of points that were actually supposed to be there. Thanks a lot guys
  2. I am reading what you guys are saying, but I don't see how this makes the code any less complex and more readable. The DirectX example I looked at doesn't really shed any light on this either. As I am searching through it seems like this is going to increase the complexity of my code and make it that much more harder to manage. I might not be fully understanding the concept behind what you guys are talking about. I need a way to pick a function to launch at "random" even when the parameters of each function are not identical, otherwise I will end up with extra params in functions that I don't need as placeholders to fit the Func or Delegate. The lines public static Func<int, int, Vector2, Vector2, Vector2> currentPattern = SpawnPatterns.Line SpawnPolyGroup(gameTime, new Vector2(800, 0), 5, 6); are hard coded, but this is not the way it will remain. I guess I should have said that this code was unfinished but I am looking at a way to randomize the information provided where SpawnPatterns.Line might be SpawnPatterns.Circle at one point, and each int and Vector2 will vary in SpawnPolyGroup to some degree once I have finished it, but I can hardly make out how putting the information to these into a struct will add any cleanliness to the code. Instead of using the Func should I just make a switch/case? EDIT: So I did some more thinking and is this what you guys were explaining to me? I have kept the Circle function in another class for now, just posting it like this right now to make it easier to view. public struct Pattern { public int MaxIterations; public float Radius; public Vector2 P1; public Vector2 P2; } public static Vector2 Circle(Pattern pattern, int currentIteration) { float radians = AOneMath.AngleToRadian(360/ pattern.MaxIterations); float x = (float)Math.Cos(radians * currentIteration); float y = (float)Math.Sin(radians * currentIteration); return new Vector2(pattern.P1.X + (x * pattern.Radius), pattern.P1.Y + (y * pattern.Radius)); }
  3. I will have to look into that. I have never tried to use structs for filling parameters. You wouldnt have an example or be able to elaborate a little? This is a totally new idea to me, and i have never thought about using structs for anything really.
  4. Your explanation of good code outlines it really well for me. I will have to revisit a lot of code with these ideas in mind. I'm well on my way of practicing good habits and i appreciate the feedback
  5. I see what you are saying about having params that aren't used but what would be a clean solution to that? The idea was to have the generic Func that i just call through the SpawnGroup function and i can easily change which function is called, either random, line, or circle, but this does end up having functions that use the paremeters differently as well as not using some at all.
  6. Thanks for the critique, I wasn't aware of the PascalCase for public variables convention but I am trying to follow the "standard" convention so that is good to know. I like the recommendations and will do this and continue to do this in the future. I'm am really glad to hear that this isn't terrible because like I said, it is more recent code that I think looks much better than most of my previous.
  7. I really don't know what is considered better or even good for the most part. My code varies and has evolved over the years as a developer and sometimes I think it looks cleaner, but it is never easy to edit or add something. I fight with myself when writing things like particle engines because I know the purpose of a particle engine is to be quick and efficient, but how much overhead is there really just by giving a reference of an emitter to a particle that is contained within it? Why should I write behaviors for particles as functions that return a value vs just writing a function that returns nothing but handles all of the behavior? I feel like with the latter I end up with code that is easier to modify, but it looks terrible. With the previous I end up with very clean code but is god awful to edit as I have one iteration loop that basically controls everything based on the function it is given. Here is some more recent code I have written that I think would be considered "good" but I am really not sure. The gist of this code is that it will spawn an enemy in a pattern that right now is determined by the writer. I will eventually write functions that determine which shape should be spawned when and where, but right now it just will spawn a shape from the SpawnPolyGroup function with 5 enemies per line and 6 lines in the shape. So it makes a hexagon with 5 enemies per line. My question is, is it better to have the SpawnGroup function control the for loop and return values from each SpawnPatterns (being Vector2 as locations), or would it be better to have each function in the SpawnPatterns class have it's own iterative loop? Also, any other tips on my code for cleanliness and professionalism would be great. I am self taught and never had a tutor, but have read a lot about people being self taught writing code that is unprofessional, but I have never reached out for someone to look at my code aside from a few people so I am hoping that I can learn something to be more professional in the future in hopes to find a paying job as a programmer. public static class Spawner { public static bool isSpawning = false; public static float spawnTimer = 0; public static bool groupSpawning = false; public static Dictionary<Enemy, float> delayedSpawnDict = new Dictionary<Enemy, float>(); public static float timeDelta = 0; //Arguments for currentPattern should be (int maxEnemies, int currentIteration, int radius, Vector2 PatternLocation) public static Func<int, int, Vector2, Vector2, Vector2> currentPattern = SpawnPatterns.Line; public static void Update(GameTime gameTime) { if (!isSpawning) { return; } if (timeDelta > 0) { timeDelta -= gameTime.ElapsedGameTime.Milliseconds; } if (timeDelta <= 0 && delayedSpawnDict.Count() > 0) { KeyValuePair<Enemy, float> pair = delayedSpawnDict.ElementAt(0); Enemies.enemies.Add(pair.Key); pair.Key.Spawn(); timeDelta = pair.Value; delayedSpawnDict.Remove(pair.Key); } //If enemies alive is greater than max enemies then do not spawn if (Enemies.enemies.Count + delayedSpawnDict.Count() >= 1) { return; } //Spawn Individual if (spawnTimer >= 500) { SpawnPolyGroup(gameTime, new Vector2(800, 0), 5, 6); spawnTimer = 0; } spawnTimer += gameTime.ElapsedGameTime.Milliseconds; } public static void SpawnGroup(GameTime gameTime, Vector2 location, Vector2 mod1, int amount = 5, float delay = 100) { for (int i = 0; i < amount; i++) { Vector2 enemyLocation = currentPattern(amount, i, mod1, location); if (enemyLocation == default(Vector2)) { return; } Enemy enemy = new Enemy(15, Assets.hollowCircle, enemyLocation, EnemyUtilities.Follow, 500); if (delay > 0) { delayedSpawnDict.Add(enemy, delay); } else { Enemies.enemies.Add(enemy); } } } public static void SpawnPolyGroup(GameTime gameTime, Vector2 location, int amount = 5, int sides = 5) { float radians = AOneMath.AngleToRadian(360 / sides); float rotation = AOneMath.AngleToRadian(90 * (sides % 2)); for (int i = 0; i < sides; i ++) { int distanceFromCenter = 200; float x1 = location.X + (float)Math.Cos(radians * i + rotation) * distanceFromCenter; float y1 = location.Y + (float)Math.Sin(radians * i + rotation) * distanceFromCenter; Vector2 p1 = new Vector2(x1, y1); float x2 = location.X + (float)Math.Cos(radians * (i + 1) + rotation) * distanceFromCenter; float y2 = location.Y + (float)Math.Sin(radians * (i + 1) + rotation) * distanceFromCenter; Vector2 p2 = new Vector2(x2, y2); SpawnGroup(gameTime, p2, p1, amount); } } } public static class SpawnPatterns { /// <param name="radius">Radius, Best to have X and Y the same</param> /// <param name="patternLocation">Center location of circle</param> /// <returns>Enemy location based on current iteration of max from radius to the patternLocation as the center</returns> public static Vector2 Circle(int max, int current, Vector2 radius, Vector2 patternLocation) { float radians = AOneMath.AngleToRadian(360/max); float x = (float)Math.Cos(radians * current); float y = (float)Math.Sin(radians * current); return new Vector2(patternLocation.X + (x * radius.X), patternLocation.Y + (y * radius.Y)); } /// <param name="pointB">The end point where the last enemy should be in the line</param> /// <param name="pointA">The start point where the first enemy should be in the line</param> /// <returns>Enemy location based on current iteration of max from pointA to pointB</returns> public static Vector2 Line(int max, int current, Vector2 pointA, Vector2 pointB) { float x = MathHelper.Lerp(pointA.X, pointB.X, (float)current / (float)max); float y = MathHelper.Lerp(pointA.Y, pointB.Y, (float)current / (float)max); return new Vector2(x, y); } /// <param name="p1">Top left point of area to spawn randomly</param> /// <param name="p2">Bottom right point of area to spawn randomly</param> public static Vector2 Random(int max, int current, Vector2 p1, Vector2 p2) { float x = AOneMath.random.Next((int)p1.X, (int)p2.X); float y = AOneMath.random.Next((int)p1.Y, (int)p2.Y); return new Vector2(x, y); } }
  8. What engines do you use, and why

    I have been using the xna and more recently the monogame frameworks. These options provide a high level of code for tasks that i just prefer not to deal with such as image loading, sounds and so forth. With these tools it makes it quick to produce your item engine with as much flexibility that you need. Running in dot net gives out the added bonus of being pretty efficient. I'm not a huge fan of all in one editors such as unity. I feel to separated from the code at times and i feel it takes a much larger learning curve to pick up on a full engine rather than brewing something in house where you only have to focus on the pieces you need. That being dai said i do feel that monogame and mono have some draw backs. I would prefer to do all of my development in Linux and release and compile for Android, linux and Windows but I just came get xamarin.android to compile and work with Linux. Other than that i am very happy with it. I'm surprised i dont see more people using monogame. It's probably the easiest and cleanest framework to use when developing 2D games.
  9. I have been using xna and monogame for a few years now and i am curious about this. Are you able to boast any improvements or anything? Monogame is open source and it seems like this is redundant unless there is some major overhead difference that I'm not aware of.