Asteroids/src/index.js

33 lines
917 B
JavaScript

import * as paper from "paper";
class Ship{
constructor(size, position){
this.size = size;
this.position = position;
this.nodes = [
new paper.Point(this.position.x, this.position.y-this.size),
new paper.Point(this.position.x+this.size/2, this.position.y),
new paper.Point(this.position.x-this.size/2, this.position.y),
new paper.Point(this.position.x, this.position.y-this.size)
];
this.path = new paper.Path(this.nodes);
this.path.strokeColor = "#333333";
}
update(){
this.path.rotate(3);
}
};
//initialization
const canvas = document.getElementById("canvas");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
paper.setup(canvas);
const ship = new Ship(30, new paper.Point(canvas.width/2, canvas.height/2));
paper.view.onFrame = (event) => {
ship.path.rotate(3);
}