This commit is contained in:
Peli de Halleux 2016-07-22 15:14:50 -07:00
commit 12754acc54
7 changed files with 623 additions and 674 deletions

3
.gitignore vendored
View File

@ -1,6 +1,7 @@
node_modules
yotta_modules
yotta_targets
pxt_modules
built
typings
tmp
@ -18,4 +19,4 @@ clients/**/obj/**
*.tgz
*.db
*.suo
*.log
*.log

View File

@ -4,8 +4,9 @@ node_js:
script:
- "node node_modules/pxt-core/built/pxt.js travis"
- "(cd libs/lang-test0; node ../../node_modules/pxt-core/built/pxt.js run)"
- "node node_modules/pxt-core/built/pxt.js testdir tests"
- "node node_modules/pxt-core/built/pxt.js uploaddoc"
- "(cd libs/hello; node ../../node_modules/pxt-core/built/pxt.js testconv ../../testconv.json)"
- "(cd libs/hello; node ../../node_modules/pxt-core/built/pxt.js testconv https://az851932.vo.msecnd.net/files/td-converter-tests-v0.json)"
sudo: false
notifications:
email:

View File

@ -1,6 +1,6 @@
{
"name": "pxt-microbit",
"version": "0.2.190",
"version": "0.2.192",
"description": "BBC micro:bit target for PXT",
"keywords": [
"JavaScript",
@ -29,6 +29,6 @@
"typescript": "^1.8.7"
},
"dependencies": {
"pxt-core": "0.2.200"
"pxt-core": "0.2.202"
}
}

View File

@ -1,670 +0,0 @@
{
"apiUrl": "https://www.microbit.co.uk/api/",
"fakeids": [
"zzltaj",
"zzpgxf",
"rhisri",
"zztzyk"
],
"ids": [
"balcxr",
"bambkh",
"bbfxnw",
"bbtlly",
"bbvscl",
"bbxapr",
"bcbxtu",
"bchtnm",
"bcpnpx",
"bcredt",
"bdbwuy",
"bdddfl",
"bedihg",
"behvrp",
"bevhll",
"bezbat",
"bfrafy",
"bfvuez",
"bgqdmi",
"bguxyx",
"bhbzvc",
"bhhzvr",
"bhollk",
"biczhe",
"bieoqj",
"biwfto",
"bjayrk",
"bjcbpf",
"bjcdte",
"bjomis",
"bjqlzz",
"bkaofs",
"bkbsfh",
"bkxbji",
"blbhmr",
"blkuau",
"bllhdc",
"blougi",
"blpvxv",
"bmevma",
"bmlwtk",
"bmmayl",
"bncsjd",
"bnlfif",
"bnsfch",
"bnucdu",
"bolvvm",
"bouhxx",
"bpbvyx",
"bpmeio",
"bpqvtv",
"bptlwr",
"bqceny",
"bqgsnm",
"bqkwia",
"bqvoqy",
"bqyoyn",
"brlcdr",
"bsmmsp",
"bsncre",
"bstaqt",
"butypx",
"buuzga",
"bvnciu",
"bwbuga",
"bwhttb",
"bwkezu",
"bxswvm",
"bynkeb",
"bypanj",
"bywqzx",
"byzegt",
"bzaaya",
"bzrusu",
"bzwbps",
"dalzjm",
"damymx",
"dbdpxx",
"dcapfd",
"dceikq",
"ddikkz",
"ddjpss",
"ddtadz",
"ddxbjj",
"dfkuyn",
"dfmpxf",
"dfypdn",
"dhabye",
"dhbioa",
"dieoiu",
"diuhli",
"djchkz",
"djohvc",
"djztxc",
"dkqbyq",
"dkvxwr",
"dmbcwi",
"dmekmj",
"dmghho",
"dnmrlu",
"dnnzgd",
"dooboj",
"dosuna",
"dqgnhz",
"dqqfgv",
"dqwrsw",
"drmbxg",
"drrrty",
"dscjnc",
"dsvguv",
"dtemsf",
"dtmmmc",
"dundpx",
"dushve",
"duupgd",
"dvgzyq",
"dvnoer",
"dwcxtn",
"dwtoyp",
"dxdfbw",
"dxqdqw",
"dxroxs",
"dxvgvs",
"dycuzj",
"dyhnkt",
"dyxejk",
"dzlocb",
"dzlogl",
"fadekj",
"faffgr",
"fapznm",
"fbgdog",
"fbpnng",
"fbyrog",
"fcfoox",
"fcicvk",
"fcjlto",
"fcvwvj",
"fdjhpo",
"fdtayy",
"fdyxvx",
"fegzbd",
"felusd",
"fethzd",
"ffcqby",
"ffjeei",
"ffjuuz",
"fflxnx",
"ffpyfa",
"fhcyyx",
"fhoonu",
"fitucj",
"fitvxu",
"fjdnmb",
"fjhnpw",
"fjlzrt",
"fjwknw",
"fkgprd",
"fklpld",
"fllghh",
"flqpgb",
"fmdsdi",
"fmdzgg",
"fnimjx",
"fnjmfx",
"fnscgh",
"fomwmz",
"fpelnl",
"fpngwv",
"fpqusd",
"fpuclv",
"fpvrwv",
"fqmgsu",
"fqsbhp",
"fqsrdu",
"frlxvd",
"froxsb",
"frqqnm",
"ftcrip",
"ftrzta",
"fubsaf",
"fvgogo",
"fvgxfz",
"fvkluo",
"fvsfrv",
"fwkjkj",
"fxxsgy",
"fyazlp",
"fypaix",
"fzcoly",
"fzidej",
"hatpaz",
"haxiza",
"hbfvlb",
"hbklfv",
"hbwlkf",
"hcmpdm",
"hdnlmx",
"hetmho",
"hfklxz",
"hfkvpg",
"hfmkbt",
"hftxjx",
"hfunev",
"hgepqq",
"hivbxk",
"hjesfm",
"hklazc",
"hkncxl",
"hkrfni",
"hlenxc",
"hlhipg",
"hlhvoe",
"hlwdwo",
"hnljdp",
"howggk",
"hpjppy",
"hptebp",
"hpupwc",
"hqdpet",
"hqhclr",
"hqheal",
"hqoqjh",
"hqpuxt",
"hrnitd",
"hrooif",
"hsuiag",
"hsxmox",
"humerf",
"huqcpc",
"huydje",
"hwetsq",
"hxuwlt",
"hzcxdp",
"hzpfge",
"hzpkma",
"jaeeve",
"jcmkmq",
"jcojot",
"jcvdvp",
"jdcils",
"jddumo",
"jdsqxr",
"jerwei",
"jfwcov",
"jgdknu",
"jgjijp",
"jgofmw",
"jhjauh",
"jhrjvj",
"jhseak",
"jiyhsk",
"jiyoeq",
"jjumac",
"jkppnc",
"jkxyeh",
"jkymhg",
"jlatje",
"jlbxjm",
"jlmzps",
"jmmgyn",
"jmshop",
"jnengo",
"jnhcat",
"jnvrkr",
"jnxdok",
"jociyw",
"joryiq",
"jpbfze",
"jpcrcj",
"jrfuqz",
"jrfwyh",
"jrpbtk",
"jrwkyz",
"jrxhxe",
"jsxvju",
"jszrpp",
"jtbdng",
"jtglrx",
"jtodxy",
"julzbh",
"juqrkb",
"jvstzh",
"jwckaz",
"jwplaw",
"jwskcb",
"jxgcel",
"jxjryw",
"jxmrht",
"jxqobc",
"jzenhj",
"jzwxbr",
"jzzbqg",
"laanun",
"lagxjo",
"lamnpb",
"lapexp",
"lazmuu",
"lbeyfh",
"lbhuwc",
"lcdeuk",
"lchqfb",
"lcpmnp",
"ldgoae",
"lecrpo",
"lfpidi",
"lfrpst",
"lgsrwm",
"lhjcvy",
"licgsp",
"likrcp",
"ljauxo",
"ljkskx",
"llsepx",
"llxcdk",
"lmvoxp",
"lniybn",
"loafab",
"loehfe",
"lpnzct",
"lqwdio",
"lqxnnj",
"lracic",
"lrwotp",
"lryglt",
"lsikdy",
"ltchng",
"ltsbpa",
"lucaof",
"lvahkk",
"lvvdne",
"lwtsxc",
"lxleej",
"lxwstg",
"lxwwtd",
"lzndlk",
"lzosmg",
"lzsseg",
"naevvc",
"nawmtp",
"nbomql",
"nbuuii",
"nbwine",
"ndayhb",
"ndikwg",
"ndlikc",
"ndljim",
"ndooqj",
"ndqgow",
"nfjrxg",
"nfmunh",
"nghraa",
"nhpyof",
"nhtyzy",
"nikzhg",
"nitcfc",
"njfeff",
"njvcbs",
"njynsd",
"nkdbmy",
"nlyuwy",
"nmbxkh",
"nmdfik",
"nmuhlk",
"noftar",
"noikvz",
"novevx",
"noxyjg",
"noyovd",
"npkjbk",
"nqdtvd",
"nqgyno",
"nqxloa",
"nrjdzu",
"nsaumh",
"nsegbi",
"ntfmsx",
"ntsvek",
"nujrlc",
"nvogiv",
"nvrqzl",
"nvtfbc",
"nvymrn",
"nwowql",
"nwxlij",
"nxhnvy",
"nxpwae",
"nynwto",
"nytwlb",
"nyuakq",
"nzrgyf",
"nzrwza",
"nzzcea",
"pbsolq",
"pbtnpf",
"pcdvqu",
"pchzqo",
"pdmxpl",
"pdnntw",
"pdsghq",
"pewcsa",
"pflxxj",
"pfutwa",
"pgvoic",
"phehbm",
"phgmqm",
"phhkfi",
"phjonu",
"phvurr",
"piaksu",
"pijsrg",
"piubiw",
"pjsmac",
"pjxdoj",
"pjzfgn",
"pkmwkn",
"pkntkb",
"pkquey",
"pmxlhz",
"pnvgvr",
"pooqwk",
"ppslyh",
"ppxsux",
"prglvf",
"probjd",
"psmgrz",
"psptyd",
"psqjon",
"pughxs",
"puhetz",
"pujfoc",
"purkko",
"puthiz",
"pvjilh",
"pvqrgm",
"pvzmhz",
"pxebwk",
"pxizap",
"pxyovu",
"pymfqh",
"pzmjbx",
"pzucty",
"rannhh",
"rbnvdq",
"rccfvy",
"rceosh",
"rcobok",
"rdamey",
"rdhndz",
"rdpdll",
"rdzfjv",
"redkby",
"reqjzm",
"revjgd",
"rfihyn",
"rfzukz",
"rgtmoz",
"rheeoa",
"rheyiw",
"rilbti",
"rilexn",
"riotng",
"riqiss",
"riupfo",
"rjglqu",
"rjthvx",
"rjvjwq",
"rlporb",
"rmazpa",
"rmyvbb",
"rnkxav",
"rnvzdo",
"ropkaf",
"rozudg",
"rrvdls",
"rsdjun",
"rudelg",
"rugwft",
"rupbjr",
"rvjwiu",
"rvqkwq",
"rwdqcz",
"rwjnfq",
"rxdqqf",
"rxnztr",
"rxugmm",
"rydpvf",
"ryftuq",
"rygikf",
"ryvkkx",
"rzmnrf",
"tbehov",
"tcaulx",
"tcrfuz",
"tcvaou",
"tdfxfg",
"tdkwue",
"tfrbqz",
"tgbxuq",
"tglsyl",
"tgorrv",
"theruf",
"thhvzq",
"thncnj",
"tiircu",
"tjdpzj",
"tjliry",
"tjpwmu",
"tjqgba",
"tkhgfo",
"tkxbfr",
"tmkbao",
"tmnhhx",
"tnripk",
"tnudiw",
"tnuuwe",
"tnvnko",
"toqcgf",
"tpdiyw",
"tqeddl",
"tqhpqp",
"tqwach",
"trkitt",
"trkrrh",
"tsdmft",
"ttvzqd",
"ttxeud",
"tujsjf",
"tvbjyi",
"tvkqoe",
"twrsnj",
"txkmpg",
"txouzs",
"txszvu",
"txwbbf",
"tzqydt",
"vaszak",
"vaymbt",
"vbcdot",
"vbtmwf",
"vcijrw",
"vcoevo",
"vcrvjm",
"vcudrv",
"vczceh",
"vfcwwr",
"vftxlg",
"vfusfw",
"vgovse",
"vgvkok",
"vgxdxq",
"vhhygu",
"vioniz",
"vipnog",
"vjkwgj",
"vjmnkh",
"vkhabg",
"vkhiga",
"vkybzm",
"vlrsar",
"vmhvfa",
"vndxor",
"vodekh",
"vopucc",
"vovivd",
"vpnspf",
"vpslsg",
"vreifv",
"vrikcc",
"vrxpod",
"vsbzms",
"vslnue",
"vsrguv",
"vsyfym",
"vtfund",
"vtviqj",
"vtzfzy",
"vuwzmu",
"vwkpiw",
"vwlohb",
"vwnjqy",
"vwtwos",
"vxjfnm",
"vyewot",
"vyhvrg",
"vzmvvw",
"vzniie",
"vzrycv",
"vztdyx",
"xascqb",
"xaurjv",
"xcenyy",
"xczuut",
"xdvawd",
"xdwebc",
"xdxlsd",
"xfdrwr",
"xfrysj",
"xfytns",
"xhgnmw",
"xhjkvj",
"xjngae",
"xjuzjz",
"xkrsfl",
"xlfmnd",
"xltsru",
"xmcivt",
"xmlisq",
"xmzztb",
"xndixq",
"xnhxka",
"xnurqq",
"xolqgf",
"xoojpa",
"xoulbi",
"xoygfg",
"xpekdp",
"xpiqbj",
"xrqriw",
"xrsohj",
"xrvzyi",
"xsvwgh",
"xtrrnu",
"xtsmne",
"xuxlra",
"xvjcdf",
"xvmxti",
"xvpkiq",
"xxuosa",
"xymixn",
"xzcsqr",
"xzlzgl",
"zaidka",
"zbiznd",
"zbqfmt",
"zdfkcr",
"zdntvf",
"zdwmwu",
"zehjio",
"zelzkd",
"zewaak",
"zgozuh",
"zifrtl",
"ziqeez",
"zldufm",
"zlfusn",
"zmrcwu",
"zoyilz",
"zqlcxg",
"zqotda",
"zswztj",
"zszuqa",
"zwkhxx",
"zwpewj",
"zytfqg",
"zywows",
"zzltaj",
"zzpgxf",
"zztzyk"
]
}

232
tests/hat-game.ts Normal file
View File

@ -0,0 +1,232 @@
let correctBall: number
let ballRevealing: boolean
let cupSelect: string
let index: number
let score: number
let level: number
let swapSpeed: number
initializeGame()
input.onButtonPressed(Button.A, () => {
if (ballRevealing) {
index = index + 1
if (index > 2) {
index = 0
}
basic.showString(cupSelect[index], 150)
}
})
input.onButtonPressed(Button.B, () => {
if (ballRevealing) {
ballRevealing = false
if (correctBall == index) {
score = score + level
images.createImage(`
. . . . .
. . . . #
. . . # .
# . # . .
. # . . .
`).showImage(0)
basic.pause(1000)
basic.showString("+".concat(level.toString()), 150)
basic.pause(1000)
} else {
images.createImage(`
# . . . #
. # . # .
. . # . .
. # . # .
# . . . #
`).showImage(0)
basic.pause(1000)
basic.clearScreen()
revealBall(correctBall)
basic.pause(1000)
}
}
level = level + 1
if (level == 4) {
basic.showString("FINAL SCORE:", 75)
basic.showNumber(score, 150)
} else {
playLevel(level)
}
})
playLevel(1)
function revealBall(p: number) {
let xCoordinate = 2 * p
for (let j = 0; j < 3; j++) {
led.plot(j * 2, 2)
}
for (let i = 0; i < 3; i++) {
led.unplot(xCoordinate, 2)
led.plot(xCoordinate, 1)
basic.pause(100)
led.unplot(xCoordinate, 1)
led.plot(xCoordinate, 0)
basic.pause(200)
led.unplot(xCoordinate, 0)
led.plot(xCoordinate, 1)
basic.pause(100)
led.unplot(xCoordinate, 1)
led.plot(xCoordinate, 2)
basic.pause(75)
}
basic.pause(1000)
}
function initializeGame() {
ballRevealing = false
level = 1
score = 0
cupSelect = "LMR"
}
function swapCups(cup_1: number, cup_2: number, pauseDifficulty: number) {
let cup_1X = 2 * cup_1
let cup_2X = 2 * cup_2
let cupXAverage = (cup_1X + cup_2X) / 2
led.unplot(cup_1X, 2)
led.unplot(cup_2X, 2)
led.plot(cup_1X, 3)
led.plot(cup_2X, 1)
basic.pause(pauseDifficulty)
led.unplot(cup_1X, 3)
led.unplot(cup_2X, 1)
led.plot(cup_1X, 4)
led.plot(cup_2X, 0)
basic.pause(pauseDifficulty)
led.unplot(cup_1X, 4)
led.unplot(cup_2X, 0)
if (cupXAverage == 2) {
led.plot((cupXAverage + cup_1X) / 2, 4)
led.plot((cupXAverage + cup_2X) / 2, 0)
basic.pause(pauseDifficulty)
led.unplot((cupXAverage + cup_1X) / 2, 4)
led.unplot((cupXAverage + cup_2X) / 2, 0)
}
led.plot(cupXAverage, 4)
led.plot(cupXAverage, 0)
basic.pause(pauseDifficulty)
led.unplot(cupXAverage, 4)
led.unplot(cupXAverage, 0)
if (cupXAverage == 2) {
led.plot((cupXAverage + cup_2X) / 2, 4)
led.plot((cupXAverage + cup_1X) / 2, 0)
basic.pause(pauseDifficulty)
led.unplot((cupXAverage + cup_2X) / 2, 4)
led.unplot((cupXAverage + cup_1X) / 2, 0)
}
led.plot(cup_2X, 4)
led.plot(cup_1X, 0)
basic.pause(pauseDifficulty)
led.unplot(cup_2X, 4)
led.unplot(cup_1X, 0)
led.plot(cup_2X, 3)
led.plot(cup_1X, 1)
basic.pause(pauseDifficulty)
led.unplot(cup_2X, 3)
led.unplot(cup_1X, 1)
led.plot(cup_2X, 2)
led.plot(cup_1X, 2)
basic.pause(pauseDifficulty)
if (correctBall == cup_1) {
correctBall = cup_2
} else if (correctBall == cup_2) {
correctBall = cup_1
}
}
function swapFake(cup_1: number, cup_2: number, pauseDifficulty: number) {
let cup_1X = 2 * cup_1
let cup_2X = 2 * cup_2
let cupXAverage = (cup_1X + cup_2X) / 2
led.unplot(cup_1X, 2)
led.unplot(cup_2X, 2)
led.plot(cup_1X, 3)
led.plot(cup_2X, 1)
basic.pause(pauseDifficulty)
led.unplot(cup_1X, 3)
led.unplot(cup_2X, 1)
led.plot(cup_1X, 4)
led.plot(cup_2X, 0)
basic.pause(pauseDifficulty)
led.unplot(cup_1X, 4)
led.unplot(cup_2X, 0)
if (cupXAverage == 2) {
led.plot((cupXAverage + cup_1X) / 2, 4)
led.plot((cupXAverage + cup_2X) / 2, 0)
basic.pause(pauseDifficulty)
led.unplot((cupXAverage + cup_1X) / 2, 4)
led.unplot((cupXAverage + cup_2X) / 2, 0)
}
led.plot(cupXAverage, 4)
led.plot(cupXAverage, 0)
basic.pause(pauseDifficulty)
led.unplot(cupXAverage, 4)
led.unplot(cupXAverage, 0)
if (cupXAverage == 2) {
led.plot((cupXAverage + cup_1X) / 2, 4)
led.plot((cupXAverage + cup_2X) / 2, 0)
basic.pause(pauseDifficulty)
led.unplot((cupXAverage + cup_1X) / 2, 4)
led.unplot((cupXAverage + cup_2X) / 2, 0)
}
led.plot(cup_1X, 4)
led.plot(cup_2X, 0)
basic.pause(pauseDifficulty)
led.unplot(cup_1X, 4)
led.unplot(cup_2X, 0)
led.plot(cup_1X, 3)
led.plot(cup_2X, 1)
basic.pause(pauseDifficulty)
led.unplot(cup_1X, 3)
led.unplot(cup_2X, 1)
led.plot(cup_1X, 2)
led.plot(cup_2X, 2)
basic.pause(pauseDifficulty)
}
function playLevel(level1: number) {
basic.showNumber(level, 150)
basic.pause(3000)
basic.clearScreen()
for (let i = 0; i < 3; i++) {
led.plot(2 * i, 2)
}
basic.pause(1000)
correctBall = Math.random(3)
revealBall(correctBall)
basic.pause(1000)
let swaps = 5 + 10 * level1
if (level1 == 1) {
swapSpeed = 80
} else if (level1 == 2) {
swapSpeed = 40
} else {
swapSpeed = 20
}
for (let i1 = 0; i1 < swaps; i1++) {
let swapType = Math.random(3)
let not = Math.random(3)
if (swapType < 2) {
let swapOrientation = Math.random(2)
if (swapOrientation == 0) {
swapCups((not + 1) % 3, (not + 2) % 3, swapSpeed)
} else {
swapCups((not + 2) % 3, (not + 1) % 3, swapSpeed)
}
} else {
let swapOrientation1 = Math.random(2)
if (swapOrientation1 == 0) {
swapFake((not + 1) % 3, (not + 2) % 3, swapSpeed)
} else {
swapFake((not + 2) % 3, (not + 1) % 3, swapSpeed)
}
}
}
index = -1
ballRevealing = true
}

155
tests/meteorite.ts Normal file
View File

@ -0,0 +1,155 @@
let oneX: number
let oneY: number
let twoX: number
let twoY: number
let pause: number
let meteoriteOneX: number
let meteoriteOneY: number
let meteoriteTwoX: number
let meteoriteTwoY: number
let counter: number
basic.pause(2000)
oneX = 0
oneY = 4
twoX = 1
twoY = 4
counter = 0
pause = 700
led.plot(oneX, oneY)
led.plot(twoX, twoY)
input.onButtonPressed(Button.A, () => {
if (oneX > 0) {
led.unplot(oneX, oneY)
led.unplot(twoX, twoY)
oneX = oneX - 1
twoX = twoX - 1
led.plot(oneX, oneY)
led.plot(twoX, twoY)
}
})
input.onButtonPressed(Button.B, () => {
if (twoX < 4) {
led.unplot(oneX, oneY)
led.unplot(twoX, twoY)
oneX = oneX + 1
twoX = twoX + 1
led.plot(oneX, oneY)
led.plot(twoX, twoY)
}
})
meteoriteOneX = Math.random(5)
meteoriteOneY = 0
meteoriteTwoX = Math.random(5)
meteoriteTwoY = -3
basic.pause(1000)
for (let i = 0; i < 3; i++) {
led.plot(meteoriteTwoX, meteoriteTwoY)
led.plot(meteoriteOneX, meteoriteOneY)
basic.pause(pause)
led.unplot(meteoriteTwoX, meteoriteTwoY)
led.unplot(meteoriteOneX, meteoriteOneY)
meteoriteOneY = meteoriteOneY + 1
meteoriteTwoY = meteoriteTwoY + 1
}
basic.forever(() => {
for (let i1 = 0; i1 < 3; i1++) {
led.plot(meteoriteTwoX, meteoriteTwoY)
led.plot(meteoriteOneX, meteoriteOneY)
basic.pause(pause)
led.unplot(meteoriteOneX, meteoriteOneY)
led.unplot(meteoriteTwoX, meteoriteTwoY)
meteoriteOneY = meteoriteOneY + 1
meteoriteTwoY = meteoriteTwoY + 1
if (meteoriteOneY == 4) {
if (meteoriteOneX == oneX) {
for (let j = 0; j < 10; j++) {
led.plotAll()
basic.pause(200)
basic.clearScreen()
basic.pause(200)
}
basic.showNumber(counter, 150)
basic.pause(10000)
} else if (meteoriteOneX == twoX) {
for (let j1 = 0; j1 < 10; j1++) {
led.plotAll()
basic.pause(200)
basic.clearScreen()
basic.pause(200)
}
basic.showNumber(counter, 150)
basic.pause(10000)
}
}
}
while (Math.abs(meteoriteTwoX - meteoriteOneX) < 1) {
meteoriteOneX = Math.random(5)
}
meteoriteOneY = 0
counter = counter + 1
if (counter == 3) {
pause = pause - 250
} else if (counter == 8) {
pause = pause - 100
} else if (counter == 12) {
pause = pause - 100
} else if (counter == 20) {
pause = pause - 100
} else if (counter == 30) {
pause = pause - 70
}
if (counter == 40) {
pause = pause - 70
}
for (let i2 = 0; i2 < 3; i2++) {
led.plot(meteoriteOneX, meteoriteOneY)
led.plot(meteoriteTwoX, meteoriteTwoY)
basic.pause(pause)
led.unplot(meteoriteOneX, meteoriteOneY)
led.unplot(meteoriteTwoX, meteoriteTwoY)
meteoriteOneY = meteoriteOneY + 1
meteoriteTwoY = meteoriteTwoY + 1
if (meteoriteTwoY == 4) {
if (meteoriteTwoX == oneX) {
for (let j2 = 0; j2 < 10; j2++) {
led.plotAll()
basic.pause(200)
basic.clearScreen()
basic.pause(200)
}
basic.showNumber(counter, 150)
basic.pause(10000)
} else if (meteoriteTwoX == twoX) {
for (let j3 = 0; j3 < 10; j3++) {
led.plotAll()
basic.pause(200)
basic.clearScreen()
basic.pause(200)
}
basic.showNumber(counter, 150)
basic.pause(10000)
}
}
}
meteoriteTwoX = Math.random(5)
while (Math.abs(meteoriteTwoX - meteoriteOneX) < 1) {
meteoriteTwoX = Math.random(5)
}
meteoriteTwoY = 0
counter = counter + 1
if (counter == 3) {
pause = pause - 250
} else if (counter == 8) {
pause = pause - 100
} else if (counter == 12) {
pause = pause - 100
} else if (counter == 20) {
pause = pause - 100
} else if (counter == 30) {
pause = pause - 70
} else if (counter == 40) {
pause = pause - 70
}
})

230
tests/pac-man-runaway.ts Normal file
View File

@ -0,0 +1,230 @@
let levelTime: number
let person: Entity
let monsters: Entity[]
let totalMonsters: number
let playing: boolean
let gameSuspended: boolean
let busyPos: Point[]
class Entity {
public x: number
public y: number
public dirX: number
public dirY: number
public hitHorizontalWall(): boolean {
return this.y == 0 && this.dirY == -1 || this.y == 4 && this.dirY == 1
}
public hitVerticalWall(): boolean {
return this.x == 0 && this.dirX == -1 || this.x == 4 && this.dirX == 1
}
public possHorizontalDir(): number {
if (this.x == 0) {
return 1
} else if (this.x == 4) {
return - 1
} else {
return Math.random(2) * 2 - 1
}
}
public possVerticalDir(): number {
if (this.y == 0) {
return 1
} else if (this.y == 4) {
return - 1
} else {
return Math.random(2) * 2 - 1
}
}
public collidesX(p2: Entity): boolean {
return this.y == p2.y && this.y + this.dirY == p2.y + p2.dirY && (this.x + this.dirX == p2.x || this.x + this.dirX == p2.x + p2.dirX || p2.x + p2.dirX == this.x)
}
public collidesY(p2: Entity): boolean {
return this.x == p2.x && this.x + this.dirX == p2.x + p2.dirX && (this.y + this.dirY == p2.y || this.y + this.dirY == p2.y + p2.dirY || p2.y + p2.dirY == this.y)
}
public move1() {
this.x = this.x + this.dirX
this.y = this.y + this.dirY
}
public towardsX(p2: Entity): number {
return Math.sign(p2.x - this.x)
}
public towardsY(p2: Entity): number {
return Math.sign(p2.y - this.y)
}
public plot() {
led.plot(this.x, this.y)
}
public blink() {
led.plot(this.x, this.y)
basic.pause(125)
led.unplot(this.x, this.y)
basic.pause(125)
led.plot(this.x, this.y)
}
}
class Point {
public x: number
public y: number
}
initializeState()
redraw()
basic.pause(1000)
basic.forever(() => {
levelTime = levelTime + 12
basic.pause(12)
if (!playing) {
levelTime = 0
playing = true
}
if (levelTime >= 5000) {
gameSuspended = true
game.levelUp()
levelUp()
levelTime = 0
resetState()
redraw()
basic.pause(1000)
gameSuspended = false
}
})
basic.forever(() => {
if (!gameSuspended) {
logic()
redraw()
basic.pause(500)
}
})
input.onButtonPressed(Button.A, () => {
let temp = Math.abs(person.dirX) * (-1)
person.dirX = Math.abs(person.dirY) * (-1)
person.dirY = temp
})
input.onButtonPressed(Button.B, () => {
let temp1 = Math.abs(person.dirX)
person.dirX = Math.abs(person.dirY)
person.dirY = temp1
})
function redraw() {
basic.clearScreen()
person.plot()
for (let i = 0; i < totalMonsters; i++) {
monsters[i].blink()
}
}
function initializeState() {
person = new Entity()
playing = false
busyPos = ([] as Point[])
let busyPos1 = new Point()
busyPos1.x = 1
busyPos1.y = 1
let busyPos2 = new Point()
busyPos2.x = 1
busyPos2.y = 3
let busyPos3 = new Point()
busyPos3.x = 3
busyPos3.y = 1
busyPos.push(busyPos1)
busyPos.push(busyPos2)
busyPos.push(busyPos3)
monsters = ([] as Entity[])
addMonster()
resetState()
}
function logic() {
if (person.hitHorizontalWall()) {
person.dirY = 0
person.dirX = person.possHorizontalDir()
}
if (person.hitVerticalWall()) {
person.dirX = 0
person.dirY = person.possVerticalDir()
}
let lost = false
for (let i = 0; i < totalMonsters; i++) {
let m = monsters[i]
m.dirX = m.towardsX(person)
m.dirY = m.towardsY(person)
if (m.dirX != 0 && m.dirY != 0) {
let x = Math.random(2)
if (x == 1) {
m.dirX = 0
} else {
m.dirY = 0
}
}
if (person.collidesX(m) || person.collidesY(m)) {
lost = true
}
}
if (!lost) {
moveAll()
} else {
loseLife()
}
}
function loseLife() {
moveAll()
basic.pause(500)
basic.showLeds(`
. # . # .
. . # . .
. . . . .
. # # # .
# . . . #
`, 400)
basic.pause(1000)
basic.clearScreen()
game.removeLife(1)
playing = false
resetState()
}
function moveAll() {
person.move1()
for (let i = 0; i < totalMonsters; i++) {
monsters[i].move1()
}
}
function addMonster() {
let m = new Entity()
monsters.push(m)
totalMonsters = totalMonsters + 1
}
function levelUp() {
addMonster()
}
function resetState() {
levelTime = 0
game.setLife(5)
person.x = 4
person.y = 4
person.dirX = -1
person.dirY = 0
for (let i = 0; i < totalMonsters; i++) {
let busy = busyPos[i]
let m = monsters[i]
m.x = (busy.x + Math.random(3)) - 1
m.y = (busy.y + Math.random(3)) - 1
}
}