Zidove sam prosto nacrtao sa Rectangle, stim sto donja stranica rectanglea prelazi vidljivi deo, tako da se vidi samo gornja, leva i desna strana. Loptica se odbija tako sto se isituje da li ima X ili Y koordinatu vecu (manju) od koordinate zida, itd, itd...
Evo CELOG source coda (moras da imas Fade2.tpu i Mouse.tpu ako zelis da program radi)
Code:
Program Arkanoid(Input, Output);
Uses Crt, Graph, Fade2, Mouse;
Type
Screen = Record
Driver : Integer;
Mode : Integer;
Level : Integer;
LevelS : String;
NextLevel : Boolean;
End;
Walls = Record
LeftC : Integer;
RightC : Integer;
UpperC : Integer;
UnderC : Integer;
End;
Text = Record
PoenaX : Integer;
PoenaY : Integer;
NivoX : Integer;
NivoY : Integer;
End;
SoundT = Record
Freq : Integer;
Delay : ShortInt;
End;
Color = Record
TxtPoena : Word;
IntPoena : Word;
TxtNivo : Word;
IntNivo : Word;
Wall : Word;
Bulb : Word;
Odb : Word;
End;
Lives = Record
Number : ShortInt;
MaxNumber : ShortInt;
X : Integer;
X1 : Integer;
Y : Integer;
Space : ShortInt;
End;
Odbijac = Record
X : Integer;
X1 : Integer;
Y : Integer;
Y1 : Integer;
End;
BulbT = Record
X : Integer;
XMove : ShortInt;
Y : Integer;
YMove : ShortInt;
Radius : Integer;
Delay : ShortInt;
OnOdb : Boolean;
Dead : Boolean;
MaxXMove : Integer;
MinXMove : Integer;
End;
const
Gray50 : FillPatternType = ($AA, $55, $AA, $55, $AA, $55, $AA, $55);
var
Scr : Screen;
Wall : Walls;
Txt : Text;
Col : Color;
Liv : Lives;
Odb : Odbijac;
Bulb : BulbT;
Snd : SoundT;
C1 : Integer;
C2 : Integer;
C3 : Integer;
x : Integer;
Procedure VarSpecInit;
Begin
Scr.Level := 3;
Liv.Number := 3;
Bulb.Delay := 7 - Scr.Level;
Bulb.Radius := 3;
Col.Bulb := WHITE;
Odb.X1 := 80;
Odb.Y1 := 8;
End;
Procedure VarInit;
Begin
SetMouseSensitivity(0, 0, 0);
Wall.LeftC := 5;
Wall.RightC := 520;
Wall.UpperC := 5;
Wall.UnderC := 500;
Txt.PoenaX := 550;
Txt.PoenaY := 15;
Txt.NivoX := 555;
Txt.NivoY := 60;
Col.TxtPoena := YELLOW;
Col.IntPoena := LIGHTRED;
Col.TxtNivo := YELLOW;
Col.IntNivo := LIGHTRED;
Col.Wall := DARKGRAY;
Col.Odb := GREEN;
Liv.MaxNumber := 6;
Liv.X := 535;
Liv.X1 := 80;
Liv.Y := 110;
Liv.Space := 15;
Odb.X := 200;
Odb.Y := 450;
Bulb.X := Odb.X + Round(Odb.X1 / 2 - Bulb.Radius / 2);
Bulb.Y := Odb.Y - Bulb.Radius;
Bulb.XMove := 2;
Bulb.YMove := -2;
Bulb.OnOdb := TRUE;
Bulb.Dead := FALSE;
Bulb.MaxXMove := 6;
Bulb.MinXMove := -6;
End;
Procedure MakeSnd;
Begin
Sound(Snd.Freq);
Delay(Snd.Delay);
NoSound;
End;
Procedure OdbDraw;
Begin
SetFillPattern(Gray50, BLACK);
SetColor(DARKGRAY);
Rectangle(Odb.X, Odb.Y, Odb.X + Odb.X1, Odb.Y + Odb.Y1);
FloodFill(Odb.X + 1, Odb.Y + 1, DARKGRAY);
SetColor(BLACK);
Rectangle(Odb.X, Odb.Y, Odb.X + Odb.X1, Odb.Y + Odb.Y1);
Odb.X := MouseX;
SetFillPattern(Gray50, Col.Odb);
SetColor(DARKGRAY);
Rectangle(Odb.X, Odb.Y, Odb.X + Odb.X1, Odb.Y + Odb.Y1);
FloodFill(Odb.X + 1, Odb.Y + 1, DARKGRAY);
SetColor(BLACK);
Rectangle(Odb.X, Odb.Y, Odb.X + Odb.X1, Odb.Y + Odb.Y1);
End;
Procedure MouseInit;
Begin
MouseX := 200;
SetMouseSensitivity(20, 0, 0);
End;
Procedure ScrInit;
Begin
Scr.Driver := Detect;
InitGraph(Scr.Driver, Scr.Mode,' ');
SetTextStyle(SmallFont, HorizDir, 5);
End;
Procedure ScrDraw;
Begin
ClearViewPort;
SetColor(Col.Wall);
Rectangle(Wall.LeftC, Wall.UpperC, Wall.RightC, Wall.UnderC);
SetColor(Col.TxtPoena);
OutTextXY(Txt.PoenaX, Txt.PoenaY, 'Poena');
SetColor(Col.TxtNivo);
OutTextXY(Txt.NivoX, Txt.NivoY, 'Nivo');
End;
Procedure NivoDraw;
Begin
SetColor(Col.IntNivo);
Rectangle(Txt.NivoX, Txt.NivoY + 20, Txt.NivoX + 25, Txt.NivoY + 40);
SetFillPattern(Gray50, Black);
FloodFill(Txt.NivoX + 1, Txt.NivoY + 21, Col.IntNivo);
SetColor(BLACK);
Rectangle(Txt.NivoX, Txt.NivoY + 20, Txt.NivoX + 25, Txt.NivoY + 40);
SetColor(Col.IntNivo);
Str(Scr.Level, Scr.LevelS);
OutTextXY(Txt.NivoX + 10, Txt.NivoY + 20, Scr.LevelS);
End;
Procedure LivesDraw;
Begin
{Brise sve zivote sa ekrana}
SetFillPattern(Gray50, BLACK);
For C1 := 1 to Liv.MaxNumber Do Begin
SetColor(DARKGRAY);
Rectangle(Liv.X, Liv.Y + C1 * Liv.Space, Liv.X + Liv.X1, Liv.Y + C1 * Liv.Space + Odb.Y1);
FloodFill(Liv.X + 1, Liv.Y + C1 * Liv.Space + 1, DARKGRAY);
SetColor(BLACK);
Rectangle(Liv.X, Liv.Y + C1 * Liv.Space, Liv.X + Liv.X1, Liv.Y + C1 * Liv.Space + Odb.Y1);
End;
{Isrtava zivote}
SetFillPattern(Gray50, Col.Odb);
For C1 := 1 to Liv.Number Do Begin
SetColor(Col.Odb);
Rectangle(Liv.X, Liv.Y + C1 * Liv.Space, Liv.X + Liv.X1, Liv.Y + C1 * Liv.Space + Odb.Y1);
FloodFill(Liv.X+1, Liv.Y + C1 * Liv.Space + 1, Col.Odb);
SetColor(BLACK);
Rectangle(Liv.X, Liv.Y + C1 * Liv.Space, Liv.X + Liv.X1, Liv.Y + C1 * Liv.Space + Odb.Y1);
End;
End;
Procedure BrickDraw;
Begin
For C1 := 0 to Brick.SirinaN Do Begin
For C2 := 0 to Brick.VisinaN Do Begin
Rectangle(Brick.X + C1 * Brick.X1, Brick.Y + C2 * Brick,
Brick.X + (C1 + 1) * Brick.X1, Brick.Y + (C2 + 1) * Brick.Y1);
{ FloodFill(}
Procedure BulbWallReflect;
Begin
Snd.Freq := 600;
Snd.Delay := 3;
If (Bulb.X > Wall.RightC - Bulb.Radius - Bulb.MaxXMove - 1) or
(Bulb.X < Wall.LeftC + Bulb.Radius - Bulb.MinXMove + 1) Then Begin
Bulb.XMove := -Bulb.XMove;
MakeSnd;
End;
If Bulb.Y < Wall.UpperC + Bulb.Radius - Bulb.YMove Then Begin
Bulb.YMove := -Bulb.YMove;
MakeSnd;
End;
If Bulb.Y > Wall.UnderC Then Bulb.Dead := TRUE
End;
Procedure BulbOdbReflect;
Begin
If (Bulb.Y > Odb.Y - Bulb.Radius - Bulb.YMove) And
(Bulb.Y < Odb.Y - Bulb.Radius + 1) And
(Bulb.X > Odb.X - Bulb.Radius - 2) And
(Bulb.X < Odb.X + Odb.X1 + Bulb.Radius + 2) Then Begin
Bulb.XMove := Round((Bulb.X - Odb.X - 40) / 7) + Round(Bulb.XMove / 4);
Bulb.YMove := -Abs(Bulb.YMove);
Bulb.Delay := Round(Abs(Bulb.XMove) * 2.5);
If Abs(Bulb.XMove) > 4 Then Dec(Bulb.Delay, Round(Abs(Bulb.XMove) / 1.25));
If Bulb.XMove = 0 Then Bulb.Delay := 7 - Scr.Level;
End;
If Bulb.Y > Odb.Y - Bulb.Radius - 2 Then OdbDraw;
End;
Procedure BulbMove;
Begin
If (Bulb.XMove = 2) and (Bulb.YMove = -2) Then Bulb.Delay := 7 - Scr.Level;
If Bulb.XMove > Bulb.MaxXMove Then Bulb.XMove := Bulb.MaxXMove;
If Bulb.XMove < Bulb.MinXMove Then Bulb.XMove := Bulb.MinXMove;
BulbWallReflect;
BulbOdbReflect;
Bulb.X := Bulb.X + Bulb.XMove;
Bulb.Y := Bulb.Y + Bulb.YMove;
End;
Procedure BulbDraw;
Begin
SetColor(BLACK);
Circle(Bulb.X, Bulb.Y, Bulb.Radius);
If Bulb.OnOdb = TRUE Then
Bulb.X := Odb.X + Round(Odb.X1 / 2 - Bulb.Radius / 2) else BulbMove;
SetColor(Col.Bulb);
Circle(Bulb.X, Bulb.Y, Bulb.Radius);
If Bulb.OnOdb = FALSE Then Delay(Bulb.Delay);
End;
Procedure BulbDead;
Begin
GrabPal;
FadeOut;
Dec(Liv.Number);
VarInit;
ScrDraw;
NivoDraw;
LivesDraw;
MouseTo(200, 0);
OdbDraw;
BulbDraw;
FadeIn;
MouseTo(200, 0);
End;
Procedure OdbRead;
Begin
While (Bulb.Dead = FALSE) and (Scr.NextLevel = FALSE) Do Begin
ReadMouse;
If MouseX > Wall.RightC - 82 Then MouseX := Wall.RightC - 82;
If MouseX < Wall.LeftC + 1 Then MouseX := Wall.LeftC + 1;
If MouseX <> Odb.X Then Begin
OdbDraw;
BulbDraw;
End;
If Bulb.OnOdb = FALSE Then BulbDraw;
If LeftButtonPressed = TRUE Then Bulb.OnOdb := FALSE;
End;
End;
Begin
Randomize;
VarSpecInit;
VarInit;
ScrInit;
ScrDraw;
NivoDraw;
LivesDraw;
BrickDraw;
OdbDraw;
While Liv.Number > 1 Do Begin
If Bulb.Dead = TRUE Then BulbDead;
BulbDraw;
MouseInit;
OdbRead;
End;
FadeOut;
End.