Doggolainen

Members
  • Content count

    38
  • Joined

  • Last visited

Community Reputation

115 Neutral

About Doggolainen

  • Rank
    Member
  1. Arena - Debut Trailer

    Here is the first trailer for a game we've been doing. http://www.youtube.com/watch?v=LjlhHGZcOu0
  2. Im working on a 2D fighting/platformer game. As it is now it works fine, I handle movement by adding vectors to a Velocity vector. [source lang="csharp"]Velocity += v;[/source] Then at the end of each frame, where elapsedTime is the time elapsed since previous frame. [source lang="csharp"]Velocity += gravity; //Apply gravity Position += Velocity * elapsedTime; //Move the object Velocity *= 0.8f; //Friction[/source] Now to the problem: My above functionallity only works accurate if the game is running at 60 fps since the friction multiplication is not time varying, but a constant. Ive tried where I divide the elapsedTime by the target fps. [source lang="csharp"]Velocity *= 0.8f/0.016f * elapsedTime;[/source] I think I have to use Math.Pow() for this to work, but I cant get my head around it.
  3. Im making a ray or a "laser" for my game using GL_LINES. I want the laser to have a strong clear light in the middle and to get more and more transparent at the edges. For this I want to do a point - line distance calculation in the fragment shader. To my vertex shader I send, vertices for the laser, a directional vector for each vertex and also the modelview matrix. I wish to make something similar to this[i] (see quote/link below)[/i], but I cant get the calculations for [b]gEndpoints[2] [/b]and [b]gPosition [i](gl_FragCoord?) [/i][/b]correct. I wish to translate my vertex coordinates into the same coordinate space as the gl_FragCoord. I've tried numerous variations by googling the problem and some bruteforce matrix multiplications but I just cant get it right. Any help would be greatly appreciated. [quote] [b] Glow With Point-Line Distance[/b] [url="http://prideout.net/blog/p61/Glow.png"][img]http://prideout.net/blog/p61/MediumGlow.png[/img][/url] Here’s my fragment shader for Tron-like glow. For this to link properly, the geometry shader needs to output some screen-space coordinates for the nodes in the line strip ([b]gEndpoints[2][/b] and [b]gPosition[/b]). The fragment shader simply computes a point-line distance, using the result for the pixel’s intensity. It’s actually computing distance as “point-to-segment” rather than “point-to-infinite-line”. If you prefer the latter, you might be able to make an optimization by moving the distance computation up into the geometry shader. [left] [size=1][size=1] [/size][/size][/left] [CODE] uniform vec4 Color; varying vec2 gEndpoints[2]; varying vec2 gPosition; uniform float Radius; uniform mat4 Projection; // Return distance from point 'p' to line segment 'a b': float line_distance(vec2 p, vec2 a, vec2 b) { float dist = distance(a,b); vec2 v = normalize(b-a); float t = dot(v,p-a); vec2 spinePoint; if (t > dist) spinePoint = b; else if (t > 0.0) spinePoint = a + t*v; else spinePoint = a; return distance(p,spinePoint); } void main() { float d = line_distance(gPosition, gEndpoints[0], gEndpoints[1]); gl_FragColor = vec4(vec3(1.0 - 12.0 * d), 1.0); } [/CODE] [/quote] [url="http://prideout.net/blog/?p=61"]http://prideout.net/blog/?p=61[/url] - link to the page
  4. Circle to 2D-array

    I want to remove the overlap between a 2D-array containing a circle and another 2D-array containing alpha values of a pictures. (Think an explosion in liero or worms) But my problem is creating the circle 2D-array from a given radius. I've been looking into the midpoint circle algorithm a little bit, but I cant find any good hits on filled circles. int[,] CreateCircle(float radius) { //return a int matrix where 1 is a pixel part of the circle and 0 is outside the circle }
  5. Generic dynamic call in C#

    [quote name='TheTroll' timestamp='1322508307' post='4888542'] [quote name='Doggolainen' timestamp='1322505753' post='4888525'] [quote name='TheTroll' timestamp='1322503877' post='4888513'] This is what events are for. I have no idea why you are trying to develop your own messaging system inside a .net app. [/quote] I want my components to be loosely coupled. I havent figured out a way yet to use Delegates/Events to get the result that I'm aiming for. [url="http://devlicio.us/blogs/rob_eisenberg/archive/2011/05/30/caliburn-micro-soup-to-nuts-part-8-the-eventaggregator.aspx"]http://devlicio.us/b...aggregator.aspx[/url] My system is/will be very similar to the things described in the article above. [/quote] Events are about as loosely coupled as you can get. The problem is that we don't understand what your end goal is. So what is your end goal? [/quote] Well the article pretty much sums up what I'm trying to implement. I'm making an Entity system for my game, where components can send messages independently without knowing who is listening on the other side (sounds like events, yes). But I dont want any of the components to hold the event itself, I want that the Entity class (which is a container for the components) to be in controll and contain all of the events. But to avoid reusage of code where the compoentents have to subscribe/unsubscribe on an event their selves, I just want to let a component implement an interface with the message/messages their interessted of and let the engine call them accordingly whenever the message is fired. Again, look at the article, thats what triggered me into doing this.
  6. Generic dynamic call in C#

    [quote name='Telastyn' timestamp='1322495187' post='4888464'] [quote name='Doggolainen' timestamp='1322492708' post='4888444'] I'm implementing a message system for my entity/component system. What I do is basicly let components implement a IMessageHandle<T> where T is IMessage. Then I inherit from IMessage for diffrent types of messages. For instance DrawMessage extends IMessage. [/quote] I wouldn't use inheritance here, but whatever. [/quote] I meant implementation IMessage is an interface. [quote name='Telastyn' timestamp='1322495187' post='4888464'] [quote] But my C# reflection skills are to weak for me to figure it out. Anyone got any advice on how to implement this, cause it would really make my code feel more clean and easier to use! [/quote] There's not enough code here to really figure out what you're doing. But as soon as you start checking types, it's a code smell. Personally I'd look into simply having a dictionary of delegates (remember, delegates are multicast) and simply adding/removing entries from that. [/quote] Well I use the type checking in very primitve functions that wont affect the end user.
  7. Generic dynamic call in C#

    [quote name='TheTroll' timestamp='1322503877' post='4888513'] This is what events are for. I have no idea why you are trying to develop your own messaging system inside a .net app. [/quote] I want my components to be loosely coupled. I havent figured out a way yet to use Delegates/Events to get the result that I'm aiming for. [url="http://devlicio.us/blogs/rob_eisenberg/archive/2011/05/30/caliburn-micro-soup-to-nuts-part-8-the-eventaggregator.aspx"]http://devlicio.us/b...aggregator.aspx[/url] My system is/will be very similar to the things described in the article above.
  8. I'm implementing a message system for my entity/component system. What I do is basicly let components implement a IMessageHandle<T> where T is IMessage. Then I inherit from IMessage for diffrent types of messages. For instance DrawMessage extends IMessage. The following code works and is in the Entity class. It calls all the added components that implements the IMessageHandle for the given IMessage. [code] public void FireMessage<T>(IMessage message) where T : IMessage { List<Component> receivers = messageTable[typeof(IMessageHandle<T>)]; foreach (Component c in receivers) CallMethod(c, "Handle", message); }[/code] I use a hashtable/dictionary and C# magic for optimizing the call. [code] public void AddComponent(Component component) { components.Add(component.GetType(), component); Type[] types = component.GetType().GetInterfaces(); foreach (Type t in types) { //if (!t.IsAssignableFrom(typeof(IMessageHandle<IMessage>))) // continue; if (!messageTable.ContainsKey(t)) messageTable[t] = new List<Component>(); messageTable[t].Add(component); }[/code] What I want to do instead is something like this: [code] public void FireMessage(IMessage message) { Type t = message.GetType(); List<Component> receivers = messageTable[typeof(IMessageHandle<t>)]; foreach (Component c in receivers) CallMethod(c, "Handle", message); }[/code] But my C# reflection skills are to weak for me to figure it out. Anyone got any advice on how to implement this, cause it would really make my code feel more clean and easier to use! //Doggolainen
  9. Vector rotation and mirroring

    I'm making this 2D game where I want several textures move accordingly to another texture. So right now I got this [i]body [/i]where the [i]head[/i] has to rotate around an axis accordingly to the [i]body[/i] when the [i]body[/i] rotates. The following code does the trick: [code] Vector2 spatialPosition; //The global position Vector2 origin; // Origin relative the position Vector2 position; //Local position of the texture to draw i.e. the heads position relative the body. Vector2 bodyPosition; //The local position of the body Vector2 bodyOrigin; //origin of the body relative the bodyPosition public void Draw(SpriteBatch spriteBatch, bool mirror, Camera camera, Vector2 spatialPosition,Vector2 bodyPosition, Vector2 bodyOrigin, float bodyRotation) { Vector2 positionOffset = RotateAroundPoint(position, bodyOrigin, bodyRotation); if (!mirror) { spriteBatch.Draw(texture, positionOffset + spatialPosition - camera.Position, null, Color.White, rotation + bodyRotation, origin, 1, SpriteEffects.None, 0); } }[/code] As mentioned earlier - the code seen above works correctly. I do however want to mirror the image depending wheter the character is facing right or left, this code on the other hand does not work. It only works if the body is not rotated. The hardcoded "100" is the width of the body texture. [code] else { spriteBatch.Draw(texture, new Vector2(100 - positionOffset.X - texture.Width + origin.X * 2, positionOffset.Y) + spatialPosition - camera.Position, null, Color.White, -rotation - bodyRotation, origin, 1, SpriteEffects.FlipHorizontally, 0); }[/code] So anyone good at algebra out there, please help me solve this nut.
  10. [quote name='JTippetts' timestamp='1300407367' post='4787238'] [quote name='Doggolainen' timestamp='1300317792' post='4786791'] I've been into the idea of message passing between entities in my game framework. But I always get stuck on on how to implement the argument passing correctly for the messages. I always end up with ugly typecasts on the other end (the entity that receives the message). In your case, I assume you pass some kind of float value along with the "ModifyLife" message. Could you please tell me how you would implement the receiving part of that message? [/quote] Well, since all my high-level logic is handled in Lua rather than C++, it's not really an issue. I just populate a table and pass that as the arguments for the message. [/quote] Ive made some progress in my "engine" which I nowadays call a game. I've decided to make a few games and then take parts out of them to make an engine (thanks to this forum Ive realized it was a better approach for me). Anyhow, I've got my self a world divided into tiles. Think of it as and old-school top-view game, where an entity only can move between tiles. I've got query functions in my gameworld such as "GetEntititiesAt(Coordinate position)" which would return all the entities stored in a tile at that position. But how am I suppose to handle return parameters using my message systems? I'm thinking of implementing some kind of broadcast system. So that if a component needs to know of its surroundings, I let them subsrcibe on the "GetSurroundings" message. And then let the gameworld/someComponent fire that message each frame to let every subrscriber know of their surrounding. Either that or some kind of callback function, so that when an entity asks for its surroundings, they could pass a reference to a list or something which will be filled. This is the first problem of this type Ive ran into so far, and I expect to see more of it, so I want to have a method of dealing with it asap. My question in short terms: Do you have messages that also returns stuff? If yes: How do you handle if several objects would subscribe on the same message? If no: How do you do it? //Doggolainen Edit: @JJTippets: A quote from your blog that pretty much hits spot on what this topic is about. [url="http://www.gamedev.net/blog/33/entry-2249433-how-goblinson-crusoe-works-the-tldr-version/"]http://www.gamedev.net/blog/33/entry-2249433-how-goblinson-crusoe-works-the-tldr-version/[/url] [quote] [color=#1C2837][size=2]There is also a function,[/size][/color][color=#1C2837][size=2] [/size][/color][color=#1C2837][size=2][b]handleRequest()[/b][/size][/color][color=#1C2837][size=2], which acts similarly to[/size][/color][color=#1C2837][size=2][b]handleMessage()[/b][/size][/color][color=#1C2837][size=2], but which will return a list of results. This is used for queries, and I am unsure on whether or not it is actually needed, as I haven't really used it much.[/size][/color][color=#1C2837][size=2] [/size][/color] [/quote]
  11. Ive got this message system up and running in between the components in my game-engine. Ive just started to implement Lua and I've run into a problem. When I try to pass arguments from the lua file to a function in C# that takes arbitrary parameters, using the "params" keyword, I get the following exception: [i]"Invalid arguments to method ca[/i][i]ll"[/i] I tell the Lua which function to call. [code] lua.RegisterFunction("FireMessage", this, this.GetType().GetMethod("FireMessage"));[/code] This is what the function looks like.[code] public void FireMessage(String messageName, params object[] parameters) { if (messages.ContainsKey(messageName)) { foreach (KeyValuePair<Component, String> e in messages[messageName]) CallMethod(e.Key, e.Value, parameters); } } [/code] This is what I do in my .lua file. [code] luanet.load_assembly("LuaWorld"); Vector2D = luanet.import_type("LuaWorld.Vector2D"); dir = Vector2D(50.0, 50.0); FireMessage("Move", dir);[/code] How can I solve this problem and still, if possible, use params object[] as parameter type?
  12. [quote name='JTippetts' timestamp='1299806840' post='4784223'] I handle my own components quite differently, limiting communication with an object to the passing of messages or requests, and never asking for direct access to a component for any reason. In my system, you don't really care whether an object has a HealthComponent or not; you just pass it messages along the lines of ModifyHealth, and let any interested components handle the message as they see fit. If no component wants to handle the message, then it is silently ignored. And it is possible for multiple components to handle the same message. The only means of working with an entity that I provide are handleMessage() and handleRequest(); there is no way to get access directly to any component. So as an example, Entity A makes a damaging attack against Entity B. Instead of querying Entity B for its HealthComponent and modifying it directly, I instead calculate the damage numbers and pass them as arguments in a "ModifyLife" message sent to Entity B. Entity B has a HealthComponent that registers to listen for "ModifyLife" messages, and when the message is received it will handle applying the damage accordingly. Now, since Entity B is a non-aggressive monster, its MonsterController component also registers to listen for "ModifyLife", and upon receipt of a "ModifyLife" message, it will signal to enter a defensive combat state. Exactly what this defensive state is, of course, depends on the exact implementation of the MonsterController. Some will respond with fight, some will respond with flight, etc... Also, since Entity B is a selectable enemy that the player can target, it also has a third component which listens for "ModifyLife" messages: a CharacterNameplateDisplay component, which will modify the on-screen lifebar representation to reflect the decrease in life. Now, what if I want to make Entity B into a sort of booby-trap exploding decoy? Instead of adding a HealthComponent, CharacterNameplateDisplay component, etc... instead I add a ExplodesOnHit component. Now, without any change to the sequence of actions required on Entity A's part (I still generate an attack, roll damage numbers, and pass a "ModifyLife" message as before) I have completely changed the way Entity B responds to an attack. The ExplodesOnHit component registers to listen for "ModifyLife", only instead of performing life calculations, it just triggers an exploding response, querying the environment for all objects in a radius, calculating a damage value and delivering this damage value as "ModifyLife" messages sent to all objects in the radius, then triggering a special effect ("Explode") and finally triggering DestroySelf message to despawn the trapped object. In this way, I decouple the action (making an attack) from the response to the action (modifying health level, modifying lifebar display, exploding), and not once do I ever care exactly what component or type of component is needed to handle the message. I wrote a bit more detailed explanation in my journal [url="http://www.gamedev.net/blog/33/entry-2249433-how-goblinson-crusoe-works-the-tldr-version/"]here.[/url] [/quote] I've been into the idea of message passing between entities in my game framework. But I always get stuck on on how to implement the argument passing correctly for the messages. I always end up with ugly typecasts on the other end (the entity that receives the message). In your case, I assume you pass some kind of float value along with the "ModifyLife" message. Could you please tell me how you would implement the receiving part of that message?
  13. Looking for procedural game design

    [quote name='PrestoChung' timestamp='1296743976' post='4769021'] [quote name='Doggolainen' timestamp='1296734388' post='4768972'] This is an issue where my brain is really stuck right now. I've managed to generate a world that looks great from a distance, but as I zoom in the borders in between the tiles form straight edges etc. Could you describe more on how one can zoom into some kind noise function and genereate the noise there with a better "resolution"? [/quote] Doggolainen, Zooming in and out just becomes a matter of showing (or generating) more detail (finer sampling) close to the camera. This is a sort of LOD problem. With the terrain I generated I used a geometry clipmap similar to this [size="1"][url="http://research.microsoft.com/en-us/um/people/hoppe/proj/geomclipmap/"]http://research.micr...oj/geomclipmap/[/url][/size] [/quote] Yes, generating a higher resolution on one tile is easy. But making it seamless to the tile next to it is the issue Im stuck on.
  14. Looking for procedural game design

    First off, thanks for all the good answers, keep 'em comming Im reading with eager eyes as soon as a new reply shows up! [quote name='JTippetts' timestamp='1296697760' post='4768834'] [quote name='Doggolainen' timestamp='1296576826' post='4767994'] Im looking for some kind of Noise function that takes two float values x and y and returns a value in between -1 and 1. I've been googling around for Perlin Noise, but I all I find is where people use it for images and creating the same bitmaps with width and height as parameters. Does anyone know a good site or even more simple, have anyone written such a function? [/quote] Calling noise functions via floats (or even doubles, for extra large worlds) is actually a very good idea, if for no other reason than that if you want to 'zoom in' on the map you can do so merely by sampling a smaller domain of the function and if the function is well-structured (ie, you have sufficient octaves of layered noise, etc) then the result is a continuous level of detail down to very small areas of the domain. [/quote] This is an issue where my brain is really stuck right now. I've managed to generate a world that looks great from a distance, but as I zoom in the borders in between the tiles form straight edges etc. Could you describe more on how one can zoom into some kind noise function and genereate the noise there with a better "resolution"?
  15. Looking for procedural game design

    Im looking for some kind of Noise function that takes two float values x and y and returns a value in between -1 and 1. I've been googling around for Perlin Noise, but I all I find is where people use it for images and creating the same bitmaps with width and height as parameters. Does anyone know a good site or even more simple, have anyone written such a function?