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

Username:   Password: 
 RegisterRegister   
 Help in animation
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
triumph




PostPosted: Sat Apr 23, 2005 7:12 pm   Post subject: Help in animation

Could someone help me with some quick questions that I run into along the way? I don't want to bother the entire forums for simple things (I am a amateur TURING user) and I keep running into little things along the way while trying to complete a school project. I by no means want anyone to do this for me, or even to send me any code I just know I could do this alot faster when someone can answer me a very simple question instead of messing around for several hours trying to do it myself.

If anyone would be so kind please reply here or PM me and i'll msg you my MSN / AIM.

Thanks!
Sponsor
Sponsor
Sponsor
sponsor
jamonathin




PostPosted: Sat Apr 23, 2005 7:20 pm   Post subject: (No subject)

Don't worry about bothering. If a mod thnks it's useless they'll dispose of it. besides, it could help someone else out.
Cervantes




PostPosted: Sat Apr 23, 2005 7:33 pm   Post subject: (No subject)

The question here is how small are these questions? If they are really small, you probably won't be asking such questions for long. Wink

I'll leave the judgement up to you. You can either post the questions on the board, or ask someone via MSN. Feel free to ask me. Check the MSN button for my e-mail address. (And yes, that's the e-mail address I use for msn)
jamonathin




PostPosted: Sat Apr 23, 2005 7:39 pm   Post subject: (No subject)

do all mods use @compsci.ca? cuz im sick of hotmail Blowing up
Cervantes




PostPosted: Sat Apr 23, 2005 7:52 pm   Post subject: (No subject)

No, we use whatever we want. If you want a compsci email, amass 2500 bits. If you want an email somewhere other than hotmail, you can get gmail. PM if you want it.

Now, let's get back to the topic of waiting for triumph to ask his questions. Razz
triumph




PostPosted: Sat Apr 23, 2005 10:51 pm   Post subject: (No subject)

jamonathin helped me out with this earlier but my computer restarted out of nowhere in the middle of my program and I lost the peice of code he sent me.

I am trying to make it so the ovals bounce off the walls when they hit the given parameters. I am attempting something like this:




code:
  if xball >= maxx then
    xball := -1
    end if



xball being the x coordinate variable for drawoval. I am just learning when it comes to turing Sad When jamonathin helped me I realised you had to use two variables, but I was also wondering... am I going to have to set paramters for each side so the ovals constantly bounce off everything they hit? (By the way, I am trying to make a single "scene" to a screen saver)

Thanks for your help.
Bacchus




PostPosted: Sun Apr 24, 2005 12:10 am   Post subject: (No subject)

youd want to multiply it by -1 not set it to that
code:
x:=x*-1
basically
Cervantes




PostPosted: Sun Apr 24, 2005 7:42 am   Post subject: (No subject)

if you want to make the ball bounce off the wall, you have to reverse it's velocity. Assuming it hits the right or left wall, we reverse it's velocity in the x plane.
code:

if ballX - ballRadius <= 0 or ballX + ballRadius >= maxx then
    ballVelocityX *= -`
end if


If you want to move it to the other side of the screen:
code:

if ballX - ballRadius <= 0 then
    ballX += maxx
elsif ballX + ballRadius >= maxx then
    ballX -= maxx
end if
Sponsor
Sponsor
Sponsor
sponsor
triumph




PostPosted: Sun Apr 24, 2005 10:58 am   Post subject: (No subject)

I still cannot get it.

I replaced all my x,y radius' with the variable "ballradius" I put in the if statements and they still just fly off the screen.

code:
  if xball - ballradius <= 0 or xball + ballradius >= maxx then
        ballvelocityx *= -1
    end if
   
    if yball - ballradius <= 0 or yball + ballradius >= maxx then
        ballvelocityy *= -1
    end if


Whoa, I'm sorry ... I really suck at this Confused
shlitiouse




PostPosted: Sun Apr 24, 2005 11:35 am   Post subject: (No subject)

Hmmmm, I'm by no means the best programmer around here, and I'm fairly new to it myself, but PM me your e-mail (MSN) and I'll be willing to help out with any questions you have, could be fun to have someone to work out a problem with.
Cervantes




PostPosted: Sun Apr 24, 2005 11:56 am   Post subject: (No subject)

Are you using the ball's x and y velocities to update the ball's x and y positions?

code:

xball += ballvelocityx
yball += ballvelocityy


Also, you should be using maxy in your second if statement, not maxx.
triumph




PostPosted: Sun Apr 24, 2005 1:25 pm   Post subject: (No subject)

Let me just post my entire code up and tell me what I have done wrong.


code:
%=============================================
% Variables for Scene 1
%=============================================
var xball, yball : int := 1
var ballcolor1 : int := 1
var ballcolor2 : int := 60
var ballradius : int := 40
var ballvelocityx : int := 1
var ballvelocityy : int := 1
%=============================================
setscreen ("graphics:max,max")
%=============================================
loop

    drawoval (xball + 10, yball + 150, ballradius, ballradius, ballcolor1)
   



    drawoval (xball + 20, yball + 30, ballradius, ballradius, ballcolor1)
 



    drawoval (xball + 30, yball + 250, ballradius, ballradius, ballcolor1)
 

    drawoval (xball + 30, yball + 350, ballradius, ballradius, ballcolor1)
 



    drawoval (xball + 130, yball + 30, ballradius, ballradius, ballcolor1)
   

    %=========================
   if xball - ballradius <= 0 or xball + ballradius >= maxx then
        ballvelocityx *= -1
    end if
   
    if yball - ballradius <= 0 or yball + ballradius >= maxy then
        ballvelocityy *= -1
    end if

    %=========================




    xball := xball + 10
    yball := yball + 10
   
    ballcolor1 := ballcolor1 + 1
    ballcolor2 := ballcolor2 - 1
    xball += ballvelocityx
    yball += ballvelocityy

    delay (50)


    if ballcolor1 >= 225 then
        ballcolor1 := 1
    end if
    if ballcolor2 <= 1 then
        ballcolor2 := 60
    end if



    % exit when yball >= maxy + 20







    cls
end loop
%===============================================
Cervantes




PostPosted: Sun Apr 24, 2005 4:44 pm   Post subject: (No subject)

triumph wrote:
Let me just post my entire code up and tell me what I have done wrong.

No. You can fix this yourself, and it will benefit you more if you do it, as opposed to us doing it for you.

For the moment, I would recommend only using one ball. If you want more later, you should look into arrays. But for now, just go with one.
Why are you adding ten to the ball's x and y position each time through the loop? Also, I would think carefully about the starting position of your ball.
triumph




PostPosted: Sun Apr 24, 2005 5:34 pm   Post subject: (No subject)

The + 10 every time through the loop is so it updates it's position....? I didn't want you to do it for me if I wanted that I wouldn't of spent 3 and a half hours messing around with it.

I'll keep at it.
Cervantes




PostPosted: Sun Apr 24, 2005 6:18 pm   Post subject: (No subject)

Do you really want to move the balls ten pixels up and ten pixels right each time through the loop, forever and ever? Seems to me that wouldn't allow you to make the balls bounce off the edges of the screen... Thinking
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  [ 20 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: