
-----------------------------------
eNc
Fri Jan 21, 2005 9:54 am

Pong.
-----------------------------------
Hi umm yea I've made paddles for a ping game except they don't show up at the same time
keys are w, s up and down arrows

This is what i have so far

setscreen ("nocursor")
var uy, uy2 : int := 190
var key, key2 : string (1)
procedure boxes
    loop
        drawfillbox (20, 40 + uy, 40, uy, blue)
        getch (key)
        if key = chr (200) then
            uy := uy + 10
        elsif key = chr (208) then
            uy := uy - 10
        end if
        drawfillbox (maxx - 50, 40 + uy2, maxx-70, uy2, blue)
        getch (key2)
        if key2 = 'w' then
            uy2 := uy2 + 10
        elsif key2 = 's' then
            uy2 := uy2 - 10
        end if
        cls
    end loop
end boxes
loop
    boxes
end loop

I don't know how I can make them visible at the same time.

-----------------------------------
Tony
Fri Jan 21, 2005 12:41 pm


-----------------------------------
because your pesudocode looks like

loop
     wait for getch
     draw box
     wait for another getch
     draw another box
end loop


Not only is that horribly bad, but getch doesnt work for two player games because of key jamming (if I was to hold down a button, you would not be able to move)

Use Input.KeyDown() instead

-----------------------------------
basketball4ever
Fri Jan 21, 2005 5:54 pm


-----------------------------------
i would suggest more like this


loop
drawbox1
drawbox2
getch (key)
if arrow key = up/down then
move box1 up/down
elsif arrow key = w/s then
move box2 up/down
end loop


-----------------------------------
Leftover
Fri Jan 21, 2005 8:02 pm


-----------------------------------
Not only is that horribly bad, but getch doesnt work for two player games because of key jamming (if I was to hold down a button, you would not be able to move) Use Input.KeyDown() instead

Did you not catch that part? Getch won't work if there are 2 people pressing keys at same time. It's only meant to get 1 key. A simple program like:
var move : string (1)

getch (move)

put ord (move)


will only take input of 1 key and if you run it you will see. An AI or using InputKeyDown like tony said really is the only option for 2 players like that.

-----------------------------------
Unreal_Origin
Fri Jan 21, 2005 8:09 pm


-----------------------------------
hey how is it going, your problem is that you have two loops one at the start and one in the procedure

i mod it a bit but here it is


setscreen ("nocursor")
var uy, uy2 : int := 190
var key, key2 : string (1)
procedure boxes (var uy,uy2:int)
        getch (key)
        if key = chr (200) then
            uy := uy + 10
        elsif key = chr (208) then
            uy := uy - 10
        end if
        getch (key2)
        if key2 = 'w' then
            uy2 := uy2 + 10
        elsif key2 = 's' then
            uy2 := uy2 - 10
        end if
        cls
end boxes
loop
    drawfillbox (20, 40 + uy, 40, uy, blue)
    drawfillbox (maxx - 50, 40 + uy2, maxx-70, uy2, blue)
    boxes (uy,uy2)
end loop




that is if you want to keep getch

if you want a better way then this is what i would suggest



setscreen ("nocursor")
setscreen ("offscreenonly")
var uy, uy2 : int := 190

var chars : array char of boolean


procedure boxes (var uy, uy2 : int)
    Input.KeyDown (chars)
    delay (50)
    if chars (KEY_UP_ARROW) then
        uy := uy + 10
        cls
        drawfillbox (20, 40 + uy, 40, uy, blue)
        drawfillbox (maxx - 50, 40 + uy2, maxx - 70, uy2, blue)
        View.Update
    elsif chars (KEY_DOWN_ARROW) then
        uy := uy - 10
        cls
        drawfillbox (20, 40 + uy, 40, uy, blue)
        drawfillbox (maxx - 50, 40 + uy2, maxx - 70, uy2, blue)
        View.Update
    end if

    if chars ('w') then
        uy2 := uy2 + 10
        cls
        drawfillbox (maxx - 50, 40 + uy2, maxx - 70, uy2, blue)
        drawfillbox (20, 40 + uy, 40, uy, blue)
        View.Update
    elsif chars ('s') then
        uy2 := uy2 - 10
        cls
        drawfillbox (maxx - 50, 40 + uy2, maxx - 70, uy2, blue)
        drawfillbox (20, 40 + uy, 40, uy, blue)
        View.Update
    end if
