This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections.Generic; | |
| using UnityEngine; | |
| using UnityEngine.UIElements; | |
| using UnityEngine.EventSystems; | |
| using UnityEngine.Rendering; | |
| namespace Katas.Experimental | |
| { | |
| public class WorldSpaceUIDocument : MonoBehaviour, IPointerMoveHandler, IPointerUpHandler, IPointerDownHandler, | |
| ISubmitHandler, ICancelHandler, IMoveHandler, IScrollHandler, ISelectHandler, IDeselectHandler, IDragHandler |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var animate = window.requestAnimationFrame || | |
| window.webkitRequestAnimationFrame || | |
| window.mozRequestAnimationFrame || | |
| function(callback) { window.setTimeout(callback, 1000/60) }; | |
| var CANVAS_WIDTH = 400; | |
| var CANVAS_HEIGHT = 600; | |
| var PADDLE_HEIGHT = 10; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ///////////////////////////////////////////////////////// | |
| // COMPUTER | |
| ///////////////////////////////////////////////////////// | |
| Computer.prototype.update = function(ball) { | |
| var x_pos = ball.x; | |
| var diff = -((this.paddle.x + (this.paddle.width / 2)) - x_pos); | |
| if(diff < 0 && diff < -PADDLE_MAX_SPEED) { // max speed left | |
| diff = -PADDLE_MAX_SPEED; | |
| } else if(diff > 0 && diff > PADDLE_MAX_SPEED) { // max speed right |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ///////////////////////////////////////////////////////// | |
| // CONTROLS | |
| ///////////////////////////////////////////////////////// | |
| var keysDown = {}; | |
| window.addEventListener("keydown", function(event) { | |
| keysDown[event.keyCode] = true; | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ///////////////////////////////////////////////////////// | |
| // PLAYER | |
| ///////////////////////////////////////////////////////// | |
| function Player() { | |
| this.paddle = new Paddle((canvas.width - PADDLE_WIDTH) / 2, canvas.height - 10 - PADDLE_HEIGHT, PADDLE_WIDTH, PADDLE_HEIGHT, "#0000FF"); | |
| } | |
| Player.prototype.render = function() { | |
| this.paddle.render(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ///////////////////////////////////////////////////////// | |
| // PADDLES | |
| ///////////////////////////////////////////////////////// | |
| function Paddle(x, y, width, height, color) { | |
| this.x = x; | |
| this.y = y; | |
| this.width = width; | |
| this.height = height; | |
| this.x_speed = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if(top_y > canvas.height / 2) { | |
| if(top_y < (paddle1.y + paddle1.height) && bottom_y > paddle1.y && top_x < (paddle1.x + paddle1.width) && bottom_x > paddle1.x) { | |
| // hit the player's paddle | |
| this.y_speed = -3; | |
| this.x_speed += (paddle1.x_speed / 2); | |
| this.y += this.y_speed; | |
| this.color = paddle1.color; | |
| } | |
| } else { | |
| if(top_y < (paddle2.y + paddle2.height) && bottom_y > paddle2.y && top_x < (paddle2.x + paddle2.width) && bottom_x > paddle2.x) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if(this.x - 5 < 0) { // hitting the left wall | |
| this.x = 5; | |
| this.x_speed = -this.x_speed; | |
| } else if(this.x + 5 > canvas.width) { // hitting the right wall | |
| this.x = canvas.width - this.radius; | |
| this.x_speed = -this.x_speed; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if(this.y < 0 || this.y > canvas.height) { // a point was scored | |
| this.x_speed = this.x_initial_speed; | |
| this.y_speed = this.y_initial_speed; | |
| this.x = canvas.width / 2; | |
| this.y = canvas.height / 2; | |
| this.color = "#FFFFFF"; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ///////////////////////////////////////////////////////// | |
| // BALL | |
| ///////////////////////////////////////////////////////// | |
| function Ball(x,y) { | |
| this.x = x; | |
| this.y = y; | |
| this.x_initial_speed = 0; | |
| this.y_initial_speed = 3; | |
| this.x_speed = this.x_initial_speed; |
NewerOlder