Sfoglia il codice sorgente

Tweaked bananas for mojo changes.

Mark Sibly 9 anni fa
parent
commit
f1ff26f42d

+ 104 - 107
bananas/gridshooter/gamegraphics/gamegraphics.monkey2

@@ -1,108 +1,105 @@
-
-#Import "<mojo>"
-#Import "src/sprite"
-#Import "src/background"
-
-Using mojo..
-Using std..
-
-Class GameGraphics Abstract
-
-	Field images		:Image[]	'The array containing all frames
-	Field debug := False
-		
-	Protected
-	Field _handle:= New Vec2f
-	
-	'************************************* Public Properties *************************************
-	
-	Public
-	
-	'Sets the handles in all sub-images
-	Property Handle:Vec2f()
-		Return _handle
-	Setter( handle:Vec2f )
-		_handle = handle
-		For Local i := Eachin images
-			i.Handle = _handle
-		Next
-	End
-
-	Property Width:Double()
-		Return images[0].Width
-	End
-
-	Property Height:Double()
-		Return images[0].Height
-	End
-	
-	'************************************* Public Methods *************************************
-	
-	'Loads an array of Images from a sprite sheet
-	Method LoadFrames:Image[] ( path:String, numFrames:Int, cellWidth:Int, cellHeight:Int, filter:Bool = True, padded:Bool = False )
-	
-		Local flags :TextureFlags = Null
-		If filter Then flags |= TextureFlags.Filter
-		
-		Local atlasTextture := Texture.Load( path, flags )
-		Assert( atlasTextture, " ~n ~nGameGraphics: Image " + path + " not found.~n ~n" )
-		
-		Local atlasImg := New Image( atlasTextture )
-		Local imgs := New Image[ numFrames ]
-
-		If cellHeight = atlasImg.Height
-			Local x := 0
-			Local width := cellWidth
-			If padded
-				x += 1
-				width -= 2
-			End
-			For Local i := 0 Until numFrames
-				Local x0 := i * cellWidth + x
-				Local y0 := 0
-				imgs[i] = New Image( atlasImg, New Recti( x0, y0, x0 + cellWidth, cellHeight ) )
-			Next
-		Else
-			Local x:= 0
-			Local width:= cellWidth
-			Local y:= 0
-			Local height:= cellHeight
-			Local columns:= atlasImg.Width / width
-			If padded
-				x += 1
-				y += 1
-				width -= 2
-				height -= 2
-			End If
-			For Local i:= 0 Until numFrames
-				Local fx := i Mod columns * cellWidth
-				Local fy := i / columns * cellHeight
-				imgs[i] = New Image( atlasImg, New Recti( fx + x, fy + y, fx + cellWidth, fy + cellHeight ) )
-			Next
-		Endif
-		atlasImg = Null
-		Return imgs
-	End
-	
-	
-	Method DrawOutline( canvas:Canvas, x:Float, y:Float, width:Float, height:Float, rz:Float = 0, sx:Float = 1.0, sy:Float = 1.0 )
-		Local matrix:= canvas.Matrix
-		canvas.Translate( x, y )
-		canvas.Rotate( rz )
-		canvas.Scale( sx,sy )
-		DrawRectOutline( canvas, -( width * Handle.X ), -( height * Handle.Y ), width, height )
-		canvas.Matrix=matrix
-	End
-	
-	
-	
-	'************************************* Class Functions *************************************
-
-	Function DrawRectOutline:Void(canvas:Canvas, left:Int, top:Int, width:Int, height:Int )
-		canvas.DrawLine( left, top, left+width, top )
-		canvas.DrawLine( left, top, left ,top+height )
-		canvas.DrawLine( left, top+height, left+width, top+height )
-		canvas.DrawLine( left+width, top, left+width, top+height )
-	End
-
+
+#Import "<mojo>"
+#Import "src/sprite"
+#Import "src/background"
+
+Using mojo..
+Using std..
+
+Class GameGraphics Abstract
+
+	Field images		:Image[]	'The array containing all frames
+	Field debug := False
+		
+	Protected
+	Field _handle:= New Vec2f
+	
+	'************************************* Public Properties *************************************
+	
+	Public
+	
+	'Sets the handles in all sub-images
+	Property Handle:Vec2f()
+		Return _handle
+	Setter( handle:Vec2f )
+		_handle = handle
+		For Local i := Eachin images
+			i.Handle = _handle
+		Next
+	End
+
+	Property Width:Double()
+		Return images[0].Width
+	End
+
+	Property Height:Double()
+		Return images[0].Height
+	End
+	
+	'************************************* Public Methods *************************************
+	
+	'Loads an array of Images from a sprite sheet
+	Method LoadFrames:Image[] ( path:String, numFrames:Int, cellWidth:Int, cellHeight:Int, filter:Bool = True, padded:Bool = False )
+	
+		Local atlasTextture := Texture.Load( path, Null )
+		Assert( atlasTextture, " ~n ~nGameGraphics: Image " + path + " not found.~n ~n" )
+		
+		Local atlasImg := New Image( atlasTextture )
+		Local imgs := New Image[ numFrames ]
+
+		If cellHeight = atlasImg.Height
+			Local x := 0
+			Local width := cellWidth
+			If padded
+				x += 1
+				width -= 2
+			End
+			For Local i := 0 Until numFrames
+				Local x0 := i * cellWidth + x
+				Local y0 := 0
+				imgs[i] = New Image( atlasImg, New Recti( x0, y0, x0 + cellWidth, cellHeight ) )
+			Next
+		Else
+			Local x:= 0
+			Local width:= cellWidth
+			Local y:= 0
+			Local height:= cellHeight
+			Local columns:= atlasImg.Width / width
+			If padded
+				x += 1
+				y += 1
+				width -= 2
+				height -= 2
+			End If
+			For Local i:= 0 Until numFrames
+				Local fx := i Mod columns * cellWidth
+				Local fy := i / columns * cellHeight
+				imgs[i] = New Image( atlasImg, New Recti( fx + x, fy + y, fx + cellWidth, fy + cellHeight ) )
+			Next
+		Endif
+		atlasImg = Null
+		Return imgs
+	End
+	
+	
+	Method DrawOutline( canvas:Canvas, x:Float, y:Float, width:Float, height:Float, rz:Float = 0, sx:Float = 1.0, sy:Float = 1.0 )
+		Local matrix:= canvas.Matrix
+		canvas.Translate( x, y )
+		canvas.Rotate( rz )
+		canvas.Scale( sx,sy )
+		DrawRectOutline( canvas, -( width * Handle.X ), -( height * Handle.Y ), width, height )
+		canvas.Matrix=matrix
+	End
+	
+	
+	
+	'************************************* Class Functions *************************************
+
+	Function DrawRectOutline:Void(canvas:Canvas, left:Int, top:Int, width:Int, height:Int )
+		canvas.DrawLine( left, top, left+width, top )
+		canvas.DrawLine( left, top, left ,top+height )
+		canvas.DrawLine( left, top+height, left+width, top+height )
+		canvas.DrawLine( left+width, top, left+width, top+height )
+	End
+
 End

