Let's say I am working on my own engine using SDL.
I am working on a game that has lily pads moving down a stream and I want the pads to follow a certain path(the flow of the stream). To my surprise, this is actually turning out to be harder than I thought... What would be a good way to implement a simple path for a sprite to follow? Would it be best to just to have a hard coded path ready to do ? (This seems like it would take forever since you would need to code every single location for each frame) or is there a better option for completing this task? I was actually reconsidering my design altogether because of this issue. I was thinking maybe implementing per pixel collision for the edges of the curvy stream and just checking collision against the edges and keeping the pads in the stream this way. This would also take forever but would be much more dynamic.
Any thoughts, ideas, or suggestions would be so awesome!
Really depends on how your lake and grass are defined.
How is your grass and lake defined, is it a static image or defined as map data? - if defined as map data, you could use the left or right edge of the grass as a reference and offset your leaf resulting in the leaf adjusting its horizontal position as necessary.
That makes life more difficult for you, or at least time consuming as you would now need to go down the route of creating a path, or even reading the bitmap pixel data (like games such as Worms do as their levels are static so its easier to provide much more detail).
oh okay thanks! This is actually the way I was thinking to do it. I was asking because I was not sure if I were just having a dumb moment and was unable to fathom a better way to do it with a static picture. Right now, I have a very rough path that it follows based on the y positions. Thanks for the feedback.
This may be helpful to you, I came across this a while back which gives an insight into the different methods of collision detection - its a very good and detailed post, well worth a read.
@Softrix Again, thanks for the information! Very helpful. I read over the section and it looks like my original "creative" solution was about right in that, when dealing with slopes, it is really better to just get right at the pixel level and handle the collision as so.
I was thinking I could take time to actually map out the curves of the lake and actually put these points in some sort of linked list (probbaly use a vector). I was thinking I could use the each individual points as a track. I could move the pod along the track and even if the velocities change, each point will still be contained in track list. I would then modify the velocity of the Y coordinate and then search through the list to find the appropriate X coordinate for the track and then move the sprite to this location.
This would be much slower and use a lot of memory but with some thought I think it could easily be optimized, but either way it will use more memory.
What do you guys think of my solution?
Thanks for all the feedback, this community is amazing.
It isn't a terrible solution, and remember that memory is only a concern when you think you might run out of it; otherwise any modern system will have more then you are likely to use in a small game like this. Depending on how you want to object to move in the body of water though then that approach might be more work then it is worth. If you want the object to follow the curve of the water more or less like a log would do IRL then you'll want to describe the rivers curve in a function (remember asking "when will I ever use this?" in math class?), then you use this function to generate the path at some offset in between the two edges of the river.
yup! The solution I had more or less is like a function (from math class, stuff I did not take for granted ;)). I am just predefining each point instead of coming up with the equation. The equation method would use less memory but, like you said does not really matter, just something to keep in mind since I plan on an Android port at some point.