Pretty much working
This commit is contained in:
parent
ec97d5e228
commit
95919e67e7
@ -16,6 +16,7 @@ const (
|
||||
modeRun
|
||||
modeRunInput
|
||||
modePause
|
||||
modeGameOver
|
||||
)
|
||||
|
||||
type mainScreen struct {
|
||||
@ -170,7 +171,7 @@ func (screen *mainScreen) update() {
|
||||
screen.PauseMenu.SetTitle("Player 1 LOSES.")
|
||||
} else {
|
||||
// Victory!
|
||||
screen.PauseMenu.SetTitle("Player 1 Wins!")
|
||||
screen.PauseMenu.SetTitle("Player 2 Wins!")
|
||||
}
|
||||
screen.GameMode = modePause
|
||||
}
|
||||
@ -182,7 +183,7 @@ func (screen *mainScreen) update() {
|
||||
screen.PauseMenu.SetTitle("Player 2 LOSES.")
|
||||
} else {
|
||||
// Victory!
|
||||
screen.PauseMenu.SetTitle("Player 2 Wins!")
|
||||
screen.PauseMenu.SetTitle("Player 1 Wins!")
|
||||
}
|
||||
screen.GameMode = modePause
|
||||
}
|
||||
@ -277,7 +278,8 @@ func (p *projectile) init(pl *player) {
|
||||
p.launchTime = time.Now()
|
||||
p.angle = pl.projAngle
|
||||
p.speed = pl.projSpeed
|
||||
p.startX, p.startY = pl.GetBulletHandPos()
|
||||
p.startX, p.startY = pl.GetClosestTrajectory()
|
||||
//p.startX, p.startY = pl.x+2, pl.y+2
|
||||
p.x = p.startX
|
||||
p.y = p.startY
|
||||
}
|
||||
@ -289,11 +291,14 @@ func (p *projectile) update() {
|
||||
useA := degToRad(p.angle)
|
||||
p.x = int(useX + (useSpeed * math.Cos(useA) * tm))
|
||||
p.y = int(useY + (useSpeed*math.Sin(useA)*tm - p.gravity*tm*tm/2))
|
||||
WriteToLog(fmt.Sprintf("%f - S:%d; (%d,%d)=>(%d,%d)\n", useA, p.speed, p.startX, p.startY, p.x, p.y))
|
||||
}
|
||||
|
||||
func (p *projectile) draw() {
|
||||
termbox.SetCell(p.x, p.y, '0', termbox.ColorYellow, termbox.ColorBlack)
|
||||
if p.y < 0 {
|
||||
termbox.SetCell(p.x, 0, '^', termbox.ColorYellow, termbox.ColorBlack)
|
||||
} else {
|
||||
termbox.SetCell(p.x, p.y, '0', termbox.ColorYellow, termbox.ColorBlack)
|
||||
}
|
||||
}
|
||||
|
||||
type player struct {
|
||||
@ -345,19 +350,39 @@ func (p *player) draw() {
|
||||
// Now draw the arms
|
||||
if p.turn {
|
||||
bulletHandX, bulletHandY := p.GetBulletHandPos()
|
||||
termbox.SetCell(bulletHandX, bulletHandY, '+', termbox.ColorBlack, p.baseColor)
|
||||
termbox.SetCell(bulletHandX, bulletHandY, 'X', termbox.ColorRed|termbox.AttrBold, termbox.ColorBlack)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *player) didCollide(pr *projectile) bool {
|
||||
WriteToLog(fmt.Sprintf("Player: (%d,%d) -> (%d,%d)\n", p.x, p.y-4, p.x+4, p.y))
|
||||
WriteToLog(fmt.Sprintf("Projectile: (%d,%d)\n", pr.x, pr.y))
|
||||
if pr.x >= p.x && pr.x <= p.x+4 {
|
||||
return pr.y <= p.y && pr.y >= p.y-4
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *player) GetClosestTrajectory() (int, int) {
|
||||
// Find the spot closest to the player in a direct line with the target
|
||||
bHx, bHy := p.GetBulletHandPos()
|
||||
gx, gy := p.x+2, p.y-2
|
||||
for gx >= p.x && gx <= p.x+4 && gy >= p.y-4 && gy <= p.y {
|
||||
if math.Abs(float64(bHx-gx)) > math.Abs(float64(bHy-gy)) {
|
||||
if bHx > gx {
|
||||
gx++
|
||||
} else {
|
||||
gx--
|
||||
}
|
||||
} else {
|
||||
if bHy > gy {
|
||||
gy++
|
||||
} else {
|
||||
gy--
|
||||
}
|
||||
}
|
||||
}
|
||||
return gx, gy
|
||||
}
|
||||
|
||||
func (p *player) GetBulletHandPos() (int, int) {
|
||||
tm := 0.5
|
||||
useSpeed := float64(p.projSpeed)
|
||||
@ -366,34 +391,6 @@ func (p *player) GetBulletHandPos() (int, int) {
|
||||
retX := int(useX + (useSpeed * math.Cos(useA) * tm))
|
||||
retY := int(useY + (useSpeed*math.Sin(useA)*tm - p.gravity*tm*tm/2))
|
||||
return retX, retY
|
||||
/*
|
||||
if p.projAngle <= 11 {
|
||||
return p.x + 5, p.y - 2
|
||||
} else if p.projAngle <= 22 {
|
||||
return p.x + 5, p.y - 3
|
||||
} else if p.projAngle <= 41 {
|
||||
return p.x + 5, p.y - 4
|
||||
} else if p.projAngle <= 50 {
|
||||
return p.x + 5, p.y - 5
|
||||
} else if p.projAngle <= 77 {
|
||||
return p.x + 4, p.y - 5
|
||||
} else if p.projAngle <= 86 {
|
||||
return p.x + 3, p.y - 5
|
||||
} else if p.projAngle <= 95 {
|
||||
return p.x + 2, p.y - 5
|
||||
} else if p.projAngle <= 119 {
|
||||
return p.x + 1, p.y - 5
|
||||
} else if p.projAngle <= 130 {
|
||||
return p.x, p.y - 5
|
||||
} else if p.projAngle <= 141 {
|
||||
return p.x - 1, p.y - 5
|
||||
} else if p.projAngle <= 152 {
|
||||
return p.x - 1, p.y - 4
|
||||
} else if p.projAngle <= 165 {
|
||||
return p.x - 1, p.y - 3
|
||||
}
|
||||
return p.x - 1, p.y - 2
|
||||
*/
|
||||
}
|
||||
|
||||
type building struct {
|
||||
|
Loading…
Reference in New Issue
Block a user