common

package
v0.0.0-...-2ef9a49 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FrameTime 20ms
	FrameTime float64 = 20
	// SceneSpeed 像素每秒
	SceneSpeed float64 = 200
	// SceneSpeedUp 加速系数
	SceneSpeedUp float64 = 1.6
	// SceneWidth 场景的宽度
	SceneWidth float64 = 800
	// SceneHeight 场景高度
	SceneHeight float64 = 800
)

场景信息 速度 宽度 高度

View Source
const (
	FoodNum    uint32 = 20
	FoodEnergy int32  = 5
	// EatFoodRadius
	EatFoodRadius float64 = 2
)

食物信息

View Source
const (
	// SnakeRadius 蛇的半径 10px
	SnakeRadius float64 = 10
	// SnakeTurnSpeed 蛇的转向速度 弧度/ms
	SnakeTurnSpeed = 0.5
)

蛇的信息

View Source
const (
	BallFood uint32 = 0
)
View Source
const (
	CommonRoom uint32 = 0
)
View Source
const (
	// Task_TimeOut websocketTask 超时时间
	Task_TimeOut = 20
)

连接信息

Variables

This section is empty.

Functions

func IPToUInt32

func IPToUInt32(ipnr net.IP) uint32

func RandBetween

func RandBetween(min, max int64) int64

RandBetween 产生[min max]间的随机数

func RandBetweenUint32

func RandBetweenUint32(min, max uint32) uint32

RandBetweenUint32 产生[min max]间的随机数

func RandColor

func RandColor() uint32

func RandPOINTFloat64

func RandPOINTFloat64(min, width, height float64) (X, Y float64)

RandPOINTFloat64 随机坐标float64

func SafeRandHeadFloat64

func SafeRandHeadFloat64(min, width, height float64) (X, Y float64)

func TwoPointLen

func TwoPointLen(a, b POINT) float64

TwoPointLen 求两点之间距离

func UInt32ToIP

func UInt32ToIP(intIP uint32) net.IP

Types

type Circle

type Circle struct {
	// contains filtered or unexported fields
}

func CircleOfTriangle

func CircleOfTriangle(a, b, c POINT) Circle

CircleOfTriangle 求三角形外接圆

func MinCircle

func MinCircle(pArr []POINT) Circle

MinCircle 求最小覆盖圆

type Food

type Food struct {
	Energy int32 `json:"energy"`
	Stat   POINT `json:"stat"`
}

type MsgType

type MsgType uint16

MsgType 消息信息

const (
	MsgType_Start   MsgType = 0
	MsgType_Move    MsgType = 1
	MsgType_SpeedUp MsgType = 2
	MsgType_Finsh   MsgType = 3
	MsgType_Heart   MsgType = 4
)

type POINT

type POINT struct {
	//Id uint32
	X float64 `json:"x"`
	Y float64 `json:"y"`
}

以下为约定结构

type ReqGetIDMsg

type ReqGetIDMsg struct {
	DeviceId string `json:"deviceId"`
	Ip       string `json:"ip"`
}

ReqGetIDMsg 客户请求 json 设备信息和ip地址 存在redis中

type RetGetIDMsg

type RetGetIDMsg struct {
	Id uint32 `json:"id"`
}

RetGetIDMsg 服务器返回id

type RetOverMsg

type RetOverMsg struct {
	End bool `json:"end"`
}

RetOverMsg 发送结束消息

type RetSceneMsg

type RetSceneMsg struct {
	PlayerSnake []RetSnakeBody `json:"player_snake"`
	OthersSnake []RetSnakeBody `json:"others_snake"`
	FoodList    []Food         `json:"food_list"`
}

RetSceneMsg 服务器返回游戏场景

type RetSnakeBody

type RetSnakeBody struct {
	//color
	Id     uint32  `json:"id"`
	Name   string  `json:"name"`
	Direct float64 `json:"direct"`
	Head   POINT   `json:"head"`
	Body   []POINT `json:"body"`
	Score  int32   `json:"score"`
	Radius float64 `json:"radius"`
}

RetSnakeBody omitempty作用是在json数据结构转换时,当该字段的值为该字段类型的零值时,忽略该字段

type RetTimeMsg

type RetTimeMsg struct {
	Time uint64 `json:"time"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL