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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
#include <stdlib.h>
#include <vector>
#include <math.h>
#include <map>
#include <string>
#include <iostream>
#include <fstream>
#include <SDL\SDL.h>
#include <SDL\SDL_image.h>
#include <SDL\SDL_mixer.h>
#include <SDL\SDL_ttf.h>
#include <SDL\SDL_framerate.h>
#include <SDL\SDL_rotozoom.h>
#include <SDL\SDL_gfxPrimitives.h>
SDL_Surface* screen;
if (SDL_Init ( SDL_INIT_EVERYTHING ) != 0)
printf ("Konnte SDL nicht initialisieren: %s\n",
SDL_GetError ());
screen = SDL_SetVideoMode (640, 480, 32, SDL_SWSURFACE | SDL_ANYFORMAT | SDL_DOUBLEBUF);
if (screen == NULL)
printf ("Videomodus konnte nicht eingerichtet werden: "
" %s\n", SDL_GetError ());
TTF_Init();
class Bitmap
{
public:
Bitmap(Uint16 width,Uint16 height);
Bitmap(std::string filename);
//bei public gibts noch andere funktionen die aber in der main nicht auf gerufen werden
protected:
private:
SDL_Surface* bitmap;
SDL_Surface clean_bitmap;
Uint16 width;
Uint16 height;
friend class Sprite;
};
Bitmap::Bitmap(Uint16 width2,Uint16 height2):
width(width2),height(height2),dis(false),bitmap(NULL)
{
SDL_Surface bit;
*bitmap = bit;
if (bitmap == NULL)
printf("Das Bild konnte nicht geladen werden: %s\n",SDL_GetError());
SDL_Rect rec = {0,0,width,height};
SDL_SetClipRect(bitmap, &rec);
clean_bitmap = *bitmap;
}
Bitmap::Bitmap(std::string filename):
dis(false),bitmap(NULL)
{
bitmap = IMG_Load(filename.c_str());
if (bitmap == NULL)
printf("Das Bild konnte nicht geladen werden: %s\n",SDL_GetError());
clean_bitmap = *bitmap;
width = bitmap->w;
height = bitmap->h;
}
class Viewport
{
public:
Viewport(Sint16 x, Sint16 y,Uint16 width,Uint16 height);
Viewport(SDL_Rect rect);
SDL_Rect rect;
bool visible;
Sint16 z ,ox ,oy;
bool dispose;
protected:
private:
};
Viewport::Viewport(Sint16 x, Sint16 y,Uint16 width,Uint16 height):
visible(true),
z(0),ox(0),oy(0),
dispose(false)
{
SDL_Rect rect = {x,y,width,height};
}
Viewport::Viewport(SDL_Rect rect2):
rect(rect2),
visible(true),
z(0),ox(0),oy(0),
dispose(false)
{}
class Sprite
{
public:
Sprite(Viewport viewport = Viewport (0,0,0,0));
//bei public gibts noch andere funktionen die aber in der main nicht auf gerufen werden
protected:
private:
SDL_Rect rec;
SDL_Rect src;
Viewport start_viewport;
bool visible;
Sint16 z ,ox ,oy;
Bitmap bitmap;
double zoom_x;
double zoom_y;
double angle;
Uint8 opacity;
unsigned int id;
Sint16 frame;
Uint8 frame_max;
Bitmap save_bitmap;
};
Sprite::Sprite(Viewport viewport):
start_viewport(0,0,0,0),
visible(true),
z(0), ox(0), oy(0),
bitmap(0,0),
zoom_x(1.0),
zoom_y(1.0),
angle(0),
frame(-1),
frame_max(0),
save_bitmap(0,0),
opacity(255)
{
start_viewport = viewport;
rec = viewport.rect;
visible = viewport.visible;
z = viewport.z; ox = viewport.ox; oy = viewport.oy;
SDL_Rect src = {ox,oy,bitmap.bitmap->w,bitmap.bitmap->h};
if (SDL_BlitSurface(bitmap.bitmap,&src,screen,&rec) == -1)
printf ("Konnte das Bild nich am Screen anzeigen: %s\n",SDL_GetError ());
}
int main( int argc, char* args[] )
{
Sprite img; //wenn ich das aus kommentiere läuft das programm
//img.set_bitmap(Bitmap ("D:\\gameproject_win\\cb.bmp"));
//img.set_x(160);
//img.set_y(160);
SDL_Delay(5000);
return 0;
}
|