xxxxxxxxxx
78
let width=1000
let height=750
let bwidth=80
let bheight=80
let blocks=[]
let camera=[10,0]
let x=[10,-1]
let topb=[]
let drilling=0
let velY=0
let velX=0
let air=0
function setup() {
createCanvas(width, height);
for(let i=0;i<20;i++){
blocks.push([])
for(let j=0;j<20;j++){
let r='mud'
if(random()<0.1){
r='gold'
}
blocks[i].push(new block([i,j],r))
topb.push(0)
}
}
}
function draw() {
background(220);
let ground = min(topb[floor(x[0]+0.1)]-1,topb[floor(x[0]+0.9)]-1)
air=(x[1]<ground+velY)||keyIsDown(UP_ARROW)
mleft=1-min(blocks[floor(x[0])][(floor(x[1])>=0)*ceil(x[1])].vis,x[1]>-1)
mright=1-min(blocks[ceil(x[0])][(floor(x[1])>=0)*ceil(x[1])].vis,x[1]>-1)
velY=air*(velY+(1-2*keyIsDown(UP_ARROW))/3/bheight)
velX=air*velX
x[0]+=((x[0]<19.9)*2*keyIsDown(RIGHT_ARROW)*mright-(x[0]>0.1)*2*keyIsDown(LEFT_ARROW)*mleft+velX)/bwidth
x[1]=floor(x[1])*(1-air)+air*(x[1]+velY)
camera[0]+=((x[0]-camera[0]>3)-(x[0]-camera[0]<-4))/bwidth
camera[1]+=velY*((x[1]-camera[1]>3)+(x[1]-camera[1]<-4))
noStroke()
fill('blue')
rect(0,0,width,height)
fill('red')
rect((x[0]-camera[0]+5.1)*bwidth,(x[1]-camera[1]+5.1)*bheight,bwidth*0.8,bheight*0.9)
//print(x[1])
for(let i=floor(max(camera[0]-5,0));i<floor(max(camera[0]+6,0));i++){
for(let j=floor(max(camera[1]-5,0));j<floor(max(camera[1]+6,0));j++){
blocks[i][j].show(camera)
}
}
if(drilling>0){
}
}
class block{
constructor(pos,type){
this.pos=pos
this.type=type
this.vis=1
}
show(cam){
//print(this.pos[0]+','+this.pos[1])
if(this.vis){
let col='#643E30'
if(this.type=='gold'){col='gold'}
fill(col)
rect(bwidth*(max(this.pos[0]-cam[0]+5,0)),bheight*(max(this.pos[1]-cam[1]+5,0)),bwidth,bheight)}
}
collision(x){
}
}
function keyPressed(){
if(air==0&&keyCode!=UP_ARROW){
let blo = blocks[round(x[0])+(x[0]-floor(x[0])<0.2)*(keyCode==RIGHT_ARROW)-(ceil(x[0])-x[0]<0.2)*(keyCode==LEFT_ARROW)][max(x[1]+(keyCode==DOWN_ARROW),0)]
blo.vis=(blo.type=='rock')
topb[blo.pos[0]]+=blo.pos[1]==topb[blo.pos[0]]
}
}