Du bist nicht angemeldet.

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

11

26.02.2013, 22:44

Hier mal der ganze quelltext

Base.hpp

C-/C++-Quelltext

1
2
3
4
5
6
7
8
#ifndef BASE_HPP
#define BASE_HPP
class baseclass{
public:
    static SDL_Rect coord;
    static const int TILE_SIZE=50;
};
#endif // BASE_H




Game.hpp

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
#include <iostream>
#include <fstream>
using namespace std;
#include <vector>
#include "SDL\SDL.h"
#include "base.hpp"
#ifndef GAME_HPP
#define GAME_HPP

class game{
SDL_Surface *screen, *background,*block;
SDL_Rect camera;
std::vector<std::vector<int> > karte;
bool direction[2];
SDL_Surface *load_image(const char* filename);
void loadmap(const char* filename);
void showmap();
bool running;
void handleEvents();
static const int SCREEN_WIDTH=640;
static const int SCREEN_HEIGHT=480;
public:
    game();
    ~game();
    void start();
};
#endif



Game.cpp

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
102
103
104
105
#include "game.hpp"

using namespace std;

SDL_Rect baseclass::coord;
game::game()
{
    screen=SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,32,SDL_SWSURFACE);
    block=load_image("tiles.bmp");
    background=load_image("background.bmp");
    baseclass::coord.x=baseclass::coord.y=camera.x=camera.y=0;
    baseclass::coord.w=camera.w=SCREEN_WIDTH;
    baseclass::coord.h=camera.h=SCREEN_HEIGHT;
    direction[0]=direction[1]=0;
    running=true;
}

game::~game()
{
    SDL_FreeSurface(block);
    SDL_FreeSurface(background);
    SDL_Quit();
}


SDL_Surface*game::load_image(const char* filename)
{
 SDL_Surface* tmp=SDL_LoadBMP(filename);
 SDL_Surface *tmp2   =SDL_DisplayFormat(tmp);
 //SDL_SetColorKey(tmp2,SDL_SRCCOLORKEY,SDL_MapRGB(screen->format,0x00,0xff,0));
 SDL_FreeSurface(tmp);
 return tmp2;
}




void game::start()
{
    Uint32 start;
    loadmap("Map.txt");
    while(running)
    {
        start=SDL_GetTicks();
        SDL_BlitSurface(background,&camera,screen,NULL);
        showmap();
    SDL_Flip(screen);
    if(1000/30>(SDL_GetTicks()-start))
        SDL_Delay(1000/30-(SDL_GetTicks()-start));
    }
}

void game::loadmap(const char* filename)
{
    int width=0;
    int height=0;
  std::ifstream in(filename);
  if(!in.is_open())
  {
      std::cout <<"Datei konnte nicht geladen werden" << endl;

  }
       in >>width;
      in >>height;
      int current;
      for(int i=0; i<height;i++)
      {
          std::vector<int> vec;
          for(int j=0; j<width; j++)
          {
              if(in.eof())
              {
                  std::cout <<"File end reached too soon" << endl;
                  return;
              }
              in >>current;
              if(current>=0&&current<=1)
              {
                  vec.push_back(current);
              }else{
              vec.push_back(0);
              }
          }
          karte.push_back(vec);
      }
      in.close();
}

void game::showmap()
{
for(int i=0; i<karte.size();i++)
{

    for(int j=0; j<karte[0].size();j++)
    {
        if(karte[i][j]==0)
       {
           SDL_Rect blockrect={(karte[i][j]-1)*baseclass::TILE_SIZE, 0, baseclass::TILE_SIZE,baseclass::TILE_SIZE};
           SDL_Rect destrect={j*baseclass::TILE_SIZE-baseclass::coord.x,i*50};
           SDL_BlitSurface(block,&blockrect,screen,&destrect);
       }

    }
}
}



main.cpp

C-/C++-Quelltext

1
2
3
4
5
6
7
8
#include "game.hpp"

int main(int argc, char* argv[])
{
    game g;
    g.start();
    return 0;
}

12

26.02.2013, 22:48

Danke für die Hilfe, ^^ hat an der Einstellung gelegen.

13

26.02.2013, 22:51

Nein hat es nicht.
LIES DIE WARNUNG UND BEHEBE DIE URSACHE!
"Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: Nothing works and they don’t know why." - Anon

Architekt

Community-Fossil

Beiträge: 2 481

Wohnort: Hamburg

Beruf: Student

  • Private Nachricht senden

14

26.02.2013, 22:56

Solange es kompiliert und er zufrieden ist, lass ihn, es bringt nichts.
Der einfachste Weg eine Kopie zu entfernen ist sie zu löschen.
- Stephan Schmidt -

15

26.02.2013, 22:58

ich hab mir die warnung jetzt schon etliche male angeschaut, es hat was mit dem zweidimensionalen vektor zutun, das ist mir klar.

Habe aber bis jetzt nur die grundlagen von vektoren gelernt, und noch nie mit zweidimensionalen gearbeitet.

Deswegen hab ich mir ja das tutorial angeschaut.

Der hat das aber genau so da stehen, und was das schlimmste ist, bei mir werden keine tiles angezeigt nur der background ^^

Nimelrian

Alter Hase

Beiträge: 1 216

Beruf: Softwareentwickler (aktuell Web/Node); Freiberuflicher Google Proxy

  • Private Nachricht senden

16

26.02.2013, 23:29

omfg...

Es geht nicht um Vektoren, sondern um den Vergleich von INTEGERN.

Du vergleichst da einen unsigned integer mit einem signed integer, was dem Compiler durchaus einen Grund zum Meckern gibt...
Ich bin kein UserSideGoogleProxy. Und nein, dieses Forum ist kein UserSideGoogleProxyAbstractFactorySingleton.

Werbeanzeige