+ 43 - 45
bananas/gridshooter/gamegraphics/src/background.monkey2

@@ -1,46 +1,44 @@
-
-#Import "tilegraphics"
-
-Class Background Extends TileGraphics
-
-	Field total:Int
-
-	Method New( path:String, filter:Bool = True )
-		Local flags:TextureFlags = Null
-		If filter Then flags |= TextureFlags.Filter
-		
-		Local atlasTextture := Texture.Load( path, flags )
-		Assert( atlasTextture, " ~n ~nGameGraphics: Image " + path + " not found.~n ~n" )
-		images = New Image[]( New Image( atlasTextture ) )
-	End
-	
-	Method Draw( canvas:Canvas, x:Double, y:Double, scale:Double, camera:Rect<Double> )
-
-		total = 0
-
-		GetVisibleTiles( x, y, scale, camera )
-		
-		For Local tY := tileStartY Until tileEndY
-			For Local tX := tileStartX Until tileEndX
-				local absX := ( tX * tileWidth ) + x
-				local absY := ( tY * tileHeight ) + y
-				If images[0]
-					total += 1
-					canvas.DrawImage( images[0], absX, absY, 0, scale, scale )
-					If debug
-						DrawRectOutline( canvas, absX, absY, tileWidth, tileHeight )
-						canvas.DrawText( tX + "," + tY, absX + 4, absY + 4 )
-					End
-				End
-			Next
-		Next
-	End
-	
-	Method ToString:String()
-		Local t := ""
-		t += ( "Background: " + tileStartX + "," + tileStartY + "; " + tileEndX + "," + tileEndY + "; " )
-		t += ( "Total tiles: " + total )
-		Return t
-	End
-	
+
+#Import "tilegraphics"
+
+Class Background Extends TileGraphics
+
+	Field total:Int
+
+	Method New( path:String)
+		
+		Local atlasTextture := Texture.Load( path,Null )
+		Assert( atlasTextture, " ~n ~nGameGraphics: Image " + path + " not found.~n ~n" )
+		images = New Image[]( New Image( atlasTextture ) )
+	End
+	
+	Method Draw( canvas:Canvas, x:Double, y:Double, scale:Double, camera:Rect<Double> )
+
+		total = 0
+
+		GetVisibleTiles( x, y, scale, camera )
+		
+		For Local tY := tileStartY Until tileEndY
+			For Local tX := tileStartX Until tileEndX
+				local absX := ( tX * tileWidth ) + x
+				local absY := ( tY * tileHeight ) + y
+				If images[0]
+					total += 1
+					canvas.DrawImage( images[0], absX, absY, 0, scale, scale )
+					If debug
+						DrawRectOutline( canvas, absX, absY, tileWidth, tileHeight )
+						canvas.DrawText( tX + "," + tY, absX + 4, absY + 4 )
+					End
+				End
+			Next
+		Next
+	End
+	
+	Method ToString:String()
+		Local t := ""
+		t += ( "Background: " + tileStartX + "," + tileStartY + "; " + tileEndX + "," + tileEndY + "; " )
+		t += ( "Total tiles: " + total )
+		Return t
+	End
+	
 End

