xxxxxxxxxx
73
let FPS = 60
let playerRad = 50
let pXY = [200,200]
let apple=[]
let i=[]
let ifrugt=[]
let rand
let iban
let iæb
function preload(){
i.push(loadImage('/assets/GlintingThicket.png'))
i.push(loadImage('/assets/DiceyMeadow.png'))
i.push(loadImage('/assets/AstralOasis.png'))
}
function setup() {
createCanvas(400, 400);
//apple.push(new items([0,0],[random(0,width),random(0,height)],3,1,1,50))
for(let i=1;i<3;i++){
let s='/assets/'+str(i)+'.png'
print('/assets/1.png')
print(s)
ifrugt.push(loadImage(s))
}
apple.push(new items([0,0],[random(0,width),random(0,height)],3,2,1,50))
rand=round(random()*3-0.5)
console.log(ifrugt)
}
function draw() {
background(0);
image(i[rand],width/2,height/2,width,height,0,0,i[rand].width,i[rand].height,COVER)
imageMode(CENTER)
angleMode(DEGREES) //Til Mads: Hvis det her messer med dine radianer kan du flytte den ned i tegn()
circle(pXY[0],pXY[1],playerRad)
apple[0].move()
apple[0].tegn()
}
class items{
constructor(dir,xy,dmg,type,size,vel){
this.dir=dir
let i=floor(random()*4)
print(i)
this.xy=[(i>1)*random()*width+(i<2)*i*width,(i<2)*random()*height+(i>1)*(i-2)*height]
this.dmg=dmg
this.type=type
this.size=size
this.vel=vel
}
move(){
let xDif = pXY[0]-this.xy[0]
let yDif = pXY[1]-this.xy[1]
this.dir = [xDif/sqrt(sq(xDif)+sq(yDif)),yDif/sqrt(sq(xDif)+sq(yDif))]
this.xy[0] += this.dir[0]*this.vel/FPS
this.xy[1] += this.dir[1]*this.vel/FPS
}
tegn(){
push()
translate(this.xy[0], this.xy[1]);
rotate(frameCount/0.1)
image(ifrugt[this.type-1],0,0,ifrugt[this.type-1].width/20*this.size,ifrugt[this.type-1].height/20*this.size)
pop()
}
}