SlideShare uma empresa Scribd logo
1 de 59
Workshop India
Wilson Wingston Sharon
wingston.sharon@gmail.com
• Why?

• Learning is not just about marks.

• Its about building something.

• You cannot learn C in 2 weeks.
• You can only learn C by writing programs.
• Without writing programs OF YOUR OWN and ON YOUR
  OWN.
• We can only guide you – you have to put in some effort.
• In todays session file, you will see some files like this.

• Install all of them.

• Now see the Dev-Cpp folder?

• Copy everything in that to your
   Dev-Cpp folder (C:/Dev-Cpp). Copy the folders *inside*
this one to the one in you C drive.
• In the /game folder, you will see a folder called
  “SDL_Template(copy this folder)”

• Copy this folder to your own folder in your Exercise drive.

• After copying, rename the Folder to something like
  “SDL_1”

• In the folder you will see sdl.dev, you will have to open
  this file.
• You can open dev-cpp normally (if you need to enter
  passwrd) and then use the file>>open project or file>> to
  open this sdl.dev project file in your folder.
Code
                For the
                File that is currently
                Open in the tab



Files that
Belong to the
Current
project
-lmingw32
-lSDLmain
-lSDL
-lSGE

• The above parameters
• Must be present in
• The linker tab

• Say OK
• Press Ctr-F11to build
• And then F9 to run the program.
• If it doesn’t work.

• Recheck your project options tab
• See if you installed everything in the folder?

• Does it complain about missing dll? See if all files in the
  project folder conform to the folder image provided 3
  slides before.
• Help your friends set it up

• Learning is a collaborative process. Se what mistakes
  your friends have made. Check them. Help them.

• It makes you a better programmer by exposing you to the
  mistakes that are possible in C.

• It’ll help you avoid silly mistakes if you help others by
  correcting them.
• main.cpp
  • this file contains the main() function
  • This is called the entry point of the program.


• grapics.h
  • This file contains some structures and function that I wrote.
  • You might or might not use them as per requirement of the
    program.

  • The thing is well commented and documented.
The game itself

            Here the logic that specifies how the game behaves to the user



                                    Game Engine

SDL just gives as access to graphics card.            SGE is our game engine.



                                         SDL

       Simple Direct Media Layer               Provides a layer to access graphics card



                             Graphics Card on computer
                   Harware support for drawing stuff onto the screen
• make sure you have copied the Dev-Cpp folder i gave
  you onto your Dev-Cpp installation.
• That links up all sort of libraries for SDL to function
• Otherwise you might get an error about missing SDL.h
• This must be a global object.
• Whatever we want SDL to display has to be written to this
  screen.

•
screen = SDL_SetVideoMode(MX, MY, 32,
SDL_HWSURFACE|SDL_DOUBLEBUF);
The above line is important
• If you change MX and MY (in the beginning of
  graphics.h) you change the size of screen

• If you add,
  SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCR
  EEN
• To the last argument of the function, the program goes
  into full screen mode!
Update               Draw
     graphics              game
      models             elements




Undraw
                              Get input
 what is
                               from
  not
                               user
required

                Check
                Game
                 logic
• Events are things that happen outside the game engine
  that the game must be aware of.

• Eg: Keypresses

• SDL_pollevent(&event)
  • Returns NULL when there are no events left to handle, so then
    that while loops terminates and the game continues.
  • The event object contains details about what happened and the
    rest of the code handles it!
• Don’t touch the init() function.

• To add user interaction, code has to go in which function?
  •?



• To add some more drawings, code has to go where?
  •?
• Don’t touch the init() function.

• To add user interaction, code has to go in which function?
  • The event managing while loop in the main() function.



• To add some more drawings, code has to go where?
  • The render() function.
  • Or another function between init() and the eventhandler()
• Here are codes for most functions and all




• The main.cpp and graphics.h need to *share* the same
  global variable screen.
• This is done by the keyword extern; this specifies that
  this is not a different variable, but a same one that is
  declared in another file.
• The function _putpixel
  draws a point at the MX/2
  and MY/2 position.

• Modify the code to draw a
  horizontal line.

• ______________________
  __

• Across the screen.
• That for loop starts from i =0
• Till MX in steps of 1

• And the putpixel function
  draws a pixel at every point.



• Can you change it to vertical?
• What to do when considering to move a point.
  • What all is required to define a point?
     • X
     • Y
     • Colour.


• Keyboard handling is done on the event loop.

                       Position
       Keyboard            is
                                      Screen is   Point is
        press is       updated
                                       cleared    drawn
       checked          for the
                         point
