Accueil > > > Shoot\sprites.cpp
[C++] [WIN32] JEUX DE SHOOT ( SPACE SHOOT )
Shoot\sprites.cpp
Informations sur ce code source
Voila un petit jeux vidéo. C'est très simple, il faut shooter le max d'aliens. J'ai crée ce jeux pour tester mon moteur 2D. Donc, les sources, en plus du jeux, sont un moteur de jeux 2D entièrement écrit avec l'API Win32 et en C++. J'utilise aussi la
Fichier : Shoot\sprites.cpp
Nombre de lignes : 325 lignes
Afficher ce fichier en plein écran
-
- //------------------------------
- // sprites.cpp
- //------------------------------
-
- #include <windows.h>
- #include <fstream>
- #include "sprites.h"
-
- namespace G2D
- {
-
- //bool cSprite::mCollision = false;
-
- cSprite::cSprite(HDC hdc, bool nodes)
- {
-
- mBitmap = new cBitmap(hdc);
- mNextSprite = NULL;
- mHdc = hdc;
-
- mPosX = 0;
- mPosY = 0;
- mWidth = 0;
- mHeight = 0;
- mNumFrame = 0;
- mNumColumn = 0;
- mFrameDelay = 0;
- mNodes = nodes;
- mVisible = true;
- mAlive = true;
- mLastDisplay = true;
- }
-
-
- cSprite::cSprite(HDC hdc, RECT rect, eReaction reaction, bool nodes)
- {
- mBitmap = new cBitmap(hdc);
- mNextSprite = NULL;
- mHdc = hdc;
- mLimiteRect = rect;
- mReaction = reaction;
- mNodes = nodes;
- mVisible = true;
- mAlive = true;
- mLastDisplay = true;
-
- mPosX = 0;
- mPosY = 0;
- mWidth = 0;
- mHeight = 0;
- mNumFrame = 0;
- mNumColumn = 0;
- mFrameDelay = 0;
- }
-
-
- cSprite::~cSprite()
- {
-
- delete mBitmap;
- if(mNextSprite)
- delete mNextSprite;
- }
-
-
- void cSprite::LoadSprite(std::string name, int x, int y, int frame, int column , int delay )
- {
-
- if(!mNodes)
- {
- mPosX = x;
- mPosY = y;
- mNumFrame = frame;
- mNumColumn = column;
- mFrameDelay = delay;
- mCurrentFrame = 0;
- mCountFrameDelay = 0;
- mCurrentColumn = 0;
-
- mBitmap->LoadBitmap(name.c_str());
- mWidth = mBitmap->GetBitmapWidth();
- mHeight = mBitmap->GetBitmapHeight();
-
- static_cast<int>(mFrameWidth) = (mWidth/mNumFrame);
- static_cast<int>(mFrameHeight) = (mHeight/mNumColumn);
-
- // for pixel perfect collision
- //------------------------------------------------------
- mT = new bool*[mWidth];
- for(int i=0;i<mWidth;i++)
- mT[i] = new bool[mHeight];
-
- for(int i=0;i<mWidth;i++)
- for(int j=0;j<mHeight;j++)
- {
- if(GetPixel(mBitmap->GetMemHdc(), i, j) == RGB(255, 0, 255))
- mT[i][j] = false;
- else
- mT[i][j] = true;
- }
- //-------------------------------------------------------
-
- SetRect(&mCollisionRect,x, y, x+mWidth, y+mHeight);
- mNextSprite = new cSprite(mHdc, true);
- return;
- }
-
- if(!mNextSprite)
- {
- mPosX = x;
- mPosY = y;
- mNumFrame = frame;
- mNumColumn = column;
- mFrameDelay = delay;
- mCurrentFrame = 0;
- mBitmap->LoadBitmap(name.c_str());
- mWidth = mBitmap->GetBitmapWidth();
- mHeight = mBitmap->GetBitmapHeight();
-
- // for pixel perfect collision
- //------------------------------------------------------
- mT = new bool*[mWidth];
- for(int i=0;i<mWidth;i++)
- mT[i] = new bool[mHeight];
-
- for(int i=0;i<mWidth;i++)
- for(int j=0;j<mHeight;j++)
- {
- if(GetPixel(mBitmap->GetMemHdc(), i, j) == RGB(255, 0, 255))
- mT[i][j] = false;
- else
- mT[i][j] = true;
- }
- //-------------------------------------------------------
-
- SetRect(&mCollisionRect,x, y, x+mWidth, y+mHeight);
- mNextSprite = new cSprite(mHdc, mLimiteRect, mReaction, true);
- return;
- }
- else
- mNextSprite->LoadSprite(name, x, y, frame, column, delay);
- }
-
-
- //--------------------------------------------
- // Display a sprite
- //--------------------------------------------
- void cSprite::DisplaySprite()
- {
- if(mNextSprite)
- {
- if(mAlive)
- {
- if(mVisible || (!mVisible && mLastDisplay))
- {
- mBitmap->DisplayBitmap(mPosX, mPosY);
- SetRect(&mCollisionRect,mPosX, mPosY, mPosX+mWidth, mPosY+mHeight);
- if(!mVisible)
- mLastDisplay = false;
- }
- mNextSprite->DisplaySprite();
- }
- }
- }
-
-
- //----------------------------------------------
- // Display a transparent sprite
- //----------------------------------------------
- void cSprite::DisplaySprite(int R, int G, int B)
- {
- if(mNextSprite)
- {
- if(mAlive)
- {
- if(mVisible || (!mVisible && mLastDisplay))
- {
- mBitmap->DisplayBitmap(mPosX, mPosY, R, G, B);
- SetRect(&mCollisionRect,mPosX, mPosY, mPosX+mWidth, mPosY+mHeight);
- if(!mVisible)
- mLastDisplay = false;
- }
- mNextSprite->DisplaySprite();
- }
- }
- }
-
-
- //-----------------------------------------------------------
- // Display a transparent sprite with a BYTE[] as argument
- //-----------------------------------------------------------
- void cSprite::DisplaySprite(BYTE color[])
- {
- if(this)
- {
- if(mNextSprite)
- {
- if(mAlive)
- {
- if(mVisible || (!mVisible && mLastDisplay))
- {
- if(mNumFrame == 1)
- {
- mBitmap->DisplayBitmap(mPosX, mPosY, color);
- SetRect(&mCollisionRect,mPosX, mPosY, mPosX+mWidth, mPosY+mHeight);
- if(!mVisible)
- mLastDisplay = false;
- }
- else
- {
- mBitmap->DisplayPartBitmap(mPosX, mPosY, (mFrameWidth*mCurrentFrame), (mFrameHeight*mCurrentColumn),
- mFrameWidth, mFrameHeight, color);
-
- if(mCountFrameDelay == mFrameDelay)
- {
- if((mCurrentFrame++) == (mNumFrame+1))
- mCurrentFrame = 0;
-
- mCountFrameDelay = 0;
- }
- else
- mCountFrameDelay++;
- }
- }
- }
- }
- mNextSprite->DisplaySprite();
- }
- }
-
- void cSprite::MooveSprite(int x, int y)
- {
- if(mNextSprite)
- {
- if(mReaction == SR_NOREACTIONS)
- {
- mPosX += x;
- mPosY += y;
- SetRect(&mCollisionRect,mPosX, mPosY, mPosX+mWidth, mPosY+mHeight);
- return;
- }
-
- if(mReaction == SR_STOP)
- {
- if(mLimiteRect.top<(mPosX+x) && mLimiteRect.bottom>(mPosX+x+mWidth) &&
- mLimiteRect.left<(mPosY+y) && mLimiteRect.right>(mPosY+y+mHeight))
- {
- mPosX += x;
- mPosY += y;
- SetRect(&mCollisionRect,mPosX, mPosY, mPosX+mWidth, mPosY+mHeight);
- return;
- }
- }
-
- /*if(mReaction == SR_OTHERSIDE)
- {
- if(mLimiteRect.top<(mPosX+x) && mLimiteRect.bottom>(mPosX+x+mWidth) &&
- mLimiteRect.left<(mPosY+y) && mLimiteRect.right>(mPosY+y+mHeight))
- {
- mPosX += x;
- mPosY += y;
- SetRect(&mCollisionRect,mPosX, mPosY, mPosX+mWidth, mPosY+mHeight);
- return;
- }
- else
- {
- if(mLimiteRect.top<(mPosX+x))
- {
- mPosX = 1024-mWidth;
- mPosY = 768 - mHeight;
- SetRect(&mCollisionRect,mPosX, mPosY, mPosX+mWidth, mPosY+mHeight);
- }
- }
-
- }*/
-
- if(mReaction == SR_DELETE)
- {
- if(mLimiteRect.top<(mPosX+x) && mLimiteRect.bottom>(mPosX+x+mWidth) &&
- mLimiteRect.left<(mPosY+y) && mLimiteRect.right>(mPosY+y+mHeight))
- {
- mPosX += x;
- mPosY += y;
- SetRect(&mCollisionRect,mPosX, mPosY, mPosX+mWidth, mPosY+mHeight);
- }
- else
- mVisible = false;
- }
-
-
- mNextSprite->MooveSprite(x, y);
- }
- }
-
- void cSprite::UpdateFrame()
- {
-
-
- }
-
-
- INIT CreateSpriteObject(HDC hdc, bool nodes, cSprite** sprite)
- {
-
- *sprite = new cSprite(hdc, nodes);
-
- if(*sprite!= NULL)
- return G2D_OK;
- else
- return G2D_FAILED;
- }
-
- INIT CreateSpriteObject(HDC hdc, RECT rect_limite, eReaction reaction, bool nodes, cSprite** sprite)
- {
- *sprite = new cSprite(hdc, rect_limite, reaction, nodes);
-
- if(*sprite!=NULL)
- return G2D_OK;
- else
- return G2D_FAILED;
- }
-
-
- } //namespace G2D
Liste des fichiers du ZIP
| Fichier | Taille |
Shoot \ bitmap.cpp | 2,82 Ko |
Shoot \ bitmap.h | 1,04 Ko |
Shoot \ dinput8.dll | 177,5 Ko |
Shoot \ fmod.dll | 159 Ko |
Shoot \ Fmod \ fmod.dll | 159 Ko |
Shoot \ Fmod \ fmodvc.lib | 57,52 Ko |
Shoot \ Fmod \ libfmod.a | 183,09 Ko |
Shoot \ GameEngine2D.rc | 206 o |
Shoot \ header.h | 1,42 Ko |
Shoot \ Icons \ Games.ico | 5,91 Ko |
Shoot \ inputs.h | 1,16 Ko |
Shoot \ keyboard.cpp | 2,04 Ko |
Shoot \ keyboard.h | 740 o |
Shoot \ main.cpp | 539 o |
Shoot \ MyApplication.cpp | 7,42 Ko |
Shoot \ MyApplication.h | 585 o |
Shoot \ Pictures \ bigExplosion.bmp | 22,13 Ko |
Shoot \ Pictures \ bullet.bmp | 6,8 Ko |
Shoot \ Pictures \ Enemy1.bmp | 4,69 Ko |
Shoot \ Pictures \ explosion.bmp | 7,3 Ko |
Shoot \ Pictures \ fond.bmp | 3,75 Mo |
Shoot \ Pictures \ gameOver.bmp | 3,55 Ko |
Shoot \ Pictures \ SpaceShip.bmp | 9,69 Ko |
Shoot \ release.cpp | 257 o |
Shoot \ release.h | 255 o |
Shoot \ renderer.cpp | 7,41 Ko |
Shoot \ renderer.h | 2,2 Ko |
Shoot \ Ressources.h | 382 o |
Shoot \ sound.cpp | 2,52 Ko |
Shoot \ sound.h | 1,65 Ko |
Shoot \ Sounds \ explosion1.wav | 32,83 Ko |
Shoot \ Sounds \ explosion2.wav | 104,72 Ko |
Shoot \ Sounds \ rocket.wav | 26,2 Ko |
Shoot \ sprites.cpp | 7,16 Ko |
Shoot \ sprites.h | 2,79 Ko |
Shoot \ sprites.inl | 2,66 Ko |
Shoot \ sprites_reactions.h | 612 o |
Shoot \ time.cpp | 1,3 Ko |
Shoot \ time.h | 1,04 Ko |
Shoot \ time_convertion.h | 263 o |
Pour télécharger le zip au complet, veuillez vous rendre sur cette page :
Télécharger [C++] [WIN32] JEUX DE SHOOT ( SPACE SHOOT )
Sources du même auteur ayant un ZIP
-
Infos image pour opengl Ce programme donne toutes les informations nécessaires concernant une image afin de pouvoir la charger avec OpenGL au travers de fonctions c...
Langage : C / C++ / C++.NET, publié le 11/07/2012 par nikau
Voir la suite...
Sources du même langage comportant un zip
|
Derniers codes sources...
Logiciels à télécharger...
-
Nego Facturation (1.84) [Gratuit / Freeware]
Nego Facturation est un logiciel complet qui permet de gérer vos factures et devis très simplement.
Ce programme est doté d'une ergonomie incomparable déstinée à satisfaire les utilisateurs les plu...
-
Revealer Keylogger Free (2.07) [Gratuit / Freeware]
Keylogger invisible et gratuit pour Windows 8, 7, Vista ou XP. Revealer Keylogger Free vous permet de surveiller l'activité des utilisateurs de votre ordinateur et d'enregistrer toutes les touches du ...
-
Devis-Factures PHMSD (2.1.0.1)
Configuration minimale
Nécessite Windows™ 2000, XP, Windows 7, 8, Vista (Service Pack à jour) - Processeur 500 Mhz (700 Mhz conseillé) - 256 Mo de Ram - 100 Mo d'espace disque disponible po...
|