Alright, here is everything...
main.cpp
Code:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Main.h"
#include "Enemies.h"
#include "Ship1.h"
#include "Global_Var.h"
#include "Draw.h"
#include "Lvl1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if(Key == VK_UP) //move up
{
//;
}
if(Key == VK_DOWN) //rotate right
{
//;
}
if(Key == VK_RIGHT) //move piece right
{
// ;
}
if(Key == VK_LEFT) //move piece left
{
//;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::UpTimer(TObject *Sender)
{
static float i;
int k;
if ((Enemy[1]->y1) < ClientHeight)
{
i=5;
//sets ship coords
for(k=0;k<5;k++)
{
Enemy[k]->y1 = Enemy[k]->y1 +i;
}
/*
Enemy[2]->y1 = Enemy[2]->y1+i;
Enemy[3]->y1 = Enemy[3]->y1+i;
Enemy4->x1 = Enemy4->x1;
Enemy4->y1 = Enemy4->y1+i;
Enemy5->x1 = Enemy5->x1;
Enemy5->y1 = Enemy5->y1+i;
*/
Draw();
}
else
{
Right->Enabled = true;
Up->Enabled = false;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::LeftTimer(TObject *Sender)
{
static int i;
int k;
if ((Enemy[1]->x1) < 0)
{
i = 5;
//sets ship coords
for(k=0;k<5;k++)
{
Enemy[k]->x1 = Enemy[k]->x1 -i;
}
/*
Enemy2->x1 = Enemy2->x1-i;
Enemy2->y1 = Enemy2->y1;
Enemy3->x1 = Enemy3->x1-i;
Enemy3->y1 = Enemy3->y1;
Enemy4->x1 = Enemy4->x1-i;
Enemy4->y1 = Enemy4->y1;
Enemy5->x1 = Enemy5->x1-i;
Enemy5->y1 = Enemy5->y1;
*/
Draw();
}
else
{
Up->Enabled = true;
Left->Enabled = false;
}
}
//----------------------------------------------------------------------------
void __fastcall TForm1::RightTimer(TObject *Sender)
{
static float i;
int k;
if ((Enemy[1]->x1) < ClientWidth)
{
i=5;
//sets ship coords
for(k=0;k<5;k++)
{
Enemy[k]->x1 = Enemy[k]->x1 +i;
}
/*
Enemy2->x1 = Enemy2->x1+i;
Enemy2->y1 = Enemy2->y1;
Enemy3->x1 = Enemy3->x1+i;
Enemy3->y1 = Enemy3->y1;
Enemy4->x1 = Enemy4->x1+i;
Enemy4->y1 = Enemy4->y1;
Enemy5->x1 = Enemy5->x1+i;
Enemy5->y1 = Enemy5->y1;
*/
Draw();
}
else
{
Down->Enabled = true;
Right->Enabled = false;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DownTimer(TObject *Sender)
{
static float i;
int k;
if ((Enemy[1]->x1) < 50)
{
i=5;
//sets ship coords
for(k=0;k<5;k++)
{
Enemy[k]->y1 = Enemy[k]->y1+i ;
}
/*
Enemy2->y1 = Enemy2->y1 +i;
Enemy3->y1 = Enemy3->y1 +i;
Enemy4->y1 = Enemy4->y1 +i;
Enemy5->y1 = Enemy5->y1 +i;
*/
Draw();
}
else
{
Right->Enabled = true;
Up->Enabled = false;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
TCanvas *workCanvas = new TCanvas;
TImage *backgroundImage = new TImage(Form1);
TRect BackRect;
BackRect.Top=0;
BackRect.Left = 0;
BackRect.Right = ClientWidth ;
BackRect.Bottom = ClientHeight;
backgroundImage->Picture->LoadFromFile("Stars.bmp");
//Set up workCanvas
HDC workdc = CreateCompatibleDC(Canvas->Handle);
HBITMAP bmp = CreateCompatibleBitmap(Canvas->Handle, ClientWidth, ClientHeight);
SelectObject(workdc, bmp);
SelectPalette(workdc, backgroundImage->Picture->Bitmap->Palette, false);
workCanvas->Handle = workdc;
lvl1();
}
//---------------------------------------------------------------------------
main.h
Code:
//---------------------------------------------------------------------------
#ifndef MainH
#define MainH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TTimer *Down;
TTimer *Left;
TTimer *Up;
TTimer *Right;
void __fastcall UpTimer(TObject *Sender);
void __fastcall LeftTimer(TObject *Sender);
void __fastcall RightTimer(TObject *Sender);
void __fastcall DownTimer(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift);
/*Ship_1 *User_Ship;
Enemy_1 *Enemy1;
Enemy_1 *Enemy2;
Enemy_1 *Enemy3;
Enemy_1 *Enemy4;
Enemy_1 *Enemy5;
TImage *Ship_sprite;
TImage *Enemy1_Sprite;
TImage *Enemy2_Sprite;
TImage *Enemy3_Sprite;
TImage *Enemy4_Sprite;
TImage *Enemy5_Sprite; */
TCanvas *workCanvas;
TRect *BackRect;
TImage *backgroundImage;
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
my classes note: they are all in their separate header files, i'e just condensed them down atm for ezeir posting
Code:
//Ship1
class Ship_1
{
public:
TImage *User_Ship_sprite;
int *health;
int x1;
int y1;
//move_ship_right();
//move_ship_left();
};
//enemy1
class Enemy_1
{
public:
//ship image
TImage *Enemy1_Sprite;
//health
int *Health;
//x1 y1 for graphics
int x1;
int y1;
private:
//constructor
//Enemy_1();
//destructor
//~Enemy_1();
};
global_vars.h
Code:
#ifndef GLOBAL_VAR_H
#define GLOBAL_VAR_H
extern Ship_1 *User_Ship;
extern Enemy_1 *Enemy[];
extern TCanvas *workCanvas;
extern TRect BackRect;
extern TImage *backgroundImage;
#endif
then the draw routines
Code:
#ifndef DRAW_H
#define DRAW_H
void Draw()
{
int i;
Form1->Repaint();
for(i=0;i<5;i++)
{
Form1->workCanvas->Draw(Enemy[i]->x1,Enemy[i]->y1,Enemy[i]->Enemy1_Sprite->Picture->Graphic );
Form1->workCanvas->Draw(User_Ship->x1,User_Ship->y1,User_Ship->User_Ship_sprite->Picture->Graphic);
}
Form1->Canvas->CopyRect(BackRect,workCanvas,BackRect);
i=0;
for(i=0;i<5;i++)
{
Form1->Canvas->Draw(Enemy[i]->x1,Enemy[i]->y1,Enemy[i]->Enemy1_Sprite->Picture->Graphic );
Form1->Canvas->Draw(User_Ship->x1,User_Ship->y1,User_Ship->User_Ship_sprite->Picture->Graphic);
}
}
#endif
thx for the help. I've been stuck on this for the past month! And its due in 2 months!