Skip to content

Commit

Permalink
start decorations
Browse files Browse the repository at this point in the history
  • Loading branch information
Viet281101 committed Dec 17, 2023
1 parent 02ef354 commit 6168b22
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 3 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 27 additions & 3 deletions js/game/lvl1/game-01.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ const Game = function() {
},
};

Game.Frame = function(x, y, width, height, offset_x, offset_y) {
Game.Frame = function(x, y, width, height, offset_x = 0, offset_y = 0) {
this.x = x;
this.y = y;
this.width = width;
Expand All @@ -194,6 +194,30 @@ const Game = function() {
/* I added getCenterX, getCenterY, setCenterX, and setCenterY */
Game.Object.prototype = {
constructor:Game.Object,

/* Now does rectangular collision detection. */
collideObject:function(object) {

if (this.getRight() < object.getLeft() ||
this.getBottom() < object.getTop() ||
this.getLeft() > object.getRight() ||
this.getTop() > object.getBottom()) return false;

return true;
},

/* Does rectangular collision detection with the center of the object. */
collideObjectCenter:function(object) {

let center_x = object.getCenterX();
let center_y = object.getCenterY();

if (center_x < this.getLeft() || center_x > this.getRight() ||
center_y < this.getTop() || center_y > this.getBottom()) return false;

return true;
},

getBottom : function() { return this.y + this.height; },
getCenterX: function() { return this.x + this.width * 0.5; },
getCenterY: function() { return this.y + this.height * 0.5; },
Expand Down Expand Up @@ -330,7 +354,7 @@ const Game = function() {
this.changeFrameSet(this.frame_sets["sit-left"], "once", 10);
this.squatting = false;
} else if (this.attacking) {
this.changeFrameSet(this.frame_sets["attack-left"], "once", 5);
this.changeFrameSet(this.frame_sets["attack-left"], "loop", 5);
this.attacking = false;
} else {
this.changeFrameSet(this.frame_sets["idle-left"], "loop", 6);
Expand All @@ -342,7 +366,7 @@ const Game = function() {
this.changeFrameSet(this.frame_sets["sit-right"], "once", 10);
this.squatting = false;
} else if (this.attacking) {
this.changeFrameSet(this.frame_sets["attack-right"], "once", 5);
this.changeFrameSet(this.frame_sets["attack-right"], "loop", 5);
this.attacking = false;
} else {
this.changeFrameSet(this.frame_sets["idle-right"], "loop", 6);
Expand Down

0 comments on commit 6168b22

Please sign in to comment.