打砖块游戏源代码

aoxue 2002-12-27 05:37:10
那位游戏高手编过打砖块游戏?或者知道此游戏的源码?或者下载地址?小弟急用?请帮小弟一把?谢谢。非常感谢。
...全文
639 20 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
ZhangYv 2003-01-31
  • 打赏
  • 举报
回复
蹭分的而已...
smartluwei 2003-01-30
  • 打赏
  • 举报
回复

   分     分分   分         分    分           分分分
分分分分分分 分分     分分分分分分分分分 分    分       分分分分
 分  分  分     分    分     分  分分分分分分    分   分
  分 分  分    分     分    分分分   分  分    分   分
分分分分分分 分分分分   分分分分分分分分 分分 分  分  分   分    分  分
   分   分 分    分   分     分    分  分   分分分分分分分分分分
分分分分分分 分 分    分   分     分 分分分分分分分分    分  分分
 分 分分  分 分  分分分分分分分分分分分 分    分       分   分 分
 分 分 分 分 分        分     分   分 分     分    分  分
分  分  分  分        分     分  分   分   分     分   分
  分分 分   分        分     分分分     分分     分分分
game_sage 2003-01-30
  • 打赏
  • 举报
回复
如果不显简单,看看我的。
http://home.online.tj.cn/user/devgame/cool-x/index.html
zzwu 2003-01-30
  • 打赏
  • 举报
回复
pascal编的
song82100 2003-01-30
  • 打赏
  • 举报
回复
用什么编呀
zzwu 2003-01-10
  • 打赏
  • 举报
回复
打砖块(breakout)游戏在borland 的Turbo Pascal(TP)的各個版本中,作爲例子,提供了源代码.以上是TP7中提供的源代码,較複雜. 我最早看到的是TP4所附帶的源代码,非常簡單,但我現在已經沒有了.
breakout是Bill Geitz最喜歡玩的游戏.
zzwu 2003-01-10
  • 打赏
  • 举报
回复
{************************************************}
{ }
{ Breakout Demo Program }
{ Copyright (c) 1992 by Borland International }
{ }
{************************************************}

program Breakout;

{

This is a version of the classic arcade game, Breakout.

SCREEN.PAS
COUNT.PAS
BRICKS.PAS
BOUNDS.PAS
WALLS.PAS
BREAKOUT.PAS

To build an executable file, compile from the command line with:

tpc /m breakout

or load BREAKOUT.PAS into the integrated development
environment and press F9.

When testing the program, you may want to force the paddle to
follow the ball, so you'll never miss. The program contains
conditional compilation directives to produce this version, and
you can build it from the command line with:

tpc /DTest breakout

or load BREAKOUT.PAS into the integrated development
environment, select Alt-O/C/Alt-C, type 'Test' (without the quotes,
of course) followed by the Enter key, then select Alt-C/B to
rebuild the executable file.
}

uses Screen, Count, Bricks, Bounds, Walls, Crt, Dos;

var
ss : SaveScreen;
w : Wall;
b : Ball;
p : Paddle;
Speed : LimitCounter;
Left : LeftBound;
Top : UpperBound;
Right : RightBound;
Bottom : LowerBound;
Obstacles : ObstacleList;
PaddleMsg,
SpeedMsg,
StartMsg,
QuitMsg,
PauseMsg1,
PauseMsg2,
TypeMsg : TextString;
Score : Counter;
Highest : Counter;
Balls : DownCounter;
X : Integer;
Finished : Boolean;
FirstGame : Boolean;
TypeInc,
ch : Char;

procedure Startup;
begin
{ First set up the screen and the cursor }
ss.Init;
TextBackground(BLACK);
ClrScr;

{ Create the boundaries of the playfield }
Left.Init(0, 0, 27, False);
Top.Init(0, 0, 82, False);
Right.Init(81, 0, 27, False);
Bottom.Init(0, 24, 82, True);

{ Initialize the score displays }
Score.Init(0, 65, 24, 'Score', 15);
Score.Show;
Highest.Init(0, 60, 25, 'High Score', 14);
Highest.Show;

