summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavidovski <david@davidovski.xyz>2024-04-23 02:28:40 +0100
committerdavidovski <david@davidovski.xyz>2024-04-23 02:28:40 +0100
commit37d73474ccc38a39bea5dd3225370343262d09cc (patch)
tree08bc1e869dcab0add125f6733a2cde6749fb4438
parentf51a9efca57b561a3ccd88d04e1330dc9cc65726 (diff)
Add Side Spring
-rw-r--r--assets/tiles.pngbin4666 -> 5278 bytes
-rw-r--r--level.go7
-rw-r--r--main.go30
-rw-r--r--objects.go134
4 files changed, 157 insertions, 14 deletions
diff --git a/assets/tiles.png b/assets/tiles.png
index 9d76526..846371e 100644
--- a/assets/tiles.png
+++ b/assets/tiles.png
Binary files differ
diff --git a/level.go b/level.go
index 4d5bcec..760f872 100644
--- a/level.go
+++ b/level.go
@@ -5,7 +5,7 @@ import (
)
func StartGame(g *Game) {
- StartLevel4(g)
+ StartLevel1(g)
}
func PauseScreen(g *Game) {
@@ -63,6 +63,7 @@ func StartLevel1(g *Game ) {
0, 53, 70, 71, 69, 70, 71, 69, 70, 71, 69, 70, 71, 69, 70, 71, 69, 70, 71, 69, 70, 71, 69, 70, 0,
0, 69, 38, 39, 37, 38, 39, 37, 38, 39, 37, 38, 39, 37, 38, 39, 37, 38, 39, 37, 38, 39, 37, 38, 0,
0, 69, 38, 39, 37, 38, 39, 37, 38, 39, 37, 38, 39, 37, 38, 39, 37, 38, 39, 37, 38, 39, 37, 38, 0,
+ 0, 69, 38, 39, 37, 38, 39, 37, 38, 39, 37, 38, 39, 37, 38, 39, 37, 38, 39, 37, 38, 39, 37, 38, 0,
},
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@@ -82,6 +83,7 @@ func StartLevel1(g *Game ) {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
},
}, 25)
@@ -218,6 +220,9 @@ func StartLevel6(g *Game) {
//noMoveable(g)
g.toPlace = append(g.toPlace, NewSpring(g, 0, 0))
+ g.toPlace = append(g.toPlace, NewRightSideSpring(g, 0, 0))
+ g.toPlace = append(g.toPlace, NewLeftSideSpring(g, 0, 0))
+ g.toPlace = append(g.toPlace, NewBox(g, 0, 0))
g.exit.movable = true
// after end
diff --git a/main.go b/main.go
index fcb31c4..ee83755 100644
--- a/main.go
+++ b/main.go
@@ -100,6 +100,7 @@ type RecPoint struct {
vx float32
vy float32
alpha float32
+ delta int
}
type AudioPlayer struct {
@@ -143,6 +144,7 @@ func (g * Game)RecordPoint() {
vx: object.vx,
vy: object.vy,
alpha: object.alpha,
+ delta: object.delta,
})
}
g.recording = append(g.recording, points)
@@ -162,6 +164,7 @@ func (g * Game)ReplayPoint() {
obj.vx = point.vx
obj.vy = point.vy
obj.alpha = point.alpha
+ obj.delta = point.delta
}
}
@@ -216,6 +219,7 @@ func (g * Game) ResetAll() {
obj.y = obj.starty
obj.vx = 0
obj.vy = 0
+ obj.delta = 0
}
g.recording = g.recording[:0];
}
@@ -384,6 +388,7 @@ func (g *Game) PlaceObject(cx, cy int) {
return
}
+ placeable.delta = 0
placeable.startx = float32(cx)
placeable.starty = float32(cy)
placeable.highlight = false
@@ -429,6 +434,25 @@ func PostProcess(screen *ebiten.Image, shaderName string, time int) {
}
+func (g *Game) DrawVCRControls(surface *ebiten.Image) {
+ textSize := 15.0
+
+ var msg string
+ if g.state == REVERSING {
+ msg = fmt.Sprintf("<<")
+ } else {
+ msg = fmt.Sprintf("||")
+ }
+ textOp := &text.DrawOptions{}
+ textOp.GeoM.Translate(15, 15)
+ textOp.ColorScale.ScaleWithColor(color.RGBA{255, 255, 255, 255})
+ text.Draw(surface, msg, &text.GoTextFace{
+ Size: textSize,
+ Source: fontFaceSource,
+ }, textOp)
+
+}
+
func (g *Game) DrawTheEnd(surface *ebiten.Image, alpha float32) {
textSize := 30.0
@@ -476,7 +500,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
a = 1 - float64(math.Pow(float64(a), 2))
if g.state == PAUSED {
- a = 10.0
+ a = 1.0
}
if a < 0.0 {
@@ -496,6 +520,10 @@ func (g *Game) Draw(screen *ebiten.Image) {
screen.DrawImage(g.surface, op)
}
+ if g.state == REVERSING || g.state == PAUSED {
+ g.DrawVCRControls(screen)
+ }
+
PostProcess(screen, g.shaderName, g.time)
diff --git a/objects.go b/objects.go
index 008d712..4ebc8ce 100644
--- a/objects.go
+++ b/objects.go
@@ -10,6 +10,7 @@ import (
const (
SPRING_FORCE = 8
+ SIDE_SPRING_FORCE = 8
)
type Direction int
@@ -41,7 +42,7 @@ type GameObject struct {
onCollideLeft func(this, other *GameObject) bool
onCollideRight func(this, other *GameObject) bool
Draw func (o * GameObject, screen *ebiten.Image, tilemap Tilemap)
- UpdateFunc func (o * GameObject, tilemap Tilemap, others []*GameObject)
+ UpdateFunc func (o * GameObject, tilemap Tilemap, others []*GameObject) bool
movable bool
state int
delta int
@@ -52,7 +53,31 @@ type Player struct {
GameObject
}
-func UpdateSpring(o * GameObject, tilemap Tilemap, others []*GameObject) {
+func UpdateHPlatform(o * GameObject, tilemap Tilemap, others []*GameObject) bool {
+ o.delta += 1
+ if int(o.delta / 128) % 2 == 0 {
+ o.vx = -0.4
+ } else {
+ o.vx = 0.4
+ }
+ o.x += o.vx
+ o.vy = 0
+ return true
+}
+
+func UpdateVPlatform(o * GameObject, tilemap Tilemap, others []*GameObject) bool {
+ o.delta += 1
+ if int(o.delta / 128) % 2 == 0 {
+ o.vy = -0.4
+ } else {
+ o.vy = 0.4
+ }
+ o.y += o.vy
+ return true
+}
+
+func UpdateSpring(o * GameObject, tilemap Tilemap, others []*GameObject) bool {
+ o.delta += 1
if o.delta % 3 == 0 {
if o.state == 1 {
o.state = 0
@@ -60,27 +85,29 @@ func UpdateSpring(o * GameObject, tilemap Tilemap, others []*GameObject) {
o.state = 1
}
}
+ return false
}
func (o * GameObject) Update(tilemap Tilemap, others []*GameObject) {
- if o.UpdateFunc != nil {
- o.UpdateFunc(o, tilemap, others)
- }
- o.delta += 1
-
var direction Direction
o.vy += gravity
o.vx *= o.resistance
o.vy *= o.resistance
+ if o.UpdateFunc != nil {
+ if o.UpdateFunc(o, tilemap, others) {
+ return
+ }
+ }
+
o.x += o.vx
if o.vx > 0 {
- direction = RIGHT
- } else {
direction = LEFT
+ } else {
+ direction = RIGHT
}
if o.HasCollision(tilemap, others, direction) {
@@ -105,6 +132,7 @@ func (o * GameObject) Update(tilemap Tilemap, others []*GameObject) {
} else {
o.onGround = false;
}
+
}
func GetObjectAt(objects []*GameObject, x, y float32) *GameObject {
@@ -283,7 +311,35 @@ func NewSpring(game *Game, x, y float32) *GameObject{
tilesImage.SubImage(image.Rect(176, 16, 192, 32)).(*ebiten.Image),
tilesImage.SubImage(image.Rect(176, 32, 192, 48)).(*ebiten.Image),
}
- spring.onCollideUp = OnCollideSpring
+ spring.onCollideUp = OnCollideTopSpring
+ spring.UpdateFunc = UpdateSpring
+
+ return spring
+}
+
+func NewRightSideSpring(game *Game, x, y float32) *GameObject{
+ spring := NewObject(game, x, y)
+
+ spring.images = []*ebiten.Image{
+ tilesImage.SubImage(image.Rect(176, 48, 192, 64)).(*ebiten.Image),
+ tilesImage.SubImage(image.Rect(176, 64, 192, 80)).(*ebiten.Image),
+ tilesImage.SubImage(image.Rect(176, 80, 192, 96)).(*ebiten.Image),
+ }
+ spring.onCollideRight = OnCollideRightSideSpring
+ spring.UpdateFunc = UpdateSpring
+
+ return spring
+}
+
+func NewLeftSideSpring(game *Game, x, y float32) *GameObject{
+ spring := NewObject(game, x, y)
+
+ spring.images = []*ebiten.Image{
+ tilesImage.SubImage(image.Rect(176, 96, 192, 112)).(*ebiten.Image),
+ tilesImage.SubImage(image.Rect(176, 112, 192, 128)).(*ebiten.Image),
+ tilesImage.SubImage(image.Rect(176, 128, 192, 144)).(*ebiten.Image),
+ }
+ spring.onCollideLeft = OnCollideLeftSideSpring
spring.UpdateFunc = UpdateSpring
return spring
@@ -309,11 +365,36 @@ func NewLeftSpike(game *Game, x, y float32) *GameObject{
spike.images = []*ebiten.Image{
tilesImage.SubImage(image.Rect(195, 16, 208, 32)).(*ebiten.Image),
}
- spike.onCollideRight = OnCollideSpike
+ spike.onCollideLeft = OnCollideSpike
return spike
}
+func NewVPlatform(game *Game, x, y float32) *GameObject{
+ platform := NewObject(game, x, y)
+
+ platform.images = []*ebiten.Image{
+ tilesImage.SubImage(image.Rect(208, 0, 224, 5)).(*ebiten.Image),
+ }
+ platform.onCollideUp = OnCollideVPlatformTop
+ platform.onCollideDown = OnCollideVPlatformBottom
+ platform.UpdateFunc = UpdateVPlatform
+
+ return platform
+}
+
+func NewHPlatform(game *Game, x, y float32) *GameObject{
+ platform := NewObject(game, x, y)
+
+ platform.images = []*ebiten.Image{
+ tilesImage.SubImage(image.Rect(208, 0, 224, 5)).(*ebiten.Image),
+ }
+ platform.onCollideUp = OnCollideVPlatformTop
+ platform.UpdateFunc = UpdateHPlatform
+
+ return platform
+}
+
func OnCollideExit(this, other *GameObject) bool {
if other == this.game.player {
g := other.game
@@ -329,7 +410,6 @@ func OnCollideExit(this, other *GameObject) bool {
}
func OnCollideSpring(this, other *GameObject) bool {
- other.vy = -SPRING_FORCE
other.onGround = true
this.state = 2
this.delta = 1
@@ -338,6 +418,25 @@ func OnCollideSpring(this, other *GameObject) bool {
return false
}
+func OnCollideTopSpring(this, other *GameObject) bool {
+ other.vy = -SPRING_FORCE
+ other.y += other.vy
+
+ return OnCollideSpring(this, other)
+}
+
+func OnCollideLeftSideSpring(this, other *GameObject) bool {
+ other.vx = -SPRING_FORCE
+ other.x += other.vx
+ return OnCollideSpring(this, other)
+}
+
+func OnCollideRightSideSpring(this, other *GameObject) bool {
+ other.vx = SPRING_FORCE
+ other.x += other.vx
+ return OnCollideSpring(this, other)
+}
+
func OnCollideSpike(this, other *GameObject) bool {
if other == this.game.player {
other.game.KillPlayer()
@@ -345,3 +444,14 @@ func OnCollideSpike(this, other *GameObject) bool {
return true
}
+func OnCollideVPlatformTop(this, other *GameObject) bool {
+ other.y = this.y - float32(other.images[0].Bounds().Dy()) + this.vy
+ other.vy = this.vy
+ other.x += this.vx
+ return true
+}
+func OnCollideVPlatformBottom(this, other *GameObject) bool {
+ other.y = this.y + float32(this.images[0].Bounds().Dy())
+ other.vy = this.vy
+ return false
+}