
-----------------------------------
MfIrE
Fri May 14, 2004 3:33 pm

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 ;) )

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.

-----------------------------------
Dan
Fri May 14, 2004 4:19 pm


-----------------------------------
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.

-----------------------------------
Paul
Fri May 14, 2004 8:50 pm

Re: Help on modifying the Paddleball code.
-----------------------------------
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
Sat May 15, 2004 4:25 pm


-----------------------------------
haha! u can easily base that program usin shantz's code!

-----------------------------------
Paul
Sat May 15, 2004 5:10 pm


-----------------------------------
:evil: 
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:  I won't say anything mean...

-----------------------------------
SuperGenius
Sat May 15, 2004 10:00 pm


-----------------------------------
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
Sat May 15, 2004 10:01 pm


-----------------------------------
Shantz's codes are crap, you should never use them.

-----------------------------------
SuperGenius
Sat May 15, 2004 10:07 pm


-----------------------------------
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
Sat May 29, 2004 10:11 am


-----------------------------------
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


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 = maxy then
        incY := -incY
    end if
    if 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
Sat May 29, 2004 11:30 am


-----------------------------------
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  :lol:

-----------------------------------
MfIrE
Sat May 29, 2004 11:34 am


-----------------------------------
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
Sat May 29, 2004 11:44 am


-----------------------------------

if ball collides with cherry

cls
your math question here
if answer = correct then
points += 10
else 
points -= 10
end if

end if


-----------------------------------
MfIrE
Sat May 29, 2004 12:07 pm


-----------------------------------
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.  :D

-----------------------------------
Paul
Sat May 29, 2004 12:32 pm


-----------------------------------
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
Sat May 29, 2004 12:54 pm


-----------------------------------
The code I used to collide the ball with the cherry.  Is it right though?  I just want to make sure before I continue.

-----------------------------------
SuperGenius
Sat May 29, 2004 6:18 pm


-----------------------------------
perhaps it would be good to use window.open or whatever for the question, so that you dont have to deal with erasing and/or redrawing the main screen. I dont exactly know how it works but i gather that you can open a second window using Window.Open(winID) and close it using Window.Close(winID).

I have a question about secondary windows though.... how do you tell turing which window a certain command pertains to?

-----------------------------------
Paul
Sat May 29, 2004 8:18 pm


-----------------------------------
Im not sure, but it might be along the lines of this:

Window.SetActive()

you could check up on that.

-----------------------------------
MfIrE
Sun May 30, 2004 4:11 pm


-----------------------------------
dammit
I can't get it to work? Can someone help?
I'm not sure what to do now.  I just want to add the question now.  Although I'm not sure if my code currently is even right.
