Jeux avec un loup v1.0 (dirctx draw 2d)

Soyez le premier à donner votre avis sur cette source.

Vue 5 919 fois - Téléchargée 502 fois

Description

Permettra de mieux connaître DirectX Draw 2D
Langage : Borland C++ Bulder

Source / Exemple :


#include <vcl.h>
#include <ddraw.h>
#include <mmsystem.h>
#include "Main.h"
#include "ddutil.h"
#include "Unit2.h"
#pragma hdrstop
#pragma resource "*.dfm"

TForm1 *Form1;
char szBackground[] = "C6401000";   //  BMP
   AnsiString lpo;
int ty=0;
int x=98;       int y=285;     // cordoné du chien
int ligne=0;
int tmpx=0;     int tmpy=0;
int NbrLigne=0;
int movD=1;     int times=0;
int LingMaxY=0; int LingMaxX=0;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)  : TForm(Owner)
{
    Timer1->Enabled = false;
    Form2 = new TForm2(Application);
    Form2->ShowModal();
    Start();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Start()
{
 HRESULT res = DirectDrawCreate(NULL, &pDD, NULL);
 pDD->SetCooperativeLevel(Handle,DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);

 ddsd.dwSize = sizeof(ddsd);
 ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE|DDSCAPS_FLIP|DDSCAPS_COMPLEX;

 ddsd.dwBackBufferCount = 1;
 pDD->SetDisplayMode(640,480, 16);
 pDD->CreateSurface(&ddsd, &pDDSPrim, NULL);

 ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
 pDDSPrim->GetAttachedSurface(&ddscaps, &pDDSSec);

 pDDPal = DDLoadPalette(pDD, szBackground);

 pDDSImage = DDLoadBitmap(pDD, szBackground, 0, 0);
 DDSetColorKey(pDDSImage,RGB(0,0,0));  // Couleur de transparence

 pDDSPrim->Flip( NULL, 0 );

 Memo1->Lines->LoadFromFile("MAP.txt");
 Timer1->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
 ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
 pDDSPrim->GetAttachedSurface(&ddscaps, &pDDSSec);
 rc.left=0;   rc.top=0;   rc.right=640; rc.bottom=480;
 pDDSSec->BltFast(0,0,pDDSImage,&rc,DDBLTFAST_NOCOLORKEY);

            //////////// décore

      if (LingMaxX>=14) {LingMaxX=14;}
      if (LingMaxY>=29) {LingMaxY=29;}
      if (LingMaxY<=0)  {LingMaxY=0;}
      if (LingMaxX<=0)  {LingMaxX=0;}

 for (int ty=LingMaxX;ty<LingMaxX+19; ty++) {
 for (int ligne=LingMaxY;ligne<=LingMaxY+14; ligne++) {
     AnsiString lpo;
     lpo = Memo1->Lines->Strings[ligne];   //ligne
     Memo2->Lines->Clear();  Memo2->Lines->Add(lpo);

 AnsiString e1 (Memo2->Text.c_str()),e2;  // Nb graph
 e2 = e1.SubString(1+2*ty,2);        int nb = e2.ToInt();

if (nb==00) {rc.left=1+33*0; rc.top=502+33*2; rc.right=33+33*0; rc.bottom=534+33*2;}
if (nb==01) {rc.left=1+33*1; rc.top=502+33*2; rc.right=33+33*1; rc.bottom=534+33*2;}
if (nb==02) {rc.left=1+33*2; rc.top=502+33*2; rc.right=33+33*2; rc.bottom=534+33*2;}
if (nb==03) {rc.left=1+33*3; rc.top=502+33*2; rc.right=33+33*3; rc.bottom=534+33*2;}
if (nb==04) {rc.left=1+33*4; rc.top=502+33*2; rc.right=33+33*4; rc.bottom=534+33*2;}
if (nb==05) {rc.left=1+33*5; rc.top=502+33*2; rc.right=33+33*5; rc.bottom=534+33*2;}
if (nb==06) {rc.left=1+33*6; rc.top=502+33*2; rc.right=33+33*6; rc.bottom=534+33*2;}

if (nb==10) {rc.left=1+33*0; rc.top=502+33*3; rc.right=33+33*0; rc.bottom=534+33*3;}
if (nb==11) {rc.left=1+33*1; rc.top=502+33*3; rc.right=33+33*1; rc.bottom=534+33*3;}
if (nb==12) {rc.left=1+33*2; rc.top=502+33*3; rc.right=33+33*2; rc.bottom=534+33*3;}

if (nb==20) {rc.left=1+33*0; rc.top=502+33*4; rc.right=33+33*0; rc.bottom=534+33*4;}
if (nb==21) {rc.left=1+33*1; rc.top=502+33*4; rc.right=33+33*1; rc.bottom=534+33*4;}
if (nb==22) {rc.left=1+33*2; rc.top=502+33*4; rc.right=33+33*2; rc.bottom=534+33*4;}
if (nb==23) {rc.left=1+33*3; rc.top=502+33*4; rc.right=33+33*3; rc.bottom=534+33*4;}
if (nb==24) {rc.left=1+33*4; rc.top=502+33*4; rc.right=33+33*4; rc.bottom=534+33*4;}
if (nb==25) {rc.left=1+33*5; rc.top=502+33*4; rc.right=33+33*5; rc.bottom=534+33*4;}
if (nb==26) {rc.left=1+33*6; rc.top=502+33*4; rc.right=33+33*6; rc.bottom=534+33*4;}
if (nb==27) {rc.left=1+33*7; rc.top=502+33*4; rc.right=33+33*7; rc.bottom=534+33*4;}
if (nb==28) {rc.left=1+33*8; rc.top=502+33*4; rc.right=33+33*8; rc.bottom=534+33*4;}
if (nb==29) {rc.left=1+33*9; rc.top=502+33*4; rc.right=33+33*9; rc.bottom=534+33*4;}

if (nb==30) {rc.left=1+33*0; rc.top=502+33*5; rc.right=33+33*0; rc.bottom=534+33*5;}
if (nb==31) {rc.left=1+33*1; rc.top=502+33*5; rc.right=33+33*1; rc.bottom=534+33*5;}
if (nb==32) {rc.left=1+33*2; rc.top=502+33*5; rc.right=33+33*2; rc.bottom=534+33*5;}
if (nb==33) {rc.left=1+33*3; rc.top=502+33*5; rc.right=33+33*3; rc.bottom=534+33*5;}
if (nb==34) {rc.left=1+33*4; rc.top=502+33*5; rc.right=33+33*4; rc.bottom=534+33*5;}
if (nb==35) {rc.left=1+33*5; rc.top=502+33*5; rc.right=33+33*5; rc.bottom=534+33*5;}
if (nb==36) {rc.left=1+33*6; rc.top=502+33*5; rc.right=33+33*6; rc.bottom=534+33*5;}
if (nb==37) {rc.left=1+33*7; rc.top=502+33*5; rc.right=33+33*7; rc.bottom=534+33*5;}

if (nb==40) {rc.left=1+33*0; rc.top=502+33*6; rc.right=33+33*0; rc.bottom=534+33*6;}
if (nb==41) {rc.left=1+33*1; rc.top=502+33*6; rc.right=33+33*1; rc.bottom=534+33*6;}
if (nb==42) {rc.left=1+33*2; rc.top=502+33*6; rc.right=33+33*2; rc.bottom=534+33*6;}
if (nb==43) {rc.left=1+33*3; rc.top=502+33*6; rc.right=33+33*3; rc.bottom=534+33*6;}
if (nb==44) {rc.left=1+33*4; rc.top=502+33*6; rc.right=33+33*4; rc.bottom=534+33*6;}
if (nb==45) {rc.left=1+33*5; rc.top=502+33*6; rc.right=33+33*5; rc.bottom=534+33*6;}
if (nb==46) {rc.left=1+33*6; rc.top=502+33*6; rc.right=33+33*6; rc.bottom=534+33*6;}
if (nb==47) {rc.left=1+33*7; rc.top=502+33*6; rc.right=33+33*7; rc.bottom=534+33*6;}
if (nb==48) {rc.left=1+33*8; rc.top=502+33*6; rc.right=33+33*8; rc.bottom=534+33*6;}

if (nb==50) {rc.left=1+33*0; rc.top=502+33*7; rc.right=33+33*0; rc.bottom=534+33*7;}
if (nb==51) {rc.left=1+33*1; rc.top=502+33*7; rc.right=33+33*1; rc.bottom=534+33*7;}
if (nb==52) {rc.left=1+33*2; rc.top=502+33*7; rc.right=33+33*2; rc.bottom=534+33*7;}
if (nb==53) {rc.left=1+33*3; rc.top=502+33*7; rc.right=33+33*3; rc.bottom=534+33*7;}
if (nb==54) {rc.left=1+33*4; rc.top=502+33*7; rc.right=33+33*4; rc.bottom=534+33*7;}
if (nb==55) {rc.left=1+33*5; rc.top=502+33*7; rc.right=33+33*5; rc.bottom=534+33*7;}
if (nb==56) {rc.left=1+33*6; rc.top=502+33*7; rc.right=33+33*6; rc.bottom=534+33*7;}
if (nb==57) {rc.left=1+33*7; rc.top=502+33*7; rc.right=33+33*7; rc.bottom=534+33*7;}
if (nb==58) {rc.left=1+33*8; rc.top=502+33*7; rc.right=33+33*8; rc.bottom=534+33*7;}
if (nb==59) {rc.left=1+33*9; rc.top=502+33*7; rc.right=33+33*9; rc.bottom=534+33*7;}

if (nb==60) {rc.left=1+33*0; rc.top=502+33*8; rc.right=33+33*0; rc.bottom=534+33*8;}
if (nb==61) {rc.left=1+33*1; rc.top=502+33*8; rc.right=33+33*1; rc.bottom=534+33*8;}

if (nb==70) {rc.left=1+33*0; rc.top=502+33*9; rc.right=33+33*0; rc.bottom=534+33*9;}
if (nb==71) {rc.left=1+33*1; rc.top=502+33*9; rc.right=33+33*1; rc.bottom=534+33*9;}
if (nb==72) {rc.left=1+33*2; rc.top=502+33*9; rc.right=33+33*2; rc.bottom=534+33*9;}
if (nb==73) {rc.left=1+33*3; rc.top=502+33*9; rc.right=33+33*3; rc.bottom=534+33*9;}
if (nb==74) {rc.left=1+33*4; rc.top=502+33*9; rc.right=33+33*4; rc.bottom=534+33*9;}
if (nb==75) {rc.left=1+33*5; rc.top=502+33*9; rc.right=33+33*5; rc.bottom=534+33*9;}
if (nb==76) {rc.left=1+33*6; rc.top=502+33*9; rc.right=33+33*6; rc.bottom=534+33*9;}

pDDSSec->BltFast(tmpx+32*ty,tmpy+32*ligne,pDDSImage,&rc,DDBLTFAST_SRCCOLORKEY);
         } }

 rc.left=1+33*0; rc.top=502+33*2; rc.right=33+33*0; rc.bottom=534+33*2;
pDDSSec->BltFast(400,400,pDDSImage,&rc,DDBLTFAST_SRCCOLORKEY);

               /////////////////////  end Decore   /////////////////////////

 if (movD==1 && times == 0){  ///////////////////// ->
 rc.left=1+33*0; rc.top=496+36*0; rc.right=33+33*0; rc.bottom=531+36*0;goto ooo;}
 if (movD==1 && times == 2){x=x+16;
 rc.left=1+33*2; rc.top=496+36*0; rc.right=33+33*2; rc.bottom=531+36*0;goto ooo;}
 if (movD==1 && times == 3){x=x+16;
 rc.left=1+33*0; rc.top=496+36*0; rc.right=33+33*0; rc.bottom=531+36*0;
 movD=10; times=0;goto ooo;}

 if (movD==2 && times == 0){   ///////////////////////  <-
 rc.left=1+33; rc.top=496+36*1; rc.right=33+33; rc.bottom=531+36*1;goto ooo;}
 if (movD==2 && times == 2){x=x-16;
 rc.left=1+33*2; rc.top=496+36*1; rc.right=33+33*2; rc.bottom=531+36*1;goto ooo;}
 if (movD==2 && times == 3){x=x-16;
 rc.left=1+33; rc.top=496+36*1; rc.right=33+33; rc.bottom=531+36*1;
 movD=20; times =0;goto ooo;}

 if (movD==3 && times == 0){     /////////////////// dw
 rc.left=1+33*6; rc.top=496+36*0 ; rc.right=33+33*6; rc.bottom=531+36*0;goto ooo;}
 if (movD==3 && times == 2){y=y+16;
 rc.left=1+33*7; rc.top=496+36*0 ; rc.right=33+33*7; rc.bottom=531+36*0;goto ooo;}
 if (movD==3 && times == 3){y=y+16;
 rc.left=1+33*6; rc.top=496+36*0 ; rc.right=33+33*6; rc.bottom=531+36*0;
 movD=30; times =0;goto ooo;}

 if (movD==4 & times == 0){  ///////////////////////  up
 rc.left=1+33*5; rc.top=496+36*0 ; rc.right=33+33*5; rc.bottom=531+36*0;goto ooo;}
 if (movD==4 & times == 2){y=y-16;
 rc.left=1+33*4; rc.top=496+36*0 ; rc.right=33+33*4; rc.bottom=531+36*0;goto ooo;}
 if (movD==4 & times == 3){y=y-16;
 rc.left=1+33*5; rc.top=496+36*0 ; rc.right=33+33*5; rc.bottom=531+36*0;
 movD=40; times =0;goto ooo;}

/////////////////////////// chien se repose   ->  ///////////////////////////

if (times >= 20 & movD==10) {  times=0;
  rc.left=1+33*0; rc.top=496+36*0; rc.right=33+33*0; rc.bottom=531+36*0;goto ooo;}

if (times >= 15 & movD==10) {
   rc.left=1+33*1; rc.top=496+36*0; rc.right=33+33*1; rc.bottom=531+36*0;goto ooo;}

if (times >= 0 & movD==10) {
   rc.left=1+33*0; rc.top=496+36*0; rc.right=33+33*0; rc.bottom=531+36*0;goto ooo;}

                       ///////////////  chien se repose   <-

if (times >= 20 & movD==20) {  times=0;
   rc.left=1+33*0; rc.top=496+36*1; rc.right=33+33*0; rc.bottom=531+36*1;goto ooo;}

if (times >= 15 & movD==20) {
   rc.left=1+33; rc.top=496+36*1; rc.right=33+33; rc.bottom=531+36*1;goto ooo;}

if (times >= 0 & movD==20) {
  rc.left=1+33*0; rc.top=496+36*1; rc.right=33+33*0; rc.bottom=531+36*1;goto ooo;}
                       ///////////////  chien se repose dw

if (times >= 20 & movD==30) {  times=0;
   rc.left=1+33*6; rc.top=496+36*0 ; rc.right=33+33*6; rc.bottom=531+36*0;goto ooo;}

if (times >= 15 & movD==30) {
   rc.left=1+33*8; rc.top=496+36*0 ; rc.right=33+33*8; rc.bottom=531+36*0;goto ooo;}

if (times >= 0 & movD==30) {
  rc.left=1+33*6; rc.top=496+36*0 ; rc.right=33+33*6; rc.bottom=531+36*0;goto ooo;}

                      ///////////////  chien se repose Up
if (times >= 25 & movD==40) {  times=0;
 rc.left=1+33*3; rc.top=496+36*0; rc.right=33+33*3; rc.bottom=531+36*0;goto ooo;}

if (times >= 15 & movD==40) {
 rc.left=1+33*5; rc.top=496+36*0; rc.right=33+33*5; rc.bottom=531+36*0;goto ooo;}

if (times >= 0 & movD==40) {
 rc.left=1+33*3; rc.top=496+36*0; rc.right=33+33*3; rc.bottom=531+36*0;goto ooo;}

ooo:

pDDSSec->BltFast(x,y,pDDSImage,&rc,DDBLTFAST_SRCCOLORKEY);

       times++;
       pDDSPrim->Flip( NULL, 0 );
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
{
 if (char(Key) == VK_RIGHT)  { movD=1; times=0;}
 if (char(Key) == VK_LEFT)   { movD=2; times=0;}
 if (char(Key) == VK_DOWN)   { movD=3; times=0;}
 if (char(Key) == VK_UP)     { movD=4; times=0;}

 if (x>=500) { tmpx=tmpx-32;x=x-64;LingMaxX=LingMaxX+1;}
 if (y>=400) { tmpy=tmpy-32;y=y-64;LingMaxY=LingMaxY+1;}
 if (x<=32)  { tmpx=tmpx+32;x=x+64;LingMaxX=LingMaxX-1;}
 if (y<=32)  { tmpy=tmpy+32;y=y+64;LingMaxY=LingMaxY-1;}

if (char(Key)==(27))   { Close();}    // Echap
if (char(Key)==VK_F12) { Close();}    // Echap
}
//---------------------------------------------------------------------------
void __fastcall TForm1::SonNbr0()
{
          char const *Path = "Protoss Exclamation.wav";
          sndPlaySound(Path, SND_ASYNC | SND_FILENAME);
}
//---------------------------------------------------------------------------

Conclusion :


pas de bug sur mon PC
je voudrai suprimer cette page, c une ancienne version

Codes Sources

A voir également

Ajouter un commentaire Commentaire
Messages postés
192
Date d'inscription
vendredi 2 mars 2001
Statut
Membre
Dernière intervention
10 janvier 2006

Bah dis donc tu m'a l'air de t'etre bien pris la tete! Enfin le resultat visuel est la, mais je pense ke tu aurais pu faire plus simple, mais continu comme ca!

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.