Richardcsts

Members
  • Content Count

    4
  • Joined

  • Last visited

Everything posted by Richardcsts

  1. I making a platform game function hitTestRectangle(r1, r2) { //Define the variables we'll need to calculate let hit, combinedHalfWidths, combinedHalfHeights, vx, vy; //hit will determine whether there's a collision hit = false; //Find the center points of each sprite r1.centerX = r1.x + r1.width / 2; r1.centerY = r1.y + (r1.height / 2); r2.centerX = r2.x + r2.width / 2; r2.centerY = r2.y + r2.height / 2; //Find the half-widths and half-heights of each sprite r1.halfWidth = (r1.width / 2 ); r1.halfHeight = (r1.height / 2); r2.halfWidth = r2.width / 2; r2.halfHeight = r2.height / 2; //Calculate the distance vector between the sprites vx = r1.centerX - r2.centerX; vy = r1.centerY - r2.centerY; //Figure out the combined half-widths and half-heights combinedHalfWidths = r1.halfWidth + r2.halfWidth; combinedHalfHeights = r1.halfHeight + r2.halfHeight; //Check for a collision on the x axis if (Math.abs(vx) < combinedHalfWidths) { //A collision might be occurring. Check for a collision on the y axis if (Math.abs(vy) < combinedHalfHeights) { //There's definitely a collision happening hit = true; } else { //There's no collision on the y axis hit = false; } } else { //There's no collision on the x axis hit = false; } //`hit` will be either `true` or `false` return hit; }; I need a collision point ignoring the player's foot, the game I'm doing is the platform game to be more precise. I want a collider that allows the character to move, but keeping the block collision, vertical and horizontal Image of the bug, the player collides vertically but does not collide horizontally https://imgur.com/a/fNqpni1
  2. Today I was playing a game made in javascript, and in the game files I had several javascript files and one communicating with the other being that they all started as follows (function(){ //Codigo })(); How do I create separate files from the current one and all starting with this code so that nobody can access the function via the google chrome console?
  3. Thank you so much!!! ❤️ i love this forum
  4. Hoje eu estava aprendendo a mexer com a biblioteca Pixi.js, e estava recriando um joguinho que vi na playstore, e eu recebi um undefined mas não entendi o porquê. function Block(blockType_, x, y, id){ this.id = 0; this.blockType = blockType_ this.x = x this.y = y this.timeToBreak = new Date().getTime()-2000 //O undefined é desta variável this.hitpoints = 50; this.sprite = new PIXI.Sprite( PIXI.loader.resources[this.blockType.url].texture ) this.sprite.interactive = true; this.show = function(){ if(this.hitpoints > 0){ this.sprite.position.set(this.x, this.y) app.stage.addChild(this.sprite) } } this.sprite.on("mousedown", function(){ console.log(this.timeToBreak) //Recebi o undefined ao printar no console do navegador }) Se alguém poder me ajudar e me explicar, fico imensamente agradecido!