• Keyboard presses is update as a
  struct in graphics.h called move.

• Each point will have an associated
  move variable.

• If kLR is -1/1 the point will have to
  move Left/Right.
• And so on.
• It is the while(SDL_Pollevent(&event))

• For every loop, the event structure will have the details of
  what happens, we want to see onky keyboard events.
• These are events of event.type ==
  • SDL_KEYDOWN
  • SDL_KEYUP
  • Etc..


• Using a switch case we can write what code to happen
  when each event is fired.
• Code comes at the level of the last
                          one.
• Case SDL_KEYUP:

• What to dowhen the key has been
released?

Set the move variable m1 kUD or KLR
to 0. Signifying no movement.
• cls(0) fills the screen with
  black;

• Updates point p1 with m1 for
  which direction to move the
  point

• Putpixel to draw the point.
• Render() runs infinitely,
   • Checks if point p1 has moved by using the m1variable
   • If moved, update the point’s x & y
   • Then clear the screen and draws the point.

• When keyboard is pressed
   • The eventloop() in main now enters the loop
   • A switch case is done on the event type to determine if it’s a keypress
     or a release.
   • When the keypress is detected the m1 variable is adjusted
   • When the keyrelease is detected the m1 variable is set to 0 so not
     movement happens.

• Compile 2.Movment folder code.
   • Again: follow dev-cpp rules for opening projects and compiling them.
• We have the point p1 that we can move
  around with the keyboard.

• Lets draw a line between p1 and MX/2,
  MY/2.

• That is a line from p1 to the center.

• Line function:
• sge_Line(*screen,x1,y1,x2,y2,color);
• sge_AALine(…) is line with anti-aliasing
•   I want the other points to move by using the
•   W - UP
•   S - DOWN
•   A - LEFT
•   D – Right

• Point 2 is handled by m2.
• Using switch case do the update of m2
• And update p2 with m2

• I want the line to move by both points.
• One point moves by arrow keys
• The other moves by wasd keys.
• The SGE SDL library provides some basic primitives for
  drawing.

• Drawing in this case is mathematical drawing.

• The basic shapes that are provided are:
  •   Points
  •   Lines
  •   Circle
  •   Rectangle
  •   Ellipse
  •   Polygons
• Try to think of creative shapes and things that you can
  draw with these functions.

• You can also make interesting mathematical loop
  shapes.

• If you don’t do the cls(0) whatever the loop draws wont
  be erased in the next iteration!.

• Try and do some more hoola!
• SDL printing things on the screen means
  you need a font!

• The font file is *something*.ttf

• These sort of fonts can be opened by SDL
  and drawn onto the screen.

• First we need to make a global font *
  variable.
• We need to initialise the font
  • We have cour.ttf right now.


• sge_TTF_Init() initialises the font
  engine.

• sge_TTF_openFont(font, size)
  returns the font object that should
  be global pointer of the same,
• Get text to appear one by one on the screen.



• Get text to scroll around the screen.



• Can you get keyboard input using the event loop ?
  • Do only numbers
• First we create a struct circle. (same like point except
  with radius too).
• Same
  KEYUP/KEYDOW
  N movement code
  to move m1 and
  m2.

• Adjust this code
  and get the second
  circle moving too.
• Instead of moving the second circle use the below
  random functions

• int sge_Random(int min, int max)
  Returns a random integer between (and including) min
  and max.

 void sge_Randomize(void)
 Seed the random number generator with a number from
 the system clock. Should be called once before the first
 use of sge_Random.
• Move the second circle randomly.

• When the first circle is touching the second circle, a
  counter should start in the corner.

• As long as the two circles are touching, counter must
  keep incrementing and the second circle keeps moves
  faster and faster.

• When the first circle leaves, the counter goes to 0 and
  stays there.

Mais conteúdo relacionado

Mais procurados

