xxxxxxxxxx
83
let FPS = 60
let playerRad = 50
let pXY = [200,200]
let apple=[]
let i=[]
let rand
let ifrugt=[]
let sl=30//sl er shield length
let direction=0
let agility=360/60
let sz= 50// sz er shield size fordi ss er sus
function preload(){
i.push(loadImage('/assets/GlintingThicket.png'))
i.push(loadImage('/assets/DiceyMeadow.png'))
for(let i=1;i<3;i++){
ifrugt.push(loadImage('assets/'+i+'.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))
apple.push(new items([0,0],[random(0,width),random(0,height)],3,1,1,50))
rand=round(random()*3-0.5)
}
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()
fill("white")
strokeWeight(1)
circle(pXY[0],pXY[1],playerRad)
apple[0].move()
apple[0].collision()
apple[0].tegn()
direction+=(keyIsDown(RIGHT_ARROW)-keyIsDown(LEFT_ARROW))*agility
noFill()
strokeWeight(2.5)
stroke("white")
arc(pXY[0],pXY[1],playerRad+sz,playerRad+sz,-sl+direction,sl+direction )
}
class items{
constructor(dir,xy,dmg,type,size,vel){
this.dir=dir
this.xy=xy
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()
}
collision(){
let distance=sqrt(sq(pXY[0]-this.xy[0])+sq(pXY[1]-this.xy[1]))
let angle=asin((pXY[1]-this.xy[1])/distance)
if (distance<playerRad+this.size) {
print("du blev ramt")
}
//abs(angle-direction)<sl hvis apple er i retning af skjoldet
}
}