Zdravím, napsal jsem si kód:
#include <SDL.h>
#include <stdio.h>
#include <stdlib.h>
SDL_Surface *screen;
SDL_Surface *zbran;
SDL_Surface *background;
SDL_Surface *cil;
SDL_Surface *bullet;
int zbran_x=0;
int zbran_y=150;
int cil_x=500;
int cil_y=500;
int bull_x;
int bull_y;
void LoadImages(){
zbran = SDL_LoadBMP("zbran.bmp");
background = SDL_LoadBMP("bg.bmp");
cil = SDL_LoadBMP("cil.bmp");
bullet = SDL_LoadBMP("bullet.bmp");
}
void DrawIMG(SDL_Surface *img, int x, int y){
SDL_Rect rect;
rect.x = x;
rect.y = y;
SDL_BlitSurface(img, NULL, screen, &rect);
}
void DrawIMG(SDL_Surface *img, int x, int y, int w, int h, int x2, int y2){
SDL_Rect rect;
rect.x = x;
rect.y = y;
SDL_Rect rect2;
rect2.x = x2;
rect2.y = y2;
rect2.w = w;
rect2.h = h;
SDL_BlitSurface(img, &rect2, screen, &rect);
}
void DrawScene(){
DrawIMG(background, zbran_x-1, zbran_y-1, 200, 200, zbran_x-1, zbran_y-1);
DrawIMG(zbran, zbran_x, zbran_y);
DrawIMG(cil, cil_x, cil_y);
SDL_Flip(screen);
}
void DrawBullet(){
DrawIMG(bullet,bull_x,bull_y);
SDL_Flip(screen);
}
Uint32 Timer1(Uint32 interval, void* param){
bull_x+=1;
return interval;
}
int main(int argc, char *argv[]){
Uint8* keys;
if( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) < 0 ){
printf("Inicializace SDL se nezdařila: %s", SDL_GetError());
exit(1);
}
atexit(SDL_Quit);
screen = SDL_SetVideoMode(895, 716, 32, SDL_HWSURFACE|SDL_DOUBLEBUF);
if ( screen == NULL ){
printf("Vytvoření okna se nezdařilo: %s", SDL_GetError());
exit(1);
}
LoadImages();
DrawIMG(background, 0, 0);
bool done=false;
while(done == false){
SDL_Event event;
while(SDL_PollEvent(&event)){
if(event.type == SDL_QUIT) done = true;
if(event.type == SDL_KEYUP){
if(event.key.keysym.sym == SDLK_RETURN) done = true;
}
}
keys = SDL_GetKeyState(NULL);
if(keys[SDLK_RIGHT]) zbran_x += 1;
if(keys[SDLK_LEFT]) zbran_x -= 1;
if(keys[SDLK_DOWN]) zbran_y += 1;
if(keys[SDLK_UP]) zbran_y -= 1;
if(keys[SDLK_SPACE]) {
bull_x=zbran_x+100;
bull_y=zbran_y+10;
float chun=bull_x-cil_x;
float khun=bull_y-cil_y;
while ((chun>200)||(khun>200))
bull_x+=1;
DrawBullet();
}
DrawScene();
}
}
a mám tři dotazy:
1)Proč se kulka nechce hýbat a jak to zařídit?
2)Jak udělat aby se při každém zmáčknutí mezrníku vytvořila nová kulka, ne aby se přemístila stará?
3)Bude potom fungovat to zjištování kolize nebo to chce udělat nové..?