Skip to content

Commit

Permalink
onMsg/broadcast
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed Nov 28, 2021
1 parent 409befb commit aa805e4
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Bomb.spx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ onCloned => {
}
}

onMsg "battle", => {
onMsg msgBattle, => {
bombs = 0
for i := 0; i < 50; i++ {
wait 20
Expand Down
2 changes: 1 addition & 1 deletion GameLogo.spx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
onMsg "battle", => {
onMsg msgBattle, => {
hide
}
2 changes: 1 addition & 1 deletion GameOver.spx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
onMsg "game over", => {
onMsg msgGameOver, => {
show
wait 2
exit
Expand Down
2 changes: 1 addition & 1 deletion GameStart.spx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
onClick => {
hide
broadcast "battle"
broadcast msgBattle
}
4 changes: 2 additions & 2 deletions HugeEnemy.spx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var (
life int
)

onMsg "battle", => {
onMsg msgBattle, => {
for {
wait 25
clone
Expand Down Expand Up @@ -30,7 +30,7 @@ onCloned => {
}
}

onMsg "kill all", => {
onMsg msgKillAll, => {
addScore 50
die
}
4 changes: 2 additions & 2 deletions MiddleEnemy.spx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var (
life int
)

onMsg "battle", => {
onMsg msgBattle, => {
for {
wait 2
clone
Expand Down Expand Up @@ -30,7 +30,7 @@ onCloned => {
}
}

onMsg "kill all", => {
onMsg msgKillAll, => {
addScore 10
die
}
8 changes: 4 additions & 4 deletions MyAircraft.spx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ onStart => {
life = 1
}

onMsg "battle", => {
onMsg msgBattle, => {
for life > 0 {
wait 0.1
Bullet.clone
}
}

onMsg "battle", => {
onMsg msgBattle, => {
show
setXYpos 0, 0
score = 0
Expand Down Expand Up @@ -43,7 +43,7 @@ onMsg "battle", => {
setXYpos planeX, planeY
if touching("HugeEnemy") || touching("SmallEnemy") || touching("MiddleEnemy") {
life--
broadcast "game over"
broadcast msgGameOver
die
}
if touching("Bomb") {
Expand All @@ -55,6 +55,6 @@ onMsg "battle", => {
onKey KeySpace, => {
if bombs > 0 {
bombs--
broadcast "kill all"
broadcast msgKillAll
}
}
4 changes: 2 additions & 2 deletions SmallEnemy.spx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var (
life int
)

onMsg "battle", => {
onMsg msgBattle, => {
for {
wait 1
clone
Expand Down Expand Up @@ -30,7 +30,7 @@ onCloned => {
}
}

onMsg "kill all", => {
onMsg msgKillAll, => {
addScore 5
die
}
2 changes: 1 addition & 1 deletion TextIntro.spx
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
onMsg "battle", => {
onMsg msgBattle, => {
hide
}
2 changes: 1 addition & 1 deletion YouWin.spx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
onMsg "you win", => {
onMsg msgYouWin, => {
show
wait 2
exit
Expand Down
9 changes: 8 additions & 1 deletion index.gmx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@ const (
winscore = 500
)

const (
msgBattle = "battle"
msgYouWin = "you win"
msgGameOver = "game over"
msgKillAll = "kill all"
)

func addScore(val int) {
score += val
if score > winscore {
broadcast "you win"
broadcast msgYouWin
}
}

Expand Down

0 comments on commit aa805e4

Please sign in to comment.