Box movement help
Author |
Message |
1337.Billy
|
Posted: Wed Jun 08, 2005 6:49 pm Post subject: Box movement help |
|
|
Hey everyone, I beleive this is my first post so Hi. Im working on my final project for computer class. Im making a paddle ball game. I need help moving the box, and im not sure how to make it move
My code do far:
code: |
%Abilio Rebelo-Soares
%Final CPT
%June 3rd, 2005
import GUI in "%oot/lib/GUI"
var font : int := Font.New ("Arial:40")
var title : string := "Abilio's Pong!"
var username : string
procedure nextscreen
var quitButton : int
GUI.Quit
cls
end nextscreen
var button : int := GUI.CreateButton (250, 200, 120, "PLAY!", nextscreen)
Font.Draw (title, 150, 250, font, 12)
loop
exit when GUI.ProcessEvent
end loop
put "Before you start playing what is your name?"
get username : *
cls
var x, y : int
x := 100
y := 100
var chars : array char of boolean
loop
Input.KeyDown (chars)
if chars (KEY_RIGHT_ARROW) then
x := x + 10
end if
if chars (KEY_LEFT_ARROW) then
x := x - 10
end if
drawfillbox (x,y , 4, 4, red)
delay(25)
cls
end loop
|
Thanks in advance whoever helps me
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
vagyb
|
Posted: Wed Jun 08, 2005 9:10 pm Post subject: (No subject) |
|
|
well u are moving only the X2 coordinate, u have to move both the x1 and x2 coordiantes (when u draw the box). and cls too
|
|
|
|
|
|
1337.Billy
|
Posted: Thu Jun 09, 2005 2:34 pm Post subject: (No subject) |
|
|
Thanks for helping i was able to make the paddle move but now im not sure how to get a ball in there and make it hit the sides and bounce and such. I have looked at the collision detection tutorials but have not been successful, so can someone please help. My new code is below:
code: | import GUI in "%oot/lib/GUI"
colorback(black)
cls
color(white)
var font : int := Font.New ("Arial:40")
var title : string := "Abilio's Paddle Ball!"
var username : string
var score: int:=0
var chars : array char of boolean
var pos := maxx div 2
var ballx := maxx div 2
var bally := 15
procedure nextscreen
var quitButton : int
GUI.Quit
cls
end nextscreen
var button : int := GUI.CreateButton (255, 200, 150, "PLAY!", nextscreen)
Font.Draw (title, 100, 250, font, 12)
loop
exit when GUI.ProcessEvent
end loop
put "Before you start playing what is your name?"
get username : *
locate (3, 1)put "Game starting in..."
delay (1000)
locate (4, 1)put "3"
delay (1000)
locate (5, 1)put "2"
delay (1000)
locate (6, 1)put "1"
delay (1000)
locate (7, 1)put "GO!"
delay (1000)
cls
setscreen ("offscreenonly")
loop
drawfillbox (pos - 25, 15, pos + 25, 20, brightred)
Input.KeyDown (chars)
if chars (KEY_LEFT_ARROW) and pos - 25 > 0 then
pos -= 1
ballx -= 1
elsif chars (KEY_RIGHT_ARROW) and pos + 30 < maxx then
pos += 1
ballx += 1
end if
View.Update
cls
locate (1,1) put "Name:", username
locate (1,35) put "Score:", score
end loop |
Thanks to who helps me
|
|
|
|
|
|
1337.Billy
|
Posted: Thu Jun 09, 2005 8:39 pm Post subject: (No subject) |
|
|
Anyone, please I really need help on this one part.
|
|
|
|
|
|
MysticVegeta
|
Posted: Thu Jun 09, 2005 8:44 pm Post subject: (No subject) |
|
|
Press F10 -> Music.PlayFile -> Look at example number 2. You will see they have a star bouncing off the edges. I cant tell you anything more because i haven;t taken Grade 10 math trignometry. (cos, tan, sin)
|
|
|
|
|
|
vagyb
|
Posted: Thu Jun 09, 2005 8:49 pm Post subject: (No subject) |
|
|
well easiest thing for u would be to use whatdotcolor
so first get a picture of ur ball, import it in turing, give X and Y variables, give Height and Width variables to it. then use whatdotcolor
so for example
if whatdotcolor (x, y) = red then
put code here for w/e direction u want to go.
to make the bounce angle the same as real life is very hard, so i'm guessing u should just do a 45 degree angle bounce off.
|
|
|
|
|
|
1337.Billy
|
Posted: Thu Jun 09, 2005 8:55 pm Post subject: (No subject) |
|
|
Well, Im just drawing a circle but i want it to bounce of any where in the screen and off the paddle and somehow get a counter to keep track of their score, Im not trying to make anyone giving me source code just some help on these parts.
Description: |
So far what i got (for my school) |
|
Download |
Filename: |
CPT Beta.zip |
Filesize: |
307.58 KB |
Downloaded: |
120 Time(s) |
|
|
|
|
|
|
Cervantes
|
Posted: Fri Jun 10, 2005 3:20 pm Post subject: (No subject) |
|
|
Assuming you've got x and y coordinates of the ball that correspond to the centre of the ball:
code: |
if ball.x + ball.radius >= maxx or ball.x - ball.radius <= 0 then
ball.vx *= -1 %same as ball.vx := ball.vx * -1
%this code reverses the direction in the x plane.
% ball.vx is the velocity of the ball in the x plane.
end if
%do similar things for y.
%Let's use whatdotcolour for paddle collisions, since you seem to be struggling with standard range comparisons.
if whatdotcolour (ball.x, ball.y - ball.radius - 1) = paddle.colour then
ball.vy *= -1
end if
|
Mind you, that whatdotcolour collision isn't too good. If you want to improve it, you should use a for loop to check a range of values a certain distance below the ball.y. The values checked range from (ball.x - ball.radius, ball.y) to (ball.x + ball.radius), ball.y).
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
1337.Billy
|
Posted: Fri Jun 10, 2005 3:40 pm Post subject: (No subject) |
|
|
Well this is diffucult stuff for me because our teacher neer taught us this stuff. Well ive tried to add a ball but look what happens. O and im not sure how to do that range thing.
Description: |
|
Download |
Filename: |
Final Project.zip |
Filesize: |
308.14 KB |
Downloaded: |
125 Time(s) |
|
|
|
|
|
|
Drakain Zeil
|
Posted: Fri Jun 10, 2005 3:55 pm Post subject: (No subject) |
|
|
My teacher didn't teach a lot of stuff like this... a lot of this you need to think about for yourself. Thinking is more or less asking a lot of questions of how things would work, and answering them - the problem is, answers lead to questions! Not that I'm saying you don't think, I'm saying people today in general don't criticaly think.
|
|
|
|
|
|
1337.Billy
|
Posted: Fri Jun 10, 2005 7:48 pm Post subject: (No subject) |
|
|
I know what you mean but I/ve tried everything but I dont know how to get that flickering out of my program.
|
|
|
|
|
|
1337.Billy
|
Posted: Sat Jun 11, 2005 9:39 am Post subject: (No subject) |
|
|
Here is an update on what i have done, I just need help with 4 things. Why does it it flicker, why doesnt the background stay black, should i stay with whatdotcolour collision detection and how can i tabulate a score when the ball hits the paddle.
What I have done so far is attached below
Description: |
Here is an update on what i have done, I just need help with 4 things. Why does it it flicker, why doesnt the background stay black, should i stay with whatdotcolour collision detection and how can i tabulate a score when the ball hits the paddle. |
|
Download |
Filename: |
Project.zip |
Filesize: |
308.14 KB |
Downloaded: |
109 Time(s) |
|
|
|
|
|
|
Cervantes
|
Posted: Sat Jun 11, 2005 9:48 am Post subject: (No subject) |
|
|
I haven't downloaded your project, because I didn't feel like downloading 300kb (dial-up) and because that's about the size of a zipped turing-made .exe. If that's the case, you'll get more/better help by posting the source code.
1.)
I suspect it flickers because you're using View.Update incorrectly or not at all. Check the walkthrough for a link.
2.)
Have you got colourback (black) in conjunction with cls? Note that the colourback should be outside the loop.
3.)
If whatdotcolour is working for you, I suggest you stay with it. On the other hand, it wouldn't hurt to try another way, for educational purposes.
4.)
If the ball hits the paddle (if statement with whatdotcolour to detect this collision) then add one to the score. The score is a global variable.
|
|
|
|
|
|
|
|