improve graphics

This commit is contained in:
Luke Meyers 2020-02-08 00:35:51 -08:00
parent 7bb4272e61
commit ef4fe5eff0
3 changed files with 38 additions and 7 deletions

View File

@ -216,7 +216,7 @@ func NewState() State {
func randomObstacles(teams []Team) []Obstacle { func randomObstacles(teams []Team) []Obstacle {
var os []Obstacle var os []Obstacle
const numObstacles = 12 * NumTeams const numObstacles = 5 * NumTeams
for i := 0; i < numObstacles; i++ { for i := 0; i < numObstacles; i++ {
os = append(os, Obstacle{ os = append(os, Obstacle{
Position: randomOpenPosition(teams, os), Position: randomOpenPosition(teams, os),
@ -286,6 +286,6 @@ var (
const ( const (
Steps = 50 Steps = 50
numBots = 5 numBots = 5
NumTeams = 6 NumTeams = 8
NumLanes = NumTeams NumLanes = NumTeams
) )

View File

@ -5,6 +5,7 @@ import (
"image" "image"
"image/color" "image/color"
_ "image/png" _ "image/png"
"math/rand"
"os" "os"
"relay/game" "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 { func Render(rs RenderState, sOld, sNew game.State, w *pixelgl.Window, sb spriteBank) RenderState {
w.Clear(colornames.Black) renderBackground(w)
colors := teamColors(sNew.Teams) colors := teamColors(sNew.Teams)
ctx := context{ ctx := context{
@ -74,6 +75,31 @@ func Render(rs RenderState, sOld, sNew game.State, w *pixelgl.Window, sb spriteB
return rs 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) { func renderBots(ctx context, colors map[*game.Team]pixel.RGBA, pic pixel.Picture) {
for i, t := range ctx.sNew.Teams { for i, t := range ctx.sNew.Teams {
c := colors[&ctx.sNew.Teams[i]] c := colors[&ctx.sNew.Teams[i]]
@ -159,9 +185,9 @@ func teamColors(ts []game.Team) map[*game.Team]pixel.RGBA {
var c color.RGBA var c color.RGBA
switch i { switch i {
case 0: case 0:
c = colornames.Red c = colornames.Palevioletred
case 1: case 1:
c = colornames.Green c = colornames.Lime
case 2: case 2:
c = colornames.Cornflowerblue c = colornames.Cornflowerblue
case 3: case 3:
@ -172,6 +198,11 @@ func teamColors(ts []game.Team) map[*game.Team]pixel.RGBA {
c = colornames.Yellow c = colornames.Yellow
case 6: case 6:
c = colornames.Blueviolet c = colornames.Blueviolet
case 7:
c = colornames.Orange
case 8:
c = colornames.Coral
} }
m[&ts[i]] = pixel.ToRGBA(c) m[&ts[i]] = pixel.ToRGBA(c)
} }

View File

@ -14,7 +14,7 @@ import (
func run() error { func run() error {
cfg := pixelgl.WindowConfig{ cfg := pixelgl.WindowConfig{
Title: "Relay", Title: "Relay",
Bounds: pixel.R(0, 0, 2048, 512), Bounds: pixel.R(0, 0, 2048, 1024),
VSync: true, VSync: true,
} }
@ -47,7 +47,7 @@ func run() error {
if !rs.Animating { if !rs.Animating {
sOld = s sOld = s
} }
case w.Pressed(pixelgl.KeySpace): case w.Pressed(pixelgl.KeySpace) || true:
log.Printf("TURN %d", turn) log.Printf("TURN %d", turn)
rs.Animating = true rs.Animating = true
rs.Frame = 0 rs.Frame = 0