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

Username:   Password: 
 RegisterRegister   
 Help once again. Mousewhere general.
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
iRobsta




PostPosted: Thu May 20, 2010 5:55 pm   Post subject: Help once again. Mousewhere general.

What is it you are trying to achieve?
Hey i'm back again. I have my main character moving, but his image shows him facing the right, so when i move my mouse to the left and he moves their it makes sence. but when I move him to the left, he is still facing right.
I would like it that when i move my mouse left the image changes to left, and when i move it to the right it's the right image.
I would like to also have my enemy running at the same time i run my charater. but no, that can't work either.

What is the problem you are having?
I don't know how to get that work and i would like a hint or a push to the answer, some guidance.
for both the process to run at the same time is not working for me either. Only one of them show at any given time.

Describe what you have tried to solve this problem
Multiple if statments, loops, more mousewhere idea's. Nothing works.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Here it is.

Turing:

import GUI

setscreen ("nocursor,nobuttonbar,graphics:600;600,offscreenonly")

var chars : array char of boolean
var backround : int := Pic.FileNew ("MBT.jpg")
var mario : int := Pic.FileNew ("Mario.jpg")
var mariob : int := Pic.Mirror (mario)
var a, b, c, d : int
var koopa : int := Pic.FileNew ("koopa.jpg") % my enemy
var koopam : int := Pic.Mirror (koopa) % my enemy mirrored
View.Update

% proc Koopas
%     var rY := Rand.Int (100, 600) % random y variable
%     var rX := Rand.Int (2, 600) % random x variable
%     var rX2 := Rand.Int (2, 600) % second random x variable
%     var temp : int % temp variable
%     if rX > rX2 then % makes sure smaller number goes forst
%         temp := rX % if the second is bigger then temp becomes the bigger
%         rX := rX2 % makes the second number the bigger number
%         rX2 := temp % makes the smaller number the new bigger number
%     end if
%     %Loops the momvent
%     for x : rX .. rX2     % the area
%         Pic.Draw (koopam, x, rY, picMerge)     %draws the first movment going right
%         View.Update     % update
%         delay (10)     % delay
%         cls     % close. blah blah blah
%     end for     % exit's the movment to the right
%     for decreasing x : rX2 .. rX     % movment to the left, same distance but backwords
%         Pic.Draw (koopa, x, rY, picMerge)     % draws moving to the left
%         View.Update     % look up 4 lines.
%         delay (10)
%         cls
%     end for
%
% end Koopas

proc mariomvt
% var d : int
    loop   
        mousewhere (a, b, c)
       % mousewhere(d,b,c)
        Pic.Draw (mario, a - 50, 5, picMerge)
        View.Update
        cls
       % put d," ",a
    end loop
end mariomvt

mariomvt
put "hi"

% koopas
% fork Koopas
% fork mariomvt



Please specify what version of Turing you are using
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
iRobsta




PostPosted: Thu May 20, 2010 7:44 pm   Post subject: Re: Help once again. Mousewhere general.

Can anyone help?
DemonWasp




PostPosted: Thu May 20, 2010 7:49 pm   Post subject: RE:Help once again. Mousewhere general.

What you really want to track is where Mario is now compared to where he was an instant ago. This implies that you will want to store his location from a moment ago before you update his current position.

If his new position is further to the right, then he should be facing right; if it's further to the left, then he should be facing left.
TheGuardian001




PostPosted: Thu May 20, 2010 7:49 pm   Post subject: Re: Help once again. Mousewhere general.

Well, if you know what way to move him, you must already have if statements in place (to detect what way he should move). Instead of drawing mario outside of those if statements, put the Pic.Draw inside, with the appropriate picture depending on which way he is moving, IE

code:

if mouse_left_of_m
    move_left
    Pic.Draw(mario_left)
elsif mouse_right_of_m
    move_right
    Pic.Draw(mario_right)
end if


Alternatively you could use a boolean variable to say whether he is moving left or right, and then use that variable in a separate if statement. Either way.
Tony




PostPosted: Thu May 20, 2010 7:49 pm   Post subject: RE:Help once again. Mousewhere general.

since you are already moving your character, then you know which direction he's moving in. Draw an appropriate picture for that direction.

As for multiple characters -- the typical approach is to move them step-by-step in the same loop.
code:

loop
   move_character_1
   move_character_2
end loop


You want each move to be only a single frame long (no nested loops!). With such a setup, everything will run smoothly together.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
iRobsta




PostPosted: Thu May 20, 2010 9:52 pm   Post subject: Re: Help once again. Mousewhere general.

Thanks once again everyone, and you DemonWasp. The way you said it helped me.
and sorry tony, so that loop was the simple solution to all my multiple character problems ....
I am disappointed in myself.
DemonWasp




PostPosted: Thu May 20, 2010 10:02 pm   Post subject: RE:Help once again. Mousewhere general.

Often, the easiest way to solve a problem is to restate it. Sorry I couldn't be more illuminating on the multiple-character-animation thing: it's hard to force one's mind to look at a problem -- one that you know a solution to -- and consider it as if it were brand new.

I wonder if there's a tutorial for that design pattern yet...it comes up all the time here, so it would be helpful to just provide a link.
iRobsta




PostPosted: Thu May 20, 2010 10:25 pm   Post subject: Re: Help once again. Mousewhere general.

I tried you method but I think I failed uber macho, please take a look, its down past the 'Ignore this section':

Turing:

