Asteroids Remake

User projects written in or related to FreeBASIC.
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Asteroids Remake

Post by vdecampo »

I am using my Polygon Game Engine to remake the classic vector graphics version of Asteroids. I will also be turning the game into a tutorial for creating vector graphics games like Asteroids.

Still a work in progress but updates can be downloaded here...

Classic Asteroids Remake

More to come!

-Vince
Last edited by vdecampo on Apr 19, 2022 0:42, edited 5 times in total.
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

Post by angros47 »

When I saw your poly engine, I, too, thought about Asteroids.

That's one of the reasons I developed a fade routine, to make a better emulation of the CRT vectorial monitor.

Try this version:

Code: Select all

#Include "Polylib.bas"

sub Fade (r as integer,g as integer,b as integer)
	dim P as byte ptr=screenptr
	dim l(7) as unsigned byte
	dim level as byte ptr=@l(0)
	dim as integer w,h,d

	ScreenInfo w,h,d
	if d<>32 then exit sub

	dim as integer area=w*h/2

	l(0)=b:l(4)=b
	l(1)=g:l(5)=g
	l(2)=r:l(6)=r

	screenlock

	  asm
	
	    mov eax,[P]
	    mov ebx,[level]
	    mov ecx,[area]
   
	    Sat_Loop:
   
	    movq    mm0, [eax]
	    movq    mm1, [ebx]
	    psubusb mm0, mm1      
	    movq    [eax], mm0    'put mm0 back into image at eax?
	    add     eax, 8        'increase by two pixels
	    dec     ecx
	    jnz     Sat_Loop
   
   
	    emms
	  end asm 


	screenunlock
end sub


Const As Double GameTick = 1/60
Const As Double SpinTick = PI/360

#Define SCR_W  800
#Define SCR_H  600

#Macro ReadVertices(rpoint,poly)
   Scope
      Dim As Integer vx,vy
      Restore rpoint
      Do
         Read vx,vy
         If vx=255 Then Exit Do
         poly.AddVertex(vx,vy)
      Loop
      poly.CenterVertices()
   End Scope
#EndMacro

Type _asteroid
   poly     As _polygon 
   size     As Double
   heading  As Double
   speed    As Double
End Type

Type _player
   poly     As _polygon 
   frame    As Integer
   heading  As Double
   speed    As Double
   lives    As Integer
   level    As Integer = 1
   score    As Integer
End Type

Type _shot
   poly     As _polygon 
   heading  As Double
   speed    As Double  
End Type

Type _saucer
   poly     As _polygon 
   size     As Integer
   heading  As Double
   speed    As Double
End Type

Function GenerateAsteroids(ByRef roids As _asteroid Ptr, lvl As Integer) As Integer
Dim NumRoids As Integer = (6+lvl)
   
   If roids Then Delete[] roids   
   roids = New _asteroid[NumRoids]
   
   For i As Integer = 0 To NumRoids-1
      With roids[i]
         ReadVertices(Ast1,.poly)
         .size = 1+(Rnd*3)
         .heading = Rnd*PI*2
         .speed = 1+(Rnd*lvl)
         .poly.zoom = .size*5
         .poly.x = Rnd*SCR_W
         .poly.y = Rnd*SCR_H
      End With
   Next
   
   Return NumRoids
   
End Function

Function ProcessRoids( roids As _asteroid Ptr, Count As Integer) As Integer
Dim As Double dx,dy
   
   For i As Integer = 0 To Count-1

      With roids[i]
         'Process movement         
         dx = Cos(.heading)*.speed
         dy = Sin(.heading)*.speed
         .poly.x += dx
         .poly.y += dy
         If .poly.x < 0 Then .poly.x = SCR_W
         If .poly.y < 0 Then .poly.y = SCR_H
         If .poly.x > SCR_W Then .poly.x = 0
         If .poly.y > SCR_H Then .poly.y = 0
         'Process rotation
         .poly.rot += SpinTick*.speed
         If .poly.rot > PI Then .poly.rot = -PI
         If .poly.rot < -PI Then .poly.rot = PI
      End With
      
   Next
   
   Return 1
   
End Function

ScreenRes SCR_W,SCR_H,32

'Timers
Dim As Double tmrPROCESS

'Game Entities
Dim Player    As _player Ptr
Dim Asteroids As _asteroid Ptr 
Dim Shot      As _shot Ptr
Dim Saucer    As _saucer Ptr

'Game Variables
Dim NumRoids As Integer