Digital Calipers Software Mitutoyo / Logiciel pour Pied à coulisse Mitutoyo (...
Digital Calipers Software Mitutoyo / Logiciel pour Pied à coulisse Mitutoyo (...Digital Calipers Software Mitutoyo / Logiciel pour Pied à coulisse Mitutoyo (...
Digital Calipers Software Mitutoyo / Logiciel pour Pied à coulisse Mitutoyo (...topomax
 
Smedberg niklas bringing_aaa_graphics
Smedberg niklas bringing_aaa_graphicsSmedberg niklas bringing_aaa_graphics
Smedberg niklas bringing_aaa_graphicschangehee lee
 
Intrinsics: Low-level engine development with Burst - Unite Copenhagen 2019
Intrinsics: Low-level engine development with Burst - Unite Copenhagen 2019 Intrinsics: Low-level engine development with Burst - Unite Copenhagen 2019
Intrinsics: Low-level engine development with Burst - Unite Copenhagen 2019 Unity Technologies
 
OGDC 2014_Architecting Games in Unity_Mr. Rustum Scammell
OGDC 2014_Architecting Games in Unity_Mr. Rustum ScammellOGDC 2014_Architecting Games in Unity_Mr. Rustum Scammell
OGDC 2014_Architecting Games in Unity_Mr. Rustum Scammellogdc
 
Best Practices for Shader Graph
Best Practices for Shader GraphBest Practices for Shader Graph
Best Practices for Shader GraphUnity Technologies
 
Game Programming 07 - Procedural Content Generation
Game Programming 07 - Procedural Content GenerationGame Programming 07 - Procedural Content Generation
Game Programming 07 - Procedural Content GenerationNick Pruehs
 
Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...
Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...
Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...Unity Technologies
 
ECS: Making the Entity Debugger - Unite LA
ECS: Making the Entity Debugger - Unite LAECS: Making the Entity Debugger - Unite LA
ECS: Making the Entity Debugger - Unite LAUnity Technologies
 

Mais procurados (8)

Digital Calipers Software Mitutoyo / Logiciel pour Pied à coulisse Mitutoyo (...
Digital Calipers Software Mitutoyo / Logiciel pour Pied à coulisse Mitutoyo (...Digital Calipers Software Mitutoyo / Logiciel pour Pied à coulisse Mitutoyo (...
Digital Calipers Software Mitutoyo / Logiciel pour Pied à coulisse Mitutoyo (...
 
Smedberg niklas bringing_aaa_graphics
Smedberg niklas bringing_aaa_graphicsSmedberg niklas bringing_aaa_graphics
Smedberg niklas bringing_aaa_graphics
 
Intrinsics: Low-level engine development with Burst - Unite Copenhagen 2019
Intrinsics: Low-level engine development with Burst - Unite Copenhagen 2019 Intrinsics: Low-level engine development with Burst - Unite Copenhagen 2019
Intrinsics: Low-level engine development with Burst - Unite Copenhagen 2019
 
OGDC 2014_Architecting Games in Unity_Mr. Rustum Scammell
OGDC 2014_Architecting Games in Unity_Mr. Rustum ScammellOGDC 2014_Architecting Games in Unity_Mr. Rustum Scammell
OGDC 2014_Architecting Games in Unity_Mr. Rustum Scammell
 
Best Practices for Shader Graph
Best Practices for Shader GraphBest Practices for Shader Graph
Best Practices for Shader Graph
 
Game Programming 07 - Procedural Content Generation
Game Programming 07 - Procedural Content GenerationGame Programming 07 - Procedural Content Generation
Game Programming 07 - Procedural Content Generation
 
Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...
Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...
Developing and optimizing a procedural game: The Elder Scrolls Blades- Unite ...
 
ECS: Making the Entity Debugger - Unite LA
ECS: Making the Entity Debugger - Unite LAECS: Making the Entity Debugger - Unite LA
ECS: Making the Entity Debugger - Unite LA
 

Destaque

Game Development with SDL and Perl
Game Development with SDL and PerlGame Development with SDL and Perl
Game Development with SDL and Perlgarux
 
C language in our world 2015
C language in our world 2015C language in our world 2015
C language in our world 2015Juraj Michálek
 
General Quiz by Quiz pro. co. ,VNIT
General Quiz by Quiz pro. co. ,VNIT  General Quiz by Quiz pro. co. ,VNIT
General Quiz by Quiz pro. co. ,VNIT Kartik Adsule
 
Code Refactoring - Live Coding Demo (JavaDay 2014)
Code Refactoring - Live Coding Demo (JavaDay 2014)Code Refactoring - Live Coding Demo (JavaDay 2014)
Code Refactoring - Live Coding Demo (JavaDay 2014)Peter Kofler
 
TMS - Schedule of Presentations and Reports
TMS - Schedule of Presentations and ReportsTMS - Schedule of Presentations and Reports
TMS - Schedule of Presentations and ReportsMichel Alves
 
Using Git on the Command Line
Using Git on the Command LineUsing Git on the Command Line
Using Git on the Command LineBrian Richards
 
FLTK Summer Course - Part VIII - Eighth Impact
FLTK Summer Course - Part VIII - Eighth ImpactFLTK Summer Course - Part VIII - Eighth Impact
FLTK Summer Course - Part VIII - Eighth ImpactMichel Alves
 
Blisstering drupal module development ppt v1.2
Blisstering drupal module development ppt v1.2Blisstering drupal module development ppt v1.2
Blisstering drupal module development ppt v1.2Anil Sagar
 
Introduction to Git Commands and Concepts
Introduction to Git Commands and ConceptsIntroduction to Git Commands and Concepts
Introduction to Git Commands and ConceptsCarl Brown
 
FLTK Summer Course - Part I - First Impact - Exercises
FLTK Summer Course - Part I - First Impact - ExercisesFLTK Summer Course - Part I - First Impact - Exercises
FLTK Summer Course - Part I - First Impact - ExercisesMichel Alves
 
FLTK Summer Course - Part VI - Sixth Impact - Exercises
FLTK Summer Course - Part VI - Sixth Impact - ExercisesFLTK Summer Course - Part VI - Sixth Impact - Exercises
FLTK Summer Course - Part VI - Sixth Impact - ExercisesMichel Alves
 
Manipulating file in Python
Manipulating file in PythonManipulating file in Python
Manipulating file in Pythonshoukatali500
 
Git hooks For PHP Developers
Git hooks For PHP DevelopersGit hooks For PHP Developers
Git hooks For PHP DevelopersUmut IŞIK
 
Servicios web con Python
Servicios web con PythonServicios web con Python
Servicios web con PythonManuel Pérez
 
FLTK Summer Course - Part II - Second Impact
FLTK Summer Course - Part II - Second ImpactFLTK Summer Course - Part II - Second Impact
FLTK Summer Course - Part II - Second ImpactMichel Alves
 
FLTK Summer Course - Part VII - Seventh Impact
FLTK Summer Course - Part VII  - Seventh ImpactFLTK Summer Course - Part VII  - Seventh Impact
FLTK Summer Course - Part VII - Seventh ImpactMichel Alves
 
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...Alessandro Molina
 

Destaque (20)

Srs format
Srs formatSrs format
Srs format
 
Game Development with SDL and Perl
Game Development with SDL and PerlGame Development with SDL and Perl
Game Development with SDL and Perl
 
Quiz
QuizQuiz
Quiz
 
C language in our world 2015
C language in our world 2015C language in our world 2015
C language in our world 2015
 
General Quiz by Quiz pro. co. ,VNIT
General Quiz by Quiz pro. co. ,VNIT  General Quiz by Quiz pro. co. ,VNIT
General Quiz by Quiz pro. co. ,VNIT
 
Code Refactoring - Live Coding Demo (JavaDay 2014)
Code Refactoring - Live Coding Demo (JavaDay 2014)Code Refactoring - Live Coding Demo (JavaDay 2014)
Code Refactoring - Live Coding Demo (JavaDay 2014)
 
TMS - Schedule of Presentations and Reports
TMS - Schedule of Presentations and ReportsTMS - Schedule of Presentations and Reports
TMS - Schedule of Presentations and Reports
 
Using Git on the Command Line
Using Git on the Command LineUsing Git on the Command Line
Using Git on the Command Line
 
FLTK Summer Course - Part VIII - Eighth Impact
FLTK Summer Course - Part VIII - Eighth ImpactFLTK Summer Course - Part VIII - Eighth Impact
FLTK Summer Course - Part VIII - Eighth Impact
 
Advanced Git
Advanced GitAdvanced Git
Advanced Git
 
Blisstering drupal module development ppt v1.2
Blisstering drupal module development ppt v1.2Blisstering drupal module development ppt v1.2
Blisstering drupal module development ppt v1.2
 
Introduction to Git Commands and Concepts
Introduction to Git Commands and ConceptsIntroduction to Git Commands and Concepts
Introduction to Git Commands and Concepts
 
FLTK Summer Course - Part I - First Impact - Exercises
FLTK Summer Course - Part I - First Impact - ExercisesFLTK Summer Course - Part I - First Impact - Exercises
FLTK Summer Course - Part I - First Impact - Exercises
 
FLTK Summer Course - Part VI - Sixth Impact - Exercises
FLTK Summer Course - Part VI - Sixth Impact - ExercisesFLTK Summer Course - Part VI - Sixth Impact - Exercises
FLTK Summer Course - Part VI - Sixth Impact - Exercises
 
Manipulating file in Python
Manipulating file in PythonManipulating file in Python
Manipulating file in Python
 
Git hooks For PHP Developers
Git hooks For PHP DevelopersGit hooks For PHP Developers
Git hooks For PHP Developers
 
Servicios web con Python
Servicios web con PythonServicios web con Python
Servicios web con Python
 
FLTK Summer Course - Part II - Second Impact
FLTK Summer Course - Part II - Second ImpactFLTK Summer Course - Part II - Second Impact
FLTK Summer Course - Part II - Second Impact
 
FLTK Summer Course - Part VII - Seventh Impact
FLTK Summer Course - Part VII  - Seventh ImpactFLTK Summer Course - Part VII  - Seventh Impact
FLTK Summer Course - Part VII - Seventh Impact
 
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
 

Semelhante a C game programming - SDL

Computer Graphics with OpenGL presentation Slides.pptx
Computer Graphics with OpenGL presentation Slides.pptxComputer Graphics with OpenGL presentation Slides.pptx
Computer Graphics with OpenGL presentation Slides.pptxAnandM62785
 
BSidesDelhi 2018: Headshot - Game Hacking on macOS
BSidesDelhi 2018: Headshot - Game Hacking on macOSBSidesDelhi 2018: Headshot - Game Hacking on macOS
BSidesDelhi 2018: Headshot - Game Hacking on macOSBSides Delhi
 
Unit 2 - Complete (1).pptx
Unit 2 - Complete (1).pptxUnit 2 - Complete (1).pptx
Unit 2 - Complete (1).pptxgogulram2
 
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...Sang Don Kim
 
3 CG_U1_P2_PPT_3 OpenGL.pptx
3 CG_U1_P2_PPT_3 OpenGL.pptx3 CG_U1_P2_PPT_3 OpenGL.pptx
3 CG_U1_P2_PPT_3 OpenGL.pptxssuser255bf1
 
Better Interactive Programs
Better Interactive ProgramsBetter Interactive Programs
Better Interactive ProgramsSyed Zaid Irshad
 
Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1Amr Alaa El Deen
 
Lecture 2: C# Programming for VR application in Unity
Lecture 2: C# Programming for VR application in UnityLecture 2: C# Programming for VR application in Unity
Lecture 2: C# Programming for VR application in UnityKobkrit Viriyayudhakorn
 
Micro Keyboarding
Micro KeyboardingMicro Keyboarding
Micro KeyboardingMi L
 
Mini Computer Project
Mini Computer ProjectMini Computer Project
Mini Computer ProjectMalikWaleed19
 
Computer Graphics Project Report on Sinking Ship using OpenGL
Computer Graphics Project Report on Sinking Ship using OpenGL Computer Graphics Project Report on Sinking Ship using OpenGL
Computer Graphics Project Report on Sinking Ship using OpenGL Sharath Raj
 
Computer Programming In C.pptx
Computer Programming In C.pptxComputer Programming In C.pptx
Computer Programming In C.pptxchouguleamruta24
 
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...Lviv Startup Club
 

Semelhante a C game programming - SDL (20)

Computer Graphics with OpenGL presentation Slides.pptx
Computer Graphics with OpenGL presentation Slides.pptxComputer Graphics with OpenGL presentation Slides.pptx
Computer Graphics with OpenGL presentation Slides.pptx
 
Soc research
Soc researchSoc research
Soc research
 
Hill ch2ed3
Hill ch2ed3Hill ch2ed3
Hill ch2ed3
 
BSidesDelhi 2018: Headshot - Game Hacking on macOS
BSidesDelhi 2018: Headshot - Game Hacking on macOSBSidesDelhi 2018: Headshot - Game Hacking on macOS
BSidesDelhi 2018: Headshot - Game Hacking on macOS
 
september11.ppt
september11.pptseptember11.ppt
september11.ppt
 
Input and Interaction
Input and InteractionInput and Interaction
Input and Interaction
 
Unit 2 - Complete (1).pptx
Unit 2 - Complete (1).pptxUnit 2 - Complete (1).pptx
Unit 2 - Complete (1).pptx
 
2D graphics
2D graphics2D graphics
2D graphics
 
SDAccel Design Contest: Xilinx SDAccel
SDAccel Design Contest: Xilinx SDAccel SDAccel Design Contest: Xilinx SDAccel
SDAccel Design Contest: Xilinx SDAccel
 
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
[Td 2015] what is new in visual c++ 2015 and future directions(ulzii luvsanba...
 
3 CG_U1_P2_PPT_3 OpenGL.pptx
3 CG_U1_P2_PPT_3 OpenGL.pptx3 CG_U1_P2_PPT_3 OpenGL.pptx
3 CG_U1_P2_PPT_3 OpenGL.pptx
 
Better Interactive Programs
Better Interactive ProgramsBetter Interactive Programs
Better Interactive Programs
 
Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1Begin with c++ Fekra Course #1
Begin with c++ Fekra Course #1
 
Lecture 2: C# Programming for VR application in Unity
Lecture 2: C# Programming for VR application in UnityLecture 2: C# Programming for VR application in Unity
Lecture 2: C# Programming for VR application in Unity
 
18csl67 vtu lab manual
18csl67 vtu lab manual18csl67 vtu lab manual
18csl67 vtu lab manual
 
Micro Keyboarding
Micro KeyboardingMicro Keyboarding
Micro Keyboarding
 
Mini Computer Project
Mini Computer ProjectMini Computer Project
Mini Computer Project
 
Computer Graphics Project Report on Sinking Ship using OpenGL
Computer Graphics Project Report on Sinking Ship using OpenGL Computer Graphics Project Report on Sinking Ship using OpenGL
Computer Graphics Project Report on Sinking Ship using OpenGL
 
Computer Programming In C.pptx
Computer Programming In C.pptxComputer Programming In C.pptx
Computer Programming In C.pptx
 
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...
Данило Ульянич “C89 OpenGL for ARM microcontrollers on Cortex-M. Basic functi...
 

Mais de Wingston

OpenCV @ Droidcon 2012
OpenCV @ Droidcon 2012OpenCV @ Droidcon 2012
OpenCV @ Droidcon 2012Wingston
 
05 content providers - Android
05   content providers - Android05   content providers - Android
05 content providers - AndroidWingston
 
04 activities - Android
04   activities - Android04   activities - Android
04 activities - AndroidWingston
 
03 layouts & ui design - Android
03   layouts & ui design - Android03   layouts & ui design - Android
03 layouts & ui design - AndroidWingston
 
02 hello world - Android
02   hello world - Android02   hello world - Android
02 hello world - AndroidWingston
 
01 introduction & setup - Android
01   introduction & setup - Android01   introduction & setup - Android
01 introduction & setup - AndroidWingston
 
OpenCV with android
OpenCV with androidOpenCV with android
OpenCV with androidWingston
 
C programming - Pointers
C programming - PointersC programming - Pointers
C programming - PointersWingston
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02Wingston
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01Wingston
 
Linux – an introduction
Linux – an introductionLinux – an introduction
Linux – an introductionWingston
 
Embedded linux
Embedded linuxEmbedded linux
Embedded linuxWingston
 
04 Arduino Peripheral Interfacing
04   Arduino Peripheral Interfacing04   Arduino Peripheral Interfacing
04 Arduino Peripheral InterfacingWingston
 
03 analogue anrduino fundamentals
03   analogue anrduino fundamentals03   analogue anrduino fundamentals
03 analogue anrduino fundamentalsWingston
 
02 General Purpose Input - Output on the Arduino
02   General Purpose Input -  Output on the Arduino02   General Purpose Input -  Output on the Arduino
02 General Purpose Input - Output on the ArduinoWingston
 
Introduction to the Arduino
Introduction to the ArduinoIntroduction to the Arduino
Introduction to the ArduinoWingston
 
4.content mgmt
4.content mgmt4.content mgmt
4.content mgmtWingston
 
8 Web Practices for Drupal
8  Web Practices for Drupal8  Web Practices for Drupal
8 Web Practices for DrupalWingston
 
7 Theming in Drupal
7 Theming in Drupal7 Theming in Drupal
7 Theming in DrupalWingston
 
6 Special Howtos for Drupal
6 Special Howtos for Drupal6 Special Howtos for Drupal
6 Special Howtos for DrupalWingston
 

Mais de Wingston (20)

OpenCV @ Droidcon 2012
OpenCV @ Droidcon 2012OpenCV @ Droidcon 2012
OpenCV @ Droidcon 2012
 
05 content providers - Android
05   content providers - Android05   content providers - Android
05 content providers - Android
 
04 activities - Android
04   activities - Android04   activities - Android
04 activities - Android
 
03 layouts & ui design - Android
03   layouts & ui design - Android03   layouts & ui design - Android
03 layouts & ui design - Android
 
02 hello world - Android
02   hello world - Android02   hello world - Android
02 hello world - Android
 
01 introduction & setup - Android
01   introduction & setup - Android01   introduction & setup - Android
01 introduction & setup - Android
 
OpenCV with android
OpenCV with androidOpenCV with android
OpenCV with android
 
C programming - Pointers
C programming - PointersC programming - Pointers
C programming - Pointers
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01
 
Linux – an introduction
Linux – an introductionLinux – an introduction
Linux – an introduction
 
Embedded linux
Embedded linuxEmbedded linux
Embedded linux
 
04 Arduino Peripheral Interfacing
04   Arduino Peripheral Interfacing04   Arduino Peripheral Interfacing
04 Arduino Peripheral Interfacing
 
03 analogue anrduino fundamentals
03   analogue anrduino fundamentals03   analogue anrduino fundamentals
03 analogue anrduino fundamentals
 
02 General Purpose Input - Output on the Arduino
02   General Purpose Input -  Output on the Arduino02   General Purpose Input -  Output on the Arduino
02 General Purpose Input - Output on the Arduino
 
Introduction to the Arduino
Introduction to the ArduinoIntroduction to the Arduino
Introduction to the Arduino
 
4.content mgmt
4.content mgmt4.content mgmt
4.content mgmt
 
8 Web Practices for Drupal
8  Web Practices for Drupal8  Web Practices for Drupal
8 Web Practices for Drupal
 
7 Theming in Drupal
7 Theming in Drupal7 Theming in Drupal
7 Theming in Drupal
 
6 Special Howtos for Drupal
6 Special Howtos for Drupal6 Special Howtos for Drupal
6 Special Howtos for Drupal
 

Último

SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docxPoojaSen20
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 

Último (20)

SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 

C game programming - SDL

  • 1. Workshop India Wilson Wingston Sharon wingston.sharon@gmail.com
  • 2. • Why? • Learning is not just about marks. • Its about building something. • You cannot learn C in 2 weeks. • You can only learn C by writing programs. • Without writing programs OF YOUR OWN and ON YOUR OWN. • We can only guide you – you have to put in some effort.
  • 3. • In todays session file, you will see some files like this. • Install all of them. • Now see the Dev-Cpp folder? • Copy everything in that to your Dev-Cpp folder (C:/Dev-Cpp). Copy the folders *inside* this one to the one in you C drive.
  • 4. • In the /game folder, you will see a folder called “SDL_Template(copy this folder)” • Copy this folder to your own folder in your Exercise drive. • After copying, rename the Folder to something like “SDL_1” • In the folder you will see sdl.dev, you will have to open this file. • You can open dev-cpp normally (if you need to enter passwrd) and then use the file>>open project or file>> to open this sdl.dev project file in your folder.
  • 5.
  • 6. Code For the File that is currently Open in the tab Files that Belong to the Current project
  • 7. -lmingw32 -lSDLmain -lSDL -lSGE • The above parameters • Must be present in • The linker tab • Say OK • Press Ctr-F11to build • And then F9 to run the program.
  • 8. • If it doesn’t work. • Recheck your project options tab • See if you installed everything in the folder? • Does it complain about missing dll? See if all files in the project folder conform to the folder image provided 3 slides before.
  • 9.
  • 10.
  • 11. • Help your friends set it up • Learning is a collaborative process. Se what mistakes your friends have made. Check them. Help them. • It makes you a better programmer by exposing you to the mistakes that are possible in C. • It’ll help you avoid silly mistakes if you help others by correcting them.
  • 12. • main.cpp • this file contains the main() function • This is called the entry point of the program. • grapics.h • This file contains some structures and function that I wrote. • You might or might not use them as per requirement of the program. • The thing is well commented and documented.
  • 13. The game itself Here the logic that specifies how the game behaves to the user Game Engine SDL just gives as access to graphics card. SGE is our game engine. SDL Simple Direct Media Layer Provides a layer to access graphics card Graphics Card on computer Harware support for drawing stuff onto the screen
  • 14. • make sure you have copied the Dev-Cpp folder i gave you onto your Dev-Cpp installation. • That links up all sort of libraries for SDL to function • Otherwise you might get an error about missing SDL.h
  • 15. • This must be a global object. • Whatever we want SDL to display has to be written to this screen. •
  • 16.
  • 17.
  • 18.
  • 19. screen = SDL_SetVideoMode(MX, MY, 32, SDL_HWSURFACE|SDL_DOUBLEBUF); The above line is important • If you change MX and MY (in the beginning of graphics.h) you change the size of screen • If you add, SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCR EEN • To the last argument of the function, the program goes into full screen mode!
  • 20.
  • 21. Update Draw graphics game models elements Undraw Get input what is from not user required Check Game logic
  • 22. • Events are things that happen outside the game engine that the game must be aware of. • Eg: Keypresses • SDL_pollevent(&event) • Returns NULL when there are no events left to handle, so then that while loops terminates and the game continues. • The event object contains details about what happened and the rest of the code handles it!
  • 23.
  • 24.
  • 25.
  • 26. • Don’t touch the init() function. • To add user interaction, code has to go in which function? •? • To add some more drawings, code has to go where? •?
  • 27. • Don’t touch the init() function. • To add user interaction, code has to go in which function? • The event managing while loop in the main() function. • To add some more drawings, code has to go where? • The render() function. • Or another function between init() and the eventhandler()
  • 28. • Here are codes for most functions and all • The main.cpp and graphics.h need to *share* the same global variable screen. • This is done by the keyword extern; this specifies that this is not a different variable, but a same one that is declared in another file.
  • 29.
  • 30. • The function _putpixel draws a point at the MX/2 and MY/2 position. • Modify the code to draw a horizontal line. • ______________________ __ • Across the screen.
  • 31.
  • 32. • That for loop starts from i =0 • Till MX in steps of 1 • And the putpixel function draws a pixel at every point. • Can you change it to vertical?
  • 33. • What to do when considering to move a point. • What all is required to define a point? • X • Y • Colour. • Keyboard handling is done on the event loop. Position Keyboard is Screen is Point is press is updated cleared drawn checked for the point
  • 34. • Keyboard presses is update as a struct in graphics.h called move. • Each point will have an associated move variable. • If kLR is -1/1 the point will have to move Left/Right. • And so on.
  • 35.
  • 36. • It is the while(SDL_Pollevent(&event)) • For every loop, the event structure will have the details of what happens, we want to see onky keyboard events. • These are events of event.type == • SDL_KEYDOWN • SDL_KEYUP • Etc.. • Using a switch case we can write what code to happen when each event is fired.
  • 37.
  • 38. • Code comes at the level of the last one. • Case SDL_KEYUP: • What to dowhen the key has been released? Set the move variable m1 kUD or KLR to 0. Signifying no movement.
  • 39. • cls(0) fills the screen with black; • Updates point p1 with m1 for which direction to move the point • Putpixel to draw the point.
  • 40. • Render() runs infinitely, • Checks if point p1 has moved by using the m1variable • If moved, update the point’s x & y • Then clear the screen and draws the point. • When keyboard is pressed • The eventloop() in main now enters the loop • A switch case is done on the event type to determine if it’s a keypress or a release. • When the keypress is detected the m1 variable is adjusted • When the keyrelease is detected the m1 variable is set to 0 so not movement happens. • Compile 2.Movment folder code. • Again: follow dev-cpp rules for opening projects and compiling them.
  • 41. • We have the point p1 that we can move around with the keyboard. • Lets draw a line between p1 and MX/2, MY/2. • That is a line from p1 to the center. • Line function: • sge_Line(*screen,x1,y1,x2,y2,color); • sge_AALine(…) is line with anti-aliasing
  • 42.
  • 43.
  • 44. I want the other points to move by using the • W - UP • S - DOWN • A - LEFT • D – Right • Point 2 is handled by m2. • Using switch case do the update of m2 • And update p2 with m2 • I want the line to move by both points. • One point moves by arrow keys • The other moves by wasd keys.
  • 45. • The SGE SDL library provides some basic primitives for drawing. • Drawing in this case is mathematical drawing. • The basic shapes that are provided are: • Points • Lines • Circle • Rectangle • Ellipse • Polygons
  • 46.
  • 47.
  • 48. • Try to think of creative shapes and things that you can draw with these functions. • You can also make interesting mathematical loop shapes. • If you don’t do the cls(0) whatever the loop draws wont be erased in the next iteration!. • Try and do some more hoola!
  • 49. • SDL printing things on the screen means you need a font! • The font file is *something*.ttf • These sort of fonts can be opened by SDL and drawn onto the screen. • First we need to make a global font * variable.
  • 50. • We need to initialise the font • We have cour.ttf right now. • sge_TTF_Init() initialises the font engine. • sge_TTF_openFont(font, size) returns the font object that should be global pointer of the same,
  • 51.
  • 52.
  • 53. • Get text to appear one by one on the screen. • Get text to scroll around the screen. • Can you get keyboard input using the event loop ? • Do only numbers
  • 54. • First we create a struct circle. (same like point except with radius too).
  • 55.
  • 56.
  • 57. • Same KEYUP/KEYDOW N movement code to move m1 and m2. • Adjust this code and get the second circle moving too.
  • 58. • Instead of moving the second circle use the below random functions • int sge_Random(int min, int max) Returns a random integer between (and including) min and max. void sge_Randomize(void) Seed the random number generator with a number from the system clock. Should be called once before the first use of sge_Random.
  • 59. • Move the second circle randomly. • When the first circle is touching the second circle, a counter should start in the corner. • As long as the two circles are touching, counter must keep incrementing and the second circle keeps moves faster and faster. • When the first circle leaves, the counter goes to 0 and stays there.