+ 2 - 2
bananas/gridshooter/gridshooter.monkey2

@@ -46,8 +46,8 @@ Class Game Extends RenderWindow
 	
 		'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 )
+		bg = New Background( "asset::starfield.png" )
+		bgGrid = New Background( "asset::grid.png" )
 		
 		Local heroSprite := New Sprite( "asset::hero.png", 3, 32, 32, False )
 		heroSprite.AddAnimationClip( "idle", New Int[]( 0 ) )

+ 0 - 3
bananas/gridshooter/src/renderwindow.monkey2

@@ -119,9 +119,6 @@ Class RenderWindow Extends Window
 		ClearColor = borderColor
 		Style.BackgroundColor = bgColor
 		
-		_flags = Null
-		If filterTextures Then _flags|=TextureFlags.Filter
-		
 		Self.renderToTexture = renderToTexture
 		Self.filterTextures = filterTextures
 		

+ 1 - 1
bananas/particles/particles.monkey2

@@ -42,7 +42,7 @@ Public
 		Style.BackgroundColor=GetColor(2,2,2)
 		
 		'Load image
-		particleImage=Image.Load("asset::particle.png",TextureFlags.Filter)
+		particleImage=Image.Load("asset::particle.png")
 		particleImage.Handle=New Vec2f(0.5,0.5)
 		
 		'Initialise particles

+ 10 - 4
bananas/rendertoimage/rendertoimage.monkey2

@@ -22,10 +22,11 @@ Class MyWindow Extends mojo.app.Window
 		image.Handle=New Vec2f( .5,.5 )
 		
 		icanvas=New Canvas( image )
+		
 	End
 	
 	Method RenderImage()
-
+	
 		'render to image...
 		For Local x:=0 Until 16
 			For Local y:=0 Until 16
@@ -37,10 +38,12 @@ Class MyWindow Extends mojo.app.Window
 				icanvas.DrawRect( x*16,y*16,16,16 )
 			Next
 		Next
+		
 		icanvas.Color=Color.White
