瀏覽代碼

Tweaked bananas.

Mark Sibly 9 年之前
父節點
當前提交
95392cbae2

+ 1 - 1
bananas/commanche/commanche.monkey2

@@ -142,7 +142,7 @@ End
 Function Main()
 Function Main()
 
 
 	New AppInstance
 	New AppInstance
-
+	
 	'Show raw key mappings...	
 	'Show raw key mappings...	
 	Print "W->"+Keyboard.KeyName( Key.W | Key.Raw )
 	Print "W->"+Keyboard.KeyName( Key.W | Key.Raw )
 	Print "A->"+Keyboard.KeyName( Key.A | Key.Raw )
 	Print "A->"+Keyboard.KeyName( Key.A | Key.Raw )

+ 1 - 1
bananas/glwindowtest/glwindowtest.monkey2

@@ -32,7 +32,7 @@ Class MyWindow Extends GLWindow
 		'
 		'
 		App.RequestRender()
 		App.RequestRender()
 
 
-		'This will result in OnRnderGL being called.
+		'This will result in OnRenderGL being called.
 		'
 		'
 		Super.OnRender( canvas )
 		Super.OnRender( canvas )
 		
 		

+ 145 - 146
bananas/gridshooter/gridshooter.monkey2

@@ -1,146 +1,145 @@
-'   Copyleft notice: All code created by Leo Santos (www.leosantos.com)
-'   Feel free to use it in any form, but please include a credit.
-'   More importantly, do not claim to have created any of it, unless you modify it substantially.
-'   Thanks!
-
-#Import "gamegraphics/gamegraphics"
-#Import "src/renderwindow"
-#Import "src/actor"
-#Import "src/player"
-#Import "src/bullet"
-#Import "src/orb"
-
-#Import "fonts/classic_sans.ttf"
-#Import "images/grid.png"
-#Import "images/starfield.png"
-#Import "images/hero.png"
-#Import "images/jet.png"
-#Import "images/bullet.png"
-#Import "images/orbSmall.png"
-
-Using mojo..
-Using std..
-
-'To do: move out of collision
-
-Class Game Extends RenderWindow
-
-	Global scrollSpeed := 5.0
-	Global scrollLimitY:Double = 60
-	Global cameraSpeed := 1.0
-	
-	Field hero:Player	
-	Field bg:Background
-	Field bgGrid:Background
-	Field smallFont:Font
-
-	Field colorTint:= New Color( 0.25, 1.0, 0.5 )
-		
-	Method New()					
-		Super.New( "Test", 420, 240, False, True )		'name, width, height, filterTextures, renderToTexture
-		Layout = "letterbox-int"
-	End
-	
-	Method OnStart() Override
-		Actor.camera = camera
-	
-		'Load sprites & font
-		canvas.Font = Font.Load( "asset::classic_sans.ttf", 10 )
-		bg = New Background( "asset::starfield.png", False )
-		bgGrid = New Background( "asset::grid.png", False )
-		
-		Local heroSprite := New Sprite( "asset::hero.png", 3, 32, 32, False )
-		heroSprite.AddAnimationClip( "idle", New Int[]( 0 ) )
-		heroSprite.AddAnimationClip( "up", New Int[]( 1 ) )
-		heroSprite.AddAnimationClip( "down", New Int[]( 2 ) )
-		
-		Local jetSprite := New Sprite( "asset::jet.png", 2, 16, 16, False )
-		jetSprite.AddAnimationClip( "idle", New Int[]( 0,1 ) )
-		jetSprite.frameRate = 30
-		
-		Local bulletSprite := New Sprite( "asset::bullet.png", 5, 32, 32, False )
-		bulletSprite.AddAnimationClip( "idle", New Int[] ( 0 ) )
-		bulletSprite.AddAnimationClip( "hit", New Int[] ( 1,2,3,4 ), False )
-		bulletSprite.frameRate = 15
-		
-		Local orbSprite := New Sprite( "asset::orbSmall.png", 5, 16, 16, False )
-		orbSprite.AddAnimationClip( "idle", New Int[] ( 0,1,2,3 ) )
-		
-		'Create player sprite
-		hero = New Player( heroSprite )
-		
-		'Create reusable enemy orbs
-		SeedRnd( 12345 )
-		Local offset:= 0
-		For Local n := 0 Until 20
-			Local neworb := New Orb( orbSprite )
-			neworb.Reset()
-			neworb.position.X += offset
-			offset += 16
-		Next
-		
-		'Pool of 10 reusable bullets
-		For Local n := 0 Until 10
-			Local b := New Bullet( bulletSprite )
-			Actor.bulletPool.Push( b )
-		Next
-		Bullet.player = hero
-		Bullet.cullDistance = Width
-		
-		canvas.TextureFilteringEnabled = False	'New feature in v009
-	End
-	
-	
-	Method OnUpdate() Override
-		'camera scrolls up & down a bit, 90's shooter style
-		camera.X += scrollSpeed			
-		If Keyboard.KeyDown( Key.Up )
-			camera.Y -= cameraSpeed
-		Else If Keyboard.KeyDown( Key.Down )
-			camera.Y += cameraSpeed
-		End
-		camera.Y = Clamp( camera.Y, -scrollLimitY, scrollLimitY )
-		
-		'Update all actors
-		Actor.UpdateAll()
-		
-		'Display debug info
-		If Keyboard.KeyHit( Key.D ) Then debug = Not debug
-	End
-	
-	
-	Method OnDraw() Override
-		canvas.Color = colorTint
-
-		'Draw bg objects in three layers with different parallax
-		canvas.Alpha = 1.0
-		Parallax = 0.1
-		bg.Draw( canvas, 0, 0, 1.0, CameraRect )
-		
-		canvas.Alpha = 0.5
-		canvas.DrawText( "Monkey2 Side Scrolling Demo by Leo Santos. Press space to shoot!", 260, 100 )
-		
-		canvas.Alpha = 0.25
-		Parallax = 0.25
-		bgGrid.Draw( canvas, 32, 32, 1.0, CameraRect )
-		
-		canvas.Alpha = 0.5
-		Parallax = 1.0
-		bgGrid.Draw( canvas, 0, 0, 1.0, CameraRect )
-		
-		'Draw all actors
-		canvas.Alpha = 1.0
-		canvas.Color= Color.White
-		Actor.DrawAll( canvas )
-	End
-
-End
-
-
-Function Main()
-	New AppInstance
-	New Game()
-	App.Run()
-End
-
-
+'   Copyleft notice: All code created by Leo Santos (www.leosantos.com)
+'   Feel free to use it in any form, but please include a credit.
+'   More importantly, do not claim to have created any of it, unless you modify it substantially.
+'   Thanks!
+
+#Import "gamegraphics/gamegraphics"
+#Import "src/renderwindow"
+#Import "src/actor"
+#Import "src/player"
+#Import "src/bullet"
+#Import "src/orb"
+
+#Import "fonts/classic_sans.ttf"
+#Import "images/grid.png"
+#Import "images/starfield.png"
+#Import "images/hero.png"
+#Import "images/jet.png"
+#Import "images/bullet.png"
+#Import "images/orbSmall.png"
+
+Using mojo..
+Using std..
+
+'To do: move out of collision
+
+Class Game Extends RenderWindow
+
+	Global scrollSpeed := 5.0
+	Global scrollLimitY:Double = 60
+	Global cameraSpeed := 1.0
+	
+	Field hero:Player	
+	Field bg:Background
+	Field bgGrid:Background
+	Field smallFont:Font
+
+	Field colorTint:= New Color( 0.25, 1.0, 0.5 )
+		
+	Method New()					
+		Super.New( "Test", 420, 240, False, True )		'name, width, height, filterTextures, renderToTexture
+		Layout = "letterbox-int"
+	End
+	
+	Method OnStart() Override
+		Actor.camera = camera
+	
+		'Load sprites & font
+		canvas.Font = Font.Load( "asset::classic_sans.ttf", 10 )
+		bg = New Background( "asset::starfield.png", False )
+		bgGrid = New Background( "asset::grid.png", False )
+		
+		Local heroSprite := New Sprite( "asset::hero.png", 3, 32, 32, False )
+		heroSprite.AddAnimationClip( "idle", New Int[]( 0 ) )
+		heroSprite.AddAnimationClip( "up", New Int[]( 1 ) )
+		heroSprite.AddAnimationClip( "down", New Int[]( 2 ) )
+		
+		Local jetSprite := New Sprite( "asset::jet.png", 2, 16, 16, False )
+		jetSprite.AddAnimationClip( "idle", New Int[]( 0,1 ) )
+		jetSprite.frameRate = 30
+		
+		Local bulletSprite := New Sprite( "asset::bullet.png", 5, 32, 32, False )
+		bulletSprite.AddAnimationClip( "idle", New Int[] ( 0 ) )
+		bulletSprite.AddAnimationClip( "hit", New Int[] ( 1,2,3,4 ), False )
+		bulletSprite.frameRate = 15
+		
+		Local orbSprite := New Sprite( "asset::orbSmall.png", 5, 16, 16, False )
+		orbSprite.AddAnimationClip( "idle", New Int[] ( 0,1,2,3 ) )
+		
+		'Create player sprite
+		hero = New Player( heroSprite )
+		
+		'Create reusable enemy orbs
+		SeedRnd( 12345 )
+		Local offset:= 0
+		For Local n := 0 Until 20
+			Local neworb := New Orb( orbSprite )
+			neworb.Reset()
+			neworb.position.X += offset
+			offset += 16
+		Next
+		
+		'Pool of 10 reusable bullets
+		For Local n := 0 Until 10
+			Local b := New Bullet( bulletSprite )
+			Actor.bulletPool.Push( b )
+		Next
+		Bullet.player = hero
+		Bullet.cullDistance = Width
+		
+		canvas.TextureFilteringEnabled = False	'New feature in v009
+	End
+	
+	
+	Method OnUpdate() Override
+		'camera scrolls up & down a bit, 90's shooter style
+		camera.X += scrollSpeed			
+		If Keyboard.KeyDown( Key.Up )
+			camera.Y -= cameraSpeed
+		Else If Keyboard.KeyDown( Key.Down )
+			camera.Y += cameraSpeed
+		End
+		camera.Y = Clamp( camera.Y, -scrollLimitY, scrollLimitY )
+		
+		'Update all actors
+		Actor.UpdateAll()
+		
+		'Display debug info
+		If Keyboard.KeyHit( Key.D ) Then debug = Not debug
+	End
+	
+	
+	Method OnDraw() Override
+		canvas.Color = colorTint
+
+		'Draw bg objects in three layers with different parallax
+		canvas.Alpha = 1.0
+		Parallax = 0.1
+		bg.Draw( canvas, 0, 0, 1.0, CameraRect )
+		
+		canvas.Alpha = 0.5
+		canvas.DrawText( "Monkey2 Side Scrolling Demo by Leo Santos. Press space to shoot!", 260, 100 )
+		
+		canvas.Alpha = 0.25
+		Parallax = 0.25
+		bgGrid.Draw( canvas, 32, 32, 1.0, CameraRect )
+		
+		canvas.Alpha = 0.5
+		Parallax = 1.0
+		bgGrid.Draw( canvas, 0, 0, 1.0, CameraRect )
+		
+		'Draw all actors
+		canvas.Alpha = 1.0
+		canvas.Color= Color.White
+		Actor.DrawAll( canvas )
+	End
+
+End
+
+Function Main()
+	New AppInstance
+	New Game()
+	App.Run()
+End
+
+

