diff options
-rw-r--r-- | assets/jump1.ogg | bin | 0 -> 7095 bytes | |||
-rw-r--r-- | assets/jump2.ogg | bin | 0 -> 5784 bytes | |||
-rw-r--r-- | assets/land1.ogg | bin | 0 -> 7658 bytes | |||
-rw-r--r-- | assets/land2.ogg | bin | 0 -> 6857 bytes | |||
-rw-r--r-- | main.go | 41 | ||||
-rw-r--r-- | objects.go | 31 | ||||
-rw-r--r-- | shaders/clouds.kage | 6 |
7 files changed, 68 insertions, 10 deletions
diff --git a/assets/jump1.ogg b/assets/jump1.ogg Binary files differnew file mode 100644 index 0000000..e369d63 --- /dev/null +++ b/assets/jump1.ogg diff --git a/assets/jump2.ogg b/assets/jump2.ogg Binary files differnew file mode 100644 index 0000000..127d16a --- /dev/null +++ b/assets/jump2.ogg diff --git a/assets/land1.ogg b/assets/land1.ogg Binary files differnew file mode 100644 index 0000000..6c71e18 --- /dev/null +++ b/assets/land1.ogg diff --git a/assets/land2.ogg b/assets/land2.ogg Binary files differnew file mode 100644 index 0000000..af70def --- /dev/null +++ b/assets/land2.ogg @@ -41,6 +41,8 @@ const ( sampleRate = 44100 shadowOffset = 1 + + musicLoopLength = 230 ) var ( @@ -73,6 +75,18 @@ var ( //go:embed assets/spring.ogg springOgg_src []byte + + //go:embed assets/jump1.ogg + jump1Ogg_src []byte + + //go:embed assets/jump2.ogg + jump2Ogg_src []byte + + //go:embed assets/land1.ogg + land1Ogg_src []byte + + //go:embed assets/land2.ogg + land2Ogg_src []byte ) var ( @@ -110,6 +124,8 @@ type AudioPlayer struct { startAudio *audio.Player ambientAudio *audio.Player springAudio *audio.Player + jumpAudio []*audio.Player + landAudio []*audio.Player } type Game struct { @@ -257,6 +273,10 @@ func (g *Game) Update() error { if g.state == IN_GAME || g.state == PLACING { + if g.audioPlayer.ambientAudio.Position().Seconds() > musicLoopLength { + g.audioPlayer.ambientAudio.Rewind() + } + if ! g.audioPlayer.ambientAudio.IsPlaying() { g.audioPlayer.ambientAudio.Play() } @@ -649,6 +669,25 @@ func (g *Game) SetPlacing() { g.StopRewinding() } +func loadAudiosVorbis(oggFiles [][]byte, audioContext *audio.Context) []*audio.Player { + var players = make([]*audio.Player, 0) + for _, x := range oggFiles { + var err error + sound, err := vorbis.DecodeWithoutResampling(bytes.NewReader(x)) + if err != nil { + return nil + } + + p, err := audioContext.NewPlayer(sound) + + if err != nil { + return nil + } + players = append(players, p) + } + return players +} + func loadAudioVorbis(oggFile []byte, audioContext *audio.Context) *audio.Player { var err error @@ -689,6 +728,8 @@ func (g *Game) LoadAudio() { 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) + g.audioPlayer.jumpAudio = loadAudiosVorbis([][]byte{jump1Ogg_src, jump2Ogg_src}, g.audioPlayer.audioContext) + g.audioPlayer.landAudio = loadAudiosVorbis([][]byte{land1Ogg_src, land2Ogg_src}, g.audioPlayer.audioContext) } @@ -5,6 +5,7 @@ import ( "image" "image/color" + "math/rand/v2" "github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2/vector" ) @@ -138,7 +139,7 @@ func (o * GameObject) Update(tilemap Tilemap, others []*GameObject) { o.x += o.vx - if o.vx > 0 { + if o.vx < 0 { direction = LEFT } else { direction = RIGHT @@ -152,12 +153,15 @@ func (o * GameObject) Update(tilemap Tilemap, others []*GameObject) { o.y += o.vy if o.vy > 0 { - direction = UP - } else { direction = DOWN + } else { + direction = UP } if o.HasCollision(tilemap, others, direction) { + if ! o.onGround && o.vy > gravity*10 { + o.playLand() + } o.onGround = true; o.vx *= o.friction @@ -194,13 +198,13 @@ func (o * GameObject) HasCollision(tilemap Tilemap, others []*GameObject, dir Di if obj.Collide(o) { var f func(this, other *GameObject) bool switch dir { - case UP: - f = obj.onCollideUp case DOWN: + f = obj.onCollideUp + case UP: f = obj.onCollideDown - case LEFT: - f = obj.onCollideLeft case RIGHT: + f = obj.onCollideLeft + case LEFT: f = obj.onCollideRight } @@ -256,8 +260,21 @@ func (object * GameObject) Collide(other *GameObject) bool { return ! ( minX2 >= maxX1 || maxX2 <= minX1 || minY2 >= maxY1 || maxY2 <= minY1) } +func (object *GameObject) playLand() { + jumpid := rand.IntN(2) + object.game.audioPlayer.landAudio[jumpid].Rewind() + object.game.audioPlayer.landAudio[jumpid].Play() +} + +func (object *GameObject) playJump() { + jumpid := rand.IntN(2) + object.game.audioPlayer.jumpAudio[jumpid].Rewind() + object.game.audioPlayer.jumpAudio[jumpid].Play() +} + func (object * GameObject) Jump() { if object.onGround { + object.playJump() object.vy += -jumpHeight } } diff --git a/shaders/clouds.kage b/shaders/clouds.kage index 62a0ae0..8674d25 100644 --- a/shaders/clouds.kage +++ b/shaders/clouds.kage @@ -9,10 +9,10 @@ var Time float const cloudscale = 0.8 const speed = 0.01 const clouddark = 0.6 -const cloudlight = 0.3 +const cloudlight = 0.1 const cloudcover = 0.2 const cloudalpha = 8.0 -const skytint = 0.5 +const skytint = 0.4 const colorDepth = 64 func rand(co vec2) float { @@ -65,7 +65,7 @@ func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 { p := floor(srcPos.xy) / imageSrc0Size().xy; - uv := p*vec2(imageSrc0Size().x/imageSrc0Size().y,1.0); + uv := p*vec2(imageSrc0Size().x/imageSrc0Size().y,1.0); time := Time * speed q := fbm(uv * cloudscale * 0.5) |