- Joined
- Sep 9, 2017
- Messages
- 451
Hi
Not sure if this has been posted before. Thought I'd play last night.
Takes me back to the Amiga days
Cant think of a way to do this in Mojo 1 as it uses multiple images to draw into before flushing it onto the screen
Not sure if this has been posted before. Thought I'd play last night.
Takes me back to the Amiga days
Cerberus:
Strict
' credit https://www.pygame.org/pcr/unlimited_sprites/index.php
Import mojo2
Class game Extends App
Field canvas:Canvas
Field images:Image[25]
Field frame:Int
Field cx:Int,cy:Int
Field xa:Float,ya:Float
Field icanvas:Canvas
' increase number of frames to make a largger gap between "new balls"
Const frames:=10
Method OnCreate:Int()
Local i:Int
cx=DeviceWidth()/2
cy=DeviceHeight()/2
canvas = New Canvas
icanvas = New Canvas
SetUpdateRate(60)
i=0
While i<frames
images[i] = New Image(cx*2,cy*2)
i=i+1
Wend
xa=0
ya=0
frame=0
Return 0
End
Method OnUpdate:Int()
Return True
End
Method OnRender:Int()
Local x:Float,y:Float
' MATHS stuff, play with these numbers to produce different routes for the balls
x = cx*Sin(xa*0.74)
y = cy*Cos(ya*0.64)
' move angle
xa = xa + 1.1
ya = ya + 1.3
' draw into image frame only
icanvas.SetRenderTarget(images[frame])
' just draw the ball (dont clear old balls <<< thats the trick)
DrawBall(icanvas,cx+x,cy+y)
icanvas.Flush
' draw image frame to screen
canvas.Clear
canvas.DrawImage images[frame],cx,cy
canvas.Flush
frame=(frame+1) Mod frames
Return True
End
Method DrawBall:Void(c:Canvas,x:Float,y:Float)
' draw simple shaded ball using DrawOval (vert Amiga like)
c.SetColor 0,0,0
c.DrawOval x-20,y-20,40,40
c.SetColor 0.4,0.5,0.5
c.DrawOval x-18,y-18,36,36
c.SetColor 0.6,0.8,0.8
c.DrawOval x-17,y-17,30,30
c.SetColor 0.8,0.9,0.9
c.DrawOval x-16,y-16,20,20
c.SetColor 1,1,1
c.DrawOval x-12,y-12,8,8
End
End
Function Main:Int()
New game
Return 0
End
Attachments
Last edited by a moderator: