DEV Community

极客宫
极客宫

Posted on

a game with makecode for arcade

scene.setBackgroundColor(100)
const speed=80

let hero = sprites.create(img
. . . . . f f f f . . . . .
. . . f f 5 5 5 5 f f . . .
. . f 5 5 5 5 5 5 5 5 f . .
. f 5 5 5 5 5 5 5 5 5 5 f .
. f 5 5 5 d b b d 5 5 5 f .
f 5 5 5 b 4 4 4 4 b 5 5 5 f
f 5 5 c c 4 4 4 4 c c 5 5 f
f b b f b f 4 4 f b f b b f
f b b 4 1 f d d f 1 4 b b f
. f b f d d d d d d f b f .
. f e f e 4 4 4 4 e f e f .
. e 4 f 6 9 9 9 9 6 f 4 e .
. 4 d c 9 9 9 9 9 9 c d 4 .
. 4 f b 3 b 3 b 3 b b f 4 .
. . f f 3 b 3 b 3 3 f f . .
. . . . f f b b f f . . . .
,SpriteKind.Player)
sprites.setDataNumber(hero, "blood", 100)
controller.moveSprite(hero)
hero.setStayInScreen(true)
// scene.cameraFollowSprite(hero)

let statusbar = statusbars.create(20, 2, 0)
statusbar.attachToSprite(hero)
statusbar.max=100

controller.player1.onButtonEvent(ControllerButton.Left, ControllerButtonEvent.Pressed, function() {
animation.runImageAnimation(hero, [img
. . . f f f c c c . . . . .
. f f 5 5 5 5 5 5 f f . . .
. f 5 5 5 5 5 5 5 5 5 f . .
f 5 5 5 5 5 5 5 5 5 5 5 c .
f 5 5 b d 5 5 5 5 5 5 5 c .
f 5 d 4 4 b 5 5 5 5 5 5 5 f
f 5 b 4 4 4 c c 5 5 5 5 5 f
f f f 4 4 c b c b 5 5 5 b f
. f f d d c 1 e b b b b b c
. . f d d d d 4 f b b b b c
. . f 4 4 4 e e e 4 b b c .
. . f 9 9 9 e d d 4 f f . .
. . f 9 9 9 e d d e f . . .
. f 3 3 b 3 b e e b f . . .
. f f 3 b 3 b 3 b f f . . .
. . . f f b b f f . . . . .
,img
. . . . . . . . . . . . . .
. . . f f f c c c . . . . .
. f f 5 5 5 5 5 5 f f . . .
. f 5 5 5 5 5 5 5 5 5 f . .
f 5 5 5 5 5 5 5 5 5 5 5 c .
f 5 5 b d 5 5 5 5 5 5 5 5 c
f 5 d 4 4 b 5 5 5 5 5 5 5 f
f 5 b 4 4 4 c c 5 5 5 5 5 f
. f f 4 4 c b c b 5 5 5 b f
. . f d d c 1 e b b b b b c
. . c d d d d e e b b b b c
. . c 4 4 4 e d d 4 b b c .
. . c 9 9 9 e d d e c c . .
. c b b b b b e e b b c . .
. c 3 b 3 b 3 3 3 b c . . .
. . c c c b b c c c . . . .
],speed,true)
})
controller.player1.onButtonEvent(ControllerButton.Right, ControllerButtonEvent.Pressed, function() {
animation.runImageAnimation(hero, [img
. . . . . c c c f f f . . .
. . . f f 5 5 5 5 5 5 f f .
. . f 5 5 5 5 5 5 5 5 5 f .
. c 5 5 5 5 5 5 5 5 5 5 5 f
. c 5 5 5 5 5 5 5 d b 5 5 f
f 5 5 5 5 5 5 5 b 4 4 d 5 f
f 5 5 5 5 5 c c 4 4 4 b 5 f
f b 5 5 5 b c b c 4 4 f f f
c b b b b b e 1 c d d f f .
c b b b b f 4 d d d d f . .
. c b b 4 e e e 4 4 4 f . .
. . f f 4 d d e 9 9 9 f . .
. . . f e d d e 9 9 9 f . .
. . . f b e e b 3 b 3 3 f .
. . . f f b 3 b 3 b 3 f f .
. . . . . f f b b f f . . .
,img
. . . . . . . . . . . . . .
. . . . . c c c f f f . . .
. . . f f 5 5 5 5 5 5 f f .
. . f 5 5 5 5 5 5 5 5 5 f .
. c 5 5 5 5 5 5 5 5 5 5 5 f
c 5 5 5 5 5 5 5 5 d b 5 5 f
f 5 5 5 5 5 5 5 b 4 4 d 5 f
f 5 5 5 5 5 c c 4 4 4 b 5 f
f b 5 5 5 b c b c 4 4 f f .
c b b b b b e 1 c d d f . .
c b b b b e e d d d d c . .
. c b b 4 d d e 4 4 4 c . .
. . c c e d d e 9 9 9 c . .
. . c b b e e b b b b b c .
. . . c b 3 3 3 b 3 b 3 c .
. . . . c c c b b c c c . .
],speed,true)
})
controller.player1.onButtonEvent(ControllerButton.Up, ControllerButtonEvent.Pressed, function() {
animation.runImageAnimation(hero, [img
. . . . . . . . . . . . . .
. . . . . f f f f . . . . .
. . . f f 5 5 5 5 f f . . .
. . f 5 5 5 5 5 5 5 b f . .
. f 5 5 5 5 5 5 5 5 5 b f .
f d 5 5 5 5 5 5 5 5 5 b f .
f d 5 5 5 5 5 5 5 5 d b b f
f b 5 5 5 5 5 5 5 5 b b b f
f b b 5 5 5 5 5 d b b b b f
f b b b b b b b b b b b b f
f b b b b b b b b b b b f c
f c b b b b b b b b b c c .
4 d 4 f f f f f f f c 4 c .
. 4 c b b 3 b 3 b 4 d d 4 .
. . c c 3 3 b 3 b b 4 e . .
. . . . c b b c c c . . . .
,img
. . . . . . . . . . . . . .
. . . . . f f f f . . . . .
. . . f f 5 5 5 5 f f . . .
. . f b 5 5 5 5 5 5 5 f . .
. f b 5 5 5 5 5 5 5 5 5 f .
. f b 5 5 5 5 5 5 5 5 5 d f
f b b d 5 5 5 5 5 5 5 5 d f
f b b b 5 5 5 5 5 5 5 5 b f
f b b b b d 5 5 5 5 5 b b f
f b b b b b b b b b b b b f
c f b b b b b b b b b b b f
. c c b b b b b b b b b c f
. c 4 c f f f f f f f 4 d 4
. 4 d d 4 b 3 b 3 b b c 4 .
. . e 4 b b 3 b 3 3 c c . .
. . . . c c c b b c . . . .
],speed,true)
})
controller.player1.onButtonEvent(ControllerButton.Down, ControllerButtonEvent.Pressed, function() {
animation.runImageAnimation(hero, [img
. . . . . . . . . . . . . .
. . . . . f f f f . . . . .
. . . f f 5 5 5 5 f f . . .
. . f 5 5 5 5 5 5 5 5 f . .
. f 5 5 5 5 5 5 5 5 5 5 f .
c b 5 5 5 d b b d 5 5 5 b c
f 5 5 5 b 4 4 4 4 b 5 5 5 f
f 5 5 c c 4 4 4 4 c c 5 5 f
f b b f b f 4 4 f b f b b f
f b b e 1 f d d f 1 e b b f
c f b f d d d d d 4 4 b f c
. c e c 6 9 9 9 4 d d d c .
. e 4 c 9 9 9 9 4 d d 4 c .
. e c b b 3 b b b e e c . .
. . c c 3 3 b 3 b 3 c c . .
. . . . c b b c c c . . . .
,img
. . . . . . . . . . . . . .
. . . . . f f f f . . . . .
. . . f f 5 5 5 5 f f . . .
. . f 5 5 5 5 5 5 5 5 f . .
. f 5 5 5 5 5 5 5 5 5 5 f .
c b 5 5 5 d b b d 5 5 5 b c
f 5 5 5 b 4 4 4 4 b 5 5 5 f
f 5 5 c c 4 4 4 4 c c 5 5 f
f b b f b f 4 4 f b f b b f
f b b e 1 f d d f 1 e b b f
c f b 4 4 d d d d d f b f c
. c d d d 4 9 9 9 6 c e c .
. c 4 d d 4 9 9 9 9 c 4 e .
. . c e e b b b 3 b b c e .
. . c c 3 b 3 b 3 3 c c . .
. . . . c c c b b c . . . .
],speed,true)
})

