MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / init_positions

Function init_positions

examples/space_invaders/space_invaders.py:425–457  ·  view source on GitHub ↗

Establish a new field of play. This generates GlyphCoordinate objects and persists them to the database.

(session)

Source from the content-addressed store, hash-verified

423
424
425def init_positions(session):
426 """Establish a new field of play.
427
428 This generates GlyphCoordinate objects
429 and persists them to the database.
430
431 """
432
433 # delete all existing coordinates
434 session.query(GlyphCoordinate).delete()
435
436 session.add(
437 GlyphCoordinate(
438 session, "ship", WINDOW_WIDTH // 2 - 2, WINDOW_HEIGHT - 4
439 )
440 )
441
442 arrangement = (
443 ("enemy3", 50),
444 ("enemy2", 25),
445 ("enemy1", 10),
446 ("enemy2", 25),
447 ("enemy1", 10),
448 )
449 for ship_vert, (etype, score) in zip(
450 range(5, 30, ENEMY_VERT_SPACING), arrangement
451 ):
452 for ship_horiz in range(0, 50, 10):
453 session.add(
454 GlyphCoordinate(
455 session, etype, ship_horiz, ship_vert, score=score
456 )
457 )
458
459
460def draw(session, window, state):

Callers 1

startFunction · 0.85

Calls 4

GlyphCoordinateClass · 0.85
deleteMethod · 0.45
queryMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected