.


:




:

































 

 

 

 





Unit1.h ( 1.1) FigureType, (X,Y), (DX,DY) (SD); public , Fig [2] Sprite [4]. SpriteClass Sprite.h Sprite.cpp, .

ttifndef UnitlH

#define UnitlH

#include <vcl\Classes.hpp> ttinclude <vcl\Controls.hpp> ftinclude <vcl\StdCtrls.hpp>

#include <vc1\Forms.hpp> ttinclude "sprite.h"

#include <vcl\Buttons.hpp> ftinclude "sampreg.h" ftinclude <vcl\Dialogs.hpp>

typedef struct { int X, Y, DX, DY, SD; } FigureType;

class TFormI: public TForm (

_published: // IDE-managed Components TPaintBox *PaintBox;

TImage *DrawBox;

TImage *Background;

TImage *Figures;

TTimer *Timerl;

TPanel * Panel 1;

TSpeedButton *SpeedButtonl;

TSpeedButton *SpeedButton2;

TSpeedButton *SpeedButton3;

TSpinEdit *SpinEditl;

TOpenDialog *OpenDialog;

void _fastcall TimerlTimer(TObject * Sender);

void _fastcall SpinEditlKeyUp(TObject *Sender, WORD &Key, TShiftState Shift);

void _fastcall SpinEditlKeyDown(TObject * Sender,

WORD &Key, TShiftState Shifts- void_fastcall SpeedButtonlClick(TObject *Sender);

void_fastcall SpeedButton2Click(TObject * Sender);

void_fastcall SpeedButton3Click(TObject * Sender);

private: // User declarations public: // User declarations _fastcall TFormI(TComponent* Owner);

int W, H, w, h;

FigureType Fig[2];

SpriteClass Sprite[4];

};

extern TFormI *Forml;

#endif

1.1. Unii1.h.

 

Unit1.cpp ( 1.2 ) 5 .

//-_---------_____________-___-_-----__-____________________-

^include <vcl\vcl.h>

#pragma hdrstop

#include "Unitl.h"

#pragma link "sampreg"

#pragma resource "*.dfm" TFormI *Forml;

//-------------------------------------------

_fastcall TFormI::TFormI(TComponent* Owner): TForm(Owner) (// W = = 400; w = h =61;

} //----------------------------------------------------------

void_fastcall TFormI::SpeedButtonlClick(TObject *Sender)

{ if (OpenDialog->Execute())

{ //

Background->Picture->LoadFromFile(OpenDialog->FileName);

W = Background->Picture->Width;

H = Background->Picture->Height;

}

} //----------------------------------------

void_fastcall TFormI::SpeedButton2Click(TObject *Sender) { if (OpenDialog->Execute())

{ //

Figures->Picture->LoadFromFile(OpenDialog->FileName);

w = (Figures->Picture->Width)/6;

h = Figures->Picture->Height;

//______---------------------------------------------------

void_fastcall TFormI::SpeedButton3Click(TObject *Sender)

{ // Fig[0].X = W/4; Fig[l].X = 3*W/4;

Fig[0].Y = H/4; Fig[l].Y = 3*H/4;

Fig[0].DX = 1; Fig[l].DX = -1;

Fig[0].DY = 1; Fig[l].DY = -1;

Fig[0].SD = 0; Fig[l].SD = 0;

//

Sprite[0].SetSprite(Figures->Canvas, 0,0, 4*w,0, w,h);

Sprite[1].SetSprite(Figures->Canvas, 2*w,0, 4*w,0, w,h);

Sprite[2].SetSprite(Figures->Canvas, w,0, 5*w,0, w,h);

Sprite[3].SetSprite(Figures->Canvas, 3*w,0, 5*w,0, w,h);

Timerl->Enabled = true;

}

void _fastcall TFormI::SpinEditlKeyUp(TObject *Sender,

WORD &Key, TShiftState Shift) { Timerl->Interval++; } void _fastcall TFormI::SpinEditlKeyDown(TObject *Sender,

WORD &Key, TShiftState Shift) { Timerl->Interval--; } //-.____-_-_-_-_.....____.__________________________________

int Shift = 0; // void _fastcall TFormI::TimerlTimer(TObject *Sender) (//

Fig[0].X += Fig[0].DX; Fig[0].Y += Fig[0].DY;

if (Fig[0].X > (W/2-w)) Fig[0].DX = -1;

if (Fig[0].X < 20) Fig[0].DX = 1;

if (Fig[0].Y > (H-2*h)) Fig[0].DY = -1;

if (Fig[0].Y < 20) Fig[0].DY = 1;

Fig[l].X += Fig[l].DX; Fig[l].Y += Pig[l].DY;

if (Fig[l].X > (W-w)) Fig[l].DX = -1;

if (Fig[l].X < (W/2+w)) Fig[l].DX = 1;

if (Fig[l].Y > (H-h)) Fig[l].DY = -1;

if (Fig[l].Y < 30) Fig[l].DY = 1;

// ,

Fig[0].SD = (Fig[0].SD == 0)? 2: 0;

Fig[l].SD = (Fig[l].SD == 1)? 3: 1;

//

if (Shift == 0)

{ DrawBox->Canvas->CopyMode = cmSrcCopy;

DrawBox->Canvas->CopyRect(Rect(, , W, H),

Background->Canvas, Rect(0, 0, W, H));

}

else

{ DrawBox->Canvas->CopyMod^s = cmSrcCopy;

DrawBox->Canvas->CopyRect(Rect(0, 0, W-Shift, H),

Background->Canvas, Rect(Shift, 0, W, H));

DrawBox->Canvas->CopyRect(Rect(W-Shift, 0, W, H),

Background->Canvas, Rect(0, 0, Shift, H));

}

Shift += 2;

if (Shift >= W) Shift -= W;

//

Sprite[Fig[0].SD].Draw(DrawBox->Canvas,Fig[0].X, Fig[0].Y);

Sprite[Fig[l].SD].Draw(DrawBox->Canvas,Fig[1].X, Fig[l].Y);

//

PaintBox->Canvas->CopyMode = cmSrcCopy;

PaintBox->Canvas->CopyRect(Rect(0, 0, W, H),

DrawBox->Canvas, Rect(0, 0, W, H));

}

1.2. Unit1 cpp.

TSpeedButton . Background TImage ( w H). Figures TImage ( w h ).

SetSprite., .

TSpinEdit ( 40, 1/25 ).

OnTimer Timerl. , , "" . . 1.2 DrawBox PaintBox.

.1.2. .

-, ( " , ). , - . , , Shift. , Draw, DrawBox, , PaintBox.





:


: 2015-10-01; !; : 229 |


:

:

, , .
==> ...

1817 - | 1703 -


© 2015-2024 lektsii.org - -

: 0.018 .