Last active
January 30, 2019 04:51
-
-
Save yichenlilyc/8bc49c6dd271e478d4d5f105d694c2b7 to your computer and use it in GitHub Desktop.
SCRIPT-8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { PI, atan2, ceil, floor, min, max, sign, abs, round } = Math | |
initialState = { | |
mode:'title', | |
checks:[], | |
x:4, | |
y:65, | |
bx:random(60,127), | |
by:random(18,115), | |
cx:random(60,127), | |
cy:random(18,115), | |
dx:random(60,127), | |
dy:random(18,115), | |
ex:random(60,127), | |
ey:random(18,115), | |
fx:random(60,127), | |
fy:random(18,115), | |
counter:0, | |
lives: 0, | |
score:0, | |
elapse:0, | |
// actors: [...initialActors] | |
} | |
const planeActivity= ({ state, input }) => { | |
//const plane = state.actors.find(d => d.name === 'plane') | |
if (fsm.state === 'fly') { | |
movePlane({state,input}) | |
} | |
} | |
const movePlane = ({ state, input }) => { | |
//const plane = state.actors.find(d => d.name === 'plane') | |
if (input.left) { | |
//state.x -= 1 | |
if (state.x>127){ | |
state.x=127 | |
} | |
else if (state.x<1){ | |
state.x=1 | |
} | |
else{ | |
state.x-=1 | |
} | |
state.flip=true | |
} | |
if (input.right) { | |
if (state.x>120){ | |
state.x=120 | |
} | |
else if (state.x<0){ | |
state.x=0 | |
} | |
else{ | |
state.x+=1 | |
} | |
state.flip=false | |
} | |
if (input.up) { | |
if (state.y>115){ | |
state.y=115 | |
} | |
else if (state.y<18){ | |
state.y=18 | |
} | |
else{ | |
state.y-=1 | |
} | |
} | |
if (input.down) { | |
if (state.y>115){ | |
state.y=115 | |
} | |
else if (state.y<18){ | |
state.y=18 | |
} | |
else{ | |
state.y+=1 | |
} | |
} | |
} | |
const moveBlock= state => { | |
state.bx-=random(0.3,2) | |
state.cx+=random(0.3,2) | |
state.dx-=random(0.3,2) | |
state.ex+=random(0.3,2) | |
state.fx-=random(0.3,2) | |
state.by-=random(0.3,2) | |
state.cy+=random(0.3,2) | |
state.dy-=random(0.3,2) | |
state.ey+=random(0.3,2) | |
state.fy-=random(0.3,2) | |
} | |
update= (state, input,elapsed) => { | |
state.checks = [] | |
if (state.mode === 'play') { | |
state.elapsed += elapsed | |
movePlane({ state, input }) | |
if (state.by>=115){ | |
state.by=114 | |
} | |
else if (state.by<=18){ | |
state.by=114 | |
} | |
else{ | |
state.by-=random(0.1,1) | |
} | |
if (state.cy>=115){ | |
state.cy=114 | |
} | |
else if (state.cy<=18){ | |
state.cy=114 | |
} | |
else{ | |
state.cy-=random(0.1,1) | |
} | |
if (state.dy>=115){ | |
state.dy=19 | |
} | |
else if (state.dy<=18){ | |
state.dy=19 | |
} | |
else{ | |
state.dy+=random(0.1,1) | |
} | |
if (state.ey>=115){ | |
state.ey=19 | |
} | |
else if (state.by<=18){ | |
state.ey=19 | |
} | |
else{ | |
state.ey+=random(0.1,1) | |
} | |
if (state.fy>=115){ | |
state.fy=114 | |
} | |
else if (state.fy<=18){ | |
state.fy=114 | |
} | |
else{ | |
state.fy-=random(0.1,1) | |
} | |
if (state.bx>=120){ | |
state.bx=1 | |
} | |
else if (state.bx<=0){ | |
state.bx=1 | |
} | |
else{ | |
state.bx+=random(0.1,1) | |
} | |
if (state.cx>=120){ | |
state.cx=1 | |
} | |
else if (state.cx<=0){ | |
state.cx=1 | |
} | |
else{ | |
state.cx+=random(0.1,1) | |
} | |
if (state.dx>=120){ | |
state.dx=119 | |
} | |
else if (state.dx<=0){ | |
state.dx=119 | |
} | |
else{ | |
state.dx-=random(0.1,1) | |
} | |
if (state.ex>=120){ | |
state.ex=119 | |
} | |
else if (state.ex<=0){ | |
state.ex=119 | |
} | |
else{ | |
state.ex-=random(0.1,1) | |
} | |
if (state.fx>=120){ | |
state.fx=1 | |
} | |
else if (state.fx<=0){ | |
state.fx=1 | |
} | |
else{ | |
state.fx+=random(0.1,1) | |
} | |
if (state.bx-8<=state.x&&state.x<=state.bx+8&&state.by-8<=state.y&&state.y<=state.by+8&&state.lives>0){ | |
state.mode = 'die' | |
} | |
if (state.cx-8<=state.x&&state.x<=state.cx+8&&state.cy-8<=state.y&&state.y<=state.cy+8&&state.lives>0){ | |
state.mode = 'die' | |
} | |
if (state.dx-8<=state.x&&state.x<=state.dx+8&&state.dy-8<=state.y&&state.y<=state.dy+8&&state.lives>0){ | |
state.mode = 'die' | |
} | |
if (state.ex-8<=state.x&&state.x<=state.ex+8&&state.ey-8<=state.y&&state.y<=state.ey+8&&state.lives>0){ | |
state.mode = 'die' | |
} | |
if (state.fx-8<=state.x&&state.x<=state.fx+8&&state.fy-8<=state.y&&state.y<=state.fy+8&&state.lives>0){ | |
state.mode = 'die' | |
} | |
else if(state.x==state.bx&&state.lives<=0){ | |
state.mode='gameOver' | |
} | |
}else if (state.mode === 'title') { | |
if (input.a) { | |
state.counter = 0 | |
state.lives = 3 | |
state.mode = 'play' | |
} | |
}else if(state.mode==='die'){ | |
if (input.a) { | |
state.lives-=1 | |
state.counter = 0 | |
state.mode = 'play' | |
} | |
//state.mode='play' | |
}else if (state.mode==='gameOver'){ | |
} | |
} | |
const drawTopBar = state => { | |
//camera(0) | |
//rectFill(0, 11, 128, -6, 5) // clear | |
sprite(16, 1, 0) | |
print(28, 2, state.lives.toString().padStart(2, '0'), 0) // lives | |
print(74, 2, 'score:', 0) | |
print(106, 2, round(state.elapsed/1000) , 0) // score | |
// rectFill(0, 6, 44, 8, 7) // clear bottom | |
} | |
draw=state=>{ | |
clear() | |
//const plane = state.actors.find(d => d.name === 'plane') | |
// const cloud = state.actors.find(d => d.name === 'smallcloud') | |
// map(0,0) | |
//sprite(state.x,state.y,0,0,state.flip) | |
if (state.mode === 'title') { | |
//map(0,0) | |
drawTopBar(state) | |
rectFill(29, 34, 70, 25, 1) | |
rectFill(30, 35, 70, 25, 5) | |
rectFill(30, 35, 69, 24, 3) | |
rectFill(99, 34, 1, 1, 4) | |
rectFill(29, 59, 1, 1, 4) | |
print(43, 45, 'crazy Plane', 0) | |
print(19, 74, 'left / right / up / down', 3) | |
print(34, 88, 'PRESS A TO START', 3) | |
} | |
if (state.mode==='play'){ | |
drawTopBar(state) | |
const plane = sprite(state.x,state.y,0,state.flip) | |
const block=rectFill(state.bx,state.by,8,10,0) | |
const block2=rectFill(state.cx,state.cy,8,10,0) | |
const block3=rectFill(state.dx,state.dy,8,10,0) | |
const block4=rectFill(state.ex,state.ey,8,10,0) | |
const block5=rectFill(state.fx,state.fy,8,10,0) | |
const edgeup=rectFill(0, 17, 127, -3, 1) | |
const edgedown=rectFill(0, 127, 127, -3, 1) | |
//map(0,0) | |
} | |
if(state.mode==='die'){ | |
clear() | |
print(46, 58,'game over!', 3) | |
drawTopBar(state) | |
} | |
if(state.mode==='gameOver'){ | |
print(19, 74, 'game over!', 3) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"0": [ | |
" 01 ", | |
" 01 ", | |
" 01 ", | |
"43 34343", | |
" 434343 ", | |
" 01 ", | |
" 01 ", | |
" 01 " | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment