/////OvehitWatch Training Bots///// /* Creator: Anna Rehman Intro to Media Computation Sept 01, 2017 Assignment 2: Interactive Toy Instructor: Nicolas Hesler Instructions: - Click on enemy bot (shown in red) to attack - Enemy bot has 25Hp - Regular attack does 5Hp damage, while random critical hits double as 10Hp damage - Enemy bot disappears when eliminated and resets */ //Create intial point coordinates float pointX = 0; float pointY = 0; //Hitbox position and dimensions float sx = 272; float sy = 150; float sw = 73; float sh = 80; //Create boolean to detect when bullet must be drawn boolean detect = false; //Set initial HP of enemy bot int hp = 25; //Set up canvas void setup() { //Canvas setup size(400, 400); noStroke(); rectMode(CORNER); ellipseMode(CORNER); } void draw() { //Set default framerate frameRate(60); //Update point coordinates based on mouse positions pointX = mouseX; pointY = mouseY; //Create point point(pointX, pointY); hitBox(); createBackground(); allyBot(); enemyBot(); //Draw bullet if clicked if (detect==true) { bullet(); } resetDetection(); } void mouseClicked() { userInput(); } //Create enemy hitbox void hitBox() { fill(0); rect(sx, sy, sw, sh); } //Create background void createBackground() { background(121, 194, 199); noStroke(); fill(61, 151, 158); rect(0, 240, 400, 200); } //Create player/ally bot void allyBot() { noStroke(); //Far arm fill(76); rect(95, 198, 30, 4); rect(120, 196, 8, 8); fill(24, 95, 167); rect(100, 190, 15, 20); //Head fill(76); rect(55, 155, 10, 15); rect(115, 155, 10, 15); //Neck rect(90, 170, 8, 10); //Head part fill(253, 228, 211); rect(60, 150, 60, 25); //Body rect(70, 180, 40, 40); rect(75, 220, 30, 10); fill(24, 95, 167); rect(90, 220, 6, 10); //Close arm fill(24, 95, 167); rect(65, 190, 15, 20); fill(76); rect(80, 198, 15, 4); rect(90, 196, 8, 8); //Head detail fill(76); ellipse(86, 154, 16, 16); fill(255, 238, 125); ellipse(90, 157, 10, 10); fill(76); rect(55, 155, 10, 15); //Shadow fill(76, 155); rect(60, 250, 60, 10); } //method to draw enemybot void enemyBot() { noStroke(); //Far arm fill(76); rect(275, 198, 30, 4); rect(272, 196, 8, 8); fill(177, 43, 21); rect(285, 190, 15, 20); //Head fill(76); rect(275, 155, 10, 15); rect(302, 170, 8, 10); fill(253, 228, 211); rect(280, 150, 60, 25); //Neck fill(76); rect(335, 155, 10, 15); //Body fill(253, 228, 211); rect(290, 180, 40, 40); rect(295, 220, 30, 10); fill(177, 43, 21); rect(304, 220, 6, 10); //Close arm fill(177, 43, 21); rect(320, 190, 15, 20); fill(76); rect(305, 198, 15, 4); rect(302, 196, 8, 8); //Head detail ellipseMode(CORNER); fill(76); ellipse(298, 154, 16, 16); fill(255, 238, 125); ellipse(300, 157, 10, 10); fill(76); rect(335, 155, 10, 15); //Shadow fill(76, 155); rect(280, 250, 60, 10); //HP bar hpBar(); } //Create HP bar for enemy bot void hpBar() { if (hp == 25) { fill(177, 43, 21); stroke(177, 43, 21); strokeWeight(2); rect(275, 125, 10, 5); rect(290, 125, 10, 5); rect(305, 125, 10, 5); rect(320, 125, 10, 5); rect(335, 125, 10, 5); } else if (hp == 20) { fill(177, 43, 21); stroke(177, 43, 21); strokeWeight(2); rect(275, 125, 10, 5); rect(290, 125, 10, 5); rect(305, 125, 10, 5); rect(320, 125, 10, 5); noFill(); rect(335, 125, 10, 5); } else if (hp == 15) { fill(177, 43, 21); stroke(177, 43, 21); strokeWeight(2); rect(275, 125, 10, 5); rect(290, 125, 10, 5); rect(305, 125, 10, 5); noFill(); rect(320, 125, 10, 5); rect(335, 125, 10, 5); } else if (hp == 10) { fill(177, 43, 21); stroke(177, 43, 21); strokeWeight(2); rect(275, 125, 10, 5); rect(290, 125, 10, 5); noFill(); rect(305, 125, 10, 5); rect(320, 125, 10, 5); rect(335, 125, 10, 5); } else if (hp == 5) { fill(177, 43, 21); stroke(177, 43, 21); strokeWeight(2); rect(275, 125, 10, 5); noFill(); rect(290, 125, 10, 5); rect(305, 125, 10, 5); rect(320, 125, 10, 5); rect(335, 125, 10, 5); } } //Create boolean to detect if mouse is over enemy's hitbox boolean attack(float pointX, float pointY, float hitX, float hitY, float hitW, float hitH) { if (pointX >= hitX && pointX <= hitX + hitW && pointY >= hitY && pointY <= hitY + hitH) { return true; } return false; } //HP damage amount with random critical hit float hpUpdate() { float critical = random(1, 10); int newHp = 0; if (critical > 9) { newHp = hp -= 10; return hp; } else { newHp = hp -= 5; return hp; } } //Create bullets void bullet() { fill(200, 150, 0); noStroke(); rect(130, 198, 6, 4); rect(140, 198, 6, 4); rect(150, 198, 6, 4); rect(170, 198, 6, 4); rect(190, 198, 6, 4); rect(220, 198, 6, 4); } //Reset detection for drawing bullet void resetDetection() { detect = false; } //Bot disappears on elimintation void botEliminated() { noStroke(); frameRate(0.7); fill(121, 194, 199); rect(240, 100, 150, 150); fill(61, 151, 158); rect(200, 240, 400, 200); } //Reset HP void resetBot() { hp = 25; } //Detect when bot is eliminated based on hp void detectElimination() { detect = true; if (hp <= 0) { botEliminated(); resetBot(); } else if (hp > 5) { hpUpdate(); } else { println("Bot Eliminated"); botEliminated(); resetBot(); } } //User input void userInput() { boolean attacked = attack(pointX, pointY, sx, sy, sw, sh); if (attacked) { detectElimination(); } else { println("false"); } }