Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualCdrandin

Posted 07 December 2012 - 01:26 AM

I am a pygame person, but typically it's done as this:
if event.key == event.keydown:
   if event.ket == event.K_UP:
	   ship.location.x -= 10  // Pygame takes (0,0) top left screen MAX_width,MAX_height) to be bottom right screen

Your code handles keydown alone versus handling with some specific key being pressed AND held. Hope this helps.

#2Cdrandin

Posted 07 December 2012 - 01:26 AM

I am a pygame person, but typically it's done as this:
if event.key == event.keydown:
   if event.ket == event.K_UP:
	   ship.location.x -= 10  // Pygame takes (0,0) top left screen MAX_width,MAX_height) to be bottom right screen

Your code handles keydown alone versus handling with some specific key being pressed. Hope this helps.

#1Cdrandin

Posted 07 December 2012 - 01:25 AM

(sigh) Now I'm hitting some more problems, things may be a little mixxed up. Now it won't move at all! It shows but doesn't respond in movement. Heres the code I wrote if you or anyone can see what I'm doing wrong

#include "SDL.h"
int main(int argc, char *argv[])
{
bool bRun = true;
SDL_Surface *screen , *ship;
SDL_Rect shipRect;
shipRect.x = 100 ;
shipRect.y = 100 ;
	
SDL_WM_SetCaption("Fryday", NULL);
screen = SDL_SetVideoMode( 256 , 224 , 32 , SDL_DOUBLEBUF|SDL_HWSURFACE|SDL_ANYFORMAT);

SDL_FillRect(screen , NULL , 0x221122);
ship = SDL_LoadBMP("./ship.bmp");
SDL_SetColorKey( ship, SDL_SRCCOLORKEY, SDL_MapRGB(ship->format, 255, 0, 255) );
SDL_BlitSurface( ship , NULL , screen , &shipRect );
SDL_Flip(screen);
	 SDL_Event event;
  while(bRun) {
  bool keysHeld[323] = {false}; // everything will be initialized to false

if (SDL_PollEvent(&event))
	  {
		 if (event.type == SDL_QUIT)
		 {
			bRun = false;
		 }
		 if (event.type == SDL_KEYDOWN)
		 {
			keysHeld[event.key.keysym.sym] = true;
		 }
		 if (event.type == SDL_KEYUP)
		 {
			keysHeld[event.key.keysym.sym] = false;
		 }

	  if ( keysHeld[SDLK_ESCAPE] )
	  {
		 bRun = false;
	  }
	  if ( keysHeld[SDLK_LEFT] )
	  {
		 shipRect.x -= 1;
	  }
	  if ( keysHeld[SDLK_RIGHT] )
	  {
		 shipRect.x += 1;
	  }
	  if ( keysHeld[SDLK_UP] )
	  {
		 shipRect.y -= 1;
	  }
	  if (keysHeld[SDLK_DOWN])
	  {
		 shipRect.y += 1;
	  }
}
	}; // while(bRun) { END
return 0;
}


I am a pygame person, but typically it's done as this:
if event.ey == event.keydown:
   if event.ket == event.K_UP:
	   ship.location.x -= 10  // Pygame takes (0,0) top left screen MAX_width,MAX_height) to be bottom right screen

Your code handles keydown alone versus handling with some specific key being pressed. Hope this helps.

PARTNERS