-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.js
More file actions
31 lines (27 loc) · 839 Bytes
/
player.js
File metadata and controls
31 lines (27 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//constructor function for player object
function Player() {
this.x = 13; //left player
this.y = height / 2;
this.v = 5; //pixel speed that player will move
this.w = 20; //width attribute
this.h = 80; //height attribute
this.score = 0;
//this function will show in which position the player is
this.show = () => {
rectMode(CENTER); //center the plater
rect(this.x, this.y, this.w, this.h) //the player is a rectangle
}
// function for the player movement
// the player will follow the mouse
this.move = () =>
{
//mouse in Y position
if( mouseY < this.y ) //if mouse is above platform
{
this.y = this.y - this.v; //reduce speed
}else if( mouseY > this.y )
{
this.y = this.y + this.v;
}
}
}