Intro

How Chapter 4 works?

  1. init()
    1. SDL_Init()
    2. SDL_CreateWindow()
    3. SDL_GetWindowSurface()
  2. loadMedia()
    1. put surfaces in SDL_Surface* array( is global variable) with SDL_LoadBMP().
  3. start loop untill variable quit is true.
    1. start loop that calls SDL_PollEvent() untill it returns 0.
      1. if SDL_Event.type is SDL_QUIT, quit is true( which means first loop will end).
        • else if SDL_Event.type is SDL_KEYDOWN, choose mapped sruface to key inside SDL_Surface* array( is global variable).
      2. copy screen(Blit) with SDL_BlitSurface() from chosen surface to screen surface.
      3. update window with SDL_UpdateWindowSurface() to refresh and show what we’ve done.
  4. close()
    1. free surfacees in SDL_Surface* array( is global varable) with SDL_FreeSurface().
    2. SDL_DestroyWindow()
    3. SDL_Quit()

Function

  • nothing new

Struct

  • nothing new

Term

(enum(not official))KeyPressSurfaces

  • KEY_PRESS_SURFACE_DEFAULT
  • KEY_PRESS_SURFACE_UP
  • KEY_PRESS_SURFACE_DOWN
  • KEY_PRESS_SURFACE_LEFT
  • KEY_PRESS_SURFACE_RIGHT
  • KEY_PRESS_SURFACE_TOTAL

these enum will have global SDL_Surface* array for having mapped surface.

SDL_Event.type

  • SDL_KEYDOWN

SDL_Event.key.keysym.sym

  • SDLK_UP
  • SDLK_DOWN
  • SDLK_LEFT
  • SDLK_RIGHT