In 2009, I created the type of learning environment I wished I had had when I began to learn software development: a video game engine. Engine Alpha enables beginners to develop their own video games in Java. I was in ninth grade at the time and began the project on my own in my free time after school. In 2010, I entered it competitions and went head-to-head with other young people in Jugend Forsch, Europe's largest youth science and technology competition.
Since then, the Engine underwent several transformations and improvements, and it acquired a growing base of contributors. The Engine's public Github Organization still hosts sources and demo projects.
The Engine found its place in German classrooms, where a body of educators use it to produce didactic materials, and a body of students are able to learn coding in an engaging way through video games.
The Java code to produce the above "Eat Me" demo is below in its entirety and can be understood following the (German-language) tutorial:
import ea.*;
import ea.actor.Circle;
import ea.actor.Text;
import ea.collision.CollisionEvent;
import ea.collision.CollisionListener;
import ea.event.KeyListener;
import java.awt.Color;
import java.awt.event.KeyEvent;
public class SnakeHead
extends Scene {
private Text scoreText = new Text("Score: 0", 1.4f);
private int score = 0;
private Snake snake = new Snake();
public SnakeHead() {
add(snake);
scoreText.setPosition(-9, 5);
add(scoreText);
placeRandomGoodie();
}
public void setScore(int score) {
this.score = score;
this.scoreText.setContent("Score: " + score);
}
public void increaseScore() {
setScore(score+1);
}
public void placeRandomGoodie() {
float x = Random.range()*10 - 5;
float y = Random.range()*10 - 5;
Goodie goodie = new Goodie();
goodie.setCenter(x, y);
add(goodie);
goodie.addCollisionListener(snake, goodie);
}
public static void main(String[] args) {
Game.start(600, 400, new SnakeHead());
//Game.setDebug(true);
}
private class Snake
extends Circle
implements FrameUpdateListener, KeyListener {
private Vector v_per_s = new Vector(0,0);
public Snake() {
super(1);
setColor(Color.GREEN);
}
@Override
public void onFrameUpdate(float timeInS) {
this.moveBy(v_per_s.multiply(timeInS));
}
@Override
public void onKeyDown(KeyEvent keyEvent) {
switch (keyEvent.getKeyCode()) {
case KeyEvent.VK_W:
v_per_s = new Vector(0, 5);
break;
case KeyEvent.VK_A:
v_per_s = new Vector(-5, 0);
break;
case KeyEvent.VK_S:
v_per_s = new Vector(0, -5);
break;
case KeyEvent.VK_D:
v_per_s = new Vector(5, 0);
break;
}
}
}
private class Goodie
extends Text
implements CollisionListener<Snake> {
public Goodie() {
super("Eat Me!",1);
setColor(Color.RED);
}
@Override
public void onCollision(CollisionEvent<Snake> collisionEvent) {
increaseScore();
this.remove();
placeRandomGoodie();
}
}
}