Weliaz 0 Newbie Poster

Hi there! I am creating a game!

#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <SDL.h>
#include <string>
#include "font.h"
#include "SDL_rotozoom.h"
SDL_Surface *back;
SDL_Surface *image;
SDL_Surface *screen;
SDLFont * font1;
int y = 750;
char * string = "Made by Weliaz @ http://weliaz.me";

int xpos=512,ypos=384;
double opos = 180;

int InitImages()
{
  back = SDL_LoadBMP("bg.bmp");
  image = SDL_LoadBMP("image.bmp");
  return 0;
}

void DrawIMG(SDL_Surface *img, int x, int y)
{
  SDL_Rect dest;
  dest.x = x;
  dest.y = y;
  SDL_BlitSurface(img, NULL, screen, &dest);
}

void DrawIMG(SDL_Surface *img, int x, int y, int w, int h, int x2, int y2)
{
  SDL_Rect dest;
  dest.x = x;
  dest.y = y;
  SDL_Rect dest2;
  dest2.x = x2;
  dest2.y = y2;
  dest2.w = w;
  dest2.h = h;
  SDL_BlitSurface(img, &dest2, screen, &dest);
}

void DrawBG()
{
  DrawIMG(back, 0, 0);
}

void DrawScene()
{
  DrawIMG(back, xpos-2, ypos-2, 132, 132, xpos-2, ypos-2);
  DrawIMG(image, xpos, ypos);
  drawString(screen,font1,512-stringWidth(font1,"Square Game")/2,0,"Square Game");
  drawString(screen,font1,512-stringWidth(font1,string)/2,y,string);
  SDL_Flip(screen);
}

int main(int argc, char *argv[]) {
	Uint8 * keys;
	if(SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0) {
        fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
        return 1;
    }
	atexit(SDL_Quit);

	screen = SDL_SetVideoMode(1024, 768, 32, SDL_HWSURFACE|SDL_DOUBLEBUF);
    if(screen == NULL) {
        fprintf(stderr, "Unable to set 1024x468 video: %s\n", SDL_GetError());
        exit(1);
    }

	InitImages();
	DrawBG();
	font1 = initFont("data/font1");
	int done=0;
	while(done == 0) {
		SDL_Event event;
		while ( SDL_PollEvent(&event) ) {
			if ( event.type == SDL_QUIT )  {  done = 1;  }
			if ( event.type == SDL_KEYDOWN ) {
				if ( event.key.keysym.sym == SDLK_ESCAPE ) { done = 1; }
			}
		}
		keys = SDL_GetKeyState(NULL);
		if ( keys[SDLK_UP] ) { 
			if(!ypos <= 0) {
				ypos -= 1;
			}
		}
		if ( keys[SDLK_LEFT] ) { 
			opos = opos - 0.2;
				image = rotozoomSurface(image,opos,0,1);
		}
		if ( keys[SDLK_RIGHT] ) { 
				opos = opos + 0.2;
				image = rotozoomSurface(image,opos,0,1);
		}
		if ( keys[SDLK_DOWN] ) { 
			if(ypos < (768-38)) {
			    ypos += 1;
			}
		}
		DrawScene();
	}
	return 0;
}

I wanna make the surface image rotate 0.2 degrees when left or right is pressed. I tried using rotozoomSurface (as in the code) however it just makes the bitmap disappear. Any help to get? :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.