Artifact 6 – AI and stubborn Glowing effects

This week I have done The final AI-state “AttractedState” and I have started wrestling with the mixture of three super intelligent coding chefs in this soup of code. It’s lovely but it’s like fitting a cube inside the point of a needle.

Let’s start out with the attracted state.

This is a hunting state as explained in the previous post HERE but instead of a unit vector pointing from the enemy to the player fish, there is a vector pointing to the center of the light bulb. As of now, all fishes swim towards the light bulb when it’s lit. When the light bulb is not lit, the grey fishes flee to their “safe” distance and return to idle. The green fish are also attracted to the light but if they are close and you turn of the light, they enter hunting state. Hunting state has been updated so now when they collide with the player fish they take a bite from the player fish (dealing it damage) and flee until they are at the “safe” distance and return to idle. I believe this way is the final AI behavior with perhaps some tweaking in numbers deciding from what distance these behaviors are triggered.

The thing I am working on right now is the color coding of the fishes. The enemy fishes are supposed to have a glowing aura around them letting the player know instantly if they can eat it or if he or she should run away in shear panic while trying not to soil their pants.

If the fish has a green glow about it, it is smaller than the player’s fish and this means you can eat them. If they have a yellow glow, the player knows they are the same size, this means you can eat them and they can deal quite a bit of damage to the player’s fish.

If they have a red glow about them, the player should consider turning of the computer or risk suffering a heart attack in a primitive form of absolute panic – it means the fishes are bigger then the player’s fish! They can kill the player’s fish in a blink of an eye.

That is why and what. How is still on the drawing board.

What I’ve done so far is I am using the built in SFML VertexArray with four elements creating a rectangle. then I need to have a texture, this is also a built in class of SFML. This texture is drawn out separately but using the same position as the vertrices using the SFML’s window. The texture also uses four coordinates in the sprite sheet I use for the glowing image. This image is a transparent picture with white outlines of the fishes. this allows me to make them change colors. The Vertex array can set any color(s) to it’s shape.

I can say I wasn’t really sure where to start making these vertrices or how to fit them perfectly to the fishes since they are in different sizes as compared to the actual size in the sprite sheet. Because I use vertrices, who’s coordinates are defined at each of its corners and not in their top left corner or a specified origin such as sprites are, I need four coordinates to move it around the map. The very first thing that came into my head was the global boundaries of the sprites. Global boundaries is yet another feature of SFML. It returns a floatrect (or perhaps it’s an intrect) that gives you the coordinates – left, top, width and height of the image in question. That didn’t work out for some reason, probably because I overlooked something. In the process of doing and learning my responsibilities in a early stage of the production and because of some changes in the way we finally decided to handle our sprites, I missed a little information.

The colliders on the other hand I know inside and out. So I used the position of the colliders to update the vertrix. The colliders are placed on the sprites originating from the center of the sprite. From this information I can get all the corners. The left corner from the center of the collider is exactly the center position’s X-value minus the half of the width and the center position’s Y-value minus half its height. In the same manner you can get all the four points needed.

I just tried it and it works perfectly fine, it’s a master piece of hard coding and awesome art work.
Updatingglowposition

Just look at this wonderfully perfect fish and its glow:

GlowingFishes

The only problem right now is that the glow does not turn with the fish and that’s sort of annoying. I have three different theories that I will try after this blog.

Either I need to change the order in which the vertex array’s elements are created. In other words instead of from the top left corner to the right top corner to the right bottom corner to the left bottom corner, to draw it from the top right to the top left to the bottom left and to the bottom right. This could make the image inverted.

or I could change the texture coordinates to emerge in the same inverted order.

Or I need to do both. One of these ways should work out. I know the order does matter because I had a problem with the picture being all wrong when I had one coordinate mixed up with another.

So there you have it.

Advertisements

One thought on “Artifact 6 – AI and stubborn Glowing effects

  1. That IS a nice glowing effect, though those red fish do not seem bigger than the player… eh, whatever you might just be testing stuff out.

    I’m not sure if I like it that you have your code in pictures, it’s not very interesting to look at (for people that aren’t into code) and if I want to see it I’d have to enlarge the picture. It’s not the BIGGEST problem in the world but I’m not really fond of it.

    Other than that I think that you explain your AI behavious very well. It’s very similar to the one you mentioned in the previous post but slightly different (not sure about how I feel about having to read that post to understand this one). Overall I think that you explain well what you’re doing and how you’re doing it (still, I’d like some more code, but I’m weird like that) and you also make it pretty easy to understand why you do it as long as you’ve read the previous post.

    The glow effect sounds very interesting, I’ve never done anything similar to this so I find it rather, well, interesting (repetition, yay!) and I like that you explain what the different glows are supposed to mean and how you try to achieve the goal, for example why you choose to use the colliders instead of the sprites.

    …speaking of the glow effect it would’ve been interesting to see a picture of the glow not turning with the fish for a visual overview of the problems but that’s just me that likes to see stuff broken for some reason, oh well, you’ve probably fixed it by now and it’s fine without it.

    Phew, that was technically two artifacts y’know. Still, it was a pretty fun read so I shouldn’t complain.

    Good luck with the report and final product!
    🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s