+		
 		icanvas.DrawText( "This way up!",icanvas.Viewport.Width/2,0,.5,0 )
+		
 		icanvas.Flush()
-
 	End
 	
 	Method OnRender( canvas:Canvas ) Override
@@ -48,8 +51,11 @@ Class MyWindow Extends mojo.app.Window
 		App.RequestRender()
 		
 		RenderImage()
-				
-		canvas.DrawImage( image,App.MouseLocation.x,App.MouseLocation.y )
+
+		Global rot:=0.0
+		rot+=.001
+		
+		canvas.DrawImage( image,App.MouseLocation.x,App.MouseLocation.y,rot )
 		
 		canvas.DrawText( "Here!",0,0 )
 	End

+ 4 - 0
bananas/sdl2test/sdl2test.monkey2

@@ -12,12 +12,15 @@ Using gles20..
 Class SdlWindow
 
 	Field sdlWindow:SDL_Window Ptr
+
 	Field sdlGLContext:SDL_GLContext
 	
 	Method New()
 	
 		SDL_Init( SDL_INIT_EVERYTHING )
 		
+		libc.atexit( SDL_Quit )
+		
 		sdlWindow=SDL_CreateWindow( "SDL2 OpenGL Window",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,640,480,SDL_WINDOW_OPENGL )
 		
 		sdlGLContext=SDL_GL_CreateContext( sdlWindow )
@@ -54,6 +57,7 @@ Class SdlWindow
 			OnRender()
 			
 			SDL_GL_SwapWindow( sdlWindow )
+
 		Forever
 		
 	End

+ 9 - 4
bananas/spacechimps/spacechimps.monkey2

@@ -29,6 +29,10 @@ Class MyWindow Extends Window
 		'
 		Super.New( title,width,height )
 		
+'		Style.Border=New Recti( -16,-16,16,16 )
+'		Style.BorderColor=Color.Yellow
+
+'		Layout="fill"		
 		Layout="letterbox"
 
 		'Letterbox color
@@ -50,8 +54,9 @@ Class MyWindow Extends Window
 		'Note: Scaling image here is faster than scaling in DrawImage.
 		'
 		image=Image.Load( "asset::spaceship_32.png" )
-		image.Handle=New Vec2f( .5,.5 )
-'		image.Scale=New Vec2f( .125,.125 )
+		image.Handle=New Vec2f( .5 )
+
+'		image.TextureFilter=TextureFilter.Mipmap
 		
 		'Set initial image pos
 		'
@@ -158,7 +163,7 @@ Class MyWindow Extends Window
 	Field ms:=0
 
 	Method OnRender( canvas:Canvas ) Override
-
+	
 		Local e:=App.Millisecs-ms	'ideally, e should be 16,17,17,16,17,17 ie: 16.6666...
 '		If e<>16 And e<>17 Print "elapsed="+e	'show glitches
 		ms+=e
@@ -167,7 +172,7 @@ Class MyWindow Extends Window
 		
 		'Turn off texture filtering for a 'pixel art' look
 		'
-		canvas.TextureFilteringEnabled=filter
+		canvas.TextureFilter=filter ? TextureFilter.Mipmap Else TextureFilter.Nearest
 
 		canvas.DrawText( "FPS="+App.FPS,Width/2,0,.5,0 )
 		canvas.DrawText( "Arrow keys to fly",Width/2,16,.5,0 )

+ 2 - 2
bananas/vpaint/vpaint.monkey2

@@ -15,12 +15,12 @@ Class VPane Extends Image
 	Field pixmap:Pixmap
 
 	Method New(w:Int,h:Int,bg:Color)		
-		Super.New(w,h,TextureFlags.Dynamic|TextureFlags.Filter|TextureFlags.Mipmap)		
+		Super.New(w,h,TextureFlags.Dynamic)
 		canvas=New Canvas(Self)	
 		canvas.Clear(bg)
 		canvas.Alpha=0.8
 		canvas.Translate(w/2,h/2)
-		Handle=New Vec2f(0.5,0.5)		
+		Handle=New Vec2f(0.5,0.5)
 	End
 	
 	Method Draw(display:Canvas)