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

Username:   Password: 
 RegisterRegister   
 Pong.
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
eNc




PostPosted: Fri Jan 21, 2005 9:54 am   Post subject: 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

code:
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.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Fri Jan 21, 2005 12:41 pm   Post subject: (No subject)

because your pesudocode looks like
pseudocode:

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




PostPosted: Fri Jan 21, 2005 5:54 pm   Post subject: (No subject)

i would suggest more like this

code:

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




PostPosted: Fri Jan 21, 2005 8:02 pm   Post subject: (No subject)

tony wrote:
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:
code:

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




PostPosted: Fri Jan 21, 2005 8:09 pm   Post subject: (No subject)

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

code:

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

code:


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




PostPosted: Sat Jan 22, 2005 10:57 am   Post subject: (No subject)

ohh ok thanks 10 bits to u
eNc




PostPosted: Sat Jan 22, 2005 11:42 am   Post subject: (No subject)

Sorry Double Post Can't Delete
eNc




PostPosted: Sat Jan 22, 2005 11:47 am   Post subject: (No subject)

Check out the added code, is there anyway I can improve this?

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 - 40, 40 + uy2, maxx - 60, uy2, blue)
            %View.Update
        end if
    elsif chars ('s') then
        if uy <= 0 then
            uy := 0
        elsif 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 := 0
        elsif 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
Sponsor
Sponsor
Sponsor
sponsor
cool dude




PostPosted: Sat Jan 22, 2005 12:17 pm   Post subject: (No subject)

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




PostPosted: Sat Jan 22, 2005 1:04 pm   Post subject: (No subject)

cool dude wrote:
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




PostPosted: Sat Jan 22, 2005 1:16 pm   Post subject: (No subject)

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

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 := 0
        elsif 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 := 0
        elsif 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 <= 40 and uy = dx - 10 or uy = dx + 10 then
            dx := dx + 10
        end if
        if dy + 5 >= maxy - 5 then
            dy := dy - 10
        elsif dy + 5 <= 5 then
            dy := dy + 10
        end if
        drawfilloval (dx, dy, 5, 5, red)
        delay (10)
        drawfilloval (dx, dy, 5, 5, white)
    end loop
end ball

loop
    count := count + 1
    if count = 1 then
        cls
        intro
        getch (start)
        if start = KEY_ENTER then
            cls
            drawfillbox (20, 40 + uy, 40, uy, blue)
            drawfillbox (maxx - 30, 40 + uy2, maxx - 50, uy2, blue)

            boxes (uy, uy2)
            ball
        elsif start = 'i' or start = 'I' then
            inmation
        end if
    else

        boxes (uy, uy2)
        ball
    end if

end loop

basketball4ever




PostPosted: Sat Jan 22, 2005 1:18 pm   Post subject: (No subject)

maybe add a little bit of difficulty??? like possibly... how to complete a level. or like a random "point" thing comes out and you have to get it in a certain amount of time.... too much boring pong games out Very Happy make urs fun Very Happy
eNc




PostPosted: Sat Jan 22, 2005 1:21 pm   Post subject: (No subject)

basketball4ever wrote:
maybe add a little bit of difficulty??? like possibly... how to complete a level. or like a random "point" thing comes out and you have to get it in a certain amount of time.... too much boring pong games out Very Happy make urs fun Very Happy



lol yea but first things first i have to get it to work
Razz
eNc




PostPosted: Sat Jan 22, 2005 1:22 pm   Post subject: (No subject)

now i have some hit dection with the boxes, but they won't move...
Bacchus




PostPosted: Sat Jan 22, 2005 4:29 pm   Post subject: (No subject)

they wont move b/c you call the ball proc and then theres a loop in there, so it just keeps repeating that proc over and over. i sugest taking everything out of that proc and just stick it in ur main program
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  [ 24 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: