mam problem. Nie wiem jaki kod mam wpisac aby moja postac (ava) mogla stac belce (blok). Postac moze poruszac sie w lewo, prawo, gore i dol. Kiedy postac jest na belce, nie jest w stanie isc bardziej w dol. Problem polega na tym ze postac nie stojac na belce, nie moze zejsc nizej od wysokosci top belki. Co zrobilem zle? albo co powinien bym poprawic?
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
int x=-8;
int y=-8;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if (Key == VK_LEFT) lewo->Enabled = true;
if (Key == VK_RIGHT) prawo->Enabled = true;
if (Key == VK_UP) gora->Enabled = true;
if (Key == VK_DOWN)
{
dol->Enabled = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormKeyUp(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if (Key == VK_LEFT) lewo->Enabled = false;
if (Key == VK_RIGHT) prawo->Enabled = false;
if (Key == VK_UP) gora->Enabled = false;
if (Key == VK_DOWN) dol->Enabled = false;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::lewoTimer(TObject *Sender)
{
if(ava->Left >= 5) ava->Left -= 10;
if(ava->Left >= blok->Width) ava->Left -= 10;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::prawoTimer(TObject *Sender)
{
if(ava->Left+ava->Width < tlo->Width - 5) ava->Left += 10;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::goraTimer(TObject *Sender)
{
if(ava->Top > 5) ava->Top -= 10;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::dolTimer(TObject *Sender)
{
if(ava->Height <= tlo->Top) ava->Top += 10;
if(ava->Top+ava->Height < blok->Top) ava->Top += 10;
if(ava->Height+ava->Width > blok->Top+blok->Left) ava->Top -= 10;
}
//---------------------------------------------------------------------------