+ 99 - 99
bananas/gridshooter/src/actor.monkey2

@@ -1,99 +1,99 @@
-Class Actor
-
-	'******************************* Static Globals *******************************
-
-	Global catalog := New Stack<Actor>
-	Global bulletPool := New Stack<Bullet>
-	
-	Global camera:Area<Double>
-	Global player:Actor
-	
-	Global scrollSpeed := 5.0
-	Global currentBullet := 0
-	Global cullDistance:Double
-	
-	'******************************* Public fields *******************************
-	
-	Field name := ""
-	Field visible := True
-	Field speed:Double = 3.0
-	Field anim:= "idle"
-	Field detectCollision := True
-	
-	Field sprite:Sprite
-	Field position := New Vec2<Double>
-	
-	Field collider :Area<Double>
-	
-	'******************************* Protected fields *******************************
-	
-	Field _hide := False
-	Field _hideTimer := 0
-	Field _hideTimerStart := 0
-	Field _hideWait := 0
-	
-	'******************************* Public methods *******************************
-		
-	Method New( sprite:Sprite )
-		Self.sprite = sprite
-		catalog.Push( Self )
-		collider= New Area<Double>( 0, 0, sprite.Width, sprite.Height )
-		Reset()
-	End
-	
-	Method Hide( time:Int )
-		_hide = True
-		_hideTimerStart = Millisecs()
-		_hideWait = time
-	End
-	
-	Method Reset()
-		sprite.Reset()
-		_hide = False
-		detectCollision = True
-		OnReset()
-	End
-	
-	
-	
-	'******************************* Static functions *******************************
-
-	Function UpdateAll()
-		For Local a := Eachin catalog
-			If a.visible
-				If a._hide
-					a._hideTimer = Millisecs() - a._hideTimerStart
-					If a._hideTimer > a._hideWait
-						a.visible = False
-						a._hide = False
-					End				
-				End
-				a.position.X += scrollSpeed
-				a.OnUpdate()
-				a.collider.Position( a.position.X, a.position.Y )
-			End
-		Next
-	End
-
-	Function DrawAll( canvas:Canvas )
-		For Local a := Eachin catalog
-			If a.visible
-				a.sprite.Draw( canvas, a.anim, a.position.X, a.position.Y )
-'   				GameGraphics.DrawRectOutline( canvas, a.collider.Left, a.collider.Top, a.collider.Width, a.collider.Height )
-				a.OnDraw( canvas )
-			End
-		Next
-	End
-	
-	'******************************* Virtual methods *******************************
-	
-	Method OnUpdate() Virtual
-	End
-	
-	Method OnDraw( canvas:Canvas ) Virtual
-	End
-	
-	Method OnReset() Virtual
-	End
-	
-End
+Class Actor
+
+	'******************************* Static Globals *******************************
+
+	Global catalog := New Stack<Actor>
+	Global bulletPool := New Stack<Bullet>
+	
+	Global camera:Area<Double>
+	Global player:Actor
+	
+	Global scrollSpeed := 5.0
+	Global currentBullet := 0
+	Global cullDistance:Double
+	
+	'******************************* Public fields *******************************
+	
+	Field name := ""
+	Field visible := True
+	Field speed:Double = 3.0
+	Field anim:= "idle"
+	Field detectCollision := True
+	
+	Field sprite:Sprite
+	Field position := New Vec2<Double>
+	
+	Field collider :Area<Double>
+	
+	'******************************* Protected fields *******************************
+	
+	Field _hide := False
+	Field _hideTimer := 0
+	Field _hideTimerStart := 0
+	Field _hideWait := 0
+	
+	'******************************* Public methods *******************************
+		
+	Method New( sprite:Sprite )
+		Self.sprite = sprite
+		catalog.Push( Self )
+		collider= New Area<Double>( 0, 0, sprite.Width, sprite.Height )
+		Reset()
+	End
+	
+	Method Hide( time:Int )
+		_hide = True
+		_hideTimerStart = Millisecs()
+		_hideWait = time
+	End
+	
+	Method Reset()
+		sprite.Reset()
+		_hide = False
+		detectCollision = True
+		OnReset()
+	End
+	
+	
+	
+	'******************************* Static functions *******************************
+
+	Function UpdateAll()
+		For Local a := Eachin catalog
+			If a.visible
+				If a._hide
+					a._hideTimer = Millisecs() - a._hideTimerStart
+					If a._hideTimer > a._hideWait
+						a.visible = False
+						a._hide = False
+					End				
+				End
+				a.position.X += scrollSpeed
+				a.OnUpdate()
+				a.collider.Position( a.position.X, a.position.Y )
+			End
+		Next
+	End
+
+	Function DrawAll( canvas:Canvas )
+		For Local a := Eachin catalog
+			If a.visible
+				a.sprite.Draw( canvas, a.anim, a.position.X, a.position.Y )
+'   				GameGraphics.DrawRectOutline( canvas, a.collider.Left, a.collider.Top, a.collider.Width, a.collider.Height )
+				a.OnDraw( canvas )
+			End
+		Next
+	End
+	
+	'******************************* Virtual methods *******************************
+	
+	Method OnUpdate() Virtual
+	End
+	
+	Method OnDraw( canvas:Canvas ) Virtual
+	End
+	
+	Method OnReset() Virtual
+	End
+	
+End

