About Monkey 2 › Forums › Monkey 2 Projects › Asteroids remake
Tagged: game2d
This topic contains 41 replies, has 7 voices, and was last updated by 
 AdamStrange
 2 years, 6 months ago.
- 
		AuthorPosts
 - 
		
			
				
August 5, 2016 at 6:25 am #2773
Here is my attempt at an Asteroids remake (Windows only) using Wiebo’s Game2d framework – both a great help and I also used the example asteroids game to start from ):
[Updated] v0.6 – 19-08-16 https://1drv.ms/u/s!AgngrULjSty9kJscgMVwpojeo2pn3w
Changes
- Added UFO
 - Extra player every 10,000pts
 - Ability to enter high scores
 
Settings
Change the settings.json file to adjust the resolution (and other things such as vsync, flicker and lives) :
640 – 640×480
800 – 800×600
1024 – 1024×768 (default if nothing else matches)
1366 – 1366×768
1920 – 1920×1080I have tried to follow the arcade version fairly closely from a play view point – still got a few things to do such as the high score table and a bit more work on the tempo (very hard to get past Level 3-4) but a good start. I’ve already added some extra stuff such as level counter and remaining asteroids (ahla Wizball) and I also want to add collectable power-ups such as speed-ups, multi-bullets, bombs etc to give it a bit a of more modern flavour. As with vector games, the screenshots don’t do the visuals much justice but it looks pretty good on-screen – moving starfields and glowing explosions etc.
One of my favorite games which I’ve re-built many a time over the years since I played it on the Atari 2600. Certainly my best effort!
Any feedback would be great!
August 5, 2016 at 8:15 am #2781It good, nice particle effects and I like the screen shake
August 5, 2016 at 10:07 am #2784All works great on windows 10
One thing. it’s very ‘dark” for my tastes. The original vector scanning was very crisp and bright in comparison.
August 5, 2016 at 12:17 pm #2786Thanks guys. Yeah need to keep working on the colors. I removed a background image just last night so the colors need a bit work. Also I might bump up the resolution (from 640×480) which should crisp up the lines as they are a bit chunky ATM.
Like the shaking also – pretty much built-in to Wiebo’s Game2d framework so all credit to him!
August 5, 2016 at 2:51 pm #2794Played it! Really nice. I like the starfield and the stressfull background bump sound.
It gives it a nice atmosphere!
August 6, 2016 at 2:41 am #2811Updated version (v0.3)
You can now adjust the screen size (auto scales everything up) which makes the whole thing look much crisper! If you look in the settings file you can set the screen width which will configure the final screen size:
640 – 640×480
800 – 800×600
1024 – 1024×768 (default if nothing else matches)
1366 – 1366×768
1920 – 1920×1080Everything is scaled (vectors, font, particles, speed) so it should essentially play the same regardless of resolution (not sure if I’ve got everything as yet though as it seems slightly easier the bigger you go).
August 6, 2016 at 3:37 am #2812Great stuff!
Had to turn flicker off pretty quickly though…
August 6, 2016 at 6:13 am #2815Yeah – might be acquired taste that one! Turned it off myself earlier.
August 6, 2016 at 10:07 am #2824Softies
You should see the screen of my Vectrex
August 6, 2016 at 11:24 am #2825August 10, 2016 at 5:35 am #2910Updated version (v0.5)
Make some (more!) big internal changes the past couple of days. I wasn’t happy with my first attempt at scaling so thought more about it and started again. Previously just about everything was scaled pre-render (this included speed, distance and size calcs) but I’ve changed that so it just when rendering now. The game now will run, process and validate at a set screen size (in this case 640×480) but it now renders everything automatically to the actual screen size.
Overall it now looks and runs the same regardless of resolution and I don’t have to change a thing! The net effect is that the graphics become much cleaner and defined as you increase the resolution.
I also re-org’d a whole lot of other stuff to make it cleaner and easier to access (the eternal on-going tidy-up!). Now time to push on and look at the UFO, power-ups and final review of the colors.
August 10, 2016 at 6:47 am #2915how are you storing the graphics/vector data. For example the ship (which is made from 4 lines)
Is it some form of vector class where you just give it a vertex list and it draws it at a location with rotation?
August 10, 2016 at 9:30 am #2917Adam,
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!
August 10, 2016 at 9:50 am #2918I use this vector script in monkey1, need/going to translate it to mx2.
http://www.monkey-x.com/Community/posts.php?topic=568
But i will try to use the vec2f class and extend it with thing (i guess)
August 10, 2016 at 12:42 pm #2920@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.
 - 
		AuthorPosts
 
You must be logged in to reply to this topic.





