Draw Image as iso-floor tile

Monkey Forums/Monkey Code/Draw Image as iso-floor tile

slenkar(Posted 2011) [#1]
use a 128x128 square image that could be a floor pattern
Import mojo

Const WIDTH#=320'/4
Const HEIGHT#=240'/4

Global shearx:Float=1

Global sheary:Float=-1

Class Sprite



	Field x#,vx#
	Field y#,vy#
	Field f#,vf#
	
	Method New(xx,yy)
		Self.x=xx
		Self.y=yy
		
	End
		
	Method Update()
		'x+=vx
		'If x<0 Or x>=WIDTH vx=-vx
		'y+=vy
		'If y<0 Or y>=HEIGHT vy=-vy
		'f+=vf
		'If f>=8 f-=8
	End
	
End

Class MyApp Extends App

	Field time,frames,fps
	Field image:Image
	Field sprites:=New Stack<Sprite>

	Method OnCreate()
	
		image=LoadImage( "floor.png",Image.MidHandle )
		
		
			sprites.Push New Sprite(127,0)
		
		time=Millisecs
		
		SetUpdateRate 60
		
		PushMatrix()
	End
	
	Method OnUpdate()
		If TouchDown(0) And TouchY(0)<16
			If TouchX(0)<DeviceWidth/2
				If Not sprites.IsEmpty() sprites.Pop
			Else
				sprites.Push New Sprite
			Endif
		Endif
	
		For Local sprite:=Eachin sprites
			sprite.Update
		Next
	If KeyDown(KEY_LEFT)
	shearx=shearx+0.01
	Endif
	If KeyDown(KEY_RIGHT)
	shearx=shearx-0.01
	Endif
	If KeyDown(KEY_UP)
	sheary=sheary+0.01
	Endif
	If KeyDown(KEY_DOWN)
	sheary=sheary-0.01
	Endif
	
	End
	
	Method OnRender()

		frames+=1
		Local e=Millisecs-time
		If e>=1000
			fps=frames
			frames=0
			time+=e
		Endif
	
		Cls
		DrawText "shear x "+shearx,0,0
		
		DrawText "shear y "+sheary,0,20
		';lPushMatrix 
				
		
		
		For Local sprite:=Eachin sprites
		PushMatrix
		Scale DeviceWidth/WIDTH,DeviceHeight/HEIGHT
		Translate sprite.x,sprite.y
		Scale(0.5,0.25)
		Transform 1,shearx,sheary,1,0,0
			DrawImage image,0,0,sprite.f
		PopMatrix
		Next
		
		'PopMatrix
		
		DrawText "[<<]",0,8,0,.5
		DrawText "sprites="+sprites.Length()+", fps="+fps,DeviceWidth/2,8,.5,.5
		DrawText "[>>]",DeviceWidth,8,1,.5

	End

End

Function Main()

	New MyApp
	
End