makergame
play

MakerGame Game Programming Language Outline Motivation Features - PowerPoint PPT Presentation

Cindy Wang Steven Shao Yuncheng Jiang MakerGame Game Programming Language Outline Motivation Features Runtime Architecture & Tests Demo Motivation Game Maker C/C++ Game asset management A real programming language


  1. Cindy Wang Steven Shao Yuncheng Jiang MakerGame Game Programming Language

  2. Outline ● Motivation ● Features ● Runtime ● Architecture & Tests ● Demo

  3. Motivation Game Maker C/C++ Game asset management A real programming language ● ● ● Graphics, sounds, input built in ● Arbitrary data structures - arrays Entity resource handling Object & Library encapsulation - ● ● ● Execution flow following object methods, namespaces lifetimes Fast - a blank slate ●

  4. Motivation ● GameMaker for programmers ● Gems from both worlds ○ General collections ○ Objects & inheritance ○ Event-driven ○ Standard library & types for games

  5. Features ● C with "objects" ● Entity life & event handling ● External linking & libraries

  6. C with Objects - Types & Functions int x = 3 + 5; float pi = 3.14; bool answer = true; int table[2][3] = [[1,2,3],[4,5,6]]; string file = "player.png"; sprite p = std::spr::load(file); sound q = std::snd::load("bonk.ogg"); int square(int x) { return x * x; } int sum(int x[2]) { return x[0] + x[1]; }

  7. C with Objects - Control Flow if (x < 100) x += 3; else { x = 100; hit_end = true; } while (!settled) { moveDown(); } { int x = 3; } for (int i = 0; i < n; ++i) { sum += i; if (tooHigh(sum)) break; }

  8. C with Objects - Objects Definition Manipulation object Player { void doStuff(Enemy e) { object o = none ; int x; int y; ... int getHealth() { ... } Player p = create Player(...); ... object m = p; int y = p.getHealth(); event create (...) { ... } event step { ... } p.x = 3; event draw { ... } if (p == o) { ... } event destroy { ... } } destroy e; }

  9. C with Objects - Inheritance Definition Inheritance object Enemy { object Missile : Enemy { int health; sprite s; event create() { bool touchingPlayer() { ... } super(100); event create (int hp) { ... } s = spr::load("missile.png"); event step { ... } } event draw { ... } event destroy { ... } void explode() { ... } } event destroy() { if (touchingPlayer()) explode(); super(); } }

  10. C with Objects - Modules Nested Namespaces Files & Scope namespace math { // from MAKERGAME_PATH int square(int x) { ... } namespace math = open "math.mg"; extern float sin(float x); namespace spr = open "spr.mg"; } using math; Access Levels ... { ... namespace spr { sprite s = spr::load(...); private namespace p { int x = pi; extern sprite load_sprite(...); float y = sin(5); } ... sprite load(...) { ... } } } ... { spr::p:: load_sprite(...); }

  11. Entity Life & Event Handling Key Operation: Iteration Examples foreach (Enemy e) { void destroyAllButMe(object m) { foreach (object o) { if (colliding(e, this)) { if (o != m) destroy o; --health; } destroy e; } } bool isAlive(object m) { } foreach (object o) if (o == m) return true; return false; }

  12. global_create() create main global_step() foreach (object o) game::end(); "step o;" timeout after 100 loop break noop steps global_draw() foreach (object o) "draw o;"

  13. Life & Event Handling: Runtime global_create() global_step(); end_game(); window.display(); cleanup(); window.clear(); sleep(); global_draw();

  14. Life & Event Handling: Runtime Accessing from MakerGame Sample functions: void printb(bool b) extern sound load_sound(...); void print(int x) ... { sf::Sound *load_sound(...) sound s = load_sound(...); sf::Sprite *load_image(...) } void draw_sprite(sf::Sprite *, ...) void play_sound(sf::Sound *, ...) (extern definitions in std.mg) ... bool key_pressed(int code) { ... } ... void set_window_size(...) void set_window_clear(...) void end_game()

  15. Life & Event Handling: Objects The universal Example parent Anatomy of an enemy object vtable step destroy object draw delete vptr child L node R object parent id vptr L node R L node R L node R members id health x y

  16. Life & Event Handling: Objects enemy player enemy object object object vptr vptr vptr L head R L node R L node R L node R id id id enemy head (player node) L R L node R L node R ... health ... health x y x y

  17. Full Sample Program object Player { sprite spr; int x; int y; event create { spr = spr::load("res/player.png"); x = 350; y = 500; } event step { if (key::is_down(key::Left)) x -= 5; if (key::is_down(key::Right)) x += 5; } event draw { spr::render(spr, x, y); } } object main { event create { create Player; } }

  18. Compiler Architecture Scanner standard input AST contains: Parser functions objects variables namespaces SAST: Semant namespaces resolved type annotations game.ll: global_create, Codegen step, draw, etc. libmakergame.cpp game.s LLC gcc libmakergame.a linker game.exe

  19. Testing: The tests ● Unit tests - language features ○ 410 tests ● Games - runtime, stress testing ○ Egg drop ○ Tetris

  20. Testing: Compiler Architecture Scanner standard input AST contains: Parser functions objects variables namespaces SAST: Semant namespaces resolved type annotations game.ll: global_create, Codegen step, draw, etc. libtestergame.cpp game.s LLC gcc libtestergame.a linker game.exe

  21. Testing: Unit Test Framework create main foreach (object o) game::end(); "step o;" window.display(); cleanup(); window.clear(); sleep(); foreach (object o) "draw o;"

  22. Testing: Unit Test Framework create main foreach (object o) game::end(); "step o;" fail after 100 loop break noop steps (timeout) foreach (object o) "draw o;"

  23. Testing: Unit Tests // basic features: arrays // complex game loop cases object parent { void detonate() { destroy this; } } int make_ten_of[10](int x) { object child : parent { } int ret[10]; object main { int i; int j; for (i = 0; i < 10; ++i) event create { j = 0; } ret[i] = x; event step { return ret; for (int i = 0; i < 10; ++i) create child; } for (int i = 0; i < 10; ++i) create parent; int i = 0; object main { foreach (child c) c.detonate(); event create { foreach (parent c) ++i; int i = 3; std::print::i(i); int j[10] = make_ten_of(5); ++j; std::print::i(j[i]); if (j >= 6) std::game::end(); std::game::end(); } } } }

  24. Testing: Demos

  25. Thank you! Questions?

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend