summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavidovski <david@davidovski.xyz>2024-04-23 01:24:40 +0100
committerdavidovski <david@davidovski.xyz>2024-04-23 01:24:40 +0100
commitf51a9efca57b561a3ccd88d04e1330dc9cc65726 (patch)
treea88786e70c7bcb26aa71f34e171c85ecc95bdf1d
parent2824bb82ccb8b336779a78cd1f82bc675efaca91 (diff)
add spring boing
-rw-r--r--assets/ambient.oggbin2893087 -> 4605681 bytes
-rw-r--r--assets/spring.oggbin0 -> 12022 bytes
-rw-r--r--assets/tiles.pngbin4654 -> 4666 bytes
-rw-r--r--level.go51
-rw-r--r--main.go33
-rw-r--r--objects.go2
6 files changed, 63 insertions, 23 deletions
diff --git a/assets/ambient.ogg b/assets/ambient.ogg
index f64284c..b858738 100644
--- a/assets/ambient.ogg
+++ b/assets/ambient.ogg
Binary files differ
diff --git a/assets/spring.ogg b/assets/spring.ogg
new file mode 100644
index 0000000..0ab726b
--- /dev/null
+++ b/assets/spring.ogg
Binary files differ
diff --git a/assets/tiles.png b/assets/tiles.png
index 58096da..9d76526 100644
--- a/assets/tiles.png
+++ b/assets/tiles.png
Binary files differ
diff --git a/level.go b/level.go
index 24c79ff..4d5bcec 100644
--- a/level.go
+++ b/level.go
@@ -3,6 +3,11 @@ package main
import (
"fmt"
)
+
+func StartGame(g *Game) {
+ StartLevel4(g)
+}
+
func PauseScreen(g *Game) {
g.SetPaused()
fmt.Printf("PAUSE\n", 0, len(g.playerAi))
@@ -28,14 +33,14 @@ func levelStart(g *Game) {
g.ResetAll()
g.playerAiIdx = 0
g.SetInGame()
+}
+
+func noMoveable(g *Game) {
for _, o := range g.objects {
o.movable = false
}
}
-func StartGame(g *Game) {
- StartLevel1(g)
-}
func StartLevel1(g *Game ) {
g.SetInGame()
@@ -106,6 +111,7 @@ func StartLevel1(g *Game ) {
func StartLevel2(g *Game) {
g.SetPlacing()
+ noMoveable(g)
g.toPlace = append(g.toPlace, NewLeftSpike(g, 0, 0))
@@ -118,6 +124,7 @@ func StartLevel2(g *Game) {
func StartLevel3(g *Game) {
g.SetPlacing()
+ noMoveable(g)
g.toPlace = append(g.toPlace, NewSpike(g, 0, 0))
@@ -130,6 +137,8 @@ func StartLevel3(g *Game) {
func StartLevel4(g *Game) {
g.SetPlacing()
+ noMoveable(g)
+
g.toPlace = append(g.toPlace, NewSpring(g, 0, 0))
g.ClearAll()
@@ -139,11 +148,11 @@ func StartLevel4(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,
- 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, 35, 36, 34, 35, 36, 34, 35, 36, 34, 67, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 50, 34, 67, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 37, 69, 70, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 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, 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, 83, 84, 82, 83, 84, 82, 83, 84, 82, 115, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 84, 82, 83, 84, 82, 83, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 0,
@@ -174,7 +183,7 @@ func StartLevel4(g *Game) {
g.tilemap = &tilemap
g.tilemap.UpdateSurface()
- g.exit.startx = 20 * tileSize
+ g.exit.startx = 18 * tileSize
g.exit.starty = 6 * tileSize
g.ResetAll()
@@ -188,9 +197,27 @@ func StartLevel4(g *Game) {
g.QueueState(StartLevel5)
}
+// HMM maybe we can make this a bit harder, lets try moving the exit by clicking on it
func StartLevel5(g *Game) {
g.SetPlacing()
- g.toPlace = append(g.toPlace, NewSpike(g, 0, 0))
+ //noMoveable(g)
+
+ //g.toPlace = append(g.toPlace, NewSpring(g, 0, 0))
+ g.exit.movable = true
+ g.toPlace = append(g.toPlace, NewSpring(g, 0, 0))
+ // after end
+ g.QueueState(ReverseLevel)
+ // after reversed
+ g.QueueState(afterReversed)
+ g.QueueState(StartLevel5)
+}
+
+// Ok lets add a spring there as well
+func StartLevel6(g *Game) {
+ g.SetPlacing()
+ //noMoveable(g)
+
+ g.toPlace = append(g.toPlace, NewSpring(g, 0, 0))
g.exit.movable = true
// after end
diff --git a/main.go b/main.go
index 1be1bef..fcb31c4 100644
--- a/main.go
+++ b/main.go
@@ -11,7 +11,7 @@ import (
"math"
"github.com/hajimehoshi/ebiten/v2"
- "github.com/hajimehoshi/ebiten/v2/ebitenutil"
+ _ "github.com/hajimehoshi/ebiten/v2/ebitenutil"
"github.com/hajimehoshi/ebiten/v2/inpututil"
"github.com/hajimehoshi/ebiten/v2/text/v2"
"github.com/hajimehoshi/ebiten/v2/examples/resources/fonts"
@@ -28,7 +28,6 @@ const (
tileSize = 16
playerSpeed = 2.1
jumpHeight = 4
- rewindSpeed = 2
gravity = 0.16
friction = 0.75
airResistance = 0.98
@@ -71,6 +70,9 @@ var (
//go:embed assets/ambient.ogg
ambientOgg_src []byte
+
+ //go:embed assets/spring.ogg
+ springOgg_src []byte
)
var (
@@ -78,6 +80,8 @@ var (
tilesImage *ebiten.Image
characterImage *ebiten.Image
fontFaceSource *text.GoTextFaceSource
+
+ rewindSpeed = 2
)
type State int
@@ -104,6 +108,7 @@ type AudioPlayer struct {
stopAudio *audio.Player
startAudio *audio.Player
ambientAudio *audio.Player
+ springAudio *audio.Player
}
type Game struct {
@@ -236,6 +241,12 @@ func (g *Game) Init() {
}
}
+func (g *Game) SetEditingMode() {
+ g.SetPlacing()
+ //g.playerAi = g.playerAi[:0]
+ g.ResetAll()
+ g.playerAiIdx = 0
+ }
func (g *Game) Update() error {
g.time += 1
@@ -255,6 +266,10 @@ func (g *Game) Update() error {
}
if g.state == IN_GAME {
+ if inpututil.IsKeyJustPressed(ebiten.KeyE) {
+ g.SetEditingMode()
+ }
+
if inpututil.IsKeyJustPressed(ebiten.KeyR) {
g.SetReversing()
next := func (g *Game){
@@ -420,7 +435,7 @@ func (g *Game) DrawTheEnd(surface *ebiten.Image, alpha float32) {
msg := fmt.Sprintf("THE END")
textOp := &text.DrawOptions{}
textOp.GeoM.Translate((screenWidth - textSize*7 ) / 2, (screenHeight - textSize) / 2)
- textOp.ColorScale.ScaleWithColor(color.White)
+ textOp.ColorScale.ScaleWithColor(color.RGBA{55, 53, 53, 255})
textOp.ColorScale.ScaleAlpha(alpha)
text.Draw(surface, msg, &text.GoTextFace{
Size: textSize,
@@ -458,7 +473,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
// draw THE END
a := float64(endCardDuration - (g.time - g.animStart)) / float64(endCardDuration);
- a = 1 - float64(math.Pow(float64(a), 10))
+ a = 1 - float64(math.Pow(float64(a), 2))
if g.state == PAUSED {
a = 10.0
@@ -484,7 +499,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
PostProcess(screen, g.shaderName, g.time)
- ebitenutil.DebugPrint(screen, fmt.Sprintf("tps: %.4f", ebiten.ActualFPS()))
+ //ebitenutil.DebugPrint(screen, fmt.Sprintf("tps: %.4f", ebiten.ActualFPS()))
}
func (g *Game) Layout(outsideWidth, outsideHeight int) (int, int){
@@ -533,9 +548,6 @@ func (g *Game) KillPlayer() {
g.playerAi = g.playerAi[:0]
g.SetInGame()
- for _, o := range g.objects {
- o.movable = false
- }
}
}
}
@@ -578,6 +590,7 @@ func (g *Game) SetPaused() {
}
func (g *Game) SetReversing() {
g.state = REVERSING
+ rewindSpeed = 1 + int(len(g.recording) / 120)
g.shaderName = "vcr"
g.player.alpha = 1.0
g.audioPlayer.rewindAudio.Rewind()
@@ -647,10 +660,8 @@ func (g *Game) LoadAudio() {
g.audioPlayer.stopAudio = loadAudio(stopWav_src, g.audioPlayer.audioContext)
g.audioPlayer.startAudio = loadAudio(startWav_src, g.audioPlayer.audioContext)
g.audioPlayer.ambientAudio = loadAudioVorbis(ambientOgg_src, g.audioPlayer.audioContext)
+ g.audioPlayer.springAudio = loadAudioVorbis(springOgg_src, g.audioPlayer.audioContext)
- if g.audioPlayer.ambientAudio == nil {
- fmt.Printf("AUDIO NUL")
- }
}
func (g *Game) LoadImages() {
diff --git a/objects.go b/objects.go
index b26d1c8..008d712 100644
--- a/objects.go
+++ b/objects.go
@@ -333,6 +333,8 @@ func OnCollideSpring(this, other *GameObject) bool {
other.onGround = true
this.state = 2
this.delta = 1
+ this.game.audioPlayer.springAudio.Rewind()
+ this.game.audioPlayer.springAudio.Play()
return false
}