Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Writing Games with Processing: Enemies
// Version 2: Enemies
int px = 320, py = 240;
int tileSize = 20;
class Enemy {
color c;
int x, y;
String name;
Enemy(String name) {
this.name = name;
c = color(222,40,107);
}
void draw() {
fill(c);
ellipse(x + tileSize/2, y + tileSize/2, tileSize, tileSize);
fill(0);
textAlign(CENTER, TOP);
textSize(12);
text(name, x + tileSize/2, y + tileSize + 2);
}
}
ArrayList<Enemy> enemies = new ArrayList<Enemy>();
void addEnemy(int x, int y, String name) {
Enemy enemy = new Enemy(name);
enemy.x = x;
enemy.y = y;
enemies.add(enemy);
}
void drawEnemies() {
for(Enemy e: enemies) {
e.draw();
}
}
void setup() {
size(640, 480); //VGA for those old enough to remember
addEnemy(20, 20, "Kenny");
addEnemy(600, 20, "Benny");
}
void drawPlatty() {
fill(235,220,160);
rect(px, py, tileSize, tileSize);
fill(0);
textSize(tileSize-2);
textAlign(CENTER, CENTER);
text("P", px+tileSize/2, py+tileSize/2-2);
}
void drawBackground() {
fill(174, 204, 27);
rect(0, 0, width, height);
}
void draw() {
drawBackground();
drawPlatty();
drawEnemies();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.