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

Username:   Password: 
 RegisterRegister   
 Help on modifying the Paddleball code.
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
MfIrE




PostPosted: Fri May 14, 2004 3:33 pm   Post subject: Help on modifying the Paddleball code.

For the final project for computer science, we were to find a source code, use that and also make the game educational. So I choose the paddleball.t (not the paddleball2.t) What I decided to do was: every 30 secs, a fruit would come up on a random part of the screen. Upon the ball hitting the fruit, it would clear the screen and give you a math question. If you got it right, you would get +10, if wrong -10. After you would go back to the game and continue.

I got how to randomize the fruit, but not how to change the screen. Any help?

Here's the randomizing fruit (kinda looks like a ball lol. I suck Wink )

var x, y : int := 0
randint (x, 21, 378)
randint (y, 220, 470)
drawfilloval (x, y, 20, 20, 12)

Lastly, Credit goes to Paul Bian. You. Are. Awesome.
Sponsor
Sponsor
Sponsor
sponsor
Dan




PostPosted: Fri May 14, 2004 4:19 pm   Post subject: (No subject)

well you need to uses colsion dection to check if the ball has hit it. You have the x and y of the ball and the x and y of the fruit so you can uses some math and if staments to check if the ball has hit the fruit.

Here are some links to tutorials on this site about colsion dection:

http://www.compsci.ca/v2/viewtopic.php?t=75 (look down this one two, there are some tips on difrent kinds of closion dection)

http://www.compsci.ca/v2/viewtopic.php?t=129 (this one whould help with making the ball boucning better)

http://www.compsci.ca/v2/viewtopic.php?t=2381 (some info on whatdot color, not the best way of doing colosion dection but will work)


there are also many help posts and submisions that deal with colisione dection that you could find by using the search fuction of this site.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
Paul




PostPosted: Fri May 14, 2004 8:50 pm   Post subject: Re: Help on modifying the Paddleball code.

MfIrE wrote:
Lastly, Credit goes to Paul Bian. You. Are. Awesome.

Awesome indeed, though I must warn u, the path of the ball is sometimes predictable (actually almost all the time) thats the point of the paddleball 2 source, so u wouldn't get it so easily. Anyway, I didn't do the randomizing slope of path thingy, because I hated it, it sped up irregularily and stuff. You'd prolly wanna try it out, just to see.
white_dragon




PostPosted: Sat May 15, 2004 4:25 pm   Post subject: (No subject)

haha! u can easily base that program usin shantz's code!
Paul




PostPosted: Sat May 15, 2004 5:10 pm   Post subject: (No subject)

Evil or Very Mad
FYI I made this in 20 min, the first class shantz was explaining, and B4 he finished explaining how to move the freaking paddle Evil or Very Mad I won't say anything mean...
SuperGenius




PostPosted: Sat May 15, 2004 10:00 pm   Post subject: (No subject)

You guys may find this amusing but I'm doing Super Breakout for my summative. What I've got so far is based on Shantz's code, although I may have to change it in the name of efficency.
Paul




PostPosted: Sat May 15, 2004 10:01 pm   Post subject: (No subject)

Shantz's codes are crap, you should never use them.
SuperGenius




PostPosted: Sat May 15, 2004 10:07 pm   Post subject: (No subject)

Ouch, that hurts. I agree that the origional code he gave us was not very efficent, but I fixed that up a little. The thing is though, our class is very stupid compared to yours paul. in our class 14 people failed the Work Hours test, for example. This means that he has to spend a lot of time explaining things to people that a few of us understood right away. The end result of a year of this is that we haven't learned all the good stuff to make a game with.
MfIrE




PostPosted: Sat May 29, 2004 10:11 am   Post subject: (No subject)

With what i've learned from the collision thing..
I've tried it, but it didn't work properly
Can someone check whats wrong?
Thanks

code:

setscreen ("graphics: 400, 500")
setscreen ("offscreenonly")
setscreen ("noecho")
var PaddleX, PaddleY : int := 11
var BallX, BallY : int := 50
var incX, incY : int := 3
var score, lives, count, count2, count3 : int := 0
var CherryX, CherryY : int
var chars : array char of boolean
var anykey : string (1)
var PaddleLength, PaddleWidth := 76
var continue : string := " "
PaddleWidth := 15
proc border
    drawbox (0, 0, maxx, maxy, black)
    drawbox (10, 10, maxx - 10, maxy - 10, black)
    drawfill (5, 5, 12, black)
end border

proc drawPaddle
    drawfillbox (PaddleX, PaddleY, PaddleX + 75, PaddleY + PaddleWidth, 43)
    drawbox (PaddleX - 1, PaddleY - 1, PaddleX + 76, PaddleY + 16, black)
end drawPaddle

proc movePaddle
    drawfillbox (PaddleX - 1, PaddleY - 1, PaddleX + PaddleLength, PaddleY + 16, 0)
    Input.KeyDown (chars)
    if chars (KEY_LEFT_ARROW) and PaddleX - 2 > 0 then
        PaddleX -= 4
    elsif chars (KEY_RIGHT_ARROW) and PaddleX + 77 < maxx then
        PaddleX += 4
    end if