end boxes

drawfillbox (20, 40 + uy, 40, uy, blue)
drawfillbox (maxx - 50, 40 + uy2, maxx - 70, uy2, blue)

loop
    boxes (uy, uy2)
end loop



-----------------------------------
eNc
Sat Jan 22, 2005 10:57 am


-----------------------------------
ohh ok thanks 10 bits to u

-----------------------------------
eNc
Sat Jan 22, 2005 11:42 am


-----------------------------------
Sorry Double Post Can't Delete

-----------------------------------
eNc
Sat Jan 22, 2005 11:47 am


-----------------------------------
Check out the added code, is there anyway I can improve this?


setscreen ("nocursor")
%setscreen ("offscreenonly")
var uy, uy2 : int := 190

var chars : array char of boolean
var iFont, count : int
count := 0
var start, info : string (1)
procedure intro
    iFont := Font.New ("Arial Black:24:bold,italic")
    Font.Draw ("Welcome to Pong", 150, 300, iFont, blue)
    locate (19, 32)
    put "Press Enter to Begin"
    locate (20, 30)
    put "Press I for instructions"
end intro

procedure boxes (var uy, uy2 : int)
    Input.KeyDown (chars)
    delay (50)
    if chars ('w') then
        if uy >= maxy - 40 then
            uy := maxy - 40
        elsif uy < maxy - 40 then
            uy := uy + 10
            cls
            drawfillbox (20, 40 + uy, 40, uy, blue)
            drawfillbox (maxx - 40, 40 + uy2, maxx - 60, uy2, blue)
            %View.Update
        end if
    elsif chars ('s') then
        if uy  0 then
            uy := uy - 10
            cls
            drawfillbox (20, 40 + uy, 40, uy, blue)
            drawfillbox (maxx - 40, 40 + uy2, maxx - 60, uy2, blue)
            %View.Update
        end if
    end if
    if chars (KEY_UP_ARROW) then
        if uy2 >= maxy - 40 then
            uy2 := maxy - 40
        elsif uy2 < maxy - 40 then
            uy2 := uy2 + 10
            cls
            drawfillbox (maxx - 40, 40 + uy2, maxx - 60, uy2, blue)
            drawfillbox (20, 40 + uy, 40, uy, blue)
            %View.Update
        end if
    elsif chars (KEY_DOWN_ARROW) then
        if uy2  0 then
            uy2 := uy2 - 10
            cls
            drawfillbox (maxx - 40, 40 + uy2, maxx - 60, uy2, blue)
            drawfillbox (20, 40 + uy, 40, uy, blue)
            %View.Update
        end if
    end if
end boxes

procedure inmation
    locate (9, 35)
    put "Instructions"
    locate (12, 1)
    color (red)
    put "Left Paddle"
    color (black)
    put ""
    put "Press w to move paddle up."
    put "Press s to move paddle down."
    locate (12, 69)
    color (red)
    put "Right Paddle"
    color (black)
    locate (13, 70)
    put ""
    locate (14, 48)
    put "Press up arrow to move paddle up."
    locate (15, 44)
    put "Press down arrow to move paddle down."
    getch (info)
    if info = (KEY_ENTER) then
        cls
    end if
end inmation

drawfillbox (20, 40 + uy, 40, uy, blue)
drawfillbox (maxx - 40, 40 + uy2, maxx - 60, uy2, blue)

