Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
#ifndef MAP_HPP #define MAP_HPP #define MAPHEIGHT 550 // Fields #define MAPWIDTH 1000 // Fields #include "Singleton.hpp" #include "Sprite.hpp" #define g_pMap CMap::Get () class CMap : public TSingleton<CMap> { public: CMap(); void Init(); void Render (); bool UseField (int xPos, int yPos, int Object_ID, bool bOverwrite); void MoveMap (int x, int y); void LoadImages (); void CreateWorld(); int GetMapXPos () {return mapXPos;} int GetMapYPos () {return mapYPos;} int GetZoom () {return Zoom;} void Quit (); struct m_SField { int XPos; // Pixels int YPos; // Pixels int ObjectID; float AnimPhase; float Timer; }; m_SField Field[MAPWIDTH][MAPHEIGHT]; const int Width; const int Height; int Zoom; private: Uint32 CMap::get_pixel32( SDL_Surface *surface, int x, int y ); CSprite *m_pSpriteWater; // Sprite für das Wasser CSprite *m_pSpriteLand; // Sprite für das Land CSprite *m_pSpriteCoast; // Sprite für die Küste CSprite *m_pSpriteForest; // Sprite für Wald CSprite *m_pSpriteMountain; // Sprite für Berg CSprite *m_pSpriteTenement; // Sprite für Wohnhaus CSprite *m_pSpriteLumberjack; // Sprite für Holzfäller CSprite *m_pSpritePath; // Sprite für Feldweg int mapXPos; // Pixels int mapYPos; // Pixels SDL_Surface *m_pBitmap; Uint8 r, g, b; SDL_PixelFormat *format; }; #endif |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
#include "Map.hpp" #include <iostream> using namespace std; CMap::CMap() : Width (MAPWIDTH), Height (MAPHEIGHT) { m_pSpriteWater = NULL; m_pSpriteLand = NULL; m_pSpriteCoast = NULL; m_pSpritePath = NULL; m_pBitmap = NULL; r = g = b = 0; format = NULL; mapXPos = 0; mapYPos = 0; Zoom = 1; for(int i=0; i<MAPHEIGHT; i++) { for (int j=0; j<MAPWIDTH; j++) { Field[j][i].ObjectID=0; Field[j][i].XPos=j*10; Field[j][i].YPos=i*10; Field[j][i].AnimPhase = 0; Field[j][i].Timer = 0; } } r = g = b = 0; } void CMap::Init() { LoadImages (); CreateWorld (); } void CMap::Render() { // ... } bool CMap::UseField(int xPos, int yPos, int Object_ID, bool bOverwrite) { // ... } void CMap::MoveMap(int x, int y) { // ... } void CMap::Quit() { // ... } void CMap::LoadImages() { // ... } void CMap::CreateWorld() { if (m_pBitmap == NULL && format == NULL) { m_pBitmap = new SDL_Surface; m_pBitmap = SDL_LoadBMP ("C:/Users/Manfred/Verschiedenes/PC/Programmieren/C++/Projekte/In Bearbeitung/1492/Debug/Data/Weltkarte.bmp"); if (m_pBitmap != NULL) cout << "Bitmap wurde geladen" << endl; cout << SDL_LockSurface (m_pBitmap); format = m_pBitmap->format; Uint32 pixel = get_pixel32(m_pBitmap, 0, 0); SDL_GetRGB(get_pixel32(m_pBitmap, 0, 0), format, &r, &g, &b); cout << "Rot: " << (int)(r) << " Grün: " << (int)(g) << " Blau: " << (int)(b) << endl; cout << "BytesPerPixel: " << (int) m_pBitmap->format->BytesPerPixel; cout << endl; SDL_UnlockSurface (m_pBitmap); } } Uint32 CMap::get_pixel32( SDL_Surface *surface, int x, int y ) { //Convert the pixels to 32 bit Uint32 *pixels = (Uint32 *)surface->pixels; //Get the requested pixel return pixels[ ( y * surface->w ) + x ]; } |
C-/C++-Quelltext |
|
1 |
#define g_pMap CMap::Get () |
C-/C++-Quelltext |
|
1 2 |
Field[j][i].XPos=j*10; Field[j][i].YPos=i*10; |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Koschi« (31.07.2014, 19:56)
Werbeanzeige