3D Game Programming 2D game
description
Transcript of 3D Game Programming 2D game
![Page 1: 3D Game Programming 2D game](https://reader035.fdocuments.net/reader035/viewer/2022081418/56814607550346895db3152c/html5/thumbnails/1.jpg)
3D Game Programming2D game
3D Game Programming2D game
Ming-Te ChiDepartment of Computer Science,
National Chengchi University
![Page 2: 3D Game Programming 2D game](https://reader035.fdocuments.net/reader035/viewer/2022081418/56814607550346895db3152c/html5/thumbnails/2.jpg)
OutlineOutline
2D game history
Simple 2D game example
![Page 3: 3D Game Programming 2D game](https://reader035.fdocuments.net/reader035/viewer/2022081418/56814607550346895db3152c/html5/thumbnails/3.jpg)
2D VIDEO GAME HISTORY
2D VIDEO GAME HISTORY
![Page 4: 3D Game Programming 2D game](https://reader035.fdocuments.net/reader035/viewer/2022081418/56814607550346895db3152c/html5/thumbnails/4.jpg)
The first video gameThe first video game
Tennis for Two was a game developed in 1958 on an analog computer, which simulates a game of tennis or ping pong on an oscilloscope.
![Page 5: 3D Game Programming 2D game](https://reader035.fdocuments.net/reader035/viewer/2022081418/56814607550346895db3152c/html5/thumbnails/5.jpg)
2D GAME2D GAME
PONG 1972. – earliest video game
![Page 6: 3D Game Programming 2D game](https://reader035.fdocuments.net/reader035/viewer/2022081418/56814607550346895db3152c/html5/thumbnails/6.jpg)
Snake (1970s)Snake (1970s)
Control a snake to move, and avoid hitting to wall or its growing tail.
![Page 7: 3D Game Programming 2D game](https://reader035.fdocuments.net/reader035/viewer/2022081418/56814607550346895db3152c/html5/thumbnails/7.jpg)
Galaxian (1979 by Namco)Galaxian (1979 by Namco)
![Page 8: 3D Game Programming 2D game](https://reader035.fdocuments.net/reader035/viewer/2022081418/56814607550346895db3152c/html5/thumbnails/8.jpg)
Pac Man 1980 by NamcoPac Man 1980 by Namco
![Page 9: 3D Game Programming 2D game](https://reader035.fdocuments.net/reader035/viewer/2022081418/56814607550346895db3152c/html5/thumbnails/9.jpg)
Game & Watch 1980Game & Watch 1980
Game & Watch is a line of handheld electronic games produced by Nintendo from 1980 to 1991.
Ball: the first game & watch game
![Page 10: 3D Game Programming 2D game](https://reader035.fdocuments.net/reader035/viewer/2022081418/56814607550346895db3152c/html5/thumbnails/10.jpg)
Family Computer(FAMICOM)Family Computer(FAMICOM)
Mario series. By Nintendo
Super Mario Bros.1985
Mario Bros.1983
Donkey Kong1981
![Page 11: 3D Game Programming 2D game](https://reader035.fdocuments.net/reader035/viewer/2022081418/56814607550346895db3152c/html5/thumbnails/11.jpg)
TetrisTetrisDesign by 阿列克謝 ·帕基特諾夫 ( Алексей Леонидович Пажитнов ) in 1984Puzzle game
![Page 12: 3D Game Programming 2D game](https://reader035.fdocuments.net/reader035/viewer/2022081418/56814607550346895db3152c/html5/thumbnails/12.jpg)
Super Mario World. 1990Super Mario World. 1990
Rich color, Parallax scrolling, zoom and rotate sprite.
![Page 13: 3D Game Programming 2D game](https://reader035.fdocuments.net/reader035/viewer/2022081418/56814607550346895db3152c/html5/thumbnails/13.jpg)
Doom 1993Doom 1993
• A landmark 1993 first-person shooter (FPS)video game by id Software.
![Page 14: 3D Game Programming 2D game](https://reader035.fdocuments.net/reader035/viewer/2022081418/56814607550346895db3152c/html5/thumbnails/14.jpg)
3D graphics3D graphics
![Page 15: 3D Game Programming 2D game](https://reader035.fdocuments.net/reader035/viewer/2022081418/56814607550346895db3152c/html5/thumbnails/15.jpg)
Social gameSocial game
Happy Farm
![Page 16: 3D Game Programming 2D game](https://reader035.fdocuments.net/reader035/viewer/2022081418/56814607550346895db3152c/html5/thumbnails/16.jpg)
Mobile phone Mobile phone
Angry Birds by Rovioflight control by Firemint
![Page 17: 3D Game Programming 2D game](https://reader035.fdocuments.net/reader035/viewer/2022081418/56814607550346895db3152c/html5/thumbnails/17.jpg)
2D GAME2D GAME
![Page 18: 3D Game Programming 2D game](https://reader035.fdocuments.net/reader035/viewer/2022081418/56814607550346895db3152c/html5/thumbnails/18.jpg)
What is a Game?What is a Game?
Games are an exercise of voluntary control systems, in which there is a contest between powers, confined by rules in order to produce a disequilibrial outcome.
– Elliot Avedon and Brian Sutton-Smith
![Page 19: 3D Game Programming 2D game](https://reader035.fdocuments.net/reader035/viewer/2022081418/56814607550346895db3152c/html5/thumbnails/19.jpg)
Game architectureGame architecture
Game Loop
init()
update(delta)
paint(delta)
I/O System
Keyboard, mouse
audio
storage
Asset Management
loading
saving
caching
![Page 20: 3D Game Programming 2D game](https://reader035.fdocuments.net/reader035/viewer/2022081418/56814607550346895db3152c/html5/thumbnails/20.jpg)
Glut and game loopGlut and game loopGame Loop
init()
update(delta)
display(delta)
I/O System
Keyboard, mouse
audio
storage
main() { initglut() init(); RegisterCallback() update(0); glutMainLoop()}
keyboard(key) { switch(key) { case ’j’: jump() break; }}
update(int i){ //update state glutTimerFunc(delta, update, ++i); glutPostRedisplay();}
display() { //draw something}
![Page 21: 3D Game Programming 2D game](https://reader035.fdocuments.net/reader035/viewer/2022081418/56814607550346895db3152c/html5/thumbnails/21.jpg)
A simple exampleA simple example
A character has three states: stand, walk, and jumpUse “left” and “right”key to move
the characterWhen press “j”, the character will
jump, and the score will increase by 1.
![Page 22: 3D Game Programming 2D game](https://reader035.fdocuments.net/reader035/viewer/2022081418/56814607550346895db3152c/html5/thumbnails/22.jpg)
StateState
Position, direction, Gamesocre
Stand Walk
Jump
Press“left” or “right”
Press “j” to trigger jump()
Press “j” to trigger jump()
![Page 23: 3D Game Programming 2D game](https://reader035.fdocuments.net/reader035/viewer/2022081418/56814607550346895db3152c/html5/thumbnails/23.jpg)
State and ImageState and Image
Stand Walk
Jump
![Page 24: 3D Game Programming 2D game](https://reader035.fdocuments.net/reader035/viewer/2022081418/56814607550346895db3152c/html5/thumbnails/24.jpg)
Change stateChange state
void SpecialKeys(int key, int x, int y){
switch(key) {case GLUT_KEY_LEFT:
picX -= 5;if (whichPic==0) whichPic=1;else whichPic=0;DirectionState=1;break;
}
![Page 25: 3D Game Programming 2D game](https://reader035.fdocuments.net/reader035/viewer/2022081418/56814607550346895db3152c/html5/thumbnails/25.jpg)
Draw image with stateDraw image with stateif(DirectionState==0) {
glPixelZoom(1.0, 1.0); glRasterPos2i(picX, picY);
pic[whichPic].blend();}else {
glPixelZoom(-1.0, 1.0);glRasterPos2i(picX+pic[whichPic].nCols, picY);pic[whichPic].blend();glPixelZoom(1.0, 1.0);
}
In display()
![Page 26: 3D Game Programming 2D game](https://reader035.fdocuments.net/reader035/viewer/2022081418/56814607550346895db3152c/html5/thumbnails/26.jpg)
Font renderingFont rendering
//Fontchar mss[30];sprintf(mss, "Score %d", Gamescore);
glColor3f(1.0, 0.0, 0.0); //set font color glRasterPos2i(10, 550); //set font start position
void * font = GLUT_BITMAP_9_BY_15;for(int i=0; i<strlen(mss); i++) {
glutBitmapCharacter(font, mss[i]);}
![Page 27: 3D Game Programming 2D game](https://reader035.fdocuments.net/reader035/viewer/2022081418/56814607550346895db3152c/html5/thumbnails/27.jpg)
Press J to Trigger jump()Press J to Trigger jump()void myKeys(unsigned char key, int x, int y){
switch(key){
case ‘J':if(jumpState==0) {
jumpState=1;Gamescore++;jump(0);
}break;
}glutPostRedisplay();
}
![Page 28: 3D Game Programming 2D game](https://reader035.fdocuments.net/reader035/viewer/2022081418/56814607550346895db3152c/html5/thumbnails/28.jpg)
Jump motionJump motion
void jump(int i){ whichPic=2; //switch state
if (i<5) picY+=4; else picY-=4;
if(i<=10) {i++;glutTimerFunc( 100, jump, i);
}else {whichPic=0;jumpState=0;
}
glutPostRedisplay();}
i
picY
0 5
![Page 29: 3D Game Programming 2D game](https://reader035.fdocuments.net/reader035/viewer/2022081418/56814607550346895db3152c/html5/thumbnails/29.jpg)
Basic elementsBasic elements
Elements Tetrads– Jesse Schell
Mechanics Story
Aesthetics
Technology
![Page 30: 3D Game Programming 2D game](https://reader035.fdocuments.net/reader035/viewer/2022081418/56814607550346895db3152c/html5/thumbnails/30.jpg)
Mechanics– the procedures and rules
Story– the sequence of events that unfolds in
your game
Aesthetics– how your game looks, sounds, tastes,
and feels.
Technology– any materials and interactions that
make your game possible
![Page 31: 3D Game Programming 2D game](https://reader035.fdocuments.net/reader035/viewer/2022081418/56814607550346895db3152c/html5/thumbnails/31.jpg)
Art challenges technology; technology inspires the art.
- John Lasseter