+ 317 - 317
bananas/gridshooter/src/renderwindow.monkey2

@@ -1,317 +1,317 @@
-
-#Rem
-Features:
-- Simple camera coordinates. Any x and y drawing coordinate becomes a world coordinate.
-- Easy to use Parallax
-- "World space" mouse coordinates
-- Render to texture, allows "pixel perfect" games
-- Display debug info on screen with Echo( "info" )
-#End
-
-#Import "<mojo>"
-#Import "area"
-
-Using mojo..
-Using std..
-
-Class RenderWindow Extends Window
-
-	Field canvas :Canvas						'Main canvas currently in use
-	Field camera :Area<Double>					'Camera coordinates
-	
-	Field renderToTexture := False				'Causes all canvas rendering to be directed to a fixed size texture
-	Field filterTextures := True				'Turns on/off texture smoothing. Off for pixel art.
-	Field bgColor := Color.DarkGrey				'Background color
-	Field borderColor := Color.Black 			'Letterboxing border color
-	Field debug := False						'Toggles display of debug info ( Echo() )
-	
-	Protected
-	
-	Global _echoStack:= New Stack<String>		'Contains all the text messages to be displayed
-	
-	Field _init := False
-	Field _flags :TextureFlags					'flags used on the render texture
-	
-	Field _parallax := 1.0
-	Field _parallaxCam :Area<Double>
-	
-	Field _virtualRes:= New Vec2i				'Virtual rendering size
-	Field _mouse := New Vec2i					'temporarily stores mouse coords
-	Field _adjustedMouse := New Vec2i			'Mouse corrected for layout style and camera position
-	Field _layerInitiated := False
-
-	
-	Field _fps	:= 60							'fps counter
-	Field _fpscount	:= 0.0						'temporary fps counter
-	Field _tick := 0							'Only stores the current time once every second
-	
-	Field _renderTexture :Texture				'Render target for renderToTexture
-	Field _renderImage :Image					'Image that uses the render target
-	Field _textureCanvas :Canvas				'Canvas that uses _renderImage
-	Field _windowCanvas: Canvas					'main window canvas
-	
-	Public
-	
-	
-	'**************************************************** Properties ****************************************************
-	
-	'Mouse coordinates in WORLD units, corrected for camera
-	Property Mouse:Vec2i()						
-		Return _adjustedMouse
-	End
-	
-	'You can set the parallax before any drawing operation
-	Property Parallax:Float()					
-		Return _parallax
-	Setter( value:Float )
-		_parallax = value
-		_parallaxCam.Position( camera.X * _parallax, camera.Y * _parallax )
-		If _layerInitiated
-			canvas.PopMatrix()
-			_layerInitiated = False
-		End
-		canvas.PushMatrix()
-'   		canvas.Translate( ( -camera.X * _parallax ) + _cameraOffset.X, ( -camera.Y * _parallax ) + _cameraOffset.Y  )
-		canvas.Translate( ( -camera.X * _parallax ) + camera.Width/2.0, ( -camera.Y * _parallax ) + camera.Height/2.0  )
-
-		_layerInitiated = True
-	End
-	
-	'Returns the camera corrected for current parallax 
-	Property CameraRect:Rect<Double>()
-		Return _parallaxCam.Rect
-	End
-	
-	'Flags used by the Render Texture
-	Property Flags:TextureFlags()
-		Return _flags
-	End
-	
-	'Efective frame rate
-	Property FPS:Int()
-		Return _fps
-	End
-	
-	'corner window coordinates	
-	Property Left:Float()
-		Return -Width/2.0
-	End
-	
-	Property Right:Float()
-		Return Width/2.0
-	End
-	
-	Property Top:Float()
-		Return -Height/2.0
-	End
-	
-	Property Bottom:Float()
-		Return Height/2.0
-	End
-	
-	
-	'**************************************************** Public methods ****************************************************
-	
-	
-	Method New( title:String, width:Int, height:Int, filterTextures:Bool = True, renderToTexture:Bool = False, flags:WindowFlags = WindowFlags.Resizable )
-		Super.New( title, width, height, flags )
-		Layout = "letterbox"
-		ClearColor = borderColor
-		Style.BackgroundColor = bgColor
-		
-		_flags = Null
-		If filterTextures Then _flags|=TextureFlags.Filter
-		
-		Self.renderToTexture = renderToTexture
-		Self.filterTextures = filterTextures
-		
-		camera = New Area<Double>( 0, 0, width, height )
-		_parallaxCam = New Area<Double>( 0, 0, width, height )
-		
-		SetVirtualResolution( width, height )
-'   		SelectCanvas()
-	End
-	
-
-	Method OnRender( windowCanvas:Canvas ) Override
-		App.RequestRender()
-		
-		If Not _init
-			_init = True
-'   			canvas = windowCanvas
-			SelectCanvas()
-			WindowStart()
-			Return
-		End
-		
-		FrameUpdate()
-		
-		Style.BackgroundColor = bgColor
-		Self._windowCanvas = windowCanvas
-		
-		'Picks current drawing canvas based on renderToTexture
-		SelectCanvas()
-
-		'Mouse in world coordinates
-		_mouse = TransformPointFromView( App.MouseLocation, Null )
-		_adjustedMouse.x = _mouse.x + camera.Left
-		_adjustedMouse.y = _mouse.y + camera.Top
-		
-		'the Parallax property will always set the canvas translation before drawing.
-		Parallax = 1.0		
-		FrameDraw()
-		
-		''Closes' the drawing for any parallax layer
-		If _layerInitiated
-			canvas.PopMatrix()
-			_layerInitiated = False
-		End
-		
-		'Draws render to texture image onto _windowCanvas
-		If renderToTexture
-			canvas.Flush()
-			_windowCanvas.DrawImage( _renderImage, 0, 0 )
-		End
-		
-		'Resets canvas colors for each frame
-		_textureCanvas.Color = Color.White
-		_windowCanvas.Color = Color.White
-		
-		'Draw message stack, then clear it every frame
-		If debug Then DebugInfo()
-		Local y := 2
-		For Local t := Eachin _echoStack
-			_windowCanvas.DrawText( t, 5, y )
-			y += _windowCanvas.Font.Height
-		Next
-		_echoStack.Clear()
-		
-		'Basic fps counter
-		If Millisecs() - _tick > 1008
-			_fps = _fpscount
-			_tick = Millisecs()
-			_fpscount=0
-		Else
-			_fpscount +=1
-		End
-		
-		'App quit
-		If ( Keyboard.KeyHit( Key.Escape ) ) 
-			App.Terminate()
-		End
-	End
-	
-	
-	Method OnMeasure:Vec2i() Override
-		Return _virtualRes
-	End		
-
-	
-	
-	Method OnWindowEvent(event:WindowEvent) Override
-		Select event.Type
-			Case EventType.WindowMoved
-			Case EventType.WindowResized
-				App.RequestRender()
-			Case EventType.WindowGainedFocus
-			Case EventType.WindowLostFocus
-			Default
-				Super.OnWindowEvent(event)
-		End
-	End
-	
-
-	Method SetVirtualResolution( width:Int, height:Int )
-		_virtualRes = New Vec2i( width, height )
-		MinSize = New Vec2i( width/2, height/2 )
-		
-		camera.Width = width
-		camera.Height = height
-		_parallaxCam.Width = Width
-		_parallaxCam.Height = Height
-		
-		_renderTexture = New Texture( width, height, PixelFormat.RGBA32, _flags )
-		_renderImage = New Image( _renderTexture )
-		_renderImage.Handle=New Vec2f( 0, 0 )
-		_textureCanvas = New Canvas( _renderImage )
-		_textureCanvas.Font = App.DefaultFont
-	End
-
-
-	Method CycleLayout()
-		Select Layout
-		Case "fill"
-			Layout="letterbox"
-		Case "letterbox"
-			Layout="stretch"
-		Case "stretch"
-			Layout="float"
-		Case "float"
-'   			Layout="fill"
-			Layout = "letterbox"
-		End
-	End
-	
-	
-	'**************************************************** Protected Methods ****************************************************
-	'These allow RenderWindow to be extended without the need for OnUpdate and OnDraw to call Super.xxx().
-	'i.e: A MyGameEngine class can extend RenderWindow and override FrameDraw() and add specific features, leaving OnDraw() alone, as long as it is called somewhere.
-	
-	Protected
-	
-	Method WindowStart() Virtual
-		OnStart()
-	End
-	
-	Method FrameUpdate() Virtual
-		OnUpdate()
-	End
-	
-	Method FrameDraw() Virtual
-		OnDraw()
-	End
-	
-	Method DebugInfo() Virtual
-		Echo( "Window resolution: " + Frame.Width + ", " + Frame.Height )
-		Echo( "Virtual resolution: " + Width + ", " + Height )
-		Echo( "Mouse:" + Mouse.x + "," + Mouse.y )
-		Echo( "Camera:" + Int( camera.X ) + "," + Int( camera.Y ) )
-		Echo( "Layout: " + Layout )
-		If renderToTexture
-			Echo( "renderToTexture = True" )
-		Else
-			Echo( "renderToTexture = False" )
-		End
-		Echo( "Camera: " + camera.ToString() )
-		Echo( "FPS: " + FPS )
-	End
-	
-	Method SelectCanvas()
-		If renderToTexture
-			canvas = _textureCanvas
-		Else
-			canvas = _windowCanvas
-		End
-		canvas.Clear( bgColor )
-	End
-	
-	'**************************************************** Virtual Methods ****************************************************
-	Public
-	
-	Method OnStart() Virtual
-	End
-	
-	Method OnUpdate() Virtual
-	End
-	
-	Method OnDraw() Virtual
-	End
-
-	'**************************************************** Static functions ****************************************************
-	
-	Function Echo( text:String )
-		_echoStack.Push( text )
-	End
-	
-End
-
+
+#Rem
+Features:
+- Simple camera coordinates. Any x and y drawing coordinate becomes a world coordinate.
+- Easy to use Parallax
+- "World space" mouse coordinates
+- Render to texture, allows "pixel perfect" games
+- Display debug info on screen with Echo( "info" )
+#End
+
+#Import "<mojo>"
+#Import "area"
+
+Using mojo..
+Using std..
+
+Class RenderWindow Extends Window
+
+	Field canvas :Canvas						'Main canvas currently in use
+	Field camera :Area<Double>					'Camera coordinates
+	
+	Field renderToTexture := False				'Causes all canvas rendering to be directed to a fixed size texture
+	Field filterTextures := True				'Turns on/off texture smoothing. Off for pixel art.
+	Field bgColor := Color.DarkGrey				'Background color
+	Field borderColor := Color.Black 			'Letterboxing border color
+	Field debug := False						'Toggles display of debug info ( Echo() )
+	
+	Protected
+	
+	Global _echoStack:= New Stack<String>		'Contains all the text messages to be displayed
+	
+	Field _init := False
+	Field _flags :TextureFlags					'flags used on the render texture
+	
+	Field _parallax := 1.0
+	Field _parallaxCam :Area<Double>
+	
+	Field _virtualRes:= New Vec2i				'Virtual rendering size
+	Field _mouse := New Vec2i					'temporarily stores mouse coords
+	Field _adjustedMouse := New Vec2i			'Mouse corrected for layout style and camera position
+	Field _layerInitiated := False
+
+	
+	Field _fps	:= 60							'fps counter
+	Field _fpscount	:= 0.0						'temporary fps counter
+	Field _tick := 0							'Only stores the current time once every second
+	
+	Field _renderTexture :Texture				'Render target for renderToTexture
+	Field _renderImage :Image					'Image that uses the render target
+	Field _textureCanvas :Canvas				'Canvas that uses _renderImage
+	Field _windowCanvas: Canvas					'main window canvas
+	
+	Public
+	
+	
+	'**************************************************** Properties ****************************************************
+	
+	'Mouse coordinates in WORLD units, corrected for camera
+	Property Mouse:Vec2i()						
+		Return _adjustedMouse
+	End
+	
+	'You can set the parallax before any drawing operation
+	Property Parallax:Float()					
+		Return _parallax
+	Setter( value:Float )
+		_parallax = value
+		_parallaxCam.Position( camera.X * _parallax, camera.Y * _parallax )
+		If _layerInitiated
+			canvas.PopMatrix()
+			_layerInitiated = False
+		End
+		canvas.PushMatrix()
+'   		canvas.Translate( ( -camera.X * _parallax ) + _cameraOffset.X, ( -camera.Y * _parallax ) + _cameraOffset.Y  )
+		canvas.Translate( ( -camera.X * _parallax ) + camera.Width/2.0, ( -camera.Y * _parallax ) + camera.Height/2.0  )
+
+		_layerInitiated = True
+	End
+	
+	'Returns the camera corrected for current parallax 
+	Property CameraRect:Rect<Double>()
+		Return _parallaxCam.Rect
+	End
+	
+	'Flags used by the Render Texture
+	Property Flags:TextureFlags()
+		Return _flags
+	End
+	
+	'Efective frame rate
+	Property FPS:Int()
+		Return _fps
+	End
+	
+	'corner window coordinates	
+	Property Left:Float()
+		Return -Width/2.0
+	End
+	
+	Property Right:Float()
+		Return Width/2.0
+	End
+	
+	Property Top:Float()
+		Return -Height/2.0
+	End
+	
+	Property Bottom:Float()
+		Return Height/2.0
+	End
+	
+	
+	'**************************************************** Public methods ****************************************************
+	
+	
+	Method New( title:String, width:Int, height:Int, filterTextures:Bool = True, renderToTexture:Bool = False, flags:WindowFlags = WindowFlags.Resizable )
+		Super.New( title, width, height, flags )
+		Layout = "letterbox"
+		ClearColor = borderColor
+		Style.BackgroundColor = bgColor
+		
+		_flags = Null
+		If filterTextures Then _flags|=TextureFlags.Filter
+		
+		Self.renderToTexture = renderToTexture
+		Self.filterTextures = filterTextures
+		
+		camera = New Area<Double>( 0, 0, width, height )
+		_parallaxCam = New Area<Double>( 0, 0, width, height )
+		
+		SetVirtualResolution( width, height )
+'   		SelectCanvas()
+	End
+	
+
+	Method OnRender( windowCanvas:Canvas ) Override
+		App.RequestRender()
+		
+		If Not _init
+			_init = True
+'   			canvas = windowCanvas
+			SelectCanvas()
+			WindowStart()
+			Return
+		End
+		
+		FrameUpdate()
+		
+		Style.BackgroundColor = bgColor
+		Self._windowCanvas = windowCanvas
+		
+		'Picks current drawing canvas based on renderToTexture
+		SelectCanvas()
+
+		'Mouse in world coordinates
+		_mouse = TransformPointFromView( App.MouseLocation, Null )
+		_adjustedMouse.x = _mouse.x + camera.Left
+		_adjustedMouse.y = _mouse.y + camera.Top
+		
+		'the Parallax property will always set the canvas translation before drawing.
+		Parallax = 1.0		
+		FrameDraw()
+		
+		''Closes' the drawing for any parallax layer
+		If _layerInitiated
+			canvas.PopMatrix()
+			_layerInitiated = False
+		End
+		
+		'Draws render to texture image onto _windowCanvas
+		If renderToTexture
+			canvas.Flush()
+			_windowCanvas.DrawImage( _renderImage, 0, 0 )
+		End
+		
+		'Resets canvas colors for each frame
+		_textureCanvas.Color = Color.White
+		_windowCanvas.Color = Color.White
+		
+		'Draw message stack, then clear it every frame
+		If debug Then DebugInfo()
+		Local y := 2
+		For Local t := Eachin _echoStack
+			_windowCanvas.DrawText( t, 5, y )
+			y += _windowCanvas.Font.Height
+		Next
+		_echoStack.Clear()
+		
+		'Basic fps counter
+		If Millisecs() - _tick > 1008
+			_fps = _fpscount
+			_tick = Millisecs()
+			_fpscount=0
+		Else
+			_fpscount +=1
+		End
+		
+		'App quit
+		If ( Keyboard.KeyHit( Key.Escape ) ) 
+			App.Terminate()
+		End
+	End
+	
+	
+	Method OnMeasure:Vec2i() Override
+		Return _virtualRes
+	End		
+
+	
+	
+	Method OnWindowEvent(event:WindowEvent) Override
+		Select event.Type
+			Case EventType.WindowMoved
+			Case EventType.WindowResized
+				App.RequestRender()
+			Case EventType.WindowGainedFocus
+			Case EventType.WindowLostFocus
+			Default
+				Super.OnWindowEvent(event)
+		End
+	End
+	
+
+	Method SetVirtualResolution( width:Int, height:Int )
+		_virtualRes = New Vec2i( width, height )
+		MinSize = New Vec2i( width/2, height/2 )
+		
+		camera.Width = width
+		camera.Height = height
+		_parallaxCam.Width = Width
+		_parallaxCam.Height = Height
+		
+		_renderTexture = New Texture( width, height, PixelFormat.RGBA32, _flags )
+		_renderImage = New Image( _renderTexture )
+		_renderImage.Handle=New Vec2f( 0, 0 )
+		_textureCanvas = New Canvas( _renderImage )
+'		_textureCanvas.Font = App.DefaultFont
+	End
+
+
+	Method CycleLayout()
+		Select Layout
+		Case "fill"
+			Layout="letterbox"
+		Case "letterbox"
+			Layout="stretch"
+		Case "stretch"
+			Layout="float"
+		Case "float"
+'   			Layout="fill"
+			Layout = "letterbox"
+		End
+	End
+	
+	
+	'**************************************************** Protected Methods ****************************************************
+	'These allow RenderWindow to be extended without the need for OnUpdate and OnDraw to call Super.xxx().
+	'i.e: A MyGameEngine class can extend RenderWindow and override FrameDraw() and add specific features, leaving OnDraw() alone, as long as it is called somewhere.
+	
+	Protected
+	
+	Method WindowStart() Virtual
+		OnStart()
+	End
+	
+	Method FrameUpdate() Virtual
+		OnUpdate()
+	End
+	
+	Method FrameDraw() Virtual
+		OnDraw()
+	End
+	
+	Method DebugInfo() Virtual
+		Echo( "Window resolution: " + Frame.Width + ", " + Frame.Height )
+		Echo( "Virtual resolution: " + Width + ", " + Height )
+		Echo( "Mouse:" + Mouse.x + "," + Mouse.y )
+		Echo( "Camera:" + Int( camera.X ) + "," + Int( camera.Y ) )
+		Echo( "Layout: " + Layout )
+		If renderToTexture
+			Echo( "renderToTexture = True" )
+		Else
+			Echo( "renderToTexture = False" )
+		End
+		Echo( "Camera: " + camera.ToString() )
+		Echo( "FPS: " + FPS )
+	End
+	
+	Method SelectCanvas()
+		If renderToTexture
+			canvas = _textureCanvas
+		Else
+			canvas = _windowCanvas
+		End
+		canvas.Clear( bgColor )
+	End
+	
+	'**************************************************** Virtual Methods ****************************************************
+	Public
+	
+	Method OnStart() Virtual
+	End
+	
+	Method OnUpdate() Virtual
+	End
+	
+	Method OnDraw() Virtual
+	End
+
+	'**************************************************** Static functions ****************************************************
+	
+	Function Echo( text:String )
+		_echoStack.Push( text )
+	End
+	
+End
+

二進制
bananas/normaltest/assets/t3.png


二進制
bananas/normaltest/assets/t3_NORMALS.png


二進制
bananas/normaltest/assets/t3_SPECULAR.png


+ 0 - 41
bananas/normaltest/normaltest.monkey2

@@ -1,41 +0,0 @@
-
-#Import "<std>"
-#Import "<mojo>"
-
-#Import "assets/t3.png"
-#Import "assets/t3_SPECULAR.png"
-#Import "assets/t3_NORMALS.png"
-
-Using std..
-Using mojo..
-
-Class MyWindow Extends Window
-
-	Field t3:Image
-	
-	Method New()
-	
-		t3=Image.Load( "asset::t3.png" )
-		DebugAssert( t3 )
-		
-	End
-	
-	Method OnRender( canvas:Canvas ) Override
-	
-		canvas.AmbientLight=Color.White
-	
-		canvas.DrawImage( t3,0,0 )
-		
-	End
-	
-End
-
-Function Main()
-
-	New AppInstance
-	
-	New MyWindow
-	
-	App.Run()
-	
-End

+ 1 - 1
bananas/rendertoimage/rendertoimage.monkey2

@@ -49,7 +49,7 @@ Class MyWindow Extends mojo.app.Window
 		
 		
 		RenderImage()
 		RenderImage()
 				
 				
-		canvas.DrawImage( image,App.MouseLocation.x,App.MouseLocation.y,0,.5,.5 )
+		canvas.DrawImage( image,App.MouseLocation.x,App.MouseLocation.y )
 		
 		
 		canvas.DrawText( "Here!",0,0 )
 		canvas.DrawText( "Here!",0,0 )
 	End
 	End

+ 1 - 1
bananas/spacechimps/spacechimps.monkey2

@@ -29,7 +29,7 @@ Class MyWindow Extends Window
 		'
 		'
 		Super.New( title,width,height,WindowFlags.Resizable )
 		Super.New( title,width,height,WindowFlags.Resizable )
 		
 		
-		Layout="letterbox-int"
+		Layout="letterbox"
 		
 		
 		'Black 'coz we're in space!
 		'Black 'coz we're in space!
 		'
 		'