why isn't the dot moving?
BlitzMax Forums/BlitzMax Beginners Area/why isn't the dot moving?
| ||
SuperStrict AppTitle$ = "My Application" Graphics 800 , 600 AutoMidHandle True SeedRnd(MilliSecs() ) Local player:TPlayer = New TPlayer player.PlayerMove 'append movement to dot Repeat Cls DrawRect player.X , player.Y , 10 , 10 Flip(-1) 'vsync Until AppTerminate() Or KeyDown(KEY_ESCAPE) Type TPlayer Field X:Int = 400 Field Y:Int = 300 Field speed:Int = 7.5 Method PlayerMove() If KeyDown(KEY_W) Y:+ speed EndIf If KeyDown(KEY_S) Y:- speed EndIf If KeyDown(KEY_A) X:- speed EndIf If KeyDown(KEY_D) X:+ speed EndIf EndMethod EndType So Why isn't the dot moving? |
| ||
Not wanting to be Captain Obvious, but it's not moving because you aren't moving it. You need to update the movement inside your main loop instead of once, before it. |
| ||
Oops!, I just noticed that! No wonder it wasn't working! lol |
| ||
Just one more comment - your indenting seems a bit off .. very hard to read... |
| ||
your indenting seems a bit off .. very hard to read... Looks a bit like Python! LOL |
| ||
@Matty: Everyone has their own unique coding style, Mine would be indenting beyond all reason :P Its easier for me to read and that is the only thing that matters for the coder to be able to read/write his or her own code as they please. :D |
| ||
aren't you being a little contradictory? you post code for others to help you with and yet according to you it doesn't matter if others understand it. hmm... |
| ||
There's a reason why indenting is important. If you code, and you wish to help others with it, there are certain things the common coding community has agreed on. Look at some Linux kernel source code to get an idea. Also, this is important for you to read through. -- Losing track of blocks In certain situations, there is a risk of losing track of block boundaries. This is often seen in large sections of code containing many compound statements nested to many levels of indentation - by the time the programmer scrolls to the bottom of a huge set of nested statements, he may have lost track of which control statements go where. Programmers who rely on counting the opening braces may have difficulty with indentation styles such as K&R, where the beginning brace is not visually separated from its control statement. Programmers who rely more on indentation will gain more from styles that are vertically compact, such as K&R, because the blocks are shorter. To avoid losing track of control statements such as for, one can use a large indent, such as an 8-unit wide hard tab, along with breaking up large functions into smaller and more readable functions. Linux is done this way, as well as using the K&R style. -- PS: Field speed:Int = 7.5 THAT would be a Float =| Last edited 2012 |