//changeble vars //setup int screenx = 1280;//size manualu set for HTML export. Look size int screeny = 720;//size manualu set for HTML export. Look size int framerate = 60; //man int speed = 4;//man walk speed float manx = (screenx/2); float many = (screeny/2); int mandia = 20; int laserScopeScale = 200; //zombie int zombiesToSpawn = 1;//pr. frame float zombieBaseSpeed = 1.5; float zombieBoostSpeed = 1; int spawnProtection = 400; int zombiedia = 20; //skud float shotspeed = 20; //Too high will make shot not work properly float minrecoil = 3; float maxrecoil = 25; float shotrecoil = 0.4; float downrecoil = 1.0; //Color color bg = color(20, 20, 20); color c_white = color(255, 255, 255); color c_black = color(0, 0, 0); color c_man = color(255, 43, 0); color c_zombie = color(62, 129, 0); color c_laser = color(255, 0, 0, 100); color c_skud = color(241, 255, 57); //debug boolean debug = false; int t_debug = 12; //none-changeble vars ArrayList ZombieColl; ArrayList SkudColl; boolean left = false; boolean right = false; boolean up = false; boolean down = false; int clock = framerate; float recoil = minrecoil; PImage imgbg = createImage(1280, 720, RGB); PImage imgblood = createImage(30, 30, ARGB); void setup() { size(1280, 720); frameRate(framerate); ellipseMode(CENTER); ZombieColl = new ArrayList(); SkudColl = new ArrayList(); bloodSetup(); } void draw() { background(bg); bloodbg(); //1 sec clock clock--; if (clock <0) { clock = framerate; } //Zombie spawner for (int i = 0; i < zombiesToSpawn; i++) { Zombie mainZombie = new Zombie(random(0, width), random(0, height)); ZombieColl.add(mainZombie); } //Zombie logic for (int i = 0; i < ZombieColl.size(); i++) { Zombie zm = (Zombie) ZombieColl.get(i); if (zm.alive) { zm.run(); } else {ZombieColl.remove(zm);} } //Skud logic for (int i = 0; i < SkudColl.size(); i++) { Skud sk = (Skud) SkudColl.get(i); if (sk.alive) { sk.run(); } else {SkudColl.remove(sk);} } //debug if (debug) { fill(c_white); textSize(t_debug); text(point_direction(manx, many, mouseX, mouseY), mouseX+10, mouseY); text(point_distance(manx, many, mouseX, mouseY), mouseX+10, mouseY+10); text("Zombies spawned: "+ZombieColl.size()+" Shots spawned: "+SkudColl.size()+" Zombies alive: "+ZombieColl.size(), 10, 16); } manlogic(); } void bloodSetup() { imgbg.loadPixels(); imgblood.loadPixels(); for (int i = 0; i < imgbg.pixels.length; i++) { imgbg.pixels[i] = color(20, 20,20); } imgbg.updatePixels(); for (int i = 0; i < imgblood.pixels.length; i++) { imgblood.pixels[i] = color(random(100,255), 50, 50,30); } imgblood.updatePixels(); } void bloodbg() { image(imgbg, 0, 0); } void cblood(float x, float y) { int x2 = round(x); int y2 = round(y); imgbg.blend(imgblood, 0, 0, 30, 30, x2, y2, 30, 30, BLEND); imgbg.updatePixels(); } //Draw mand void dman() { fill(c_man); stroke(c_black); ellipse(manx, many, mandia, mandia); stroke(c_laser); line (manx, many, (mouseX-manx)*laserScopeScale+manx, (mouseY-many)*laserScopeScale+many); } //Movement and shoot void manlogic() { if (left) { manx-=speed; } if (right) { manx+=speed; } if (up) { many-=speed; } if (down) { many+=speed; } if (mousePressed) { Skud mainSkud = new Skud(); SkudColl.add(mainSkud); if (recoilminrecoil) { recoil -= downrecoil; } if (recoilwidth||y<0||y>height) { alive=false; x = -100; y = -100; } } void move() { x += lengthdir_x(speed, direction); y += lengthdir_y(speed, direction); } void display() { stroke(c_skud); line(x, y, x+lengthdir_x(shotspeed, direction), y+lengthdir_y(shotspeed, direction)); fill(0, 0, 0); if (debug) { fill(c_white); textSize(t_debug); text(direction, x+10, y); text(distance, x+10, y+10); } } } class Zombie { //global var float x = 0; float y = 0; float speed = zombieBaseSpeed+random(0, zombieBoostSpeed); boolean alive = true; //constrictor Zombie(float _x, float _y) { x = _x; y = _y; while (point_distance (x, y, manx, many)x-zombiedia/2&&sk.xy-zombiedia/2&&sk.y