Changing the animation and velocity in water - libgdx

I'm trying to make a 2D game in Java, and I'm using Libgdx. But, I don't know how to change the animation and velocity in water, for instance, changing the movement from walking to swimming.
Can anyone help me with the code and methods please?

Assuming that you use rectangular areas for your water and your sprites, you might want to look at checking if a rectangle (your water) contains another rectangle (your sprite). If you use non-rectangle shapes, you should find the appropriate methods to check if the hitbox of your sprite is inside your water.
If your water contains your sprite, you can handle (update, render, etc.) it differently.

Related

How to make the sprite.BoundingRectangle fit the sprite exactly

In LibGDX, I'm trying to create a game where you play a character who must survive waves of zombies. The plan is, when a zombie touches the player, the player loses health, and the zombie despawns; this works well until any of the sprites are rotated. Here's a screenshot of what I can imagine to be why:
To check the collisions, I use:
if (sprite.getBoundingRectangle().overlaps(Game.pl1.sprite.getBoundingRectangle())) {}
.. this is inside the Zombie class, and Game.pl1.sprite refers to the sprite belonging to the player.
So the red box is where I'm assuming the bounding rectangle is, based on where zombies despawn around it.
This is what I want the bounding rectangle to be:
I'm not sure if I can achieve this just using sprite.getBoundingRectangle so I was thinking perhaps I would need to use Box2D or maybe convert the sprite to a texture.
You could get the dimensions for a rectangle the size of the sprite if it wasn't rotated, and then rotate that.

Blood flow in a circular maze?

How can I create an animation in flash as3 in which I can show a blood stream ppassing through a circular maze?
for example, here's a maze: http://lonestar.texas.net/~dianes/labyrinth/maze.jpg
I want to make blood flow through that maze like in veins... Or better that that if I could make a circular venular image and make blood flow through it in smooth motion.
I'm trying to make an analog clock, in which I want to keep this venular circle as the background. I don't have much knowledge in as3, but I'll try to understand if there's a code for this...
Also if it can also be possible to get the blood around the border of some text (logo)
Thanks.
Animation
The simplest way would be to do the animation, without any code, with Flash. I assume you have only one animation to do, the maze and/or logo won't change.
The idea is to use your maze as a mask and have the blood in a layer below. Then you may draw the flow of blood with the brush frame by frame quite roughly (it will be masked anyway).
Code
Using some code will be more complex. The only advantage is that it's dyanmic and will adapt to any shape, I don't know if it is what you want.
I would first choose the first point, the origin of the blood stream and paint it red.
Then I would use a convolution matrix to do a dilation of this pixel.
Then I would remove the pixels that do not belong to the masking shape (the maze)
I would compare this image to the image given by the previous iteration, if it is not the same, I would loop to 2.

AS3 for moving a movieclip along a path

I am looking for a simple AS3 script to move/follow a movieclip (arrrow) along a manually drawn path in flash. Like.. it moves for the start point if the line to the end point of the line, also should rotate at curves automatically.
Also is it possible to duplicate this movieclip (arrrow) tho specific distance, like a ground of arrows moving along a path continuously with specific distance from eachother?
I am working on few infoGraphs and need this arrows animation to show the workflow.
I desperately needs this, pls help!
Cheers,
bp
There could be libraries that help with this, as George Profenza mentions in his comment, and it is certainly possible to calculate points along a bezier.
However, a much simpler solution is to do what people have done since Flash 4. Draw the curve in Flash, then create a motion tween along the curve using an empty MovieClip. At runtime, you can use addChild() to insert your MovieClip as a child of the empty one. You will have a lot more manual control this way, compared to the bezier library.

Animating a path between two objects on HTML5 canvas

We're developing a game with impactjs that allows 'chaining' of entities as they are clicked. Basically this just draws a line between the two points, with a neon glow effect. So far, so good. Now, we have a request to make the 'chain' connections animated - fire, sparkles, etc. Essentially things that seem like they'd need actual graphic animations to look right. As the entities can be any distance/angle from each other, we're stuck at how to best implement a solution for this - that is, how to draw a diagonal image, for example, between two random points that we can animate. Any thoughts our suggestions on how to pull this off would be much appreciated.
Maybe create a particle entity with an Animation Sheet containing the necessary animations/particle effects. And then draw these particles along the line that from point A to point B.
When you want to animate it to fire/sparkles etc. run the animation for all those entities. in that line.
I'd be inclined to agree with Prat. Particle effects would most likely be what you need.
Here is a tutorial on generating particle effects in impact.js that might help you out.
http://www.pointofimpactjs.com/snippets/view/24/particle-effects-generation

How can I turn an image file of a game map into boundaries in my program?

I have an image of a basic game map. Think of it as just horizontal and vertical walls which can't be crossed. How can I go from a png image of the walls to something in code easily?
The hard way is pretty straight forward... it's just if I change the image map I would like an easy way to translate that to code.
Thanks!
edit: The map is not tile-based. It's top down 2D.
I dabble in video games, and I personally would not want the hassle of checking the boundaries of pictures on the map. Wouldn't it be cleaner if these walls were objects that just happened to have an image property (or something like it)? The image would display, but the object would have well defined coordinates and a function could decide whether an object was hit every time the player moved.
I need more details.
Is your game tile based? Is it 3d?
If its tile based, you could downsample your image to the tile resolution and then do a 1:1 conversion with each pixel representing a tile.
I suggest writing a script that takes each individual pixel and determines if it represents part of a wall or not (ie black or white). Then, code your game so that walls are built from individual little block, represented by the pixels. Shouldn't be TOO hard...
If you don't need to precompute anything using the map info. You can just check in runtime logic using getPixel(x,y) like function.
Well, i can see two cases with two different "best solution" depending on where your graphic comes from:
Your graphics is tiled, and thus you can easily "recognize" a block because it's using the same graphics as other blocks and all you would have to do is a program that, when given a list of "blocking tiles" and a map can produce a "collision map" by comparing each tile with tiles in the "blocking list".
Your graphics is just some graphics (e.g. it could be a picture, or some CG graphics) and you don't expect pixels for a block to be the same as pixels from another block. You could still try to apply an "edge detection" algorithm on your picture, but my guess is then that you should rather split your picture in a BG layer and a FG layer so that the FG layer has a pre-defined color (or alpha=0) and test pixels against that color to define whether things are blocking or not.
You don't have much blocking shapes, but they are usually complex (polygons, ellipses) and would be unefficient to render using a bitmap of the world or to pack as "tile attributes". This is typically the case for point-and-click adventure games, for instance. In that case, you're probably to create path that match your boundaries with a vector drawing program and dig for a library that does polygon intersection or bezier collisions.
Good luck and have fun.