diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 0000000..f05f3e2
Binary files /dev/null and b/.DS_Store differ
diff --git a/data/grass.tsx b/data/grass.tsx
new file mode 100644
index 0000000..5b5badb
--- /dev/null
+++ b/data/grass.tsx
@@ -0,0 +1,4 @@
+
+
+
+
diff --git a/data/map.tmx b/data/map.tmx
new file mode 100644
index 0000000..47fcaba
--- /dev/null
+++ b/data/map.tmx
@@ -0,0 +1,28 @@
+
+
diff --git a/dev_screenshot.png b/dev_screenshot.png
new file mode 100644
index 0000000..7581b9b
Binary files /dev/null and b/dev_screenshot.png differ
diff --git a/img/farmer.png b/img/farmer.png
new file mode 100644
index 0000000..49ab7a6
Binary files /dev/null and b/img/farmer.png differ
diff --git a/img/front_man.png b/img/front_man.png
new file mode 100644
index 0000000..ecfb62e
Binary files /dev/null and b/img/front_man.png differ
diff --git a/img/gameOver.png b/img/gameOver.png
new file mode 100644
index 0000000..08b7696
Binary files /dev/null and b/img/gameOver.png differ
diff --git a/img/grass.png b/img/grass.png
new file mode 100644
index 0000000..7951377
Binary files /dev/null and b/img/grass.png differ
diff --git a/img/grass2.png b/img/grass2.png
new file mode 100644
index 0000000..7739774
Binary files /dev/null and b/img/grass2.png differ
diff --git a/img/grass3.png b/img/grass3.png
new file mode 100644
index 0000000..e331265
Binary files /dev/null and b/img/grass3.png differ
diff --git a/img/guy.tsx b/img/guy.tsx
new file mode 100644
index 0000000..fa8eaa6
--- /dev/null
+++ b/img/guy.tsx
@@ -0,0 +1,4 @@
+
+
+
+
diff --git a/img/house1.png b/img/house1.png
new file mode 100644
index 0000000..aec000f
Binary files /dev/null and b/img/house1.png differ
diff --git a/img/map.json.p10876 b/img/map.json.p10876
new file mode 100644
index 0000000..f377b51
--- /dev/null
+++ b/img/map.json.p10876
@@ -0,0 +1,29 @@
+{ "height":20,
+ "infinite":false,
+ "layers":[
+ {
+ "data":[11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11],
+ "height":20,
+ "name":"Tile Layer 1",
+ "opacity":1,
+ "type":"tilelayer",
+ "visible":true,
+ "width":20,
+ "x":0,
+ "y":0
+ }],
+ "nextobjectid":1,
+ "orientation":"orthogonal",
+ "renderorder":"right-down",
+ "tiledversion":"1.1.6",
+ "tileheight":32,
+ "tilesets":[
+ {
+ "firstgid":1,
+ "source":"grass.tsx"
+ }],
+ "tilewidth":32,
+ "type":"map",
+ "version":1,
+ "width":20
+}
\ No newline at end of file
diff --git a/img/tree.png b/img/tree.png
new file mode 100644
index 0000000..b3b5f3a
Binary files /dev/null and b/img/tree.png differ
diff --git a/index.html b/index.html
index 98d1b62..3a6a447 100644
--- a/index.html
+++ b/index.html
@@ -17,10 +17,15 @@
-->
+
+
+
+
+
diff --git a/libraries/game.js b/libraries/game.js
index a211e39..d52a98a 100644
--- a/libraries/game.js
+++ b/libraries/game.js
@@ -92,25 +92,40 @@
this.entities = [];
this.group = [];
this.player;
-
+ this.despawn = false;
+
// this.screenwrap = false;
this.willdespawn = false;
this.include = function(entity) {
this.entities.push(entity);
}
+ this.includes = function(entity) {
+ for (var i = 0; i < entity.length; i++) {
+ this.entities.push(entity[i]);
+ }
+ }
this.setplayer = function(player){
this.player = player;
}
- this.run = function(){
+ this.run = function(player,func){
for (var i = 0; i < this.entities.length; i += 1) {
//check if the entitis array has objects within it
if(this.entities && this.entities[i]){
+ // this.checkCollisions(player,func);
this.entities[i].run();
- this.despawn(this.entities[i],i);
+ // if(this.despawn === true){
+ // this.despawn(this.entities[i],i);
+ // }
}
}
}
+
+ this.checkCollisions = function(sprite, func){
+ for (var i = 0; i < this.entities.length; i += 1) {
+ this.collisions(sprite, this.entities[i], func);
+ }
+ }
/*this.run = function() {
for (var i = 0; i < this.entities.length; i += 1) {
if(this.willdespawn){
@@ -181,11 +196,11 @@
this.name = name || "default";
this.type = type || "rect";
- if (typeof img === "string") {
- this.img = loadImage(img);
- } else {
- this.img = DefaultImage();
- }
+ // if (typeof img === "string") {
+ // this.img = loadImage(img);
+ // } else {
+ this.img = img || DefaultImage();
+ // }
this.visable = true;
var target = createVector(0, 0);
diff --git a/libraries/p5.collide2d.js b/libraries/p5.collide2d.js
new file mode 100755
index 0000000..9b5b017
--- /dev/null
+++ b/libraries/p5.collide2d.js
@@ -0,0 +1,411 @@
+/*
+Created by http://benmoren.com
+Some functions and code modified version from http://www.jeffreythompson.org/collision-detection
+GNU LGPL 2.1 License
+Version 0.1 | January 10th, 2016
+*/
+console.log("### p5.collide ###")
+
+p5.prototype._collideDebug = false;
+
+p5.prototype.collideDebug = function(debugMode){
+ _collideDebug = debugMode;
+}
+
+/*~++~+~+~++~+~++~++~+~+~ 2D ~+~+~++~+~++~+~+~+~+~+~+~+~+~+~+*/
+
+p5.prototype.collideRectRect = function (x, y, w, h, x2, y2, w2, h2) {
+ //2d
+ //add in a thing to detect rectMode CENTER
+ if (x + w >= x2 && // r1 right edge past r2 left
+ x <= x2 + w2 && // r1 left edge past r2 right
+ y + h >= y2 && // r1 top edge past r2 bottom
+ y <= y2 + h2) { // r1 bottom edge past r2 top
+ return true;
+ }
+ return false;
+};
+
+p5.prototype.collideRectCircle = function (rx, ry, rw, rh, cx, cy, diameter) {
+ //2d
+ // temporary variables to set edges for testing
+ var testX = cx;
+ var testY = cy;
+
+ // which edge is closest?
+ if (cx < rx){ testX = rx // left edge
+ }else if (cx > rx+rw){ testX = rx+rw } // right edge
+
+ if (cy < ry){ testY = ry // top edge
+ }else if (cy > ry+rh){ testY = ry+rh } // bottom edge
+
+ // // get distance from closest edges
+ var distance = this.dist(cx,cy,testX,testY)
+
+ // if the distance is less than the radius, collision!
+ if (distance <= diameter/2) {
+ return true;
+ }
+ return false;
+};
+
+p5.prototype.collideCircleCircle = function (x, y,d, x2, y2, d2) {
+//2d
+ if( this.dist(x,y,x2,y2) <= (d/2)+(d2/2) ){
+ return true;
+ }
+ return false;
+};
+
+p5.prototype.collidePointCircle = function (x, y, cx, cy, d) {
+//2d
+if( this.dist(x,y,cx,cy) <= d/2 ){
+ return true;
+}
+return false;
+};
+
+p5.prototype.collidePointRect = function (pointX, pointY, x, y, xW, yW) {
+//2d
+if (pointX >= x && // right of the left edge AND
+ pointX <= x + xW && // left of the right edge AND
+ pointY >= y && // below the top AND
+ pointY <= y + yW) { // above the bottom
+ return true;
+}
+return false;
+};
+
+p5.prototype.collidePointLine = function(px,py,x1,y1,x2,y2, buffer){
+ // get distance from the point to the two ends of the line
+var d1 = this.dist(px,py, x1,y1);
+var d2 = this.dist(px,py, x2,y2);
+
+// get the length of the line
+var lineLen = this.dist(x1,y1, x2,y2);
+
+// since floats are so minutely accurate, add a little buffer zone that will give collision
+if (buffer === undefined){ buffer = 0.1; } // higher # = less accurate
+
+// if the two distances are equal to the line's length, the point is on the line!
+// note we use the buffer here to give a range, rather than one #
+if (d1+d2 >= lineLen-buffer && d1+d2 <= lineLen+buffer) {
+ return true;
+}
+return false;
+}
+
+p5.prototype.collideLineCircle = function( x1, y1, x2, y2, cx, cy, diameter) {
+ // is either end INSIDE the circle?
+ // if so, return true immediately
+ var inside1 = this.collidePointCircle(x1,y1, cx,cy,diameter);
+ var inside2 = this.collidePointCircle(x2,y2, cx,cy,diameter);
+ if (inside1 || inside2) return true;
+
+ // get length of the line
+ var distX = x1 - x2;
+ var distY = y1 - y2;
+ var len = this.sqrt( (distX*distX) + (distY*distY) );
+
+ // get dot product of the line and circle
+ var dot = ( ((cx-x1)*(x2-x1)) + ((cy-y1)*(y2-y1)) ) / this.pow(len,2);
+
+ // find the closest point on the line
+ var closestX = x1 + (dot * (x2-x1));
+ var closestY = y1 + (dot * (y2-y1));
+
+ // is this point actually on the line segment?
+ // if so keep going, but if not, return false
+ var onSegment = this.collidePointLine(closestX,closestY,x1,y1,x2,y2);
+ if (!onSegment) return false;
+
+ // draw a debug circle at the closest point on the line
+ if(this._collideDebug){
+ this.ellipse(closestX, closestY,10,10);
+ }
+
+ // get distance to closest point
+ distX = closestX - cx;
+ distY = closestY - cy;
+ var distance = this.sqrt( (distX*distX) + (distY*distY) );
+
+ if (distance <= diameter/2) {
+ return true;
+ }
+ return false;
+}
+
+p5.prototype.collideLineLine = function(x1, y1, x2, y2, x3, y3, x4, y4,calcIntersection) {
+
+ var intersection;
+
+ // calculate the distance to intersection point
+ var uA = ((x4-x3)*(y1-y3) - (y4-y3)*(x1-x3)) / ((y4-y3)*(x2-x1) - (x4-x3)*(y2-y1));
+ var uB = ((x2-x1)*(y1-y3) - (y2-y1)*(x1-x3)) / ((y4-y3)*(x2-x1) - (x4-x3)*(y2-y1));
+
+ // if uA and uB are between 0-1, lines are colliding
+ if (uA >= 0 && uA <= 1 && uB >= 0 && uB <= 1) {
+
+ if(this._collideDebug || calcIntersection){
+ // calc the point where the lines meet
+ var intersectionX = x1 + (uA * (x2-x1));
+ var intersectionY = y1 + (uA * (y2-y1));
+ }
+
+ if(this._collideDebug){
+ this.ellipse(intersectionX,intersectionY,10,10);
+ }
+
+ if(calcIntersection){
+ intersection = {
+ "x":intersectionX,
+ "y":intersectionY
+ }
+ return intersection;
+ }else{
+ return true;
+ }
+ }
+ if(calcIntersection){
+ intersection = {
+ "x":false,
+ "y":false
+ }
+ return intersection;
+ }
+ return false;
+}
+
+p5.prototype.collideLineRect = function(x1, y1, x2, y2, rx, ry, rw, rh, calcIntersection) {
+
+ // check if the line has hit any of the rectangle's sides. uses the collideLineLine function above
+ var left, right, top, bottom, intersection;
+
+ if(calcIntersection){
+ left = this.collideLineLine(x1,y1,x2,y2, rx,ry,rx, ry+rh,true);
+ right = this.collideLineLine(x1,y1,x2,y2, rx+rw,ry, rx+rw,ry+rh,true);
+ top = this.collideLineLine(x1,y1,x2,y2, rx,ry, rx+rw,ry,true);
+ bottom = this.collideLineLine(x1,y1,x2,y2, rx,ry+rh, rx+rw,ry+rh,true);
+ intersection = {
+ "left" : left,
+ "right" : right,
+ "top" : top,
+ "bottom" : bottom
+ }
+ }else{
+ //return booleans
+ left = this.collideLineLine(x1,y1,x2,y2, rx,ry,rx, ry+rh);
+ right = this.collideLineLine(x1,y1,x2,y2, rx+rw,ry, rx+rw,ry+rh);
+ top = this.collideLineLine(x1,y1,x2,y2, rx,ry, rx+rw,ry);
+ bottom = this.collideLineLine(x1,y1,x2,y2, rx,ry+rh, rx+rw,ry+rh);
+ }
+
+ // if ANY of the above are true, the line has hit the rectangle
+ if (left || right || top || bottom) {
+ if(calcIntersection){
+ return intersection;
+ }
+ return true;
+ }
+ return false;
+}
+
+
+p5.prototype.collidePointPoly = function(px, py, vertices) {
+ var collision = false;
+
+ // go through each of the vertices, plus the next vertex in the list
+ var next = 0;
+ for (var current=0; current py && vn.y < py) || (vc.y < py && vn.y > py)) &&
+ (px < (vn.x-vc.x)*(py-vc.y) / (vn.y-vc.y)+vc.x)) {
+ collision = !collision;
+ }
+ }
+ return collision;
+}
+
+// POLYGON/CIRCLE
+p5.prototype.collideCirclePoly = function(cx, cy, diameter, vertices, interior) {
+
+ if (interior == undefined){
+ interior = false;
+ }
+
+ // go through each of the vertices, plus the next vertex in the list
+ var next = 0;
+ for (var current=0; current 0 && angle <= arcAngle / 2 && angle >= -arcAngle / 2) {
+ return true;
+ }
+ }
+ return false;
+}
diff --git a/libraries/p5.tiledmap.min.js b/libraries/p5.tiledmap.min.js
new file mode 100644
index 0000000..58c2775
--- /dev/null
+++ b/libraries/p5.tiledmap.min.js
@@ -0,0 +1 @@
+!function(t,i){"function"==typeof define&&define.amd?define("p5.tiledmap",["p5"],function(t){i(t)}):"object"==typeof exports?i(require("../p5")):i(t.p5)}(this,function(t){function i(t){"use strict";if(t=this.staggerindex-1;g--)d+g>=0&&d+gp&&(a.pixels[l]=p);a.updatePixels()}a.pop()},t.TiledMap.prototype.draw=function(t,i,e){for(var a,s=0;s=0&&s>=0&&a=0&&h>=0&&s= 0 && name < this.bullets.length) {
+ //remove item 'name' = 1 means remove bullets[1]
+ this.bullets.splice(name, 1);
+ }
+ }
+ }catch(e){
+ console.error("ERROR:this.bullets was empty"+e)
+ }
+ }
+
+ this.despawn = function(entity,i){
+ if(entity.screenwraped()){
+ print("Deleted: " + i);
+ this.destroy(i);
+ }
+ }
+
}
\ No newline at end of file
diff --git a/scripts/player.js b/scripts/player.js
index 1d25aa0..9601e0a 100644
--- a/scripts/player.js
+++ b/scripts/player.js
@@ -1,24 +1,33 @@
-p5.prototype.Player = function() {
- return new createPlayer();
+p5.prototype.Player = function(img,x,y,w,h) {
+ return new createPlayer(img,x,y,w,h);
}
-function createPlayer() {
- this.player = Entity(30, height / 2, null, null, null, CORNER);
- this.speed = 3;
+function createPlayer(img,x,y,w,h) {
+ // x, y, w, h, Color, mode, speed, angle, debug, name, type, img
+ this.player = Entity(x,y,w,h,null, CORNER, null, null, null, null, null, img);
+ this.player.type = "image";
+ this.player.MODE = CORNER;
+ this.player.img = img;
+
+ this.speed = w;
+
this.direction = "stop";
+
this.tileMovement = function() {
push();
-
- var sc = width / 15;
- var p = locatePlayer(this.player.pos.x, this.player.pos.y, 15, 15);
- fill(150, map(this.player.pos.x, 0, width, 255, 0), map(this.player.pos.y, 0, width, 0, 255));
- rect(p.x * sc, p.y * sc, sc, sc);
+ /*var sc = width / 10;
+ var p = locatePlayer(this.player.pos.x, this.player.pos.y, 15, 15);
+ fill(150, map(this.player.pos.x, 0, width, 255, 0), map(this.player.pos.y, 0, width, 0, 255));
+ rect(p.x, p.y , sc, sc);
+ image(playerSprite,p.x , p.y , 50,100);*/
+ image(playerSprite,this.player.pos.x , this.player.pos.y , 50,100);
+
pop();
}
this.move = function(item) {
// rect(this.player.pos.x-100, this.player.pos.y-100, 200, 200)
- this.player.arrowkeys(this.speed, -this.speed, -this.speed, this.speed);
+ // this.player.arrowkeys(this.speed, -this.speed, -this.speed, this.speed);
// this.player.arrowkeys(function(movement){
// movement.vel.x +=1;
// movement.direction ="left";
diff --git a/scripts/tower.js b/scripts/tower.js
new file mode 100644
index 0000000..496645a
--- /dev/null
+++ b/scripts/tower.js
@@ -0,0 +1,45 @@
+p5.prototype.Tower = function(x, y, w, h,img){
+ return new createTower(x, y, w, h,img);
+}
+function createTower(x, y, w, h,img) {
+ // this.baseTower = Entity(x, y, w, h, null, CORNER);
+ // x, y, w, h, Color, mode, speed, angle, debug, name, type, img
+ this.pos = createVector(x , y);
+ this.vel = createVector(0, 0);
+ this.acc = createVector(0, 0);
+ this.upperTower = Entity(x, y , w , h , "blue", CORNER, null, null, null, null, "image", img);
+ // this.upperTower = Entity(x + w * 0.5, y + h * 0.5, w * 0.5, h * 0.5, "blue", CORNER, null, null, null, null, "image", img);
+
+ this.w = w;
+ this.h = h;
+ this.gun = Gun();
+
+ this.show = function() {
+ if(frameCount % 250 === 0){
+ this.fire();
+ }
+ this.baseTower.show();
+ this.upperTower.show();
+ this.gun.show();
+ }
+ this.movement = function() {
+ }
+
+ this.screenwrap = function(){
+ }
+
+ this.run = function() {
+ this.movement();
+ this.show();
+ }
+ this.bullet = function(){
+ }
+
+ this.randomDirection = function(){
+ return random(["right", "left", "up", "down"]);
+ }
+
+ this.fire = function(){
+ this.gun.fire(this.pos.x, this.pos.y + this.h / 2.0, this.randomDirection());
+ }
+}
\ No newline at end of file
diff --git a/sketch.js b/sketch.js
index a443c91..ca16ed2 100644
--- a/sketch.js
+++ b/sketch.js
@@ -1,39 +1,137 @@
var player;
var gun;
+var tower;
+var game;
+var bg;
+var house;
+var gameOverImage;
+var playerSprite;
+var gameOverVisable = false;
+
+
+var t;
+function preload() {
+ bg = loadImage("./img/grass2.png");
+ house = loadImage("./img/house1.png");
+
+ playerSprite = loadImage("./img/front_man.png");
+ gameOverImage = loadImage("./img/gameOver.png");
+}
+
+function gameOver(visable) {
+ if (visable) {
+ image(gameOverImage, 0, 0, width, height);
+ }
+}
function setup() {
createCanvas(600, 600);
- player = Player();
+ noSmooth();
+ player = Player(playerSprite,100,300,100,100);
gun = Gun();
+ game = Game();
+ tower = Tower(100, 100, 100, 100, house);
+ game.setplayer(player);
+ game.include(tower);
background(50);
}
function draw() {
- background(50);
+ background(bg);
+ var a = player.player;//Entity(mouseX, mouseY, 30, 30, null, CORNER);
+ // a.pos.y += 100;
+ var b = t;
+ // rect(a.pos.x, a.pos.y, a.w, a.h);
+ // rect(a.pos.x, a.pos.y,5,5);
+
player.move();
player.tileMovement();
-
+
+ tower.upperTower.run();
+
gun.show();
-
+ // print(playerCollision(a,tower.upperTower))
+ // playerCollision(a,tower.upperTower)
+bulletCollsion(gun,tower.upperTower)
+ game.run();
fill(color("white"));
textSize(30);
- text("Arrows, and Z to shoot",100,height-60);
+ text("Arrows, and Z to shoot", 100, height - 60);
+ gameOver(gameOverVisable);
+}
+function bulletCollsion(bulletArray,targer){
+
+ // var apos = a.pos.copy();
+ try{
+ var apos = gun.bullets[0].bullet.pos.copy();
+ collideRectRect(apos.x, apos.y , a.w, a.h, b.pos.x, b.pos.y, b.w, b.h);
+ collideRectRect()
+
+ }catch(e){
+ console.error("ERROR: bulletCollsion() :"+e);
+ }
+}
+function playerCollision (a,b,offsetx,offsety) {
+ var apos = a.pos.copy();
+ try{
+ return collideRectRect(apos.x + offsetx+2, apos.y + offsety +2, a.w-4, a.h-4, b.pos.x, b.pos.y, b.w, b.h);
+ }catch(e){
+ console.error("ERROR: playerCollision() function shit the bed"+e);
+ }
}
-function keyPressed(){
- if(key === "Z"){
- var t = input.player.pos.copy()
- var dir = input.player.direction;
+function keyPressed() {
+ if (key === "Z") {
+ var playerPos = player.player.pos.copy()
//
//starting x,y, and Direction to fire ex: "up","down","right"
- gun.fire(t.x,t.y, dir);
+ gun.fire(playerPos.x, playerPos.y);
print("shoot");
}
+
+ if(key === "=") {
+ gameOverVisable = true;
+ }
+ if(keyCode === RIGHT_ARROW) {
+
+ if(!playerCollision(player.player,tower.upperTower,100,0)){
+ player.player.pos.x += 100;
+ }
+
+ gun.currentDirection = "right";
+ }
+ if(keyCode === UP_ARROW) {
+ if(!playerCollision(player.player,tower.upperTower,0,-100)){
+ player.player.pos.y -= 100;
+ }
+ gun.currentDirection = "up";
+ }
+ if(keyCode === LEFT_ARROW) {
+ if(!playerCollision(player.player,tower.upperTower,-100,0)){
+ player.player.pos.x -= 100;
+ }
+ gun.currentDirection = "left";
+ }
+ if(keyCode === DOWN_ARROW) {
+ if(!playerCollision(player.player,tower.upperTower,0,100)){
+ player.player.pos.y += 100;
+ }
+ gun.currentDirection = "down";
+ }
+ print(this)
}
-function mousePressed(){
+
+function collide(a, b,func) {
+ if (a && b) {
+ func(collideRectRect(a.pos.x, a.pos.y, a.w, a.h, x, y, w, h));
+ }
}
+function mousePressed() {
+ var playerPos = player.player.pos.copy()
+ gun.fire(playerPos.x, playerPos.y);
+}
\ No newline at end of file