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

Username:   Password: 
 RegisterRegister   
 Final Moving Canadian Flag HELP
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Robotkubo




PostPosted: Mon Feb 22, 2016 9:31 am   Post subject: Final Moving Canadian Flag HELP

Okay, I've been doing this project and I've made a two other posts about it, This should be my final one.
I've gotten the flag so it moves randomly around the screen, but the flag still goes outside of the area I want.

View.Set ("graphics,offscreenonly,nobuttonbar")
var x, y, xChange, yChange : int := 1
const R : int := 5
Draw.Box (0, 0, 638, 399, black)
x := maxx div 2
y := maxy div 2
loop
Draw.Cls
Draw.Box (0, 0, maxx, maxy, black)
Draw.MapleLeaf (x, y, x + 60, y + 60, red)
Draw.Fill (x + 30, y + 30, red, red)
Draw.FillBox (x - 30, y, x - 2, y + 60, red)
Draw.Box (x - 30, y, x + 90, y + 60, red)
Draw.Box (x - 30, y, x + 63, y + 60, red)
Draw.Fill (x + 80, y + 2,red, red)
View.Update
Time.Delay (5)
x += xChange
y += yChange
if View.WhatDotColor (x, y + R) = black then
yChange *= -1
elsif View.WhatDotColor (x, y - R) = black then
yChange *= -1
end if
if View.WhatDotColor (x + R, y) = black then
xChange *= -1
elsif View.WhatDotColor (x - R, y) = black then
xChange *= -1
end if
end loop

Please help
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Mon Feb 22, 2016 12:24 pm   Post subject: RE:Final Moving Canadian Flag HELP

What is the variable R? Let me guess, it's a variable from the code you borrowed for this and you're not sure, and now it's causing a problem.

All of your problems have come from trying to convert someone else's code to do what you want, without understanding how that code works. Even if you do manage to make this project work, it will be by accident. You still won't know how or why it works. It will be a lot easier to do it on your own from scratch, and then you'll actually know how to do it, so you'll have less trouble on your next assignment.
Robotkubo




PostPosted: Tue Feb 23, 2016 8:42 am   Post subject: RE:Final Moving Canadian Flag HELP

I completely understand how the code works, The R is my constant.

if View.WhatDotColor (x, y + R) = black then
yChange *= -1
elsif View.WhatDotColor (x, y - R) = black then
yChange *= -1
end if
if View.WhatDotColor (x + R, y) = black then
xChange *= -1
elsif View.WhatDotColor (x - R, y) = black then
xChange *= -1

is causing when the Flag hits the black box around the screen, but for some reason, but still the parts of the flag still go past the boarder and I'm not sure why that is.
Robotkubo




PostPosted: Tue Feb 23, 2016 8:44 am   Post subject: RE:Final Moving Canadian Flag HELP

Should I try and remove the R constant completely and replace it with a another var?
Insectoid




PostPosted: Tue Feb 23, 2016 12:36 pm   Post subject: RE:Final Moving Canadian Flag HELP

Quote:
The R is my constant


That doesn't tell me anything. Constant what? Why are you adding it to x and y in your collision code? Why is its value 5?
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 1  [ 5 Posts ]
Jump to:   


Style:  
Search: