Forum Replies Created
- 
		AuthorPosts
 - 
		
			
				
Been a while since I last used Monkey – I must say Ted2Go is now very impressive with all its features! Great job nerobot!
Yeah the simultaneous relanding of the boosters was amazing – the crowd going crazy!! I always remember the days of getting up early in Australia watching the space shuttles go up in amazement. Hopefully we see much more of this going forward!
Take care Mark.
Thanks!
looking great Adam! How is the data being stored and loaded?
nice! you don’t need anything too fancy but looks like it will do a great job! Certainly easier than a manual plot!
Adam,
With the code I used it stored the data in a 2d array which is laid out in grid co-ordinates (x,y) with centre as 0,0. For example the ship is initialised as follows:
Monkey12345Self.CreatePoint(-8,-8)Self.CreatePoint(12,0)Self.CreatePoint(-8,8)Self.CreatePoint(-5,0)Self.CreatePoint(-8,-8)The one thing you may want to consider is the ability to have multiple start points (I guess you could also overlay multiple vectors as an alternate) which would allow you to construct more detailed vectors – for example with the UFO I did have to draw over the some areas twice to get to the next area I needed to draw:
Monkey123456789101112Self.CreatePoint( -5, -3)Self.CreatePoint( -3, -7)Self.CreatePoint( 3, -7)Self.CreatePoint( 5, -3)Self.CreatePoint( -5, -3)Self.CreatePoint(-12, 0)Self.CreatePoint( -5, 4)Self.CreatePoint( 5, 4)Self.CreatePoint( 12, 0)Self.CreatePoint( 5, -3)Self.CreatePoint( 12, 0)Self.CreatePoint(-12, 0)The vector code I used is available here if you wanted to take a look:
https://github.com/chunkypixel/monkey2/blob/master/Asteroids/src/entity/vector.monkey2
What the code does is initially store the vector in one array and then as scaling or rotation is applied it updates the object into a drawing vector. Then when drawn a virtual scale is also applied (Asteroids runs under a base 640,480 but a virtual scale is applied when drawn to match the actual screen size ie. 1024,768).
Hope that gives you a starting point!
Very nice!! Plays very well!
@wiebow looking forward too seeing it!
Updated version (0.6)
https://1drv.ms/u/s!AgngrULjSty9kJscgMVwpojeo2pn3w
Added UFOs, extra player every 10,000pts and ability to enter high scores. Also done a general tidy-up of the game play – plays quite well now.
The new change follow the reasonably established Asteroids game play – UFOs have a large and small (after 10,000pts). Large UFO fire randomly whist small UFOs are quite accurate (less accurate initially but get more so the higher you score.
Now onto the bonus stuff and maybe some color changes.
Nice!
I’m getting a similar crashing thing compiling (on Windows) but on different modules. Sometimes works some times doesn’t – trying to think of how to replicate before I log it.
Note: both ‘external’ modules downloaded ok.
Adam,
Yes certainly sounds interesting! The ability to have some basic editing of a number of file types would enhance a game making application such as Monkey2. Doing a great job on Ted21 BTW!
@gcmartin – quite a comprehensive module! I’ve just done the basic requirements myself to do the job. Shouldn’t be too hard to convert over.
Adam,
This is my VectorEntity (whilst using Wiebo’s Game2d entity classes)
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189Class VectorEntity Extends ObjectEntityPrivateField _renderPoints:VectorPoint[]Field _basePoints:VectorPoint[]Field _points:Int=0Field _currentScale:Vec2fField _currentRotation:FloatPublicField Speed:Float=0.0Method New()'InitialiseSelf.BlendMode=BlendMode.AdditiveSelf.Color=GetColor(224,224,224)_renderPoints=New VectorPoint[20]_basePoints=New VectorPoint[20]End MethodProperty RenderPoints:VectorPoint[]()Return _renderPointsEndProperty Points:Int()Return _pointsEndMethod CreatePoint(x:Float,y:Float)'Set_basePoints[_points].x=x_basePoints[_points].y=y_points+=1'PlotSelf.PlotPoints()End MethodMethod Reset:Void() Virtual'PlotSelf.PlotPoints()End MethodMethod Update:Void() Override'ValidateIf (Not Self.Enabled) Return'Validate (wrap)If (Self.X<-5) Self.ResetPosition(VirtualResolution.Width+5,Self.Y)If (Self.X>VirtualResolution.Width+5) Self.ResetPosition(-5,Self.Y)If (Self.Y<-5) Self.ResetPosition(Self.X,VirtualResolution.Height+5)If (Self.Y>VirtualResolution.Height+5) Self.ResetPosition(Self.X,-5)'Changed?If (_currentScale<>Self.Scale Or _currentRotation<>Self.Rotation)'(Re)PlotSelf.PlotPoints()'Store_currentScale=Self.Scale_currentRotation=Self.RotationEndEnd MethodMethod Render:Void(canvas:Canvas) Override'ValidateIf (Not Self.Enabled Or Not Self.Visible) Return'Canvascanvas.LineWidth=GetLineWidth(2.0) 'For now make all lines >1.0 for smoothingcanvas.Color=Self.Color'PrepareLocal dx:Float=(_renderPoints[0].x+Self.X)*VirtualResolution.sxLocal dy:Float=(_renderPoints[0].y+Self.Y)*VirtualResolution.sy'ProcessFor Local index:Int=1 Until _points'Draw (line)canvas.Alpha=GetAlpha() 'Flickercanvas.DrawLine(dx,dy,(_renderPoints[index].x+Self.X)*VirtualResolution.sx,(_renderPoints[index].y+Self.Y)*VirtualResolution.sy)'Draw (point)canvas.Alpha=0.8canvas.DrawPoint(Int(dx),Int(dy))'Position (for next line)dx=(_renderPoints[index].x+Self.X)*VirtualResolution.sxdy=(_renderPoints[index].y+Self.Y)*VirtualResolution.syNext'Resetcanvas.Color=Color.Whitecanvas.Alpha=1.0End MethodMethod CheckCollision:Bool(entity:Entity) Override'ValidateIf (Not Self.Collision) Return FalseReturn Self.OverlapCollision(Cast<VectorEntity>(entity))End Method'Comparision between two objectsMethod OverlapCollision:Bool(entity:VectorEntity)'Process (object)For Local k:Int=0 until entity.Points'PrepareLocal ex:Float=entity.RenderPoints[k].x+entity.XLocal ey:Float=entity.RenderPoints[k].y+entity.Y'ValidateIf (Self.CollisionState(_renderPoints,_points,Self.X,Self.Y,ex,ey)) Return TrueNext'Process (point)Return Self.PointInPolyCollision(entity)'Process (Double check??)'For Local k:Int=0 until _points' 'Prepare' Local sx:Float=_renderPoints[k].x+Self.X' Local sy:Float=_renderPoints[k].y+Self.Y'' 'Validate' If (Self.CollisionState(entity.RenderPoints,entity.Points,entity.X,entity.Y,sx,sy)) Return True'Next'Return'Return FalseEnd'Comparison between object and pointMethod PointInPolyCollision:Bool(entity:VectorEntity)Return Self.CollisionState(_renderPoints,_points,Self.X,Self.Y,entity.X,entity.Y)End MethodPrivateMethod PlotPoints()'ProcessFor Local index:Int=0 Until _points'PrepareLocal fx:Float=_basePoints[index].xLocal fy:Float=_basePoints[index].y'Scalefx*=Self.Scale.xfy*=Self.Scale.y'Rotation?If (Self.Rotation<>0.0)Local radian:=DegreesToRadians(-Self.Rotation)Local rx:Float=Cos(radian)*fx-Sin(radian)*fyLocal ry:Float=Sin(radian)*fx+Cos(radian)*fyfx=rxfy=ryEnd'Finalise_renderPoints[index].x=fx_renderPoints[index].y=fyNextEnd MethodMethod CollisionState:Bool(points:VectorPoint[],totalPoints:Int,x1:Int,y1:Int,x2:Int,y2:Int)'PrepareLocal j:Int=totalPoints-1Local isColliding:Bool=False'ProcessFor Local i:Int=0 Until totalPoints'PrepareLocal xI:Float=points[i].x+x1Local yI:Float=points[i].y+y1Local xJ:Float=points[j].x+x1Local yJ:Float=points[j].y+y1'Validate'https://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.htmlIf (((yI>y2)<>(yJ>y2)) And (x2<(xJ-xI)*(y2-yI)/(yJ-yI)+xI)) isColliding=Not isColliding'Storej=iNext'Return resultReturn isCollidingEndEnd ClassStruct VectorPointField x:Float=0.0Field y:Float=0.0End StructPretty much my objects such as the player, bullets and asteroids are created from this base vector class. Here is my base ship:
Monkey123456789101112131415161718192021222324Class ShipEntity Extends VectorEntityMethod New()'InitialiseSelf.Initialise()EndMethod Initialise:Void() Virtual'PointsSelf.CreatePoint(-8,-8)Self.CreatePoint(12,0)Self.CreatePoint(-8,8)Self.CreatePoint(-5,0)Self.CreatePoint(-8,-8)'OtherSelf.Rotation=90.0Self.Scale=New Vec2f(0.75,0.75)'ResetSelf.Reset()End MethodEnd ClassSo what is doing is storing the points as a base [basePoints] and it then re-plots [PlotPoints] that based on scale and rotation [renderPoints] as necessary during an update. From there it renders (overall scale adjusted by the VirtualResolution object as required as discussed above).
I’ve had this vector code sitting around for donkeys in my folder collection – unfortunately not sure who created originally!
 - 
		AuthorPosts