Computer Science Canada mario movement |
Author: | coldmine16 [ Wed Aug 09, 2006 5:27 pm ] |
Post subject: | mario movement |
Hey im having trouble moving mario, i cant get it to be a complete motion it just shoots him froom one side of the screen to the other, im doing it in a procedure as you can see but somehow to me i think im doing it wrong i know the movement to the left is not yet complet because i have to rotate the pic so it faces to the left but if you could help me move mario so its not shooting him across the screen that would be great thanks. |
Author: | richcash [ Wed Aug 09, 2006 6:03 pm ] | ||||||
Post subject: | |||||||
Umm... I don't see your code anywhere. If you could provide some of your code someone could help you further. If your character is moving too fast across the screen, slow down your counter or add a delay. I assume that you have your character imported with a picture like this :
And then in your procedure you have a counter to make mario move like this :
so modify it like this :
Obviously, the value you add to x each time should be smaller to make it go slower and the value in the delay () should be larger to make it go even slower. I need the code to help you more specifically. |
Author: | coldmine16 [ Wed Aug 09, 2006 6:12 pm ] | ||
Post subject: | |||
heres some of the code
|
Author: | Cervantes [ Wed Aug 09, 2006 6:16 pm ] |
Post subject: | |
The code is within the rar. To solve the problem, add a delay to the main portion of your loop. You should not call that mariodraw procedure within your if statements. Aside from just not making sense (you'll be drawing him more often if he's moving), it will cause all sorts of troubles. Rather, create some boolean variables to remember Mario's state: is he walking? standing still? jumping? facing right? facing left? You will only have one spot in your loop where Mario is drawn, and which picture to draw will depend on Mario's state: those variables. |
Author: | coldmine16 [ Wed Aug 09, 2006 6:21 pm ] |
Post subject: | |
isnt that quite a bit of extra code there has to be some easier and faster method to do it |
Author: | Cervantes [ Wed Aug 09, 2006 6:28 pm ] |
Post subject: | |
It may seem like more work, but it's work that you need to do. You'll need to keep track of Mario's state for purposes other than simply drawing. Besides, this way works. ![]() |
Author: | TheOneTrueGod [ Wed Aug 09, 2006 6:47 pm ] |
Post subject: | |
I actually prefer having an integer keep track of his state. I.E. 0 = walking left, 1 = walking right, 2 = jumping left, 3 = jumping right, 4 = dying, etc... This way, it works REALLY nicely with a 2-D array when you're trying to draw him from a character map. |
Author: | coldmine16 [ Wed Aug 09, 2006 7:13 pm ] | ||
Post subject: | |||
ahhh its buggy well i got it to move well like it isnt speeding across the screen anymore but stil however the animation of mario moving left and right is terrible plus there is a fliker and i know u put view.set ofscreenonly thing but then that makes him disapear sry i forgot what you had to do so that the object stays on the screen its been a while since i programmed but anyway here is the code so far
|
Author: | TheOneTrueGod [ Wed Aug 09, 2006 7:21 pm ] | ||
Post subject: | |||
Theres a View.Update tutorial, but i'll summarize it here in pseudocode
|
Author: | coldmine16 [ Wed Aug 09, 2006 7:23 pm ] |
Post subject: | |
o ya the view.update things thanx and can anyone help on the other stuff |
Author: | TokenHerbz [ Thu Aug 10, 2006 11:19 am ] | ||
Post subject: | |||
your calling your mariodraw too many times, i think... When Cervantes mentioned the use of booleans i believe he wanted you to do do somthing like have it all in your proc.. here lemmy ex. you.
%%variables %%proc loop Input.KeyDown(keys) cls draw_mario View.Update delay(20) end loop [/code] Cervantes, i would like to know what you think of useing Input.KeyDown inside your procs?? Is it bad? |
Author: | Cervantes [ Thu Aug 10, 2006 11:24 am ] |
Post subject: | |
It means using global variables. (In this case, keys is your global variable.) So yes, it's bad. But not overly so. If you wanted a subroutine to get your input, use a function that returns an 'array char of boolean' (which is the data type for your keys variable). Of course, there's no getting away from letting procedures manipulate the state of your variables. Input.KeyDown is itself a procedure that changes the variable you pass it. This is one of those ways that Turing fails: so much use of procedures, not enough use of functions. |
Author: | coldmine16 [ Thu Aug 10, 2006 12:54 pm ] | ||
Post subject: | |||
one second the way u explained it i dont really need boolean variables
i have mario walking perfectly with this procedure like it draws the pictures however it draws them at such a speed like hes on steroids or something anything i can do about that |
Author: | Cervantes [ Thu Aug 10, 2006 4:22 pm ] |
Post subject: | |
No. No no no no no! If you do that, every other part of your program will stall for 40ms while mario takes one step to the right. Do you know why that might be? |
Author: | coldmine16 [ Thu Aug 10, 2006 4:50 pm ] |
Post subject: | |
o yea ur right because i have 2 20 ms delays in my draw mario, i understand how to get him to move its just that 2 picture thing you know to get it to look like he's actually moving |
Author: | TokenHerbz [ Fri Aug 11, 2006 3:27 am ] |
Post subject: | |
you dont need delays to slow a program down |
Author: | coldmine16 [ Fri Aug 11, 2006 1:10 pm ] |
Post subject: | |
well is there some way of slowing the transition of pic1 to pic2 of movement for mario? |
Author: | Clayton [ Fri Aug 11, 2006 2:56 pm ] |
Post subject: | |
you dont need to slow down the program to get him to be drawn nicely, all you have to do is limit how many times he is draw per second, or in other words how many frames will be drawn to the screen, so just make use of the Time. commands to create a fps limiter and draw mario whenever you want to, using if constructs ![]() |
Author: | [Gandalf] [ Fri Aug 11, 2006 3:32 pm ] |
Post subject: | |
SuperFreak82, that would be the exact same thing as using delays, albeit in a more controlled way. The simplest way to control the execution speed of your program, as you would have seen my looking at TheOneTrueGod's pseudocode, is to use Time.DelaySinceLast(). It works exactly the same as delay() (which is really Time.Delay()), except it tries to make the speed equal on any computer. |
Author: | Clayton [ Fri Aug 11, 2006 4:33 pm ] |
Post subject: | |
actually [Gandalf] ill have to disagree with you on that one, a fps limiter is not slowing down your program, all it is doing is telling the program when to draw your frames ![]() |
Author: | coldmine16 [ Fri Aug 11, 2006 6:00 pm ] | ||
Post subject: | |||
alrite lol i still cant get mario to move around ive never tried to do a moving animation b4 in turing so im having lots of probs heres wut hte code looks like so far
c im jsut having problems drawing the pictures to move left or right so that it actually looks like a regular moving mario i tried looking at other peoples movements but i couldnt quite understand how to do it i know crevantes said with the boolean variables im not sure exactly how to do it so if u guys can elaborate on it thatd be great thanx |
Author: | Clayton [ Fri Aug 11, 2006 6:07 pm ] |
Post subject: | |
okay for the left and right running animations you have two pictures right? now, do you understand how booleans work? if you do you know that there are two choices, true or false, so just assign a picture to either of the choices (eg. marioleft1 when your boolean variable is true and marioleft2 when your boolean variable is false) and try it out ![]() |
Author: | [Gandalf] [ Fri Aug 11, 2006 7:56 pm ] |
Post subject: | |
SuperFreak, a controlled delay also tells the program when to draw the frames (ie. after 15 milliseconds have passed). Yeah, alright, it's not the exact same thing. ![]() |