Movement in Monkey !!

Monkey Forums/Monkey Programming/Movement in Monkey !!

trainer(Posted 2013) [#1]
Hello guys ..
Can u plz tell me how can I make some self movement in the background of my game .. for example, I want to let the bird flying at the background while I'm playing .. ??

Is there any such a way to do this ?? :\


Gerry Quinn(Posted 2013) [#2]
Sure.

You have moving objects in your game anyway, right? The bird is just another one, except it doesn't interact with anything (its movement is simply based on time passing).

Method OnRender:Int()
Cls( 0, 0, 0 )
DrawBird()
DrawTetrisBlocks()
Return 0
End


There is no direct way to import an animated image like a GIF to use as a background, if that's what you're thinking of. But you can import a series of frames and just draw the correct one based on the time.


trainer(Posted 2013) [#3]
Can u plz explain this more
What shall I write inside those two methods :
DrawBird()
DrawTetrisBlocks()
??


CodeGit(Posted 2013) [#4]
Try this link -

http://www.monkeycoder.co.nz/Community/posts.php?topic=3318


Gerry Quinn(Posted 2013) [#5]
Here's an app that draws a moving dot.




dawlane(Posted 2013) [#6]
Well I would have posted here a lot sooner, but I've been a little busy as of late.

@NoraHarthi:
I take it that you are new to programming. So first study the tutorials in the link that codeGit has supplied and any others that you can find as I will be mentioning Class, Lists and using Bitwise operations for checking certain states.

There are a number of ways to make a game object (in this case sprites) automatically move. Some are simple while others can get complicated. It all depends on what you are trying to do.
The simplest would be to add an offset value to the current sprites position and then changing the offset value when a condition is met.

e.g
If x <= target_position_left OR x >= target_position_right then offset = -offset
x = x + offset

So how to use it? Well lets make a sort of simple class that's going to do all the work of moving, animating and collision checking.
Note in general I would write a simple base sprite class to handle the display, animation and collision data side of things and then extend it for doing things like movement, including collision checking. I would also write a class and make it global to control timing and to do number of other tasks. Look up delta timing around the forum and internet for one usage example.



The the example above would be good for some thing like a platform game like Manic Miner (using a different collision method and adding delta time), but wouldn't work well if you wanted to do diagonal or direction movement. Then you would use vectors which open up lots of possibilities.
Lookup vector sprite movement on the internet; the language isn't important but the maths and logic are and can be adapted to work with any programming language with a little work.

Other things to search for are.
Sprite Z-Order
Sprite path way points
Sprite path following
Path finding algorithms