write a top down shooter game in processing. use cruetly sqaud style ui elements. use…
- User
write a top down shooter game in processing. use cruetly sqaud style ui elements. use custom fonts, customised enemies and interesting mechanics.
- Assistant
write a top down shooter game in processing. use cruetly sqaud style ui elements. use custom fonts, customised enemies and interesting mechanics.
Certainly! Let's create a top-down shooter game in Processing with Cruelty Squad-style UI elements, custom fonts, customized enemies, and interesting mechanics.
Game Features:
Create a New Sketch:
Open Processing and create a new sketch.
Add Assets:
data directory of your sketch.Below is the code for the game. I've added comments to explain each part. Remember to replace "CustomFont.ttf" with the actual name of your font file.
// Global Variables
PFont customFont;
Player player;
ArrayList<Bullet> bullets;
ArrayList<Enemy> enemies;
ArrayList<Particle> particles;
ArrayList<PowerUp> powerUps;
int score = 0;
int highScore = 0;
int spawnTimer = 0;
// Setup function
void setup() {
size(800, 600);
smooth();
// Load Custom Font
customFont = createFont("CustomFont.ttf", 24);
textFont(customFont);
// Initialize Player and Game Objects
player = new Player(width/2, height/2);
bullets = new ArrayList<Bullet>();
enemies = new ArrayList<Enemy>();
particles = new ArrayList<Particle>();
powerUps = new ArrayList<PowerUp>();
}
// Draw function
void draw() {
// Background with a bold color (inspired by Cruelty Squad)
background(30, 12, 50);
// Update and Display Game Objects
player.update();
player.display();
for (int i = bullets.size()-1; i >= 0; i--) {
Bullet b = bullets.get(i);
b.update();
b.display();
if (b.isOffScreen()) {
bullets.remove(i);
}
}
for (int i = enemies.size()-1; i >= 0; i--) {
Enemy e = enemies.get(i);
e.update();
e.display();
if (e.isOffScreen()) {
enemies.remove(i);
}
// Check collision with player
if (e.intersects(player)) {
gameOver();
return;
}
// Check collision with bullets
for (int j = bullets.size()-1; j >= 0; j--) {
Bullet b = bullets.get(j);
if (e.contains(b.position)) {
// Enemy hit by bullet
e.health -= b.damage;
bullets.remove(j);
// Particle effect
particles.add(new Particle(e.position.x, e.position.y));
if (e.health <= 0) {
enemies.remove(i);
score += e.pointValue;
break;
}
}
}
}
for (int i = particles.size()-1; i >= 0; i--) {
Particle p = particles.get(i);
p.update();
p.display();
if (p.isDead()) {
particles.remove(i);
}
}
for (int i = powerUps.size()-1; i >= 0; i--) {
PowerUp p = powerUps.get(i);
p.update();
p.display();
if (player.contains(p.position)) {
p.apply(player);
powerUps.remove(i);
}
}
// Spawn Enemies
spawnTimer++;
if (spawnTimer > 120) { // Adjust spawn rate as needed
enemies.add(new Enemy(random(width), -20));
spawnTimer = 0;
}
// Display UI
displayUI();
}
// Handle Key Presses
void keyPressed() {
if (key == ' ') {
player.shoot();
}
}
// Display UI Elements
void displayUI() {
fill(200, 10, 150); // Vibrant color
textSize(24);
textAlign(LEFT, TOP);
text("Score: " + score, 10, 10);
text("High Score: " + highScore, 10, 40);
}
// Game Over Function
void gameOver() {
if (score > highScore) {
highScore = score;
}
score = 0;
enemies.clear();
bullets.clear();
particles.clear();
powerUps.clear();
player.reset();
}
// Player Class
class Player {
PVector position;
float speed = 4;
int size = 20;
int health = 100;
int maxHealth = 100;
int fireRate = 15;
int fireTimer = 0;
boolean canShoot = true;
Player(float x, float y) {
position = new PVector(x, y);
}
void update() {
// Movement
if (keyPressed) {
if (keyCode == UP || key == 'w') {
position.y -= speed;
}
if (keyCode == DOWN || key == 's') {
position.y += speed;
}
if (keyCode == LEFT || key == 'a') {
position.x -= speed;
}
if (keyCode == RIGHT || key == 'd') {
position.x += speed;
}
}
// Limit to screen bounds
position.x = constrain(position.x, size/2, width - size/2);
position.y = constrain(position.y, size/2, height - size/2);
// Shooting control
if (!canShoot) {
fireTimer++;
if (fireTimer >= fireRate) {
canShoot = true;
fireTimer = 0;
}
}
}
void display() {
fill(10, 200, 30); // Contrasting color
ellipse(position.x, position.y, size, size);
}
void shoot() {
if (canShoot) {
PVector target = new PVector(mouseX, mouseY);
PVector direction = PVector.sub(target, position).normalize();
bullets.add(new Bullet(position.copy(), direction));
canShoot = false;
}
}
void reset() {
position.set(width/2, height/2);
health = maxHealth;
}
boolean contains(PVector point) {
return dist(position.x, position.y, point.x, point.y) < size/2;
}
}
// Bullet Class
class Bullet {
PVector position;
PVector velocity;
float speed = 8;
int damage = 25;
int size = 6;
Bullet(PVector pos, PVector dir) {
position = pos;
velocity = dir.mult(speed);
}
void update() {
position.add(velocity);
}
void display() {
fill(255, 230, 0); // Yellowish color
ellipse(position.x, position.y, size, size);
}
boolean isOffScreen() {
return (position.x < 0 || position.x > width || position.y < 0 || position.y > height);
}
}
// Enemy Class
class Enemy {
PVector position;
float speed = 2;
int size = 25;
int health = 50;
int pointValue = 10;
Enemy(float x, float y) {
position = new PVector(x, y);
}
void update() {
// Move towards player
PVector dir = PVector.sub(player.position, position).normalize().mult(speed);
position.add(dir);
}
void display() {
fill(200, 20, 20); // Reddish color
rectMode(CENTER);
rect(position.x, position.y, size, size);
}
boolean contains(PVector point) {
return abs(position.x - point.x) < size/2 && abs(position.y - point.y) < size/2;
}
boolean intersects(Player p) {
return dist(position.x, position.y, p.position.x, p.position.y) < (size/2 + p.size/2);
}
boolean isOffScreen() {
return position.y > height + size;
}
}
// Particle Class for Explosions
class Particle {
PVector position;
PVector velocity;
float lifespan = 255;
Particle(float x, float y) {
position = new PVector(x, y);
velocity = PVector.random2D().mult(random(1, 3));
}
void update() {
position.add(velocity);
lifespan -= 4;
}
void display() {
noStroke();
fill(255, lifespan);
ellipse(position.x, position.y, 5, 5);
}
boolean isDead() {
return lifespan <= 0;
}
}
// PowerUp Class
class PowerUp {
PVector position;
int size = 15;
int type; // 1 for health, 2 for speed, etc.
PowerUp(float x, float y, int t) {
position = new PVector(x, y);
type = t;
}
void update() {
// You can add movement or animation if desired
}
void display() {
if (type == 1) {
fill(0, 255, 0); // Green for health
} else if (type == 2) {
fill(0, 0, 255); // Blue for speed
}
ellipse(position.x, position.y, size, size);
}
void apply(Player p) {
if (type == 1) {
p.health = min(p.health + 25, p.maxHealth);
} else if (type == 2) {
p.speed += 1;
}
}
}
Player Class:
W, A, S, D or arrow keys.Bullet Class:
Enemy Class:
Particle Class:
PowerUp Class:
Game Mechanics:
UI Elements:
Custom Fonts and UI:
displayUI() to add more UI elements, like health bars or ammo counts.Customized Enemies:
Interesting Mechanics:
Sound Effects and Music:
Levels and Progression:
Optimization:
Modularity:
Testing:
Controls:
W, A, S, D keys or arrow keys to move.Spacebar to shoot towards the mouse cursor.Objective:
Feel free to modify and expand upon this code to suit your vision. The possibilities are endless, and customizing the game will help you learn more about Processing and game development.
Let me know if you need further assistance or have any questions!
Not yet included in a published release.