Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 mario movement
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
coldmine16




PostPosted: 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.


mario game.rar
 Description:
Mario Game

Download
 Filename:  mario game.rar
 Filesize:  12.86 KB
 Downloaded:  71 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
richcash




PostPosted: Wed Aug 09, 2006 6:03 pm   Post subject: (No 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 :
code:
var picID := Pic.FileNew ("whatever_file_name.bmp")
Pic.Draw (picID, x, y, picCopy)


And then in your procedure you have a counter to make mario move like this :
code:
proc moveMario
     x := x + 10                         %10 is just an example value
end moveMario


so modify it like this :
code:
proc moveMario
     x := x + 1           %adjust the 1 and the
     delay (10)           %10 to make it the right speed
end moveMario

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.
coldmine16




PostPosted: Wed Aug 09, 2006 6:12 pm   Post subject: (No subject)

heres some of the code

code:

View.Set ("graphics:400;400")
var dead : int := Pic.FileNew ("Dead.bmp")
var jump : int := Pic.FileNew ("Jump.bmp")
var stand : int := Pic.FileNew ("Stand.bmp")
var walk1 : int := Pic.FileNew ("Walk1.bmp")
var walk2 : int := Pic.FileNew ("Walk2.bmp")
var walk3 : int := Pic.FileNew ("Walk3.bmp")
var chars : array char of boolean
var x : int := -1
var y : int := 5
procedure mariodraw ()
    Pic.Draw (walk1, x, y, picMerge)
    Pic.Draw (walk2, x, y, picMerge)
    Pic.Draw (walk3, x, y, picMerge)
end mariodraw

loop
    Pic.Draw (stand, x, y, picMerge)
    Input.KeyDown (chars)
    if chars (KEY_RIGHT_ARROW) then
        x := x + 1
        mariodraw ()
    end if
    if chars (KEY_LEFT_ARROW) then
        x := x - 1
        mariodraw ()
    end if
end loop
Cervantes




PostPosted: Wed Aug 09, 2006 6:16 pm   Post subject: (No 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.
coldmine16




PostPosted: Wed Aug 09, 2006 6:21 pm   Post subject: (No subject)

isnt that quite a bit of extra code there has to be some easier and faster method to do it
Cervantes




PostPosted: Wed Aug 09, 2006 6:28 pm   Post subject: (No 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. Wink
TheOneTrueGod




PostPosted: Wed Aug 09, 2006 6:47 pm   Post subject: (No 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.
coldmine16




PostPosted: Wed Aug 09, 2006 7:13 pm   Post subject: (No 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

code:

var moveright1 : int := Pic.FileNew ("Moveright1.bmp")
var moveright2 : int := Pic.FileNew ("Moveright2.bmp")
var jumpright : int := Pic.FileNew ("Jumpright.bmp")
var down : int := Pic.FileNew ("Down.bmp")
var stand : int := Pic.FileNew ("Stand.bmp")
var jumpleft : int := Pic.FileNew ("Jumpleft")
var moveleft1 : int := Pic.FileNew ("Moveleft1.bmp")
var moveleft2 : int := Pic.FileNew ("Moveleft2.bmp")
var a1 : boolean := false%move left%
var a2 : boolean := false%move right%
var a3 : boolean := true%standing%
var a4 : boolean := false%Jump right%
var a5 : boolean := false%jump left%
var chars : array char of boolean
var x : int := -1
var y : int := 5
loop
    a3 := true
    if a3 = true then
        Pic.Draw (stand, x, y, picMerge)
    end if
    Input.KeyDown (chars)
    if chars (KEY_RIGHT_ARROW) then
        x := x + 1
        a1 := true
        a3 := false
    end if
    if chars (KEY_LEFT_ARROW) then
        x := x - 1
        a2 := true
        a3 := false
    end if
    if a1 = true then
        Pic.Draw (moveright1, x, y, picMerge)
        delay (10)
        Pic.Draw (moveright2, x, y, picMerge)
    end if
    if a2 = true then
        Pic.Draw (moveleft1, x, y, picMerge)
        delay (10)
        Pic.Draw (moveleft2, x, y, picMerge)
    end if
    delay (30)
    cls
    a1 := false
    a2 := false
    a3 := false
    a4 := false
    a5 := false
end loop
Sponsor
Sponsor
Sponsor
sponsor
TheOneTrueGod




PostPosted: Wed Aug 09, 2006 7:21 pm   Post subject: (No subject)

Theres a View.Update tutorial, but i'll summarize it here in pseudocode

code:

View.Set('offscreenonly')
%Variable Declarations
loop
   %Stuff happens
   %Draw things
   View.Update
   %delay for however long using whatever method (Use Time.DelaySinceLast)
   cls
end loop
coldmine16




PostPosted: Wed Aug 09, 2006 7:23 pm   Post subject: (No subject)

o ya the view.update things thanx

and can anyone help on the other stuff
TokenHerbz




PostPosted: Thu Aug 10, 2006 11:19 am   Post subject: (No 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.


code:

%%get pic vars
var a1,a2,a3,a4 : boolean := false %%id use better variables myself...

%%now we make your draw proc

proc draw_mario
    %%i dont think theres anything wrong with accepting input from a     proc, i could be misstaken... cervantes should know :)

    Input.KeyDown(keys)
    if keys (right) then
        draw your picture right 1
        a1 := true
        a2 := false
        a3 := false
        a4 := false
     elseif keys (down) then
         draw you pic down 1
         a1 := false
         a2 := true
        etc:
      end if

end draw_mario

Setting the booleans after you draw him allow you to know which way he is facing so you can optomise your code.  You can have 2 variations of you picture to make walking "more realistic" and have another boolean to show you which of the variation pics you should draw.   You can even have your drawing check to see if your char will be out of bounds, and not draw him ahead of time :)

Anyways with this set up, your main code would look like:


%%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?
Cervantes




PostPosted: Thu Aug 10, 2006 11:24 am   Post subject: (No 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.
coldmine16




PostPosted: Thu Aug 10, 2006 12:54 pm   Post subject: (No subject)

one second the way u explained it i dont really need boolean variables

code:

procedure draw_mario ()
    Input.KeyDown (chars)
    if chars (KEY_RIGHT_ARROW) then
        x := x + 1
        Pic.Draw (moveright1, x, y, picMerge)
        delay (20)
        cls
        Pic.Draw (moveright2, x, y, picMerge)
        delay(20)
        cls
    end if
end draw_mario

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
Cervantes




PostPosted: Thu Aug 10, 2006 4:22 pm   Post subject: (No 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?
coldmine16




PostPosted: Thu Aug 10, 2006 4:50 pm   Post subject: (No 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
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 23 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: