This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
var ( | |
backgroundColor = color.RGBA{50, 100, 50, 50} | |
snakeColor = color.RGBA{200, 50, 150, 150} | |
foodColor = color.RGBA{200, 200, 50, 150} | |
) | |
type Game struct { | |
input *Input |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package snake | |
import ( | |
"math/rand" | |
"time" | |
"github.com/hajimehoshi/ebiten/v2" | |
) | |
type Board struct { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package snake | |
import "github.com/hajimehoshi/ebiten/v2" | |
type Coord struct { | |
x, y int | |
} | |
type Snake struct { | |
body []Coord |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package snake | |
import ( | |
"github.com/hajimehoshi/ebiten/v2" | |
"github.com/hajimehoshi/ebiten/v2/inpututil" | |
) | |
type Input struct{} | |
func NewInput() *Input { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package snake | |
type Food struct { | |
x, y int | |
} | |
func NewFood(x, y int) *Food { | |
return &Food{ | |
x: x, | |
y: y, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"github.com/hajimehoshi/ebiten/v2" | |
"github.com/plutov/packagemain/drafts/ebiten-snake/snake" | |
) | |
func main() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package snake | |
import ( | |
"fmt" | |
"image/color" | |
"github.com/hajimehoshi/ebiten/v2" | |
"github.com/hajimehoshi/ebiten/v2/ebitenutil" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package snake | |
import ( | |
"fmt" | |
"image/color" | |
"github.com/hajimehoshi/ebiten/v2" | |
"github.com/hajimehoshi/ebiten/v2/ebitenutil" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"net/http" | |
) | |
var limiter = NewIPRateLimiter(1, 5) | |
func main() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"sync" | |
"golang.org/x/time/rate" | |
) | |
// IPRateLimiter . | |
type IPRateLimiter struct { |
NewerOlder