Witam. od wczoraj bawie sie w c++, wczesniej mialem doczynienia tylko z php. Niby wszystko działa ale nie tak jakbym chciał.
Chciałbym żeby na ekranie po wcisnieciu spacji za kazdym razem wylatywała jedna kula maxymalnie 100, Problem polega na tym ze na ekranie nastepna kula wyleci dopiero po tym jak poprzednia wyjdzie poza obszar gry;
Nie mam pojecia w czym tkwi problem :(
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TGame *Game;
// 0 = Góra(top) // 1 = Dół(down) // 2 = lewo(left) // 3 prawo (right)
int Distance = 5;
bool Direct[4];
bool shot = false;
TShape *Bullets[101];
bool BulletsActive[101];
//---------------------------------------------------------------------------
__fastcall TGame::TGame(TComponent* Owner)
: TForm(Owner)
{
for(int i=0; i<101; i++){
BulletsActive[i] = false;
// Startowe wartosci
Bullets[i] = new TShape(Owner);
Bullets[i]->Parent = this;
Bullets[i]->Visible = false;
Bullets[i]->Width = 10;
Bullets[i]->Height = 5;
Bullets[i]->Brush->Color = clBlack;
}
}
//---------------------------------------------------------------------------
void __fastcall TGame::TimerPlayerTimer(TObject *Sender){
if(Direct[0] && Player->Top > 0) Player->Top -= Distance;
if(Direct[1] && Player->Top < Game->Height - Player->Height) Player->Top += Distance;
if(Direct[2] && Player->Left >0) Player->Left -= Distance;
if(Direct[3] && Player->Left < Game->Width - Player->Width) Player->Left += Distance;
}
//---------------------------------------------------------------------------
void __fastcall TGame::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift){
if(Key == 87 || Key == 119) Direct[0] = true;
if(Key == 83 || Key == 115) Direct[1] = true;
if(Key == 65 || Key == 97) Direct[2] = true;
if(Key == 68 || Key == 100) Direct[3] = true;
if(Key == 32) shot = true;
}
//---------------------------------------------------------------------------
void __fastcall TGame::FormKeyUp(TObject *Sender, WORD &Key, TShiftState Shift){
if(Key == 87 || Key == 119) Direct[0] = false;
if(Key == 83 || Key == 115) Direct[1] = false;
if(Key == 65 || Key == 97) Direct[2] = false;
if(Key == 68 || Key == 100) Direct[3] = false;
if(Key == 32) shot = false;
}
//---------------------------------------------------------------------------
void __fastcall TGame::TimerBulletTimer(TObject *Sender){
for(int i=0; i<101; i++){
if(shot && !BulletsActive[i]){
BulletsActive[i] = true;
// Pozycja startowa kuli
Bullets[i]->Left = Player->Left + Player->Width;
Bullets[i]->Top = Player->Top + 25;
Bullets[i]->Visible = true;
}
if(BulletsActive[i]){
Bullets[i]->Left += 5;
// tutaj sprawdzanie kolizji
//
//
//
//
// Kula wyszła poza obszar gry
if(Bullets[i]->Left > Game->Width){
Bullets[i]->Visible = false;
BulletsActive[i] = false;
Bullets[i]->Left = 0;
}
}
}
}