Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Creating variables
- var myX = 0, myY = 0, yes=0
- var patX=[], patY=[], ip, patSize=10, enemyX=[], enemyY=[], ie, broiEnemy=0, ticks=0, currentPosition=[], healthEnemy=[], towerX=[], towerY=[], broiTowers=0, it, target=[]
- for(ip=0; ip<150; ip++) {
- patX[ip]=ip
- patY[ip]=20
- }
- for(ip=150; ip<300; ip++) {
- patX[ip]=150
- patY[ip]=ip-150+20
- }
- for(ip=300; ip<400; ip++) {
- patX[ip]=ip-150
- patY[ip]=170
- }
- for(ip=400; ip<500; ip++) {
- patX[ip]=250
- patY[ip]=170-ip+400
- }
- for(ip=500; ip<700; ip++) {
- patX[ip]=250+ip-500
- patY[ip]=170-600+ip
- }
- for(ip=700; ip<1160; ip++) {
- patX[ip]=250-ip-500+1400
- patY[ip]=170-600+700
- }
- function update() {
- myX=mouseX
- myY=mouseY
- ticks++
- if(ticks%60==0) {
- broiEnemy++
- healthEnemy[broiEnemy]=120
- currentPosition[broiEnemy]=0
- enemyX[broiEnemy]=patX[currentPosition[broiEnemy]]
- enemyY[broiEnemy]=patY[currentPosition[broiEnemy]]
- }
- for(ie=0; ie<broiEnemy; ie++) {
- if(enemyX[ie]!=undefined) {
- currentPosition[ie]+=1
- enemyX[ie]=patX[currentPosition[ie]]
- enemyY[ie]=patY[currentPosition[ie]]
- }
- for(it=0; it<=broiTowers; it++) {
- if(areCirclesColliding(towerX[it], towerY[it], 100, enemyX[ie], enemyY[ie], 10)) {
- yes++
- target[it]=broiEnemy;
- for(ie=broiEnemy; ie>0; ie--) {
- if(ie<target[it]) {
- target[it]=ie
- }
- }
- healthEnemy[target[it]]-=0.6
- if(healthEnemy[ie]<=0) {
- enemyX[target[it]]=undefined
- enemyY[target[it]]=undefined
- healthEnemy[target[it]]=undefined
- }
- }
- yes=0
- }
- }
- }
- function FindTarget() {
- }
- function draw() {
- // This is how you draw a rectangle
- context.fillStyle="blue";
- fillCircle(myX, myY, 10);
- context.globalAlpha=0.1
- context.fillStyle="grey";
- fillCircle(myX, myY, 100);
- context.globalAlpha=1
- for(ip=0; ip<1160; ip++) {
- context.fillStyle="brown"
- context.fillRect(patX[ip], patY[ip], patSize, patSize)
- }
- for(ie=0; ie<broiEnemy; ie++) {
- context.fillStyle="blue"
- fillCircle(enemyX[ie], enemyY[ie], 10)
- context.fillStyle="black"
- context.fillRect(enemyX[ie]-1-15, enemyY[ie]-16, 32, 6)
- context.fillStyle="green"
- context.fillRect(enemyX[ie]-15, enemyY[ie]-15, healthEnemy[ie]/4, 5)
- }
- for(it=0; it<=broiTowers; it++) {
- context.globalAlpha=1
- context.fillStyle="green"
- fillCircle(towerX[it], towerY[it], 10)
- context.globalAlpha=0.1
- context.fillStyle="grey"
- fillCircle(towerX[it], towerY[it], 100)
- }
- };
- function keyup(key) {
- // Show the pressed keycode in the console
- console.log("Pressed", key);
- };
- function mouseup() {
- // Show coordinates of mouse on click
- console.log("Mouse clicked at", mouseX, mouseY);
- broiTowers++
- towerX[broiTowers]=mouseX
- towerY[broiTowers]=mouseY
- };
- function areCirclesColliding(x1, y1, r1, x2, y2, r2){
- let dist = Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2))
- return dist<=r1+r2;
- }
- function fillCircle(x, y, r) {
- context.beginPath();
- context.arc(x, y, r, 0, 2*Math.PI);
- context.fill();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement