mirror of
https://gitee.com/wa-lang/wa.git
synced 2025-12-06 09:18:53 +08:00
完善 w4-life 游戏交互
This commit is contained in:
@@ -21,6 +21,9 @@ func BitImage.At(x, y: int) => bool {
|
||||
}
|
||||
|
||||
func BitImage.Set(x, y: int, c: bool) {
|
||||
if x < 0 || x >= this.Width || y < 0 || y >= this.Height {
|
||||
return
|
||||
}
|
||||
idx := (y*this.Width + x) / 8
|
||||
if c {
|
||||
this.Pix[idx] = byte(setBit(uint(this.Pix[idx]), uint(x%8)))
|
||||
|
||||
@@ -45,6 +45,14 @@ func LifeInit {
|
||||
}
|
||||
}
|
||||
|
||||
func LifeSetRect(x0, y0, x1, y1: int) {
|
||||
for x := x0; x < x1; x++ {
|
||||
for y := y0; y < y1; y++ {
|
||||
cells0.Set(x, y, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type DIR :struct {
|
||||
x: int
|
||||
y: int
|
||||
|
||||
@@ -18,5 +18,22 @@ func Update {
|
||||
LifeStart()
|
||||
}
|
||||
|
||||
mouseX := int(wasm4.GetMouseX())
|
||||
mouseY := int(wasm4.GetMouseY())
|
||||
|
||||
if byte(wasm4.GetMouseButtons()) == wasm4.MOUSE_LEFT {
|
||||
LifeSetRect(mouseX-2, mouseY-2, mouseX+2, mouseY+2)
|
||||
}
|
||||
|
||||
LifeStep()
|
||||
|
||||
drawMouse(mouseX, mouseY)
|
||||
}
|
||||
|
||||
func drawMouse(mouseX, mouseY: int) {
|
||||
if mouseX < 0 || mouseY < 0 || mouseX >= wasm4.SCREEN_SIZE || mouseY >= wasm4.SCREEN_SIZE {
|
||||
return
|
||||
}
|
||||
wasm4.SetDrawColors(2)
|
||||
wasm4.Rect(mouseX-1, mouseY-1, 3, 3)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user