write a top down 2.5d shooter game in processing. use cruetly sqaud style ui elements.
- User
write a top down 2.5d shooter game in processing. use cruetly sqaud style ui elements.
- Assistant
write a top down 2.5d shooter game in processing. use cruetly sqaud style ui elements.
Certainly! Below is a simple implementation of a top-down 2.5D shooter game in Processing, featuring UI elements inspired by the aesthetic of "Cruelty Squad". This example includes basic player movement, shooting mechanics, enemy spawning, and a stylized UI.
Note: To run this code, make sure you have the Processing IDE installed. You can download it from processing.org.
sketch.pde)Player player;
ArrayList<Bullet> bullets;
ArrayList<Enemy> enemies;
PFont uiFont;
int score = 0;
int health = 100;
int wave = 1;
int enemySpawnTimer = 0;
int enemySpawnInterval = 120; // Frames between enemy spawns
void setup() {
size(800, 600, P3D); // P3D renderer for 2.5D effects
player = new Player();
bullets = new ArrayList<Bullet>();
enemies = new ArrayList<Enemy>();
uiFont = createFont("Arial-BoldMT-18.vlw", 18);
textFont(uiFont);
}
void draw() {
background(30);
// Update and display player
player.update();
player.display();
// Update and display bullets
for (int i = bullets.size()-1; i >= 0; i--) {
Bullet b = bullets.get(i);
b.update();
b.display();
if (b.isOffScreen()) {
bullets.remove(i);
}
}
// Spawn enemies
enemySpawnTimer++;
if (enemySpawnTimer > enemySpawnInterval) {
enemies.add(new Enemy());
enemySpawnTimer = 0;
}
// Update and display enemies
for (int i = enemies.size()-1; i >= 0; i--) {
Enemy e = enemies.get(i);
e.update(player);
e.display();
// Check for collisions with bullets
for (int j = bullets.size()-1; j >= 0; j--) {
Bullet b = bullets.get(j);
if (e.contains(b.pos)) {
enemies.remove(i);
bullets.remove(j);
score += 10;
break;
}
}
// Check for collisions with player
if (e.contains(player.pos)) {
health -= 10;
enemies.remove(i);
if (health <= 0) {
gameOver();
return;
}
}
}
// Display UI
displayUI();
}
void keyPressed() {
if (key == 'w' || key == 'W') player.up = true;
if (key == 's' || key == 'S') player.down = true;
if (key == 'a' || key == 'A') player.left = true;
if (key == 'd' || key == 'D') player.right = true;
}
void keyReleased() {
if (key == 'w' || key == 'W') player.up = false;
if (key == 's' || key == 'S') player.down = false;
if (key == 'a' || key == 'A') player.left = false;
if (key == 'd' || key == 'D') player.right = false;
}
void mousePressed() {
bullets.add(new Bullet(player.pos.copy(), player.getAimDirection()));
}
void displayUI() {
// Overlay semi-transparent UI background
noStroke();
fill(10, 200);
rect(0, 0, width, 50);
// Stylized text
fill(255, 50, 50);
text("HEALTH: " + health, 20, 30);
fill(50, 255, 50);
text("SCORE: " + score, width/2 - 50, 30);
fill(50, 50, 255);
text("WAVE: " + wave, width - 120, 30);
// Additional UI elements in Cruelty Squad style
stroke(255);
noFill();
rect(10, 10, 150, 30); // Health bar frame
fill(255, 0, 0);
rect(10, 10, map(health, 0, 100, 0, 150), 30); // Health bar
// Random noise overlay for aesthetic
loadPixels();
for (int i = 0; i < pixels.length; i++) {
if (random(1) < 0.02) {
pixels[i] = color(random(255));
}
}
updatePixels();
}
void gameOver() {
background(0);
fill(255, 0, 0);
textAlign(CENTER, CENTER);
textSize(64);
text("GAME OVER", width/2, height/2 - 30);
textSize(32);
text("Final Score: " + score, width/2, height/2 + 30);
noLoop();
}
Player.pde)class Player {
PVector pos;
float speed = 4;
boolean up, down, left, right;
Player() {
pos = new PVector(width/2, height/2);
}
void update() {
PVector movement = new PVector();
if (up) movement.y -= speed;
if (down) movement.y += speed;
if (left) movement.x -= speed;
if (right) movement.x += speed;
pos.add(movement);
pos.x = constrain(pos.x, 0, width);
pos.y = constrain(pos.y, 0, height);
}
void display() {
pushMatrix();
translate(pos.x, pos.y);
rotate(getAimDirection());
fill(200);
noStroke();
rectMode(CENTER);
rect(0, 0, 20, 10);
popMatrix();
}
float getAimDirection() {
return atan2(mouseY - pos.y, mouseX - pos.x);
}
}
Bullet.pde)class Bullet {
PVector pos;
PVector vel;
float speed = 8;
Bullet(PVector startPos, float angle) {
pos = startPos.copy();
vel = new PVector(cos(angle), sin(angle)).mult(speed);
}
void update() {
pos.add(vel);
}
void display() {
pushMatrix();
translate(pos.x, pos.y);
fill(255, 200, 0);
noStroke();
ellipse(0, 0, 5, 5);
popMatrix();
}
boolean isOffScreen() {
return pos.x < 0 || pos.x > width || pos.y < 0 || pos.y > height;
}
}
Enemy.pde)class Enemy {
PVector pos;
float speed = 2;
float size = 30;
Enemy() {
pos = new PVector(random(width), -size);
}
void update(Player player) {
PVector dir = PVector.sub(player.pos, pos).normalize().mult(speed);
pos.add(dir);
}
void display() {
pushMatrix();
translate(pos.x, pos.y);
fill(150, 0, 0);
noStroke();
ellipse(0, 0, size, size);
popMatrix();
}
boolean contains(PVector point) {
float distance = dist(pos.x, pos.y, point.x, point.y);
return distance < size/2;
}
}
Player class handles movement and rendering of the player character.Bullet class manages bullet movement and rendering.displayUI() function draws the health bar, score, and wave number, styled in a way reminiscent of "Cruelty Squad". It includes bold fonts, bright contrasting colors, and a bit of randomness/noise to emulate the game's unique aesthetic.To further emulate "Cruelty Squad"'s UI style:
You can download and use custom fonts that more closely match the game's aesthetic. Place the font file inside a data folder within your Processing sketch folder and load it using createFont().
wave variable and adjust enemy spawn rates to introduce difficulty scaling.Feel free to modify and expand upon this code to create a more complex and polished game. Building upon this foundation, you can implement additional features and refine the aesthetics to more closely match the style of "Cruelty Squad".