controller.player1.onButtonEvent(ControllerButton.Left, ControllerButtonEvent.Released, function() {
animation.stopAnimation(animation.AnimationTypes.All, hero)
})
controller.player1.onButtonEvent(ControllerButton.Right, ControllerButtonEvent.Released, function() {
animation.stopAnimation(animation.AnimationTypes.All, hero)
})
controller.player1.onButtonEvent(ControllerButton.Up, ControllerButtonEvent.Released, function() {
animation.stopAnimation(animation.AnimationTypes.All, hero)
})
controller.player1.onButtonEvent(ControllerButton.Down, ControllerButtonEvent.Released, function() {
animation.stopAnimation(animation.AnimationTypes.All, hero)
})

game.onUpdate(function() {
statusbar.value=sprites.readDataNumber(hero, "blood")
})

game.onUpdateInterval(50, function() {
const blood = sprites.readDataNumber(hero, "blood")
if(blood>0){
sprites.setDataNumber(hero, "blood", blood-1)
}else{
game.over()
}
if(blood<50){
hero.say("卧槽,我饿死了")
}else{
hero.say("")
}
})

game.onUpdateInterval(3000, function() {
if(randint(0,5)==4){
let food = sprites.create(img
. . . . . . b b b b . . . . . .
. . . . b b 3 3 3 3 b b . . . .
. . . c b 3 3 3 3 1 1 b c . . .
. . c b 3 3 3 3 3 1 1 1 b c . .
. c c 1 1 1 3 3 3 3 1 1 3 c c .
c c d 1 1 1 3 3 3 3 3 3 3 b c c
c b d d 1 3 3 3 3 3 1 1 1 b b c
c b b b 3 3 1 1 3 3 1 1 d d b c
c b b b b d d 1 1 3 b d d d b c
. c b b b b d d b b b b b b c .
. . c c b b b b b b b b c c . .
. . . . c c c c c c c c . . . .
. . . . . . b 1 1 b . . . . . .
. . . . . . b 1 1 b b . . . . .
. . . . . b b d 1 1 b . . . . .
. . . . . b d d 1 1 b . . . . .
,SpriteKind.Enemy)
const x=randint(0,scene.screenWidth()-16)
const y=randint(0,scene.screenHeight()-16)
food.setPosition(x, y)
}else{
let food = sprites.create(img
. . . . . . . 6 . . . . . . . .
. . . . . . 8 6 6 . . . 6 8 . .
. . . e e e 8 8 6 6 . 6 7 8 . .
. . e 2 2 2 2 e 8 6 6 7 6 . . .
. e 2 2 4 4 2 7 7 7 7 7 8 6 . .
. e 2 4 4 2 6 7 7 7 6 7 6 8 8 .
e 2 4 5 2 2 6 7 7 6 2 7 7 6 . .
e 2 4 4 2 2 6 7 6 2 2 6 7 7 6 .
e 2 4 2 2 2 6 6 2 2 2 e 7 7 6 .
e 2 4 2 2 4 2 2 2 4 2 2 e 7 6 .
e 2 4 2 2 2 2 2 2 2 2 2 e c 6 .
e 2 2 2 2 2 2 2 4 e 2 e e c . .
e e 2 e 2 2 4 2 2 e e e c . . .
e e e e 2 e 2 2 e e e c . . . .
e e e 2 e e c e c c c . . . . .
. c c c c c c c . . . . . . . .
,SpriteKind.Food)
const x=randint(0,scene.screenWidth()-16)
const y=randint(0,scene.screenHeight()-16)
food.setPosition(x, y)
}
})

sprites.onOverlap(SpriteKind.Player, SpriteKind.Food, function(hero: Sprite, foot: Sprite) {
let blood = sprites.readDataNumber(hero, "blood")
blood+=50
if(blood>100){
blood=100
}
sprites.setDataNumber(hero, "blood", blood)
foot.destroy()
})

sprites.onOverlap(SpriteKind.Player, SpriteKind.Enemy, function(hero: Sprite, enemy: Sprite) {
let blood = sprites.readDataNumber(hero, "blood")
blood-=50
if(blood<0){
blood=0
}
sprites.setDataNumber(hero, "blood", blood)
hero.say("蘑菇有毒!")
enemy.destroy()
})

Top comments (0)