Skip to content

Instantly share code, notes, and snippets.

@claytical
Created November 17, 2015 16:18
Show Gist options
  • Save claytical/b41b8521bc2d49f389e8 to your computer and use it in GitHub Desktop.
Save claytical/b41b8521bc2d49f389e8 to your computer and use it in GitHub Desktop.
Simple p5.play Example
var sprite;
var angle;
var speed;
function setup() {
createCanvas(windowWidth,windowHeight);
sprite = createSprite(width/2, height/2, 50, 50);
speed = 1;
angle = 270;
}
function draw() {
background(255,255,255);
sprite.setSpeed(speed, angle);
drawSprites();
checkForWallCollisions();
}
function checkForWallCollisions() {
if (sprite.position.x > width) {
angle = 180;
}
if (sprite.position.x < 0) {
angle = 0;
}
if (sprite.position.y > height) {
angle = 270;
}
if (sprite.position.y < 0) {
angle = 90;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment