Module · Detail

Space Invaders: Defense Against the Formation

This module leads from a small, walkable game module to a structured Space-Invaders project. The focus is on step-by-step building of control, enemy data, hit logic, score, life system, wave structure, and restart.

Time 90 minutes
Format AI-Coding
Technology frameCraft
Online testing Demo
Preview Image: Space Invaders: Defense Against the Formation

BuildFromZero with KI-Coding

Structured Code Development from a Small Start Base

This module uses KI-Coding as context-aware support for further development of an existing project status. The starting point is not a finished game, but a minimal, walkable game module with spaceship, formation marking, status display, and pre-prepared inputs.

The tasks lead step by step from visual enhancements over control and scene values to shooting logic, enemy formations, collisions, points, lives, waves, and restart. This makes the programming process visible as a comprehensible sequence of small changes that can be tested and professionally categorized.

This structure supports transparent work with KI-generated changes in teaching: prompts, code adjustments, and versions remain bound to concrete sub-goals. The focus is on understandable code development, targeted extensions, and directly verifiable intermediate results.

Didactic classification

The module is compactly integrated into the subject matter and teaching practice.

Subjective goal setting

At its center stands the construction of a simple 2D game from clearly separated code components: scene, figures, inputs, rules, and states. The professional achievement consists in not taking over game mechanics as a complete product, but step by step modeling and implementing them through data structures, state values, and recurring rules.

Competence development

  • Structuring: The project code is divided into construction, helper functions, scene values, and game rules.
  • Modeling: Enemies, shots, points, lives, and waves are depicted as data and states.
  • Algorithmic thinking: Movement, boundary check, collision, and status change are implemented as rule-based processes.
  • Debugging and iteration: Every extension remains small enough to be immediately checked and targeted corrected.

Teacher's added value

  • The module offers a clear progression from visual orientation to complete game states.
  • Breaking down into smaller work steps facilitates result assurance and intermediate reflection.
  • Extensions such as speed, waves or restart allow differentiation within the same project context.

Flow of the lesson unit

The tasks are presented in the order of the JSON and content-wise condensed.

1

Make the game field more readable

The start scene is supplemented with a visible defense line at the lower edge of the game field. This gives the player area a clear spatial orientation without changing any game rules yet.

2

Improve the spaceship as player figure

The existing defender figure is visually made more distinctive. The change remains limited to the representation and thus separates design consciously from control and game logic.

3

Prepare left-right movement

The prepared inputs are connected for the first time with a real horizontal movement. In addition, the position is limited so that the spaceship stays within the window.

4

Movement speed as scene value

The fixed movement number is replaced by a scene value. This makes it visible how game parameters can be released from logic and later adjusted more easily.

5

Convert Baustellenregel into game rule

The previous status rule is cleaned up so it no longer permanently overrides messages. The existing movement remains and the rule is stabilized as a location for further game logic.

6

Prepare shooting figure

A single shooting figure is placed and initially positioned outside the visible window. This creates the structure for later firing without already building trigger or flight logic.

7

Untrigger shooting start

A marker holds whether the fire button was pressed already. This prepares so that a key press will only trigger a single action later and not be processed again in every frame.

8

Trigger shooting

The prepared shot starts at new recognized firing action at the position of the spaceship. It continues to use only one shooting figure, thus keeping resources and state clearly controlled.

9

Move shooting up

An active shot moves upwards and is reset when leaving the game field. This implements a simple lifecycle of a game object.

10

Plan enemy data as list

The enemy formation is initially prepared as a list of names and positions. No enemy figures are created yet, so the separation between data model and presentation remains clear.

11

Display enemy formation

Visible enemy figures are generated from the prepared start data. Names, positions, and tags are consistently adopted so that later rules can access the formation.

12

Set enemy active status

A separate list keeps track of which enemies are currently active, distinguishing them from all the created enemies.

13

Complete hit structure

A collision reaction between a shot and an enemy is added. A valid hit removes the enemy from the active list, moves it out of sight, and resets the shot.

14

Score points

The score is increased by exactly one point with a valid hit. The calculation remains separate from the display to keep data changes and presentation separate.

15

Show score in HUD

The score is made visible through a UI element and bound to the scene value, establishing the connection between internal state and screen feedback.

16

Move enemies slowly

Active enemies move slowly sideways. The movement uses own scene values for direction and tempo and remains limited to the currently active enemies.

17

Edge change for the formation

When reaching the game field edge, the formation changes direction and moves down. The check is done so that the direction change is not triggered multiple times in the same frame.

18

Reset formation safely

A helper function resets all enemies to their starting positions and restores the active enemy list. The function does not create new figures and supports future wave and restart logic.

19

Introduce lives and danger

If active enemies get too deep, a life is deducted and the formation is reset. The firing state is also cleaned up so that each danger situation can be processed clearly.

20

Show lives in HUD

The remaining lives are visible as a separate HUD value. The display is placed separately from the title and score, so that different game information remains distinguishable.

21

Start new wave

When all enemies are defeated, the wave is increased and the formation is prepared anew using the reset function. Points and lives remain intact, creating a continuous game progression.

22

Game Over without restart

When lives are exhausted, a Game-Over state is set. Normal gameplay elements such as movement, firing, enemy movement, and new waves are not continued in this state.

23

Restart with button and touch

After Game Over, an unblocked restart action is added. Points, lives, wave, player position, firing, and formation are reset consistently to a starting state.

Code snippet

The excerpt shows the separation of scene values, access helpers, and recurring rules as the structural core of the module.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
class Zugriff:
    @staticmethod
    def figur(ctx, name):
        return ctx.E(name)
    @staticmethod
    def wert(ctx, name, standard=None):
        return ctx.vars.get(name, standard)
    @staticmethod
    def aktion_aktiv(ctx, name):
        return ctx.down(name)
SZENE('hauptszene', punkte=0, leben=3,
      status='Baustelle: bereit zum Erweitern',
      gegner_namen=[], schuss_aktiv=False, welle=1)
def baustellen_regel(ctx):
    spieler = Zugriff.figur(ctx, 'verteidiger')
    if spieler is None:
        return
    if Zugriff.aktion_aktiv(ctx, 'links') or Zugriff.aktion_aktiv(ctx, 'rechts'):
        ctx.vars['status'] = 'Eingabe erkannt: Bewegung wird erweitert.'
This module connects game modeling with step-by-step implementation and makes states, rules, and feedback traceable.

The clear sequence of tasks supports lesson organization, intermediate security, and the development of a complete game course from small code changes. Extensions such as tempo, waves or restart allow for flexible adaptation to different learning levels.

Request a demo access and test the module in your own course context.