Ich versuche momentan den folgenden Code zum kompilieren. Ein Bild soll per Pfeiltasten bewegt werden.
Sobald ich das kompliere liefert er mir eine Fehlermeldung und zwar:
Code: Alles auswählen
\Garten-Animation.c|83|error: expected ';', ',' or ')' before '=' token|

Zeile 83:
Code: Alles auswählen
void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL )
{
//Holds offsets
//Get offsets
offset.x = x;
offset.y = y;
//Blit
SDL_BlitSurface( source, clip, destination, &offset );
}
Code: Alles auswählen
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
const int Kind_h = 20;
const int Kind_w = 20;
SDL_Surface* Hintergrund = NULL;
SDL_Surface* garten = NULL;
SDL_Surface* kind = NULL;
SDL_Rect rc;
SDL_Event Event;
int x = 0,y = 0;
int xVel = 0, yVel = 0;
void keytaste()
{
if(Event.type == SDL_KEYDOWN)
{
switch(Event.key.keysym.sym)
{
case SDLK_UP:
yVel-=Kind_h/2;
break;
case SDLK_DOWN:
yVel+=Kind_h/2;
break;
case SDLK_LEFT:
xVel-=Kind_w/2;
break;
case SDLK_RIGHT:
xVel+=Kind_w/2;
break;
}
}
else if(Event.type == SDL_KEYUP)
{
switch(Event.key.keysym.sym)
{
case SDLK_UP:
yVel+=Kind_h/2;
break;
case SDLK_DOWN:
yVel-=Kind_h/2;
break;
case SDLK_LEFT:
xVel+=Kind_w/2;
break;
case SDLK_RIGHT:
xVel-=Kind_w/2;
break;
}
}
}
void show();
void move()
{
x += xVel;
if( ( x < 0 ) || ( x + Kind_w > 640 ) )
{
//move back
x -= xVel;
}
//Move the dot up or down
y += yVel;
//If the dot went too far up or down
if( ( y < 0 ) || ( y + Kind_h > 480 ) )
{
//move back
y -= yVel;
}
}
void show()
{
apply_surface(x,y,kind,Hintergrund);
}
void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL )
{
//Holds offsets
//Get offsets
offset.x = x;
offset.y = y;
//Blit
SDL_BlitSurface( source, clip, destination, &offset );
}
int main(int argc,char* argv[])
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Quit();
Hintergrund = SDL_SetVideoMode(640,480,0,SDL_ANYFORMAT);
garten = IMG_Load("Garten.jpg");
kind = IMG_Load("Kind.jpg");
rc.w=kind->w;
rc.h=kind->h;
for(;;)
{
if(SDL_PollEvent(&Event)==0)
{
keytaste();
move();
show();
SDL_BlitSurface(garten,0,Hintergrund,0);
SDL_UpdateRect(Hintergrund,0,0,0,0);
}
}
return(0);
}