unit mBall;
interface
uses mSuM, mSpielfeld, mbalken, mhindernis;
type Ball =
class
private
hatStift:Buntstift;
ersteshindernis:hindernis;
meinbalken:balken;
g:integer;
protected
public
constructor init;
procedure zeichne;
procedure loeschen;
procedure bewege;
function gibrichtung:zahl;
function gibx:zahl;
function gibpunkte:integer;
destructor gibfrei;
published
end;
implementation
constructor Ball.init;
begin
randomize;
g:=0;
meinbalken:=balken.init;
ersteshindernis:=hindernis.init;
hatStift:=Buntstift.init;
hatstift.bewegeBis(510,370);
hatstift.drehebis(random(360));
end;
procedure Ball.zeichne;
begin
hatStift.setzeFuellMuster(Gefuellt);
hatStift.zeichneKreis(8);
end;
procedure Ball.loeschen;
begin
hatstift.radiere;
hatStift.setzeFuellMuster(Gefuellt);
hatStift.bewegeBis(hatStift.hPosition,hatStift.vPosition);
hatStift.zeichneKreis(8);
hatStift.normal;
end;
procedure Ball.bewege;
begin
self.loeschen;
hatStift.bewegeUm(1) ;
if (hatStift.hPosition >1000)
and (hatstift.vPosition > meinbalken.yposition)
and (hatstift.vPosition < meinbalken.yposition+60)
then
begin
g:=g+1 ;
hatstift.dreheBis(540-self.gibrichtung) ;
end;
if hatstift.hPosition < 0
then hatstift.drehebis(540-self.gibrichtung);
if hatstift.vposition > 710
then hatstift.drehebis(360-self.gibrichtung) ;
if hatstift.vposition < 10
then hatstift.drehebis(360-self.gibrichtung);
//hindernisse
if (hatstift.hPosition = ersteshindernis.gibhgrenze1)
and (hatstift.vposition > ersteshindernis.gibvgrenze1)
and (hatstift.vposition < ersteshindernis.gibvgrenze2)
then hatstift.drehebis(360-self.gibrichtung);
if (hatstift.hPosition = ersteshindernis.gibhgrenze2)
and (hatstift.vposition > ersteshindernis.gibvgrenze1)
and (hatstift.vposition < ersteshindernis.gibvgrenze2)
then hatstift.drehebis(360-self.gibrichtung);
if (hatstift.vPosition = ersteshindernis.gibvgrenze1)
and (hatstift.hposition > ersteshindernis.gibhgrenze1)
and (hatstift.hposition < ersteshindernis.gibhgrenze2)
then hatstift.drehebis(540-self.gibrichtung);
if (hatstift.vPosition = ersteshindernis.gibvgrenze2)
and (hatstift.hposition > ersteshindernis.gibvgrenze1)
and (hatstift.hposition < ersteshindernis.gibvgrenze2)
then hatstift.drehebis(540-self.gibrichtung);
self.zeichne;
end;
function ball.gibrichtung:zahl;
begin
result:=hatstift.winkel;
end;
function ball.gibx:zahl;
begin
result:=hatstift.hposition;
end;
function ball.gibpunkte:integer;
begin
result:=g;
end;
destructor ball.gibfrei;
begin
self.loeschen;
hatstift.gibfrei;
meinbalken.gibfrei;
end;
end.