loop
    count := count + 1
    if count = 1 then
        cls
        intro
        getch (start)
        if start = KEY_ENTER then
            cls
            boxes (uy, uy2)
        elsif start = 'i' or start = 'I' then
            inmation
        end if
    else
        boxes (uy, uy2)
    end if

end loop


-----------------------------------
cool dude
Sat Jan 22, 2005 12:17 pm


-----------------------------------
looking good so far. change the background colour, add a ball, make score, make a high score list, but so far good. also when u press enter to play the game the paddles don't show up until u hit the key. thats easy to fix. all u have to do is give a starting point to the paddles so draw them first.

-----------------------------------
eNc
Sat Jan 22, 2005 1:04 pm


-----------------------------------
looking good so far. change the background colour, add a ball, make score, make a high score list, but so far good. also when u press enter to play the game the paddles don't show up until u hit the key. thats easy to fix. all u have to do is give a starting point to the paddles so draw them first.


thanks

-----------------------------------
eNc
Sat Jan 22, 2005 1:16 pm


-----------------------------------
I've created the ball, however now the paddles won't move and I'm not sure how to do hit detection of the paddles, here's the code


setscreen ("nocursor")
%setscreen ("offscreenonly")
var uy, uy2 : int := 190

var chars : array char of boolean
var iFont, count : int
count := 0
var start, info : string (1)
procedure intro
    iFont := Font.New ("Arial Black:24:bold,italic")
    Font.Draw ("Welcome to Pong", 150, 300, iFont, blue)
    locate (19, 32)
    put "Press Enter to Begin"
    locate (20, 30)
    put "Press I for instructions"
end intro

procedure boxes (var uy, uy2 : int)
    Input.KeyDown (chars)
    delay (50)
    if chars ('w') then
        if uy >= maxy - 40 then
            uy := maxy - 40
        elsif uy < maxy - 40 then
            uy := uy + 10
            cls
            drawfillbox (20, 40 + uy, 40, uy, blue)
            drawfillbox (maxx - 30, 40 + uy2, maxx - 50, uy2, blue)
            View.Update
        end if
    elsif chars ('s') then
        if uy  0 then
            uy := uy - 10
            cls
            drawfillbox (20, 40 + uy, 40, uy, blue)
            drawfillbox (maxx - 30, 40 + uy2, maxx - 50, uy2, blue)
            View.Update
        end if
    end if
    if chars (KEY_UP_ARROW) then
        if uy2 >= maxy - 40 then
            uy2 := maxy - 40
        elsif uy2 < maxy - 40 then
            uy2 := uy2 + 10
            cls
            drawfillbox (maxx - 30, 40 + uy2, maxx - 50, uy2, blue)
            drawfillbox (20, 40 + uy, 40, uy, blue)
            View.Update
        end if
    elsif chars (KEY_DOWN_ARROW) then
        if uy2  0 then
            uy2 := uy2 - 10
            cls
            drawfillbox (maxx - 30, 40 + uy2, maxx - 50, uy2, blue)
            drawfillbox (20, 40 + uy, 40, uy, blue)
            View.Update
        end if
    end if
end boxes

procedure inmation
    locate (9, 35)
    put "Instructions"
    locate (12, 1)
    color (red)
    put "Left Paddle"
    color (black)
    put ""
    put "Press w to move paddle up."
    put "Press s to move paddle down."
    locate (12, 69)
    color (red)
    put "Right Paddle"
    color (black)
    locate (13, 70)
    put ""
    locate (14, 48)
    put "Press up arrow to move paddle up."
    locate (15, 44)
    put "Press down arrow to move paddle down."
    getch (info)
    if info = (KEY_ENTER) then
        cls
    end if
end inmation

procedure ball
    var dx, dy : int := 300
    var xc : int := 0
    loop
        dx := dx + 10
        dy := dy + 10
        if dx + 5 >= maxx - 50 and uy2 = dx - 10 or uy2 = dx + 10 then
            dx := dx - 10
        elsif dx + 5 = maxy - 5 then
            dy := dy - 10
        elsif dy + 5 