'Poly Renderer
Dim DrawIt   As _render_poly

   /'
      Initialize Player 
   '/
   Player   = New _player
   ReadVertices(Player1, Player->poly)
   
   /'
      Initialize Asteroids
   '/
   NumRoids = GenerateAsteroids(Asteroids, Player->level)

   Do 'Outer Game Loop

      /'
         Process Sprite Movement
      '/
      If Timer-tmrPROCESS > GameTick Then
         ProcessRoids( Asteroids, NumRoids )
         tmrPROCESS = Timer
      EndIf
      
      /'
         Rendering
      '/
      ScreenLock
         For a As Integer = 0 To NumRoids
            DrawIt.RenderPoly(Asteroids[a].poly)
         Next        
      Fade 64,4,64
      ScreenUnLock
      
      Sleep 1,1
      
   Loop Until MultiKey(FB.SC_ESCAPE)
   
/'
   Vertex Data
'/
Ast1:
Data 0,0,3,0,4,1,4,2,5,2,6,3,6,4,4,7,2,7,2,6,1,5,0,5,0,3,1,2,0,1,0,0,255,255

Player1:
Data 0,0,8,3,0,6,2,3,0,0,255,255
I simply added my fade routine, and replaced a CLS command with it (but I put it after, and not before the routine that draws asteroids)
rolliebollocks
Posts: 2655
Joined: Aug 28, 2008 10:54
Location: new york

Post by rolliebollocks »

@Angros

The fade routines I've seen availible have only one variable and preserve the ratio of R:G:B. In order to fade properly with your routine I'd think you'd need to know the initial RGB values.

I'm going to be handling all this with a color class.
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Post by vdecampo »

rolliebollocks wrote:@Angros

The fade routines I've seen availible have only one variable and preserve the ratio of R:G:B. In order to fade properly with your routine I'd think you'd need to know the initial RGB values.
He is reading the color values directly from the screen and fading them proportionally.

-Vince
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Post by vdecampo »

Update!

Added the player ship and got the movement down...rotate and thrusting. Now working on the thrust animation and shooting.

-Vince
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

Post by angros47 »

@rolliebollocks

My goal was not to preserve RGB ratio, but to get some trail effects: in this example, I actually wanted to fade toward green (since, in the original vectorial screen of Asteroids arcades, green phosphors were used)
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Post by vdecampo »

Update!

OK! Got the ship moving and shooting correctly.

Next up, collisions!

-Vince
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Post by vdecampo »

Update!

You can fly around and blow up asteroids! Still can't get killed. Need to add ship collision and UFO. Then I just need to add increasing skill levels.

Anybody gotten a chance to test and see how fluid it plays?

Download link

Thanks
-Vince
h4tt3n
Posts: 698
Joined: Oct 22, 2005 21:12
Location: Denmark

Post by h4tt3n »

Looking good! For collision detection you can use Relsofts SAT implementation.

Cheers,
Mike
Dr_D
Posts: 2451
Joined: May 27, 2005 4:59
Contact:

Post by Dr_D »

Seems good to me. The only thing I can see is that maybe it accelerates a bit too fast. It may just be me though...
Prime Productions
Posts: 147
Joined: May 24, 2009 23:13
Location: Texas, United States, Planet Earth
Contact:

Post by Prime Productions »

Runs nicely. I think it's looking good. As to the ship accelerating to fast, I think it is a little fast also.
Can't wait to see it done!

David
angros47
Posts: 2321
Joined: Jun 21, 2005 19:04

Post by angros47 »

Works well in Linux, too.
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Post by vdecampo »

BIG UPDATE!

I have all collisions working and we are now in a playable state. Scoring, ship count are now active. Sound is working too! (FBSound by DJ Peters)

Things to do....

1. Get UFO enemy working
2. Implement Hi-Score entry and display
3. Implement vector text display just like original
4. Implement a demo play function
5. Implement respawn when no asteroids are around!
6. Implement progressing levels

Moving forward!!!!

Download link


-Vince
h4tt3n
Posts: 698
Joined: Oct 22, 2005 21:12
Location: Denmark

Post by h4tt3n »

Nice! It was a little buggy though. At some point the ship became invisible, and when exiting the program it returned a windows error. Looking forward to the next iteration.

Cheers,
Mike
vdecampo
Posts: 2992
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Post by vdecampo »

h4tt3n wrote:Nice! It was a little buggy though. At some point the ship became invisible, and when exiting the program it returned a windows error. Looking forward to the next iteration.

Cheers,
Mike
Hmmm. I did not see anything like that. Did you recompile or use the included binary? XP, VISTA, or Win7?

-Vince
Post Reply