AntiHax

AntiHax is a strategic defense game where the objective is to survive for as long as possible.

Summary

AntiHax is a strategic defense game where the objective is to survive for as long as possible. Players are tasked with strategically placing cannons and walls to safeguard their computer from relentless viruses hell-bent on its destruction. These viruses continuously spawn and traverse the screen, cleverly maneuvering around any obstacles the player has set up.

My Role

My role in the project involved designing and programming both the cannons and the health bar. Object-oriented programming was employed to ensure efficient coding. I specifically coded the cannon and CPU (health) objects, as well as the initial launch screen that intriguingly displays your actual name (give it a try, I’m serious).

Meanwhile, my teammate was responsible for programming the enemies and creating all the visuals. The enemies utilize a pathfinding script through the grid to determine the shortest route to the CPU.

Code snippet

The project was rich with code and various objects. Below, you’ll find a code snippet illustrating the Cannon object, which I believe accurately represents the project’s code structure during our development phase.

//Constructor of the canon
  Canon(Tile canonTile) {
    //Tile if the canon
    tile = canonTile;
    //Set the tile to Occupied, as a canon is now placed on it
    canonTile.bOccupied = true;
    //Set the positions of the canon to it's tile's positions.
    x = canonTile.x;
    y = canonTile.y;
    //Create a new lifebar for the canon.
    lifebar = new LifeBar(x, y+30, 75, 3, lifespanCanon, color(0,255,0), "CENTER");
  }

  void shoot() {
    //Try to shoot at an enemy
    time++;
    //If the timer is now at the value that it shoots at, and that it has a target to aim at
    if (time == shootSpeed && target != null)
    {
      //Shoot, and add a bullet to the scene. Reset the timer to 0, as you wait for the countdown to go back up to shooting speed.
      Bullets.add(new Bullet(bulletWidth, target, this));
      time = 0;
    }
  }

  void canonAim() {
    //If there's an enemy on the board
    if(enemies.size() > 0){
      //Target the first enemy of the board, temporarily.
      target = enemies.get(0);
      //Check if there is a closer enemy to shoot at.
      for (int i = 0; i < enemies.size(); i++) {
        if (dist(enemies.get(i).x, enemies.get(i).y, x, y) < dist(target.x, target.y, x, y)) {
          //Set the target at the closest enemy possible.
          target = enemies.get(i);
        }
      }
      //Shoot a bullet.
      shoot();
    }
  }

  //Display the canon
  void display() {
    //Diminish his life over time
    lifebar.currentLife--;
    push();
    translate(x, y);
    //Get the rotation angle from its target
    if(target != null){
      angleRotation = atan2(target.y-y, target.x-x);
    }
    //Rotate the canon towards the target
    rotate(angleRotation);
    imageMode(CENTER);
    //Display the image of the canon of the tile. It's now 0,0 as we translated to its positions.
    image(imageCanon, 0, 0);
    pop();
  }
  
  //Destroy the canon
  void destroy(){
    //Remove the canon for the ArrayList
    canons.remove(this);
    //Set the tile to not occupied anymore.
    tile.bOccupied = false;
  }

Contact me

Play it now

81 MB on Itch.io

Main involvement

  • Object-oriented
  • Cannons
  • Health system
  • Launch screen

Made by

Made with

Other projects

Lucy

My team and I had to create an

Epic Gym

Website created for the Epic Gym training center

All projects

Take a look at all the projects I’ve done as part of my classes, contracts, or just out of personal interest.

Portfolio

About