improve graphics
This commit is contained in:
parent
7bb4272e61
commit
ef4fe5eff0
|
@ -216,7 +216,7 @@ func NewState() State {
|
|||
func randomObstacles(teams []Team) []Obstacle {
|
||||
var os []Obstacle
|
||||
|
||||
const numObstacles = 12 * NumTeams
|
||||
const numObstacles = 5 * NumTeams
|
||||
for i := 0; i < numObstacles; i++ {
|
||||
os = append(os, Obstacle{
|
||||
Position: randomOpenPosition(teams, os),
|
||||
|
@ -286,6 +286,6 @@ var (
|
|||
const (
|
||||
Steps = 50
|
||||
numBots = 5
|
||||
NumTeams = 6
|
||||
NumTeams = 8
|
||||
NumLanes = NumTeams
|
||||
)
|
||||
|
|
37
gfx/gfx.go
37
gfx/gfx.go
|
@ -5,6 +5,7 @@ import (
|
|||
"image"
|
||||
"image/color"
|
||||
_ "image/png"
|
||||
"math/rand"
|
||||
"os"
|
||||
"relay/game"
|
||||
|
||||
|
@ -55,7 +56,7 @@ func loadPicture(path string) (pixel.Picture, error) {
|
|||
}
|
||||
|
||||
func Render(rs RenderState, sOld, sNew game.State, w *pixelgl.Window, sb spriteBank) RenderState {
|
||||
w.Clear(colornames.Black)
|
||||
renderBackground(w)
|
||||
|
||||
colors := teamColors(sNew.Teams)
|
||||
ctx := context{
|
||||
|
@ -74,6 +75,31 @@ func Render(rs RenderState, sOld, sNew game.State, w *pixelgl.Window, sb spriteB
|
|||
return rs
|
||||
}
|
||||
|
||||
var stars []pixel.Vec
|
||||
|
||||
func renderBackground(w *pixelgl.Window) {
|
||||
w.Clear(colornames.Black)
|
||||
|
||||
if len(stars) == 0 {
|
||||
const numStars = 100
|
||||
for i := 0; i < numStars; i++ {
|
||||
stars = append(stars, pixel.Vec{
|
||||
X: rand.Float64() * w.Bounds().W(),
|
||||
Y: rand.Float64() * w.Bounds().H(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
for _, star := range stars {
|
||||
im := imdraw.New(nil)
|
||||
im.Color = colornames.White
|
||||
im.Push(star)
|
||||
im.Clear()
|
||||
im.Circle(2, 0)
|
||||
im.Draw(w)
|
||||
}
|
||||
}
|
||||
|
||||
func renderBots(ctx context, colors map[*game.Team]pixel.RGBA, pic pixel.Picture) {
|
||||
for i, t := range ctx.sNew.Teams {
|
||||
c := colors[&ctx.sNew.Teams[i]]
|
||||
|
@ -159,9 +185,9 @@ func teamColors(ts []game.Team) map[*game.Team]pixel.RGBA {
|
|||
var c color.RGBA
|
||||
switch i {
|
||||
case 0:
|
||||
c = colornames.Red
|
||||
c = colornames.Palevioletred
|
||||
case 1:
|
||||
c = colornames.Green
|
||||
c = colornames.Lime
|
||||
case 2:
|
||||
c = colornames.Cornflowerblue
|
||||
case 3:
|
||||
|
@ -172,6 +198,11 @@ func teamColors(ts []game.Team) map[*game.Team]pixel.RGBA {
|
|||
c = colornames.Yellow
|
||||
case 6:
|
||||
c = colornames.Blueviolet
|
||||
case 7:
|
||||
c = colornames.Orange
|
||||
case 8:
|
||||
c = colornames.Coral
|
||||
|
||||
}
|
||||
m[&ts[i]] = pixel.ToRGBA(c)
|
||||
}
|
||||
|
|
4
main.go
4
main.go
|
@ -14,7 +14,7 @@ import (
|
|||
func run() error {
|
||||
cfg := pixelgl.WindowConfig{
|
||||
Title: "Relay",
|
||||
Bounds: pixel.R(0, 0, 2048, 512),
|
||||
Bounds: pixel.R(0, 0, 2048, 1024),
|
||||
VSync: true,
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ func run() error {
|
|||
if !rs.Animating {
|
||||
sOld = s
|
||||
}
|
||||
case w.Pressed(pixelgl.KeySpace):
|
||||
case w.Pressed(pixelgl.KeySpace) || true:
|
||||
log.Printf("TURN %d", turn)
|
||||
rs.Animating = true
|
||||
rs.Frame = 0
|
||||
|
|
Loading…
Reference in New Issue