
-----------------------------------
R2D2
Thu Jan 19, 2017 1:05 pm

Help with Game!
-----------------------------------
Hey guys so i need help with pong game that i am making. How can i make it when the ball hits sides it resets in middle and starts again. And also how can i add a timer, for example after 5 sec the game will start. Thanks :D


Here are the codes:


View.Set ("graphics:400;300,nobuttonbar")
colorback (white)

var key : array char of boolean
var p1pad, p2pad, ballx, bally, p1dir, p2dir, balldir, ballny, ballnx, speed, winner, win, snd : int

p1pad := maxy div 2
p2pad := maxx div 2
ballx := maxx div 2
bally := maxy div 2
ballnx := 5
ballny := 5
speed := 5
snd := 0

loop
    Input.KeyDown (key)
    if key (KEY_UP_ARROW) and p1pad = 25 then
        p1dir := 2
    else
        p1dir := 0
    end if

    if key ('w') and p2pad = 25 then
        p2dir := 2
    else
        p2dir := 0
    end if

    if p1dir = 1 then
        p1pad := p1pad + 10
    elsif p1dir = 2 then
        p1pad := p1pad - 5
    end if

    if p2dir = 1 then
        p2pad := p2pad + 5
    elsif p2dir = 2 then
        p2pad := p2pad - 5
    end if

    if ballx = maxy - 10 then
        ballny := -speed
    end if

    if ballx >= maxx - 25 then
        if p1pad + 20 >= bally + 5 and p1pad - 20 