{ Set up the various menu messages }
PauseMsg1.Init(31, 18, 'Paused. Press any', 15);
PauseMsg2.Init(31, 19, ' key to continue.', 15);
SpeedMsg.Init(5, 23, #24 + #25 + ' to change speed', 14);
StartMsg.Init(5, 24, #17 + #196 + #217 + ' to begin game', 14);
PaddleMsg.Init(5, 24, #27 + #26 + ' to move paddle', 14);
QuitMsg.Init(5, 25, 'ESC to quit', 14);
QuitMsg.Show;

{ Set up the information messages }
Balls.Init(5, 40, 24, -1, 'Balls', 15);
Balls.Show;
Speed.Init(1, 40, 25, 1, 10, 'Speed', 14);
Speed.Show;

{ Build the wall }
w.Init(1, 1, 16, 10);
w.Show;

{ Need to initialize these, even though we're going to move them later }
b.Init(10, 22, 1, -1, YELLOW);
p.Init(8, 23, WHITE);

{ Put the various obstacles into a list. We don't really need
to do this, but it makes changing things around much easier }
Obstacles.Init;
Obstacles.Append(@p);
Obstacles.Append(@w);
Obstacles.Append(@Left);
Obstacles.Append(@Top);
Obstacles.Append(@Right);
Obstacles.Append(@Bottom);

TypeMsg.Init(22, 12, 'Increase typematic rate? (y/n) ', WHITE);
TypeMsg.Show;
repeat
TypeInc := UpCase(ReadKey);
until (TypeInc = 'Y') or (TypeInc = 'N');
TypeMsg.Hide;

if TypeInc = 'Y' then
ss.Speedup;

ss.SetCursor($2000);
Randomize;
FirstGame := True;
end;

procedure NewGame;
begin
Balls.Reset;
Score.Reset;
if not FirstGame then
w.Reset;
X := Random(78) + 3;
b.MoveTo(X, 22);
p.MoveTo(X-2, 23);
b.Show;
p.Show;
Balls.Decrement;
FirstGame := False;
end;

{ This procedure handles keystrokes between games.
It returns False if the user presses ESC, otherwise it returns True. }
function MainMenu : Boolean;
var
Done : Boolean;
begin
MainMenu := True;
Done := False;
SpeedMsg.Show;
StartMsg.Show;
while not Done do
begin
ch := ReadKey;
case ch of
Chr(27) :
begin
MainMenu := False;
Done := True;
end;
#13 : Done := True;
#0 :
begin
ch := ReadKey;
if Ord(ch) = 72 then
Speed.Increment
else if Ord(ch) = 80 then
Speed.Decrement;
end;
end;
end;
SpeedMsg.Hide;
StartMsg.Hide;
end;

{ This procedure handles keystrokes while the game is in progress }
procedure ProcessKeyStroke;

{ Pause the game }
procedure Pause;
begin
PauseMsg1.Show;
PauseMsg2.Show;
ch := ReadKey;
if KeyPressed then
ch := ReadKey; { Swallow extended keystrokes }
PauseMsg1.Hide;
PauseMsg2.Hide;
b.Show;
end;

begin
ch := ReadKey;
case ch of
Chr(27) : Finished := True;
Chr(0) :
begin
ch := ReadKey;
{$IFNDEF Test}
case Ord(ch) of
75: p.MoveTo(p.GetX - 1, p.GetY); { Left Arrow }
77: p.MoveTo(p.GetX + 1, p.GetY); { Right Arrow }
else
Pause;
end;
{$ELSE}
Pause;
{$ENDIF}
end
else
Pause;
end;
end;

{ This procedure checks for collisions with any of the obstacles
and updates the screen accordingly. }
procedure Update;
var
Offset : Integer;
begin
if Obstacles.CheckCollisions(b, Score) then
begin
b.MoveY;
p.MoveTo(b.GetX - 2, p.GetY);
sound(150);
Delay(300);
nosound;
Balls.Decrement;
while KeyPressed do
ch := ReadKey;
end;

b.MoveX;
b.MoveY;

{$IFDEF Test}
p.MoveTo(b.NextX -2, p.GetY);
{$ENDIF}
end;

{ This procedure cleans up when we're exiting from the program }
procedure ShutDown;
begin
b.Hide;
Obstacles.Hide;
Balls.Hide;
Score.Hide;

Obstacles.Done;

ss.Restore;
if TypeInc = 'Y' then
ss.Slowdown;
ClrScr;
end;

{ This procedure plays a game. The main loop allows up to ten keystrokes,
then moves the ball and checks for collisions }
procedure Play;
var
KeyLoops : Integer;
begin
NewGame;
{$IFNDEF Test}
PaddleMsg.Show;
{$ENDIF}
Finished := False;
KeyLoops := 0;
repeat
if KeyPressed then
ProcessKeyStroke;
Inc(KeyLoops);
if (KeyLoops = 10) and not Finished then
begin
KeyLoops := 0;
UpDate;
end;
Delay(12 - Speed.GetValue);
until Finished or Balls.Last;
PaddleMsg.Hide;
end;

begin
Startup;
while MainMenu do
begin
Play;
Balls.Reset;
b.Hide;
p.Hide;
if Score.GetValue > Highest.GetValue then
Highest.SetValue(Score.GetValue);
end;
ShutDown;
end.
loveghb 2003-01-10
  • 打赏
  • 举报
回复
哈哈,原来这个游戏还真是有得研究啊,我前若干个礼拜用BGI编了一个不成熟的,但是效率确实不是很高,而且只有16色。各位看来都有些经验,就不要用QQ了吧,都把话留在这里,我们大家都能看到,岂不更好?
DDRBillOB 2003-01-10
  • 打赏
  • 举报
回复
你是用640*480吗?

顺便,各位能留下QQ交流一下吗?

我的是QQ:8901772
DarthVader 2003-01-07
  • 打赏
  • 举报
回复
sorry,16位色
DarthVader 2003-01-07
  • 打赏
  • 举报
回复
sorry,16位色
DarthVader 2003-01-07
  • 打赏
  • 举报
回复
1.球在一个时刻最多和8块砖相交。只用检测在球前进方向上会不会和砖块碰撞,不用检查一次碰撞包括球和所有砖块的碰撞,使用的是预测法,即提前看看球在下一时刻会不会碰壁,若是,则弹射;反之,可以继续前进。
2.16色模式不会比256色慢多少,我写的类星际(一小部分)游戏有160多帧。
你在Dx里面设置一下刷新率试试,或者优化一下代码。
3.装了.net后我原来写的游戏集体提速,看来.net框架有优化功能?所以我认为用.net下的C#写游戏不会慢的。
AloneWolf 2003-01-07
  • 打赏
  • 举报
回复
我遍过,仿dxball做的
DDRBillOB 2003-01-04
  • 打赏
  • 举报
回复
我想问几个问题:
1.如果每移动一次球就检查一次碰撞包括球和所有砖块的碰撞等(假设每个砖块大小32*16,在640*480的画面中最多就有600个砖块) 会不会很慢?
2.关于dx的模式选择一般都是用256色吧?!原来dx7里面有一个vb编的飞机游戏就是用的256色.我试过用16位色,巨慢,什么都不做只有60fps,但那些3d游戏不可能只用256色吧...它们是怎么优化的?
3.管理代码(比如c#)写游戏会不会很慢?
sssxueren 2002-12-28
  • 打赏
  • 举报
回复
方法很多,说一下大致思路

首先,确定一个数据结构,用来表示整个游戏世界(地图)的状态,如果按tile把屏幕分成若干块,一个简单的2维数组就可以搞定

用这个数据结构确定当前坐标是否有方块,如果有方块,方块多大之类,是否是墙壁、是否是控制块这些

然后,球的移动
按当前速度算出下一个位置的坐标,如果下一个位置为空(检查上面的数据结构),则移动,否则产生打击事件,如果那个位置的方块可以消掉的话,就消掉;这时还要处理球和物体的碰撞(碰撞分好几种,如果是控制块,则根据位置产生不同的初速度,普通的碰撞没什么好说的,转向而已)

以小球的移动来驱动整个游戏循环,

每次显示的时候根据数据结构显示背景、小球的位置显示小球,就ok了

可能说得不是很清楚,其实就是数学化一些东西而已,怎么判断一些具体时间的发生,怎么根据这些时间改变状态等等,没什么的

至于不是很赞同看源码,主要是因为网上的源码水平参差不齐,如果遇到习惯不好的,没有注释,没有算法说明,读懂它还不如自己好好想想呢
aoxue 2002-12-28
  • 打赏
  • 举报
回复
如果你有思路那更好了,给俺讲讲哦。
aoxue 2002-12-28
  • 打赏
  • 举报
回复
学习编游戏,不知道从那入手,看看别人的代码。可能有点启示吧。
sssxueren 2002-12-27
  • 打赏
  • 举报
回复
不知道你做什么用,其实,如果要学的话,不建议看源代,问问大概的思路自己做比较好
aoxue 2002-12-27
  • 打赏
  • 举报
回复
非常感谢。aoxue163@163.net
DarthVader 2002-12-27
  • 打赏
  • 举报
回复
邮箱?我发一个给你,不过满土的,希望有用。

8,325

社区成员

发帖
与我相关
我的任务
社区描述
游戏开发相关内容讨论专区
社区管理员
  • 游戏开发
  • 呆呆敲代码的小Y
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