Pa C aml Pac-Man Game Programming Language Chun-Kang Chen/Hui-Hsiang Kuo/Wenxin Zhu/Shuwei Cao
Overview � PaCaml = Pac-Man + Ocaml � A game programming language facilitating the design of elements in PAC-MAN scene � Simple – people with little experience in programming can do the work / a good inspiration for children � Interesting – be the God in the world of Pac-Man
Motivation � Pac-Man: an arcade game immensely popular since its original release � Pac-Man has made a great impact on a generation of people and is still appealing to the public for today � Recall ourselves of the best memory in childhood
Game-specified Types Name Field Value Map … Add contain by build-in functions Point x Integer y Integer Player p_point Point Item type _GHOST _BARRIER _BARRIER _GIFT i_point Point level GHOST: _EASY, _NORMAL,_HARD GIFT: _GIFT_SPEEDUP _GIFT_SLOWDOWN _GIFT_KILLER _GIFT_SCORE duration Integer
Built-in Functions Return Function Name bool setPlayer(player pacman ) bool addGhost ( item ghost) bool addBarrier ( item barrier) bool bool addGift ( item gift ) addGift ( item gift ) int getMapWidth () int getMapHeight () string getMapItemName (point p) bool isPointAvailable ( point p) bool getAvailablePoint ()
Tutorial Place the player item createItem( int type, int x, int y) // initiate a pacman { pacman.p_point = getAvailablePoint(); item i; Place the setPlayer(pacman); point p; // initiate a ghost ghost Type: item p.x = x; ghost1 = createItem(_GHOST, 5, 5); p.y = y; addGhost(ghost1); i.i_type = type; // initiate a barrier barrier1 = createItem(_BARRIER, 8 , 8); i.i_point = p; Place the Place the main main addBarrier(barrier1); addBarrier(barrier1); return i; return i; barrier function // initiate a gift } gift1 = createItem(_GIFT, 8 , 9 ); void main() addGift(gift1); { Place the gift play(); player pacman; } item ghost1; item barrier1; item gift1; Play the Type: player game
Tutorial Functions Assignment print(b); int plus( int a, int b ) void main() print(c); Loops { { print(p.x); void main() return a + b; Logic print( 1 != 2 ); int a; print(p.y); { } Resursive void main() print( 1 != 1 ); int b; int i; int minus( int a, int b) int fib( int x ) { print(“less”); int c; //T esting additional for( i = 0; i < 10; i++) Arithmetic print("Divide"); { { print(“NOT”); print( 1 < 2 ); point p; assignment operators { Functionality print(p1/p2); return a - b; if (x < 2) print( !(1==1) ); print( 2 < 1 ); a = 1; print(a += 1); print(i); void main() //T est integer } { print( !(1==2) ); print(“LessEqual”); print(a++); //++ is } { arithmetic void main() Condition return 1; print( 1 <= 2 ); //Assigning variables equivalent to x += 1; } } //T //T est point est point print("Integer"); print("Integer"); { { void main() void main() } } print(“AND”); print(“AND”); print( 1 <= 1 ); print( 1 <= 1 ); print(a); print(a); print(a -= 1); print(a -= 1); arithmetic print( 1 + 5 ); print(plus( 1, 2 )); { else print( (1==1) && (1==1) ); // ( true && print( 2 <= 1 ); print(b=a); print(a--); //-- is /* T est the while statement. */ point p1; print( 5 - 2 ); print(minus( 1, 2 )); { if(1) true) print(“Greater”); equivalent to x -= 1; point p2; print( 4 * 2 ); } { return fib(x-1) + fib(x-2); print( (1==1) && (1==2) ); // ( true && print( 1 > 2 ); //Assigning members print(a *= 10); void main() p1.x = 4; print( 1 / 2 ); } print( 0 ); false) print( 2 > 1 ); p.x = 6; print(a /= 2); { p1.y = 3; print( 5 % 3 ); } } print( (1==2) && (1==1) ); // ( false && print(“GreaterEqual”); p.y = 2; } int i; p2.x = 1; void main() true) print( 1 >= 2 ); print(p.x); i = 0; p2.y = 2; //Order of { if(0) print( (1==2) && (1==2) ); // ( false && print( 1 >= 1 ); print(p.y); while( i < 10 ) operations with print(fib(0)); { false) print( 2 >= 1 ); { print("Plus"); integer arithmetic print(fib(1)); print( 1 ); print(“OR”); //Successive assignment print(i); print(p1+p2); print( 1 + 2 * 3 + print(fib(2)); } print( (1==1) || (1==1) ); // ( true || true) print(“Order”); print(a = b = c = p.x = p.y i++; print("Minus"); 4 ); print(fib(3)); else print( (1==1) || (1==2) ); // ( true || false) print( !(1==1) || (1==1) ); = 13); } print(p1-p2); print( ( 1 + 2 ) * print(fib(4)); { print( (1==2) || (1==1) ); // ( false || true) print( !( (1==1) || (1==1) ) ); print(a); } ( 3 + 4 ) ); print(fib(5)); print( 2 ); print( (1==2) || (1==2) ); // ( false || false) } print("Multiply"); } } } print(p1*p2); } print(“NotEqual”);
Implementation Scanner example.pacaml scanner.ml /* Pacaml */ void main() Tokens { player pacman; item ghost1; Parser item barrier1; parser.mly item gift1; pacman.p_point = getAvailablePoint(); setPlayer(pacman); setPlayer(pacman); AST . . . Interpreter play(); } interpret.ml Ocaml objects Graphics Interface game.ml
Lessons Learned � Start early, otherwise you will stay up late � A good plan is a half success � Ocaml is hard to get familiar with, so practice makes � Ocaml is hard to get familiar with, so practice makes perfect � Debug is not easy. It creates more when you fix some. � More testing, less errors
Demo Time
Recommend
More recommend