Skip to main content

Introduction to the Game Engine — Meet the single window.OyunMotoru interface. Learn the 2D and 3D modes, why module registration order matters, and your first basla() call.

Game engine API · Lesson 1

Introduction to the Game Engine

Meet the single window.OyunMotoru interface. Learn the 2D and 3D modes, why module registration order matters, and your first basla() call.

The engine is a small API layer that runs in the browser. Every operation goes through window.OyunMotoru; there are no external libraries or network requests.

What you will learn

  • Recognise the window.OyunMotoru interface
  • Understand why script order matters
  • Start your first game with basla()

API signatures

CallResult
surum1.0.0 · a property, not a function
basla(mod, config){ok, hata?} · validates mode and config
kayitliModuller()array of module names

One interface, two modes

The core file creates a global API object: window.OyunMotoru. The mode is either 2d or 3d; the source MOD_ADLARI table also accepts the short forms 2 and 3.

Every call returns a result object with ok and an optional hata field instead of throwing. DOM writes use textContent and setAttribute; eval, new Function and innerHTML are never used.

Add the engine scripts in the correct order

<!-- cekirdek.js comes LAST: it registers the modules at that moment. -->
<script src="/js/oyun-motor/oyunlar-2d.js?v=20261119c" defer></script>
<script src="/js/oyun-motor/oyunlar-2d-yeni.js?v=20261119c" defer></script>
<script src="/js/oyun-motor/motif-2d.js?v=20261119c" defer></script>
<script src="/js/oyun-motor/motif-3d.js?v=20261119c" defer></script>
<script src="/js/oyun-motor/cekirdek.js?v=20261119c" defer></script>
<div id="oyunAlani2D"></div>

What happens in this code? At the end of cekirdek.js, the modules are registered automatically if Oyun2D and Oyun3D exist. Reverse the order and that block never runs; basla() then reports that the module is not loaded.

The first call

basla(mod, config) selects a mode, sets up the controller and resets the state. The config holds kok (the game host element), the game name and optional genislik/yukseklik values.

On failure the result has ok:false. Print the hata field to see the reason.

Start the maze game

var M = window.OyunMotoru;
var alan = document.getElementById('oyunAlani2D');
var sonuc = M.basla('2d', {
  kok: alan,
  oyun: 'labirent',
  genislik: 480,
  yukseklik: 320
});
if (!sonuc.ok) console.log('Could not start:', sonuc.hata);

What happens in this code? Calling basla() again with the same mode and config does not create a second loop. This behaviour is called idempotency.

Version and registered modules

surum is a property, not a function; the source defines it as 1.0.0. kayitliModuller() returns the module names currently in the registry.

Inspect the engine

console.log(window.OyunMotoru.surum);
console.log(window.OyunMotoru.kayitliModuller());
console.log(window.OyunMotoru.oyunlar().length);

What happens in this code? With both modules registered, kayitliModuller() returns ["2d","3d"]. oyunlar() lists every game and scene from all registered modules.

Common mistakes

Wrong approachResultCorrect approach
Loading cekirdek.js firstModules are not registered and basla() failsLoad cekirdek.js last
Filling the host with innerHTMLCSP violation and security riskUse textContent
Passing null as kokbasla() reports an invalid game areaPass a real DOM node
Writing var M = OyunMotoruRelies on a global lookupUse window.OyunMotoru

Try it yourself

Copy the script order into an empty HTML file. Move the cekirdek.js line to the top and watch the console; then restore the original order and confirm the maze opens.