コード例 #1
0
ファイル: main.go プロジェクト: Nightgunner5/gogame
func Handle(msg *packet.Packet) {
	switch {
	case msg.Handshake != nil:
		world.Send <- *msg.Handshake

	case msg.Location != nil:
		world.Send <- *msg.Location

	case msg.Despawn != nil:
		world.Send <- *msg.Despawn

	case msg.MapOverride != nil:
		layout.SetChanges(msg.MapOverride.NewMap)

	case msg.MapChange != nil:
		for !layout.SetCoord(msg.MapChange.Coord, layout.GetCoord(msg.MapChange.Coord), msg.MapChange.Tile) {
		}

	default:
		log.Fatalf("unknown packet: %#v", msg)
	}
}
コード例 #2
0
ファイル: lighting.go プロジェクト: Nightgunner5/gogame
func (l *Lighting) spread(c layout.Coord, brightness uint8) {
	if l.lightmap[c] < 220 {
		if 220-l.lightmap[c] < brightness {
			l.lightmap[c] = 220
		} else {
			l.lightmap[c] += brightness
		}
	}

	if layout.GetCoord(c).BlocksVision() {
		return
	}

	var lightLoss = brightnessMap[brightness]
	if brightness <= lightLoss {
		return
	}
	brightness -= lightLoss
	l.spread(layout.Coord{c.X - 1, c.Y}, brightness)
	l.spread(layout.Coord{c.X + 1, c.Y}, brightness)
	l.spread(layout.Coord{c.X, c.Y - 1}, brightness)
	l.spread(layout.Coord{c.X, c.Y + 1}, brightness)
}
コード例 #3
0
ファイル: main.go プロジェクト: Nightgunner5/gogame
func UI() {
	defer wde.Stop()

	w, err := wde.NewWindow(ViewportWidth<<res.TileSize, ViewportHeight<<res.TileSize)
	if err != nil {
		panic(err)
	}
	defer w.Close()

	w.SetTitle("Stace Spation 2½") // Yes, that is the correct spelling.

	w.LockSize(true)

	w.Show()

	go paintHandler(w)

	Invalidate(w.Screen().Bounds())

	keys := make(map[string]bool)

	for event := range w.EventChan() {
		switch e := event.(type) {
		case wde.MouseMovedEvent:
			xOffset, yOffset := GetTopLeft()

			newX, newY := e.Where.X>>res.TileSize-xOffset, e.Where.Y>>res.TileSize-yOffset
			if newX != mouseTile.X || newY != mouseTile.Y {
				mouseTile.X, mouseTile.Y = newX, newY

				if layout.Visible(layout.Coord{ViewportWidth/2 - xOffset, ViewportHeight/2 - yOffset}, mouseTile) {
					tooltip := strings.Join(layout.GetCoord(mouseTile).Describe(), ", ")

					mouseTileLock.Lock()
					mouseTileString = tooltip
					mouseTileLock.Unlock()
				} else {
					mouseTileLock.Lock()
					mouseTileString = ""
					mouseTileLock.Unlock()
				}
				Invalidate(image.Rect(0, 0, ViewportWidth<<res.TileSize, 1<<res.TileSize))
			}

		case wde.MouseDownEvent:
			Network <- &packet.Packet{
				Interact: &packet.Interact{
					Coord: mouseTile,
				},
			}

		case wde.MouseUpEvent:
		case wde.MouseDraggedEvent:
		case wde.MouseEnteredEvent:
		case wde.MouseExitedEvent:
		case wde.KeyDownEvent:
			if !keys[e.Key] {
				keys[e.Key] = true
				if f := keyDown[e.Key]; f != nil {
					f(keys)
				}
			}

		case wde.KeyUpEvent:
			if keys[e.Key] {
				delete(keys, e.Key)
				if f := keyUp[e.Key]; f != nil {
					f(keys)
				}
			}

		case wde.KeyTypedEvent:
		case wde.ResizeEvent:
			w.SetSize(ViewportWidth<<res.TileSize, ViewportHeight<<res.TileSize)

		case wde.CloseEvent:
			Disconnected()
			return
		}
	}
}
コード例 #4
0
ファイル: main.go プロジェクト: Nightgunner5/gogame
func UI() {
	defer wde.Stop()

	w, err := wde.NewWindow(ViewportWidth<<res.TileSize, ViewportHeight<<res.TileSize)
	if err != nil {
		panic(err)
	}
	defer w.Close()

	w.SetTitle("Stace Spation 2½ Map Editor") // Yes, that is the correct spelling.

	toolbox, err := wde.NewWindow(ToolboxWidth<<res.TileSize, ToolboxHeight<<res.TileSize)
	if err != nil {
		panic(err)
	}
	defer toolbox.Close()

	toolbox.SetTitle("Tiles")

	draw.Draw(toolbox.Screen(), toolbox.Screen().Bounds(), image.White, image.ZP, draw.Src)
	for i := 0; i < ToolboxWidth; i++ {
		for j := 0; j < ToolboxHeight; j++ {
			res.Tile(toolbox.Screen(), res.Terrain, uint16(i+j*ToolboxWidth), i, j)
		}
	}
	toolbox.FlushImage(toolbox.Screen().Bounds())

	toolbox.LockSize(true)
	w.LockSize(true)

	toolbox.Show()
	w.Show()

	go paintHandler(w)

	Invalidate(w.Screen().Bounds())

	keys := make(map[string]bool)

	go func() {
		for event := range toolbox.EventChan() {
			switch e := event.(type) {
			case wde.MouseDownEvent:
				mouseLock.Lock()
				switch e.Which {
				case wde.LeftButton:
					mouseTile = layout.Tile((e.Where.X >> res.TileSize) + (e.Where.Y>>res.TileSize)*ToolboxWidth)
					mouseValid = true
				case wde.RightButton:
					mouseValid = false
				}
				mouseLock.Unlock()
			case wde.ResizeEvent:
				toolbox.SetSize(ToolboxWidth<<res.TileSize, ToolboxHeight<<res.TileSize)
			}
		}
	}()

	for event := range w.EventChan() {
		switch e := event.(type) {
		case wde.MouseMovedEvent:
			xOffset, yOffset := GetTopLeft()

			mouseLock.Lock()
			mouseCoord.X, mouseCoord.Y = e.Where.X>>res.TileSize-xOffset, e.Where.Y>>res.TileSize-yOffset
			mouseLock.Unlock()

			Invalidate(viewport.Bounds())

		case wde.MouseDownEvent:
			switch e.Which {
			case wde.LeftButton:
				mouseLock.Lock()
				if mouseValid {
					for {
						old := layout.GetCoord(mouseCoord)
						var changed layout.MultiTile

						if WireView() {
							old_ := old
							if len(old_) == 0 {
								old_ = layout.MultiTile{layout.Plating}
							}
							changed = append(changed, old_[0])
							changed = append(changed, mouseTile)
							changed = append(changed, old_[1:]...)
						} else {
							changed = append(changed, old...)

							changed = append(changed, mouseTile)
						}

						if layout.SetCoord(mouseCoord, old, changed) {
							break
						}
					}
				} else {
					for {
						tile := layout.GetCoord(mouseCoord)
						if len(tile) == 0 {
							break
						}
						t, removed := tile[len(tile)-1], tile[:len(tile)-1]
						if WireView() {
							if len(tile) == 1 {
								break
							}
							t = tile[1]
							removed = append(layout.MultiTile{tile[0]}, tile[2:]...)
						}
						if layout.SetCoord(mouseCoord, tile, removed) {
							mouseTile = t
							mouseValid = true
							break
						}
					}
				}
				mouseLock.Unlock()

			case wde.RightButton:
				mouseLock.Lock()
				mouseValid = false
				mouseLock.Unlock()
			}

			Invalidate(viewport.Bounds())

		case wde.MouseUpEvent:
		case wde.MouseDraggedEvent:
		case wde.MouseEnteredEvent:
		case wde.MouseExitedEvent:
		case wde.KeyDownEvent:
			if !keys[e.Key] {
				keys[e.Key] = true
				if f := keyDown[e.Key]; f != nil {
					f(keys)
				}
			}

		case wde.KeyUpEvent:
			if keys[e.Key] {
				delete(keys, e.Key)
				if f := keyUp[e.Key]; f != nil {
					f(keys)
				}
			}

		case wde.KeyTypedEvent:
		case wde.ResizeEvent:
			w.SetSize(ViewportWidth<<res.TileSize, ViewportHeight<<res.TileSize)

		case wde.CloseEvent:
			Disconnected()
			return
		}
	}
}