Created
November 17, 2015 16:18
-
-
Save claytical/b41b8521bc2d49f389e8 to your computer and use it in GitHub Desktop.
Simple p5.play Example
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 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