setscreen ("nocursor,nobuttonbar,graphics:600;600,offscreenonly")
var chars : array char of boolean
var backround : int := Pic.FileNew ("MBT.jpg")
var mario : int := Pic.FileNew ("Mario.jpg")
var mariob : int := Pic.Mirror (mario)
var a, b, c, d : int
var koopa : int := Pic.FileNew ("koopa.jpg") % my enemy
var koopam : int := Pic.Mirror (koopa) % my enemy mirrored

%%%%%%%%%%%%%%%%%%%%%%%%%%% Ignore this section %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
proc Koopas
    var rY := Rand.Int (100, 600) % random y variable
    var rX := Rand.Int (2, 600) % random x variable
    var rX2 := Rand.Int (2, 600) % second random x variable
    var temp : int % temp variable
    if rX > rX2 then % makes sure smaller number goes forst
        temp := rX % if the second is bigger then temp becomes the bigger
        rX := rX2 % makes the second number the bigger number
        rX2 := temp % makes the smaller number the new bigger number
    end if
    for x : rX .. rX2     % the area
        Pic.Draw (koopam, x, rY, picMerge)     %draws the first movment going right
        View.Update     % update
        delay (10)     % delay
        cls     % close. blah blah blah
    end for     % exit's the movment to the right
    for decreasing x : rX2 .. rX     % movment to the left, same distance but backwords
        Pic.Draw (koopa, x, rY, picMerge)     % draws moving to the left
        View.Update     % look up 4 lines.
        delay (10)
        cls
    end for
    %end loop
end Koopas % finish
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
proc mariomvt
    loop
        for a1 : 1 .. 600
            mousewhere (a, b, c)
            put a1
            put a
            if a > a1 then
                Pic.Draw (mario, a, 5, picMerge)
                View.Update
                cls
            else
                Pic.Draw (mariob, a, 5, picMerge)
                View.Update
                cls
            end if
        end for
    end loop
end mariomvt

% loop      This whole peice here does not work. Same problem were only one of the
%     mariomvt  apear at a time.
%     Koopas
% end loop


What I did just made my mario switch from left to right really fast. D:
God this is frustrating.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu May 20, 2010 10:45 pm   Post subject: RE:Help once again. Mousewhere general.

what is 600 in
code:

for a1 : 1 .. 600

?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
iRobsta




PostPosted: Thu May 20, 2010 11:02 pm   Post subject: Re: Help once again. Mousewhere general.

Thats all the positions it could possible because my screen is 600x600. it could be. Idk. I screwed up. I'm so lost and brain dead because of this i don't know what to do. I think I spend like 3 hours trying to get this code what you saw working.


Trying to get the character to switch from left to right when I move my mouse right or left
and
having my enemy's (koopas) flying in the air the same time i'm moving my character (mario).
Nothing has been freaken working.
Tony




PostPosted: Thu May 20, 2010 11:30 pm   Post subject: RE:Help once again. Mousewhere general.

Sometimes it helps to step away, take a break, and come back again later, when you are feeling less frustrated.

For then, here are a few things to consider:

Your for-loop checks all 600 possible positions (is that necessary?) and draws a result for each one. It does this non-stop really fast, and draws a result for each outcome.

Then, all this checking is inside a loop that never exits, so mariomvt procedure never ends. Because mario is the only loop that gets to run, Koopas doesn't have a chance to run any lines of code at all.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
iRobsta




PostPosted: Thu May 20, 2010 11:44 pm   Post subject: Re: Help once again. Mousewhere general.

I figured that was the problem. But how would I stop it then?

Or would I have to combine both procedures?
Tony




PostPosted: Fri May 21, 2010 12:02 am   Post subject: RE:Help once again. Mousewhere general.

You could keep the procedures separate, as long as they don't have loops inside of them (as loops capture the control flow).

The best analogy I have is that a game is an interactive animation, and animations are a series of frames -- think movie reels. (You are constructing the next frame based on the current state and input variables, but the idea still holds)

If you construct your code in a manner like
code:

var frame_number : int := 0

loop
   draw_mario_at_frame(frame_number)
   draw_koopa_at_frame(frame_number)
   ...
   % done, go to next frame
   frame_number = frame_number + 1
end loop


One loop is enough. If you want to loop over something inside a character draw procedure, it already gets an incrementing counter variable from the main outside loop.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
DemonWasp




PostPosted: Fri May 21, 2010 9:26 am   Post subject: RE:Help once again. Mousewhere general.

Alternately, think of this like a turn-based game, like Tic-Tac-Toe. First you move, then your opponent moves, then you move again, then your opponent moves again.

Now, imagine that we speed up the process -- a lot! Now each time you "move" you may only move a few pixels at a time. Still, you take turns - you move a tiny bit, your opponent moves a tiny bit, then it's back to you to move a very tiny bit again. This way, you both get turns (and an equal number of them), but because turns go so fast, it looks like you're "moving simultaneously" to human eyes.
Monduman11




PostPosted: Sat May 22, 2010 7:40 pm   Post subject: Re: Help once again. Mousewhere general.

and if you still cant get it to work with the mouse you can just use the Input.KeyDown ( LEFT_ARROW_KEY)
and the right arrow key to get mario moving. and that way you just have a simple procedure stating that if you press the left button you mirror the mario pic and make him move left and if you press the right button then mario moves towards the right. if you still need more help ask me in class lol. Razz later man
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  [ 16 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: