Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4106
Number of posts: 14016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
breakout - a little help needed Posted by beardtrix on 25 Oct 2001 at 3:24 PM
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:
var type barinfo = record
                x,y:integer;
                visible: boolean;
                end;

bars: array [1..7*5] of barinfo;

if you can help then please e-mail me (mailto:phatsuma@hotmail.com) and i'll send you all my code.

Report
Re: breakout - a little help needed Posted by iby on 25 Oct 2001 at 3:53 PM
: 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:
:
: var type barinfo = record
:                 x,y:integer;
:                 visible: boolean;
:                 end;
: 
: bars: array [1..7*5] of barinfo;
: 

: if you can help then please e-mail me (mailto:phatsuma@hotmail.com) and i'll send you all my code.
:

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


Iby


Report
The slowmotion-effect... Posted by Nordquist on 26 Oct 2001 at 2:59 AM
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.

Report
keyboard handler maybe solves the problem Posted by chobo on 26 Oct 2001 at 12:08 PM
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.


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:

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.





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.