breakout - a little help needed - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

breakout - a little help needed

beardtrixbeardtrix Posts: 44Member
I'm making the game breakout in pascal as part of a school project. I'm a bit stuck on a couple of things.

in the main game loop i have a procedure called ball_move; I have done this so that the ball will be constantly moving/bouncing. however, because the keypresses are also monitered in the main game loop, whenever you move the paddle the ball waits for the paddle to move then carries on thus creating a slow motion effect on the ball. how do i stop this from happening?

the next problem is to do with collision detection. I have drawn all my blocks in a procedure called bar. however, i don't know how to make the ball bounce off these blocks. I can only do it for 1 block. how do i make it bounce off all the blocks?

my last problem is that i don't know how to delete the block that the ball has hit. i have a bit of an idea but i need some help with it.

my blocks are in an array like this:
[code]
var type barinfo = record
x,y:integer;
visible: boolean;
end;

bars: array [1..7*5] of barinfo;
[/code]
if you can help then please e-mail me (mailto:[email protected]) and i'll send you all my code.

Comments

  • ibyiby Posts: 323Member
    : I'm making the game breakout in pascal as part of a school project. I'm a bit stuck on a couple of things.
    :
    : in the main game loop i have a procedure called ball_move; I have done this so that the ball will be constantly moving/bouncing. however, because the keypresses are also monitered in the main game loop, whenever you move the paddle the ball waits for the paddle to move then carries on thus creating a slow motion effect on the ball. how do i stop this from happening?
    :
    : the next problem is to do with collision detection. I have drawn all my blocks in a procedure called bar. however, i don't know how to make the ball bounce off these blocks. I can only do it for 1 block. how do i make it bounce off all the blocks?
    :
    : my last problem is that i don't know how to delete the block that the ball has hit. i have a bit of an idea but i need some help with it.
    :
    : my blocks are in an array like this:
    : [code]
    : var type barinfo = record
    : x,y:integer;
    : visible: boolean;
    : end;
    :
    : bars: array [1..7*5] of barinfo;
    : [/code]
    : if you can help then please e-mail me (mailto:[email protected]) and i'll send you all my code.
    :

    Send me an email and I'll try to help you...


    Iby


  • NordquistNordquist Posts: 49Member
    I've made a Pong-clone and had trouble with the same thing (if I understood it right).
    -> The ball slows down when a keypress is detected in the game loop.

    I corrected this with a
    delay(8)
    placed in the game loop, and only run when the keypressed isn't.
    Like this...

    if keypressed then key:=UPCASE(readkey);
    if key=#27 then end:=1;
    if key= blablabla;
    else delay(8);

    The number needs to be tested until it's the right number. Maybe someone else has a more beautilful way to do it, but this works.

  • chobochobo Posts: 30Member
    [code]PROGRAM Keyboard;
    USES Crt, DOS;
    VAR
    OldKbd: PROCEDURE;
    Abort : BOOLEAN;

    {$F+}
    PROCEDURE NewKbd; INTERRUPT;
    VAR
    ScanCode: BYTE;
    BEGIN
    ScanCode := Port[$60];

    WriteLn(ScanCode);
    IF ScanCode = 1
    THEN
    Abort := TRUE;

    ASM
    mov ax,0C00h
    int 21h
    END;

    INLINE($9C); {Same as Asm pushf end}
    OldKbd
    END;
    {$F-}

    PROCEDURE SetNewKbd;
    VAR
    i : BYTE;
    BEGIN
    GetIntVec(9, @OldKbd);
    SetIntVec(9, addr(NewKbd));
    END;

    PROCEDURE SetOldKbd;
    BEGIN
    SetIntVec(9, @OldKbd)
    END;

    BEGIN
    ClrScr;
    SetNewKbd;
    REPEAT
    UNTIL Abort;
    SetOldKbd
    END.[/code]

    this is are three procedures i wrote after an idea of Daniel John Walker. after setnewkbd has been called newkbd will be called whenever a key is pressed. i think this solves your problem, but i am not sure. try it. if you change the procedure to fit ur program it could look like:

    [code]PROGRAM Keyboard;
    USES Crt, DOS;
    VAR
    OldKbd: PROCEDURE;
    Abort : BOOLEAN;

    {$F+}
    PROCEDURE NewKbd; INTERRUPT;
    VAR
    ScanCode: BYTE;
    BEGIN
    ScanCode := Port[$60];

    IF ScanCode = 75 {code for left arrow}
    THEN
    moveleft; {do whatever is needed to move the paddle left}
    IF ScanCode = 77 {code for right arrow}
    THEN
    moveright; {do whatever is needed to move the paddle right}

    ASM
    mov ax,0C00h
    int 21h
    END;

    INLINE($9C); {Same as Asm pushf end}
    OldKbd
    END;
    {$F-}

    PROCEDURE SetNewKbd;
    VAR
    i : BYTE;
    BEGIN
    GetIntVec(9, @OldKbd);
    SetIntVec(9, addr(NewKbd));
    END;

    PROCEDURE SetOldKbd;
    BEGIN
    SetIntVec(9, @OldKbd)
    END;

    BEGIN
    ClrScr;
    SetNewKbd;
    REPEAT
    UNTIL Abort;
    SetOldKbd
    END.[/code]

Sign In or Register to comment.