end movePaddle

proc drawball
    drawoval (BallX, BallY, 10, 10, black)
    drawfilloval (BallX, BallY, 9, 9, 12)
end drawball

proc drawcherry
    if count = 0 then
        randint (CherryX, 20, 380)
        randint (CherryY, 70, 430)
        drawfilloval (CherryX, CherryY, 20, 20, 12)
        drawarc (CherryX - 12, CherryY - 12, 15, 54, 30, 90, 3)
        count := 1
    else
    end if
end drawcherry

proc moveball
    drawfilloval (BallX, BallY, 11, 11, white)
    BallX += incX
    BallY += incY
    delay (7)
end moveball

lives := 3

proc checkBall
    if BallX + 11 >= maxx or BallX - 11 < 0 then
        incX := -incX
    end if
    if BallY - 11 <= 0 or BallY + 11 >= maxy then
        incY := -incY
    end if
    if BallY - 11 <= 0 then
        lives -= 1
        count := 0
        cls
        put "Press AnyKey"
        getch (anykey)
        cls
        BallX := maxx div 2
        BallY := maxy div 2
    end if
    if BallX + 11 <= PaddleX + PaddleLength and BallX - 11 >= PaddleX and BallY - 11 <= PaddleY + PaddleWidth then
        incY := -incY
    elsif BallX - 11 < PaddleX + PaddleLength and BallX - 11 > PaddleX and BallY - 11 > PaddleY and BallY - 11 < PaddleY + PaddleWidth then
        incX := -incX
        incY := -incY
    elsif BallX + 11 < PaddleX + PaddleLength and BallX + 11 > PaddleX and BallY - 11 > PaddleY and BallY - 11 < PaddleY + PaddleWidth then
        incX := -incX
        incY := -incY
    end if
end checkBall

proc cherry
    for h : 1 .. 3
        if count2 = 0 then
            CherryX := CherryX - 20
            CherryY := CherryY - 1
            count2 := count2 + 1
            for i : 1 .. 40
                if CherryX = BallX and CherryY = BallY then
                    count3 := 1
                else
                    CherryX := CherryX + 1
                end if
                exit when count3 = 1
            end for
            exit when count3 = 1
        elsif count2 = 1 then
            CherryX := CherryX - 40
            CherryY := CherryY + 1
            for i : 1 .. 40
                if CherryX = BallX and CherryY = BallY then
                    count3 := 1
                else
                    CherryX := CherryX + 1
                end if
                exit when count3 = 1
            end for
            exit when count3 = 1
        end if
    end for
end cherry

proc challenge
cls
delay (20000)
end challenge

proc scoreshow
    locate (1, 1)
    put "Score: ", score, " Lives: ", lives
end scoreshow

loop
    drawPaddle
    drawball
    drawcherry
    View.Update
    moveball
    movePaddle
    checkBall
    cherry
    if count3 = 1 then
        challenge
    end if
    if lives < 0 then
        count3 := 0
        exit
    end if
    scoreshow
    count2 := 0
end loop
put "Your score: ", score
Paul




PostPosted: Sat May 29, 2004 11:30 am   Post subject: (No subject)

Oh, you wanna hit the cherry? and have it dissapear? You can use whatdotcolor for that, and if the ball hits the cherry, add one point, then cls and draw the cherry somewhere else.
P.S.: you can at least change the colors around a bit lol, so it wouldn't look exactly like my program plus a cherry Laughing
MfIrE




PostPosted: Sat May 29, 2004 11:34 am   Post subject: (No subject)

haha
nonono
What I want it to do is:
When the Ball touches the Cherry, it'll freeze or something, and give you a math question to answer. Upon getting it right +10 is awarded, and you if you get it wrong -10 is awarded. (In addition to the 5 points awarded when hitting the paddle)
Cervantes




PostPosted: Sat May 29, 2004 11:44 am   Post subject: (No subject)

code:

if ball collides with cherry

cls
your math question here
if answer = correct then
points += 10
else
points -= 10
end if

end if
MfIrE




PostPosted: Sat May 29, 2004 12:07 pm   Post subject: (No subject)

So you mean what I did was right? And all I had to do was add the math question thing? What I wanted to do was "When the Ball touches the Cherry, it'll freeze or something, and give you a math question to answer. Upon getting it right +10 is awarded, and you if you get it wrong -10 is awarded. (In addition to the 5 points awarded when hitting the paddle)" Also what I forgot to say was: after answering the math question, the game would continue. Then at like maybe 50 points it'll change from addition to subtraction. Very Happy
Paul




PostPosted: Sat May 29, 2004 12:32 pm   Post subject: (No subject)

well, get or getch would effectively stop the program, all you have to do is insert the problem when the ball touches the cherry. Make sure u using View.Update to make the question show, and then after getting the answer, the game would continue. And just use the score, to determine the kinds of questions, I don't know whether ur using arrays, or text files or random numbers ...[/code]
MfIrE




PostPosted: Sat May 29, 2004 12:54 pm   Post subject: (No subject)

The code I used to collide the ball with the cherry. Is it right though? I just want to make sure before I continue.
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  [ 18 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: