Browse Source

When jumping the screen should scroll smartly.
This means when mario is jumping, the camera will look up. When going
down, the camera should look more down

Robin de Jong 2 years ago
parent
commit
4dbfa383ed
4 changed files with 52 additions and 27 deletions
  1. 1 1
      game/plugin/mario/map.go
  2. 31 8
      game/plugin/mario/plugin.go
  3. 2 0
      util/image.go
  4. 18 18
      web/js/Button.js

+ 1 - 1
game/plugin/mario/map.go

@@ -99,7 +99,7 @@ func (m *Map) IsBig() bool {
 }
 
 func (m *Map) IsJumping() bool {
-	return m.getValue(Delay) > 0
+	return m.getValue(0x001D) > 0
 }
 
 func (m *Map) IsFalling() bool {

+ 31 - 8
game/plugin/mario/plugin.go

@@ -7,6 +7,7 @@ import (
 	"glitter.jemoeders.website/biodiscus/ledbanner_nes/game/plugin"
 )
 
+//const NormalHeight = 24
 const NormalHeight = 24
 const BigHeight = 35
 
@@ -20,11 +21,14 @@ type Plugin struct {
 
 	original util.Size
 	projection util.Size
+
+	yOffset int
 }
 
 func (m *Plugin) Init(originalSize util.Size, projectionSize util.Size) {
 	m.original = originalSize
 	m.projection = projectionSize
+	m.yOffset = 0
 
 	m.camera = util.NewCamera(0, 0, int(m.original.Width), NormalHeight)
 	m.mario = NewMario(nes.Ram)
@@ -41,23 +45,42 @@ func (m *Plugin) Tick(frame screen.Frame, memory nes.Memory) {
 		m.camera.SetPosition(0, int(y))
 
 		if m.mario.IsJumping() {
-			if m.mario.IsFalling() {
-				m.scale -= 5
-
-				if m.scale < 0 {
-					m.scale = 0
-				}
-			} else {
+			if !m.mario.IsFalling() {
 				m.scale += 5
 
 				if m.scale > 50 {
 					m.scale = 50
 				}
+
+				m.yOffset -= 2
+
+				if m.yOffset < -10 {
+					m.yOffset = -10
+				}
+			} else {
+				m.yOffset += 5
+
+				if m.yOffset > 30 {
+					m.yOffset = 30
+				}
 			}
 		} else {
-			m.scale = 0
+
+			m.scale -= 5
+
+			if m.yOffset > 0 {
+				m.yOffset -= 5
+			} else {
+				m.yOffset = 0
+			}
+
+			if m.scale < 0 {
+				m.scale = 0
+			}
 		}
 
+		m.camera.Y += m.yOffset
+
 		height := NormalHeight
 		width := int(m.original.Width)
 		yOffset := height / 4

+ 2 - 0
util/image.go

@@ -5,6 +5,7 @@ import (
 	"golang.org/x/image/draw"
 	"os"
 	"image/png"
+	"image/color"
 )
 
 func getAspectScale(in Size, width uint) float64 {
@@ -46,6 +47,7 @@ func SaveImage(name string, img image.RGBA) {
 // Return an image that fits the horizontal size while keeping the aspect ratio
 func ResizeImage(img image.Image, camera Camera, projection Size) image.RGBA {
 	dst := image.NewRGBA(image.Rect(0, 0, int(projection.Width), int(projection.Height)))
+	draw.Draw(dst, dst.Bounds(), &image.Uniform{color.RGBA{R: 140, G: 155, B: 252, A: 255}}, image.ZP, draw.Over)
 
 	scaledImage := image.NewRGBA(image.Rect(0, 0, camera.W, camera.H))
 

+ 18 - 18
web/js/Button.js

@@ -3,27 +3,27 @@
  */
 
 var Key = {};
-Key.Z = {code: 90, name: "a"};
-Key.X = {code: 88, name: "b"};
-
-Key.UP = {code: 38, name: "up"};
-Key.DOWN = {code: 40, name: "down"};
-Key.LEFT = {code: 37, name: "left"};
-Key.RIGHT = {code: 39, name: "right"};
-
-Key.ENTER = {code: 13, name: "start"};
-Key.SPACE = {code: 32, name: "select"};
-
-// Key.Z = {code: 86, name: "a"};
-// Key.X = {code: 66, name: "b"};
+// Key.Z = {code: 90, name: "a"};
+// Key.X = {code: 88, name: "b"};
 //
-// Key.UP = {code: 87, name: "up"};
-// Key.DOWN = {code: 83, name: "down"};
-// Key.LEFT = {code: 65, name: "left"};
-// Key.RIGHT = {code: 68, name: "right"};
+// Key.UP = {code: 38, name: "up"};
+// Key.DOWN = {code: 40, name: "down"};
+// Key.LEFT = {code: 37, name: "left"};
+// Key.RIGHT = {code: 39, name: "right"};
 //
 // Key.ENTER = {code: 13, name: "start"};
-// Key.SPACE = {code: 8, name: "select"};
+// Key.SPACE = {code: 32, name: "select"};
+
+Key.Z = {code: 86, name: "a"};
+Key.X = {code: 66, name: "b"};
+
+Key.UP = {code: 87, name: "up"};
+Key.DOWN = {code: 83, name: "down"};
+Key.LEFT = {code: 65, name: "left"};
+Key.RIGHT = {code: 68, name: "right"};
+
+Key.ENTER = {code: 13, name: "start"};
+Key.SPACE = {code: 8, name: "select"};
 
 var Button = function() {
     var pressCallback = null;