#HTML5_CANVAS_WIDTH=1440'1280'1440
#HTML5_CANVAS_HEIGHT=900'720'900
#ANDROID_SCREEN_ORIENTATION="landscape"
#ANDROID_APP_LABEL="App"
#ANDROID_APP_PACKAGE="com.Cerberus_X.cxgame"
#ANDROID_APP_ICON=""
#ANDROID_SCREEN_ORIENTATION="user"
Import mojo2
Import brl.databuffer
Function Main ()
New Game
Return 0
End
Class Game Extends App
Field vertices:Float[]
Field indices:Int[]
Field screen2:Image
Field screen2canvas:Canvas
Field intwidth:Float, intheight:Float
Field startx:Int, starty:Int
Field fullscreen:Bool = True
Field canvas:Canvas
Field icanvas:Canvas
Field scanvas:Canvas
Field image:Image
Field sourceImage:Image
Field targetImage:Image
Field size:Int = 10 ' 20 8 ' (Also try 20 as FROM cookiecutting the sprite sheet), All combinations works without degration in speed.
Field cx:Int
Field wx:Int
Field wy:Int
Field tilemap:Int[512*512]
Field colourmap:Int[512*512]
Field cols:Int[]=[$000000, $FFFFFF, $68372B, $70A4B2, $6F3D86, $588D43, $352879, $B8C76F, $6F4F25, $433900, $9A6759, $444444, $6C6C6C, $9AD284, $6C5EB5, $959595]
Field s:Int = 1'4
Field ballx:Int = 1
Field bally:Int = 1
Field balldx:Int = 2
Field balldy:Int = 2
Field oldballx:Int = 0
Field oldbally:Int = 0
Field oldballmemory:Int = 0
Field ballwx:Int = 8
Field ballwy:Int = 8
Field ballspeed:Int = 0
Field scaling:Float=1
Field pixels:DataBuffer = New DataBuffer(4 * 320 * 200)
' Resolutions
Field vwidth:Int = 320 ' 1280 1366 1920
Field vheight:Int = 180 ' 200 ' 224 768 800 900 1080
Field awidth:Int = 1440 ' 1280 768 1280 1366 1920
Field aheight:Int = 900 ' 800 ' 768 720 800 900 1080
Field paused:Bool = False
Field particlex:Int[150]
Field particley:Int[150]
Field particlespeed:Int[150]
Field nbparticle:Int[150]
Field direction:Int = 0
Field particle:Image
Field canvas1:Canvas
Field layer1:DrawList
Field canvas2:Canvas
Field layer2:DrawList
Field imgBackground:Image
Field imgSprite:Image
Field mx:Int, my:Int
Field blend:Int=0
Field angle:Float
Field music:Sound
Field powerup:Sound
Field music_on:Bool = False
Field effect:ShaderEffect
Field level:Float=1
Field factor:Int
Method ToggleFullscreen:Void()
Local desktop:DisplayMode = DesktopMode()
' SetDeviceWindow desktop.Width, desktop.Height, 1 ' 4
awidth = desktop.Width
aheight = desktop.Height
fullscreen = Not fullscreen
If Not fullscreen
Local desktop:DisplayMode = DesktopMode()
SetDeviceWindow awidth,aheight, 4+2
ShowMouse
SetSwapInterval 1
SetUpdateRate 0
Else
SetDeviceWindow awidth,aheight, 1 + 2
HideMouse
SetSwapInterval 1
SetUpdateRate 0
Endif
End
Method OnCreate ()
' music = LoadSound("Welcomesong.wav")
' powerup = LoadSound("Powerup.wav")
canvas1 = New Canvas
layer1 = New DrawList
canvas2 = New Canvas
layer2 = New DrawList
ToggleFullscreen
For Local y:=0 To 511
For Local x:=0 To 511
colourmap [x+y*512] = Int(Rnd(15))
tilemap[x + y * 512] = Int(Rnd(127))
Next
Next
sourceImage=Image.Load("tiles.png",0,0,0)
targetImage=New Image(sourceImage.Width,sourceImage.Height,,,0)
image=New Image(128,128,0,0,0)
Image.SetFlagsMask(Image.Managed)
icanvas=New Canvas(image)
scanvas=New Canvas(targetImage)
' DW = DeviceWidth()
' DH = DeviceHeight()
canvas=New Canvas
particle=Image.Load("blob.png")
For Local i:=0 To 149
particlex[i] = Rnd(1,320)
particley[i] = Rnd(1,256)
particlespeed[i] = Rnd(1,9)
Next
' Create screen
screen2=New Image(vwidth,vheight,0,0,0)
screen2.SetFlagsMask(screen2.Managed)
screen2canvas=New Canvas(screen2)
oldballx = ballx ; oldbally = bally ; oldballmemory = tilemap[ballx + bally * 512]
' ------------------------------------------------------------
' FIX FOR NOVEMBER CX-UPDATE (NOT NEEDED OTHERWISE)
'
Local www=DeviceWidth, hhh=DeviceHeight
canvas.SetViewport 0,0,www,hhh ; canvas.SetScissor 0,0,www,hhh ; canvas.SetProjection2d 0,www,0,hhh
screen2canvas.SetViewport 0,0,www,hhh ; screen2canvas.SetScissor 0,0,www,hhh ; screen2canvas.SetProjection2d 0,www,0,hhh
icanvas.SetViewport 0,0,www,hhh ; icanvas.SetScissor 0,0,www,hhh ; icanvas.SetProjection2d 0,www,0,hhh
scanvas.SetViewport 0,0,www,hhh ; scanvas.SetScissor 0,0,www,hhh ; scanvas.SetProjection2d 0,www,0,hhh
canvas1.SetViewport 0,0,www,hhh ; canvas1.SetScissor 0,0,www,hhh ; canvas1.SetProjection2d 0,www,0,hhh
canvas2.SetViewport 0,0,www,hhh ; canvas2.SetScissor 0,0,www,hhh ; canvas2.SetProjection2d 0,www,0,hhh
' ------------------------------------------------------------
Return 0
End
Method OnUpdate ()
If KeyHit(KEY_ESCAPE) Then OnClose() ' or EndApp or Error ""
If KeyHit( KEY_A )
#If TARGET = "glfw"
ToggleFullscreen
#Endif
Endif
s = 4
wx=wx-s*KeyDown(KEY_LEFT)+s*KeyDown(KEY_RIGHT)
wy=wy-s*KeyDown(KEY_UP)+s*KeyDown(KEY_DOWN)
wx=Max(0,Min(10000,wx))
wy=Max(0,Min(10000,wy))
' If (music_on = False) And (wx > 10) Then music_on = True ; SetChannelVolume 0,1.0 SetChannelPan 0,1 PlaySound music,0
Return 0
End
Method OnRender ()
wx=wx+1
ballspeed = ballspeed + 1
' If Texture.TexturesLoading Return
Local VWIDTH:Int = 320
Local VHEIGHT:Int = 200
Local viewW:Int = 1440
Local viewH:Int = 800
canvas.PushMatrix
canvas.Scale 1,1
canvas.Clear 0,0,0
intwidth = Floor(Float(awidth)/Float(vwidth))
intheight = Floor(Float(aheight)/Float(vheight))
If intwidth > intheight Then intwidth = intheight
If intheight > intwidth Then intheight = intwidth
startx = (awidth-(vwidth*intwidth)) / 2
starty = (aheight-(vheight*intheight)) / 2
Local borderwidthpercetage:Float = Float(startx)/Float(awidth)
Local borderheightpercentage:Float = Float(starty)/Float(aheight)
scanvas.Clear
scanvas.Flush
Local w=vwidth
Local h=vheight
screen2canvas.SetViewport 0,0,w,h
screen2canvas.SetScissor 0,0,w,h
screen2canvas.SetProjection2d 0,w,0,h
canvas.Clear 0,0,0
icanvas.SetViewport 0,0,w,h
icanvas.SetScissor 0,0,w,h
icanvas.SetProjection2d 0,w,0,h
icanvas.Clear 0,0,0
icanvas.DrawImage sourceImage,0,0
cx=(cx+1) Mod 128
For Local temp:=0 To 127
icanvas.DrawRect 8+temp,8,1,8,targetImage,0+temp+cx,8,1,8
Next
icanvas.DrawRect 120,8,8,8,targetImage,120,8,8,8
' Animation test
For Local temp:=1 To 7
If Int(Rnd(1)) Then icanvas.SetColor 0,0,0 Else icanvas.SetColor 1,1,1
Local xx:= Int(Rnd(7))
Local yy:= Int(Rnd(7))
icanvas.DrawRect xx*1,yy*1,1*1,1*1
Next
screen2canvas.Clear 0,0,0' ,0
screen2canvas.SetColor 1,1,1
icanvas.Flush
If wx>4096 Then wx=wx-4096
' Draw to canvas
Local scrx:=wx Mod size ' Cookiecut 32x32 tiles from a 512x512 tilesheet and draw as tiles of any size
Local scry:=wy Mod size
Local mapx:=wx / size
Local mapy:=wy / size
Local cnty:= -scry
For Local y:=mapy To mapy+((h/size)+1)
Local cntx:=-scrx
For Local x:=mapx To mapx+((w/size)+1)
Local char:= tilemap[x + y * 512] ; Local tilex:= char & 15 ; Local tiley:= char Shr 4 ' check
Local color:Int = cols[colourmap[x + y * 512]]
Local r:Int = color Shr 16 & $FF ; Local g:Int = color Shr 8 & $FF ; Local b:Int = color Shr 0 & $FF
screen2canvas.SetColor Float(r/255.0),Float(g/255.0),Float(b/255.0)
screen2canvas.DrawRect cntx,cnty,size,size,image,tilex Shl 3,tiley Shl 3,8,8
cntx=cntx+size
Next
cnty=cnty+size
Next
screen2canvas.SetColor 1,1,1
' Draw ball using world coordinates (WORLD COORDINATE TEST)
screen2canvas.DrawRect ballwx-wx,ballwy-wy,8*8,8*8,image,0 Shl 3,1 Shl 3,8,8
ballwx=ballwx+1
If ballwx > 2000 Then ballwx = 0
screen2canvas.Flush
canvas.SetColor 1,1,1
canvas.DrawRect startx,starty,vwidth*intwidth,vheight*intheight,screen2,0,0,vwidth,vheight
If borderheightpercentage > 0.01 ' If we want to check percentage of space the border takes of the screen
' If starty > 20 ' If we want to check the number of pixels instead to get the feeling of how much room we've got to spare
canvas.DrawText("SCORE GOES HERE", awidth / 2.0, (starty-10) / 2, .5) ' top border
canvas.DrawText("SCORE GOES HERE", awidth / 2.0, aheight - ((starty+10) / 2), .5) ' bottom border
Endif
canvas.PopMatrix
' LASER
canvas.SetBlendMode BlendMode.Additive
canvas.SetAlpha 1.0
For Local i:=0 To 149
canvas.SetColor(Float(particlespeed[i]/8.0),Float(particlespeed[i]/8.0),Float(particlespeed[i]/8.0))
canvas.DrawImage particle,particlex[i],128+particley[i]/256.0,0.1
If direction=-1
particlex[i]=particlex[i]+particlespeed[i]
Else
particlex[i]=particlex[i]-particlespeed[i]
Endif
If particlex[i] < 0 particlex[i]= 320
If particlex[i] > 320 particlex[i]= 0
Next
canvas.Flush
Return 0
End
End