Clamping player's position horizontally, added camera
This commit is contained in:
parent
6119e288f8
commit
461d177cfa
42
main.go
42
main.go
|
@ -11,38 +11,39 @@ var sticks []*Stick = []*Stick{}
|
|||
var player *Player
|
||||
var frame uint64 = 0
|
||||
var lightIndex uint64 = 0
|
||||
var camX = 0
|
||||
var camY = 0
|
||||
var camX int = 0
|
||||
var camY int = 0
|
||||
|
||||
//go:export start
|
||||
func start() {
|
||||
|
||||
rand.Seed(654654321348654)
|
||||
rand.Seed(654348654)
|
||||
points = []*Point{}
|
||||
sticks = []*Stick{}
|
||||
w4.PALETTE[0] = 0xfcdeea
|
||||
w4.PALETTE[1] = 0x012824
|
||||
w4.PALETTE[2] = 0x265935
|
||||
w4.PALETTE[3] = 0xff4d6d
|
||||
for i := 0; i < 4; i++ {
|
||||
|
||||
for i := 0.0; i < 8; i++ {
|
||||
var y1, y2 float64
|
||||
if int(i)%2 == 0 {
|
||||
y1 = rand.Float64()*40 - 20
|
||||
y2 = rand.Float64() * 40
|
||||
} else {
|
||||
y1 = rand.Float64() * 40
|
||||
y2 = rand.Float64()*40 - 20
|
||||
}
|
||||
|
||||
p, s := CreateRope(
|
||||
Vector{160, rand.Float64()*40 + float64(i*40)},
|
||||
Vector{0, rand.Float64()*40 + float64(i*40)},
|
||||
10,
|
||||
Vector{0, y1 + i*30},
|
||||
Vector{320, y2 + i*30},
|
||||
14,
|
||||
)
|
||||
points = append(points, p...)
|
||||
sticks = append(sticks, s...)
|
||||
}
|
||||
for i := 0; i < 3; i++ {
|
||||
p, s := CreateRope(
|
||||
Vector{float64(i*30 + 30), 0},
|
||||
Vector{float64(i*30 + 40), 100},
|
||||
10,
|
||||
)
|
||||
p[len(p)-1].IsLocked = false
|
||||
points = append(points, p...)
|
||||
sticks = append(sticks, s...)
|
||||
}
|
||||
|
||||
player = &Player{
|
||||
Position: Vector{80, 80},
|
||||
Speed: Vector{},
|
||||
|
@ -57,12 +58,17 @@ func update() {
|
|||
*w4.DRAW_COLORS = 2
|
||||
// w4.Text("Hello from Go!", 10, 10)
|
||||
Simulate(points, sticks)
|
||||
player.Update()
|
||||
camX, camY = int(player.Position.X)-80, int(player.Position.Y)-80
|
||||
for _, s := range sticks {
|
||||
s.Draw()
|
||||
}
|
||||
for _, p := range points {
|
||||
p.Draw()
|
||||
}
|
||||
player.Update()
|
||||
player.Draw()
|
||||
|
||||
*w4.DRAW_COLORS = 0x23
|
||||
w4.Rect(-160-camX, -100-camY, 160, 500)
|
||||
w4.Rect(320-camX, -100-camY, 160, 500)
|
||||
}
|
||||
|
|
|
@ -106,6 +106,7 @@ func (p *Player) Update() {
|
|||
}
|
||||
}
|
||||
}
|
||||
p.Position.X = math.Min(math.Max(0, p.Position.X), 320)
|
||||
}
|
||||
|
||||
func (p *Player) MoveOnRope(motion Vector) {
|
||||
|
@ -116,5 +117,5 @@ func (p *Player) MoveOnRope(motion Vector) {
|
|||
|
||||
func (p *Player) Draw() {
|
||||
*w4.DRAW_COLORS = 0x34
|
||||
w4.Rect(int(p.Position.X)-4, int(p.Position.Y)-4, 8, 8)
|
||||
w4.Rect(int(p.Position.X)-4-camX, int(p.Position.Y)-4-camY, 8, 8)
|
||||
}
|
||||
|
|
6
ropes.go
6
ropes.go
|
@ -31,7 +31,7 @@ func (p *Point) Draw() {
|
|||
if fr > 40 {
|
||||
*w4.DRAW_COLORS = 0x34
|
||||
}
|
||||
w4.Oval(int(p.Position.X)-2, int(p.Position.Y)-2, 4, 4)
|
||||
w4.Oval(int(p.Position.X)-2-camX, int(p.Position.Y)-2-camY, 4, 4)
|
||||
}
|
||||
|
||||
type Stick struct {
|
||||
|
@ -80,8 +80,8 @@ func (s *Stick) GetOffset(p Vector) float64 {
|
|||
|
||||
func (s *Stick) Draw() {
|
||||
*w4.DRAW_COLORS = 0x3
|
||||
w4.Line(int(s.PointA.Position.X), int(s.PointA.Position.Y),
|
||||
int(s.PointB.Position.X), int(s.PointB.Position.Y))
|
||||
w4.Line(int(s.PointA.Position.X)-camX, int(s.PointA.Position.Y)-camY,
|
||||
int(s.PointB.Position.X)-camX, int(s.PointB.Position.Y)-camY)
|
||||
}
|
||||
|
||||
func Simulate(points []*Point, sticks []*Stick) {
|
||||
|
|
Loading…
Reference in New Issue