Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 23:36 24 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : PicoRocks - A Teaser

     Page 3 of 7    
Author Message
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4223
Posted: 10:11am 23 Jul 2024
Copy link to clipboard 
Print this post

Not sure, but I watched a video of the original arcade, and it was a b/w screen, not green.
I'll do some more investigation.
PicomiteVGA PETSCII ROBOTS
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 6780
Posted: 02:19pm 23 Jul 2024
Copy link to clipboard 
Print this post

Wasn't the original arcade version a vector display? Black and white makes more sense if it was.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2120
Posted: 02:39pm 23 Jul 2024
Copy link to clipboard 
Print this post

I worked in a factory that made asteroids and super asteroids. Used a b/w x/y crt with phosphor for animation ie no erase graphics, they just faded away.
If the intensity was increased you saw the lines connecting all the rocks.
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1109
Posted: 06:53pm 23 Jul 2024
Copy link to clipboard 
Print this post

Have at it. I don't think I have any unposted work on it but I'll check tonight.
Visit Vegipete's *Mite Library for cool programs.
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2120
Posted: 07:44pm 23 Jul 2024
Copy link to clipboard 
Print this post

This asteroids is interesting. anyone remember the atari 2600 version?
They did have rotating rocks later ... and a death star.
in the pico version, do we use trig for the ship or predefined angles?
how is wrap around done now?
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4223
Posted: 08:16pm 23 Jul 2024
Copy link to clipboard 
Print this post

Stan,

No idea yet, have to study the game first. I have the asteroids flying, the ship also, I can fire, shoot asteroids, they split in smaller pieces perpendicular to the bullet angle, and finally get destroyed. Bullets vanish at the borders, but asteroids and ship mirror at the borders. What I read on wiki is that that is the original gameplay. I have max 6 bullets on screen now.
Next is the vector font for the score, and the flying saucer ( there are 2 apparently).
Since everything in mmbasic is vector drawn, no sprites, I want the font also vector drawn. That would be cool. The YouTube video shows a very primitive font. Should be simple.

Have to study a lot….

Volhout
Edited 2024-07-24 06:22 by Volhout
PicomiteVGA PETSCII ROBOTS
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2120
Posted: 08:29pm 23 Jul 2024
Copy link to clipboard 
Print this post

@ Volhout... I got time.. if no one else done asteroids.
working on missile from x1,y1 to x2,y2.. 4 quadrants but using floating point easy :)
it's needed in many games .. missile command, 2d tanks
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4223
Posted: 08:51pm 23 Jul 2024
Copy link to clipboard 
Print this post

Based on Vegipete's teaser.
Do not comment on coding, this is experimental stage. Cleanup of code will be when I know how I am going to implement things.

Fly with cursor keys (UP, LEFT, RIGHT)
Fire with <SPACE>

 '=============================================================================|
 ' PicoRocks in Space - Teaser
 '
 ' written by Vegipete, Jan 2024
 ' Ported from CMM2 (somewhat)
 '
 ' needs:
 ' OPTION CPUSPEED 252000 (KHz)
 
 '=============================================================================
 ' Versions
 ' rocks1      'adapt VegiPete version to 640x80, copy some from CMM2 version
 ' rocks2      'fly the ship
 ' rocks3      'fire gun, detect asteroid hit
 ' rocks4      'hit asteroids, split when hit, clear keyboard buffer
 
 Option DEFAULT INTEGER
 Option LCDPANEL NOCONSOLE
 option angle degrees
 mode 1 '@Volhout MODE 2
 cls 0
 
 const MAXROCKS = 50
 dim float rock(MAXROCKS,7) ' 50 rocks: scale,angle,x,y,vx,vy,a,da
 dim trock (MAXROCKS)  ' type of rock
 math set 0, rock()    ' erase them all to start
 math set 0,trock()
 dim float v(1)        ' for math
 dim bult(5,3)         ' 6 bullets
 math set 0,bult()     ' no bullets flying around
 
 ' rock vector shapes
 ' Note: any resemblance to a country is purely coincidental
 dim r1x(14)=( 0, 3, 4, 3, 5, 4, 1,-2,-4,-5,-3,-5,-3,-2, 0)
 dim r1y(14)=( 5, 4, 3, 1, 0,-4,-5,-4,-4,-1,-1, 2, 3, 5, 5)
 dim r2x(14)=( 0,-2,-3,-4,-5,-4,-4,-3,-1, 4, 4, 5, 4, 2, 0)
 dim r2y(14)=(-6,-4,-3,-4,-1, 2, 3, 3, 5, 3, 1, 0,-3,-4,-6)
 dim r3x(14)=( 1,-2,-2,-4,-4,-5,-5,-3,-2, 0, 4, 3, 5, 3, 1)
 dim r3y(14)=(-4,-5,-3,-4,-2, 0, 3, 4, 3, 5, 3, 2, 1,-5,-4)
 dim r4x(14)=( 0,-2,-4,-4,-5,-3,-1, 2, 1, 3, 5, 3, 4, 3, 0)
 dim r4y(14)=(-5,-4,-4,-1, 1, 4, 5, 5, 3, 4, 1,-2,-3,-4,-5)
 
 ' player ship and exhaust flame shapes @Volhout *2
 dim shpx(4)=(0,-6,0,6,0)
 dim shpy(4)=(-10,10,6,10,-10)
 dim flmx(4)=(0,-2,0,2,0)
 dim flmy(4)=(8,10,14,10,8)
 
 FRAMEBUFFER Create   ' hidden layer to draw scene
 FRAMEBUFFER Write F : CLS 0
 
 dim float pv,px,py,pvx,pvy
 
 ph = 0 : pv = 0
 px = MM.HRES/2-6 : pvx = 0
 py = MM.VRES/2-6 : pvy = 0
 smash=0:newrun=0'1
 fire=0 '@Volhout copy from CMM2
 bspd=4  'bullet speed
 
 'copied from CMM2 sound
 play modfile "RISsound.mod"
 
 ' create 10 random rocks
 k = 1
 for i = 1 to 8'10
   trock(i)  = 1 + (k and 3) ' rock type (0=doesn't exist)
   rock(i,0) = 2 + int(rnd*6)' rock size @Volhout *2
   rock(i,2) = rnd*MM.HRES   ' x location
   rock(i,3) = rnd*MM.VRES   ' y location
   rock(i,4) = 1-rnd*2   ' x velocity
   rock(i,5) = 1-rnd*2   ' y velocity
   rock(i,6) = rnd*360   ' starting angle
   rock(i,7) = 3-rnd*6   ' rotation speed
   inc k
 next
 
 mot = timer 'motor on timer
 
 do
   tm=timer
   
   'extract last key from key buffer
   do
     k=e:e=asc(inkey$)
   loop until e=0  

   if k then
     burn = 0
     select case k
       Case 128  ' up
         inc pvx, sin(ph)/2
         inc pvy,-cos(ph)/2
         mot = timer + 200   ' keep flame visible for a while
       Case 130  ' left
         inc ph,-5
         if ph < 0 then ph = 355
       Case 131  ' right
         inc ph,5
         if ph > 355 then ph = 0
       case 32 'space for fire '102 'f'for fire
         fire=1:drawfire
         'print "fire"
       case 27
         print : end
     end select
   endif
   
   inc px,pvx
   if px > MM.HRES then inc px, -(MM.HRES+10)
   if px < 5 then inc px, MM.HRES+10
   
   inc py,pvy
   if py > MM.VRES then inc py, -(MM.VRES+10)
   if py < 0 then inc py, MM.VRES+10
   
   ' velocity decays away slowly
   pvx = pvx * .99 '@Volhout .995
   pvy = pvy * .99 '@Volhout .995
   
   ' move rocks
   for i = 0 to MAXROCKS
     if trock(i) then   ' rock exists
       
       'move rocks and keep in window
       inc rock(i,2),rock(i,4)
       rock(i,2)=(rock(i,2)+mm.hres) mod mm.hres
       inc rock(i,3),rock(i,5)
       rock(i,3)=(rock(i,3)+mm.vres) mod mm.Vres
       
       'move bullets and check if something is hit
       for j = 0 to 5
         ' test for player bullet hitting asteroid
         if bult(j,0) then ' does this bullet exist?
           
           'move it, when off-screen then skip bullet
           inc bult(j,1),bspd*sin(bult(j,3))
           if bult(j,1)>MM.HRES or bult(j,1)<0 then bult(j,0)=0
           inc bult(j,2),-bspd*cos(bult(j,3))
           if bult(j,2)>MM.VRES or bult(j,2)<0 then bult(j,0)=0
           
           'check for hit
           v(1) = bult(j,1) - rock(i,2) '- rock(i,0)   'coordinate compare
           'if v(1) > 1 + asiz(an) then continue for  ' early exit because gap is large
           v(0) = bult(j,2) - rock(i,3) '- rock(i,0)   'y coordinate compare
           if math(magnitude v()) < 5*rock(i,0) then
             bult(j,0) = 0   ' end of bullet
             AstHit(i,j)
             continue for
           endif
         endif
       next
       '
       '' test for ufo bullet hitting asteroid
       'if bufo(j,0) then ' does this bullet exist?
       'v(1) = bufo(j,1) - ast(i,1) - asiz(an)
       'if v(1) > 1 + asiz(an) then continue for  ' early exit because gap is large
       'v(2) = bufo(j,2) - ast(i,2) - asiz(an)
       'if math(magnitude v()) < 1 + asiz(an) then
       'bufo(j,0) = 0   ' end of bullet
       'buct = buct - 1
       'AstHit(i,0)
       'continue for
       'endif
       'endif
       'next j
       '
       if (smash = 0) and (newrun = 0) then
         ' test for asteroid hit player ship
         v(0) = px - rock(i,2) '@Volhout
         v(1) = py - rock(i,3) '@Volhout
         if math(magnitude v()) < 10 + 5*rock(i,0) then
           print "hit" 'debug
           smash = 1
           sprd = 5    ' start the debris field
           play modsample 6,4              ' player explosion
           
           'new start location
           wrkx = px + 16
           wrky = py + 16
           px = MM.HRES/2-6 : pvx = 0
           py = MM.VRES/2-6 : pvy = 0
           'AstHit(i,1)
           continue for
         endif
       endif
       
       '' test for asteroid hit ufo
       'if ufo(0) = 2 then    ' large ufo
       'v(1) = ufo(1) + 24 - ast(i,1) - asiz(an)
       'v(2) = ufo(2) + 12 - ast(i,2) - asiz(an)
       'if math(magnitude v()) < 17 + asiz(an) then
       'ufo(0) = 0 : nufo = 120   ' ufo death by asteroid
       'if ast(i,0) < 9 then NewDustCloud(ufo(1) + 24, ufo(2) + 12)
       'AstHit(i,0)
       'continue for
       'endif
       'elseif ufo(0) = 1 then  ' small ufo
       'v(1) = ufo(1) + 12 - ast(i,1) - asiz(an)
       'v(2) = ufo(2) +  6 - ast(i,2) - asiz(an)
       'if math(magnitude v()) < 10 + asiz(an) then
       'ufo(0) = 0 : nufo = 120    ' ufo death by asteroid
       'if ast(i,0) < 9 then NewDustCloud(ufo(1) + 12, ufo(2) + 6)
       'AstHit(i,0)
       'continue for
       'endif
       'endif
       
     endif
   next i
   
   'check win
   if math(sum trock())=0 then math set 0,bult()
   
   cls
   DrawShip
   DrawRocks
   Drawbullet
   text 0,0,str$(timer-tm,3,0) '@Volhout game loop time in ms
   FRAMEBUFFER copy F,N,B
   
 loop
 
 
sub Asthit(n,m)
 local i
 print "astroid ";n;" hit"
 if rock(n,0)<3 then
   trock(n)=0  'remove from game play
 else
   'split the asteroid in 2 equal pieces half the size
   
   'find second free slot
   for i = 0 to MAXROCKS
     if trock(i)=0 then exit for
   next
   
   'rock n modify, and rock i is the new ones
   trock(i)=trock(n)                                  'same type of asteroid
'    rock(i,0)=max(rock(n,0)/2,2):rock(n,0)=rock(i,0)   'both half size
   rock(i,0)=max(rock(n,0)-2,2):rock(n,0)=rock(i,0)   'both half size
   rock(i,2) = rock(n,2)   ' x location
   rock(i,3) = rock(n,3)   ' y location
   rock(i,4) = cos(bult(j,3)):rock(n,4) = -cos(bult(j,3)) ' x velocity
   rock(i,5) = sin(bult(j,3)):rock(n,5) = -sin(bult(j,3)) ' y velocity
   rock(i,6) = rnd*360     ' starting angle random
   rock(i,7) = rock(n,7)   ' rotation speed    
 end if
end sub
 
sub Drawbullet
 local i
 for i=0 to 5
   if bult(i,0) then pixel bult(i,1),bult(i,2)
 next
end sub
 
sub DrawShip
 local x(4),y(4)
 'off = (mot > timer) * 6624
 'this is the ship
 math scale shpx(),1,x()
 math scale shpy(),1,y()
 math v_rotate 0,0,ph,x(),y(),x(),y()
 math add x(),px,x()  ' position ship
 math add y(),py,y()
 polygon 5,x(),y(),rgb(green)
 'this is the exhaust flame
 if mot > timer then
   math scale flmx(),1,x()
   math scale flmy(),1,y()
   math v_rotate 0,0,ph,x(),y(),x(),y()
   math add x(),px,x()  ' position rocket flame
   math add y(),py,y()
   polygon 5,x(),y(),rgb(brown)
 endif
end sub
 
 ' Go through the list of rocks and draw any that exist
sub DrawRocks
 local i
 local x(14),y(14)
 
 for i = 0 to MAXROCKS
   if trock(i) then   ' rock exists
     inc rock(i,6),rock(i,7) ' spin rock
     if rock(i,6) > 360 then inc rock(i,6),-360
     if rock(i,6) < 0 then inc rock(i,6),360
     
     select case trock(i) ' what shape of rock is it?
       case 1
         math scale r1x(),rock(i,0),x()
         math scale r1y(),rock(i,0),y()
       case 2
         math scale r2x(),rock(i,0),x()
         math scale r2y(),rock(i,0),y()
       case 3
         math scale r3x(),rock(i,0),x()
         math scale r3y(),rock(i,0),y()
       case 4
         math scale r4x(),rock(i,0),x()
         math scale r4y(),rock(i,0),y()
     end select
     math v_rotate 0,0,rock(i,6),x(),y(),x(),y()
     math add x(),rock(i,2),x()  ' position rock
     math add y(),rock(i,3),y()
     polygon 15,x(),y()
   endif
 next i
end sub
 
sub drawfire
 local i
 if fire then
   for i=0 to 5
     if bult(i,0)=0 then
       bult(i,0)=1:bult(i,1)=px:bult(i,2)=py:bult(i,3)=ph
       fire=0:exit for
     end if
   next
 end if
end sub



Volhout
Edited 2024-07-24 18:51 by Volhout
PicomiteVGA PETSCII ROBOTS
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2120
Posted: 07:22pm 24 Jul 2024
Copy link to clipboard 
Print this post

looks good
I had to reflash vga usb and mmedit as no mmcc ?
if I don't use mmbasic for a few weeks I forget how it works


Edited 2024-07-25 07:52 by stanleyella
 
vegipete

Guru

Joined: 29/01/2013
Location: Canada
Posts: 1109
Posted: 09:37pm 25 Jul 2024
Copy link to clipboard 
Print this post

If only the MOD function worked 'nicely' with floating point values. My experience is that it removes the decimal part.

Thus, statements like
rock(i,2)=(rock(i,2)+mm.hres) mod mm.hres
result in the asteroids moving only in integer steps. Or has something changed?
Visit Vegipete's *Mite Library for cool programs.
 
stanleyella

Guru

Joined: 25/06/2022
Location: United Kingdom
Posts: 2120
Posted: 11:18pm 25 Jul 2024
Copy link to clipboard 
Print this post

I got stationary rocks. is it
  rock(i,4) = 1-rnd*2   ' x velocity
  rock(i,5) = 1-rnd*2   ' y velocity

I had to comment the sound as unknown command.
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 1113
Posted: 04:30am 26 Jul 2024
Copy link to clipboard 
Print this post

Realy nice Game  
  vegipete said  If only the MOD function worked 'nicely' with floating point values. My experience is that it removes the decimal part.

Thus, statements like
rock(i,2)=(rock(i,2)+mm.hres) mod mm.hres
result in the asteroids moving only in integer steps. Or has something changed?

Mod just works with integer so ?PI MOD 3 returns 0
To keep the floating point coordinates in the screen area, one can replace the MOD-Command with something like
inc rock(i,2),-mm.hres*(rock(i,2)>mm.hres)+mm.hres*(rock(i,2)<0)

This means that the variables retain their decimals.

the whole thing is only a little slower than the MOD command but to speed up the game a little, I have also made a small change to the overflow calculation of the player coordinates.
Inc px,pvx -(MM.HRes+10)*(px > MM.HRes)+(MM.HRes+10)*(px<5)'@Martin
  'If px > MM.HRes Then Inc px, -(MM.HRes+10)
  'If px < 5 Then Inc px, MM.HRes+10

  Inc py,pvy -(MM.VRes+10)*(py > MM.VRes)+(MM.VRes+10)*(py<0)'@Martin
  'If py > MM.VRes Then Inc py, -(MM.VRes+10)
  'If py < 0 Then Inc py, MM.VRes+10



Cheers
Martin
Edited 2024-07-26 15:35 by Martin H.
'no comment
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4223
Posted: 05:41am 26 Jul 2024
Copy link to clipboard 
Print this post

  vegipete said  If only the MOD function worked 'nicely' with floating point values. My experience is that it removes the decimal part.

Thus, statements like
rock(i,2)=(rock(i,2)+mm.hres) mod mm.hres
result in the asteroids moving only in integer steps. Or has something changed?


Screen resolutions are integers between 640,480 and 0

The actual Vectrex display used an 8 bit DAC so that was 256 resolution for the vectors… but the lines between the vectors where phosphor molecule resolution, near infinite. No pixels, but hardware analog integrator circuits.
Nice technology.

Volhout
Edited 2024-07-26 15:43 by Volhout
PicomiteVGA PETSCII ROBOTS
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4223
Posted: 05:44am 26 Jul 2024
Copy link to clipboard 
Print this post

  stanleyella said  I got stationary rocks. is it
  rock(i,4) = 1-rnd*2   ' x velocity
  rock(i,5) = 1-rnd*2   ' y velocity

I had to comment the sound as unknown command.


You should set OPTION SOUND

Volhout
PicomiteVGA PETSCII ROBOTS
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4223
Posted: 05:46am 26 Jul 2024
Copy link to clipboard 
Print this post

  Martin H. said  Realy nice Game  
  vegipete said  If only the MOD function worked 'nicely' with floating point values. My experience is that it removes the decimal part.

Thus, statements like
rock(i,2)=(rock(i,2)+mm.hres) mod mm.hres
result in the asteroids moving only in integer steps. Or has something changed?

Mod just works with integer so ?PI MOD 3 returns 0
To keep the floating point coordinates in the screen area, one can replace the MOD-Command with something like
inc rock(i,2),-mm.hres*(rock(i,2)>mm.hres)+mm.hres*(rock(i,2)<0)

This means that the variables retain their decimals.

the whole thing is only a little slower than the MOD command but to speed up the game a little, I have also made a small change to the overflow calculation of the player coordinates.
Inc px,pvx -(MM.HRes+10)*(px > MM.HRes)+(MM.HRes+10)*(px<5)'@Martin
  'If px > MM.HRes Then Inc px, -(MM.HRes+10)
  'If px < 5 Then Inc px, MM.HRes+10

  Inc py,pvy -(MM.VRes+10)*(py > MM.VRes)+(MM.VRes+10)*(py<0)'@Martin
  'If py > MM.VRes Then Inc py, -(MM.VRes+10)
  'If py < 0 Then Inc py, MM.VRes+10



Cheers
Martin



Thanks,

Volhout
PicomiteVGA PETSCII ROBOTS
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 1113
Posted: 05:57am 26 Jul 2024
Copy link to clipboard 
Print this post

here the Version with some changes i made & more sound  

'=============================================================================|
' PicoRocks in Space - Teaser
'
' written by Vegipete, Jan 2024
' Ported from CMM2 (somewhat)
'
' needs:
' OPTION CPUSPEED 252000 (KHz)

'=============================================================================
' Versions
' rocks1      'adapt VegiPete version to 640x80, copy some from CMM2 version
' rocks2      'fly the ship
' rocks3      'fire gun, detect asteroid hit
' rocks4      'hit asteroids, split when hit, clear keyboard buffer

Option DEFAULT INTEGER
Option LCDPANEL NOCONSOLE
Option angle degrees
MODE 1 '@Volhout MODE 2
CLS 0

Const MAXROCKS = 50
Dim float rock(MAXROCKS,7) ' 50 rocks: scale,angle,x,y,vx,vy,a,da
Dim trock(MAXROCKS)  ' type of rock
Math set 0, rock()    ' erase them all to start
Math set 0,trock()
Dim float v(1)        ' for math
Dim bult(5,3)         ' 6 bullets
Math set 0,bult()     ' no bullets flying around

' rock vector shapes
' Note: any resemblance to a country is purely coincidental
Dim r1x(14)=( 0, 3, 4, 3, 5, 4, 1,-2,-4,-5,-3,-5,-3,-2, 0)
Dim r1y(14)=( 5, 4, 3, 1, 0,-4,-5,-4,-4,-1,-1, 2, 3, 5, 5)
Dim r2x(14)=( 0,-2,-3,-4,-5,-4,-4,-3,-1, 4, 4, 5, 4, 2, 0)
Dim r2y(14)=(-6,-4,-3,-4,-1, 2, 3, 3, 5, 3, 1, 0,-3,-4,-6)
Dim r3x(14)=( 1,-2,-2,-4,-4,-5,-5,-3,-2, 0, 4, 3, 5, 3, 1)
Dim r3y(14)=(-4,-5,-3,-4,-2, 0, 3, 4, 3, 5, 3, 2, 1,-5,-4)
Dim r4x(14)=( 0,-2,-4,-4,-5,-3,-1, 2, 1, 3, 5, 3, 4, 3, 0)
Dim r4y(14)=(-5,-4,-4,-1, 1, 4, 5, 5, 3, 4, 1,-2,-3,-4,-5)

' player ship and exhaust flame shapes @Volhout *2
Dim shpx(4)=(0,-6,0,6,0)
Dim shpy(4)=(-10,10,6,10,-10)
Dim flmx(4)=(0,-2,0,2,0)
Dim flmy(4)=(8,10,14,10,8)

FRAMEBUFFER Create   ' hidden layer to draw scene
FRAMEBUFFER Write F : CLS 0

Dim float pv,px,py,pvx,pvy

ph = 0 : pv = 0
px = MM.HRes/2-6 : pvx = 0
py = MM.VRes/2-6 : pvy = 0
smash=0:newrun=0'1
fire=0 '@Volhout copy from CMM2
bspd=4  'bullet speed

'copied from CMM2 sound
Play modfile "RISsound.mod"

' create 10 random rocks
k = 1
For i = 1 To 8'10
  trock(i)  = 1 + (k And 3) ' rock type (0=doesn't exist)
  rock(i,0) = 2 + Int(Rnd*6)' rock size @Volhout *2
  rock(i,2) = Rnd*MM.HRes   ' x location
  rock(i,3) = Rnd*MM.VRes   ' y location
  rock(i,4) = 1-Rnd*2   ' x velocity
  rock(i,5) = 1-Rnd*2   ' y velocity
  rock(i,6) = Rnd*360   ' starting angle
  rock(i,7) = 3-Rnd*6   ' rotation speed
  Inc k
Next

mot = Timer 'motor on timer

Do
  tm=Timer

  'extract last key from key buffer
  Do
    k=e:e=Asc(Inkey$)
  Loop Until e=0

  If k Then
    burn = 0
    Select Case k
      Case 128  ' up
        Inc pvx, Sin(ph)/2
        Inc pvy,-Cos(ph)/2
        Play modsample 9,2'@Martin
        mot = Timer + 200   ' keep flame visible for a while
      Case 130  ' left
        Inc ph,-5
        If ph < 0 Then ph = 355
      Case 131  ' right
        Inc ph,5
        If ph > 355 Then ph = 0
      Case 32 'space for fire '102 'f'for fire
        fire=1:drawfire:Play modsample 3,1'@Martin
        'print "fire"
      Case 27
        Print : End
    End Select
  EndIf

  'Inc px,pvx
  Inc px,pvx-(MM.HRes+10)*(px > MM.HRes)+(MM.HRes+10)*(px<5)'@Martin
  'If px > MM.HRes Then Inc px, -(MM.HRes+10)
  'If px < 5 Then Inc px, MM.HRes+10

  'Inc py,pvy
  Inc py,pvy-(MM.VRes+10)*(py > MM.VRes)+(MM.VRes+10)*(py<0)'@Martin
  'If py > MM.VRes Then Inc py, -(MM.VRes+10)
  'If py < 0 Then Inc py, MM.VRes+10

  ' velocity decays away slowly
  pvx = pvx * .99 '@Volhout .995
  pvy = pvy * .99 '@Volhout .995

  ' move rocks
  For i = 0 To MAXROCKS
    If trock(i) Then   ' rock exists

      'move rocks and keep in window
      Inc rock(i,2),rock(i,4)
      Inc rock(i,2),-MM.HRes*(rock(i,2)>MM.HRes)+MM.HRes*(rock(i,2)<0)'@Martin
     'rock(i,2)=(rock(i,2)+MM.HRes) Mod MM.HRes
      Inc rock(i,3),rock(i,5)
      Inc rock(i,3),-MM.VRes*(rock(i,3)>MM.VRes)+MM.VRes*(rock(i,3)<0)'@Martin
     'rock(i,3)=(rock(i,3)+MM.VRes) Mod MM.VRes

      'move bullets and check if something is hit
      For j = 0 To 5
        ' test for player bullet hitting asteroid
        If bult(j,0) Then ' does this bullet exist?

          'move it, when off-screen then skip bullet
          Inc bult(j,1),bspd*Sin(bult(j,3))
          If bult(j,1)>MM.HRes Or bult(j,1)<0 Then bult(j,0)=0
          Inc bult(j,2),-bspd*Cos(bult(j,3))
          If bult(j,2)>MM.VRes Or bult(j,2)<0 Then bult(j,0)=0

          'check for hit
          v(1) = bult(j,1) - rock(i,2) '- rock(i,0)   'coordinate compare
          'if v(1) > 1 + asiz(an) then continue for  ' early exit because gap is large
          v(0) = bult(j,2) - rock(i,3) '- rock(i,0)   'y coordinate compare
          If Math(magnitude v()) < 5*rock(i,0) Then
            bult(j,0) = 0   ' end of bullet
            AstHit(i,j)
            Continue For
          EndIf
        EndIf
      Next
      '
      '' test for ufo bullet hitting asteroid
      'if bufo(j,0) then ' does this bullet exist?
      'v(1) = bufo(j,1) - ast(i,1) - asiz(an)
      'if v(1) > 1 + asiz(an) then continue for  ' early exit because gap is large
      'v(2) = bufo(j,2) - ast(i,2) - asiz(an)
      'if math(magnitude v()) < 1 + asiz(an) then
      'bufo(j,0) = 0   ' end of bullet
      'buct = buct - 1
      'AstHit(i,0)
      'continue for
      'endif
      'endif
      'next j
      '
      If (smash = 0) And (newrun = 0) Then
        ' test for asteroid hit player ship
        v(0) = px - rock(i,2) '@Volhout
        v(1) = py - rock(i,3) '@Volhout
        If Math(magnitude v()) < 10 + 5*rock(i,0) Then
          Print "hit" 'debug
          smash = 1
          sprd = 5    ' start the debris field
          Play modsample 6,4              ' player explosion

          'new start location
          wrkx = px + 16
          wrky = py + 16
          px = MM.HRes/2-6 : pvx = 0
          py = MM.VRes/2-6 : pvy = 0
          'AstHit(i,1)
          Continue For
        EndIf
      EndIf

      '' test for asteroid hit ufo
      'if ufo(0) = 2 then    ' large ufo
      'v(1) = ufo(1) + 24 - ast(i,1) - asiz(an)
      'v(2) = ufo(2) + 12 - ast(i,2) - asiz(an)
      'if math(magnitude v()) < 17 + asiz(an) then
      'ufo(0) = 0 : nufo = 120   ' ufo death by asteroid
      'if ast(i,0) < 9 then NewDustCloud(ufo(1) + 24, ufo(2) + 12)
      'AstHit(i,0)
      'continue for
      'endif
      'elseif ufo(0) = 1 then  ' small ufo
      'v(1) = ufo(1) + 12 - ast(i,1) - asiz(an)
      'v(2) = ufo(2) +  6 - ast(i,2) - asiz(an)
      'if math(magnitude v()) < 10 + asiz(an) then
      'ufo(0) = 0 : nufo = 120    ' ufo death by asteroid
      'if ast(i,0) < 9 then NewDustCloud(ufo(1) + 12, ufo(2) + 6)
      'AstHit(i,0)
      'continue for
      'endif
      'endif

    EndIf
  Next i

  'check win
  If Math(sum trock())=0 Then Math set 0,bult()

  CLS
  DrawShip
  DrawRocks
  Drawbullet
  Text 0,0,Str$(Timer-tm,3,0) '@Volhout game loop time in ms
  FRAMEBUFFER copy F,N,B

Loop


Sub Asthit(n,m)
Local i
Print "astroid ";n;" hit"
Play modsample 6,3'@Martin

If rock(n,0)<3 Then
  trock(n)=0  'remove from game play
Else
  'split the asteroid in 2 equal pieces half the size

  'find second free slot
  For i = 0 To MAXROCKS
    If trock(i)=0 Then Exit For
  Next

  'rock n modify, and rock i is the new ones
  trock(i)=trock(n)                                  'same type of asteroid
'    rock(i,0)=max(rock(n,0)/2,2):rock(n,0)=rock(i,0)   'both half size
  rock(i,0)=Max(rock(n,0)-2,2):rock(n,0)=rock(i,0)   'both half size
  rock(i,2) = rock(n,2)   ' x location
  rock(i,3) = rock(n,3)   ' y location
  rock(i,4) = Cos(bult(j,3)):rock(n,4) = -Cos(bult(j,3)) ' x velocity
  rock(i,5) = Sin(bult(j,3)):rock(n,5) = -Sin(bult(j,3)) ' y velocity
  rock(i,6) = Rnd*360     ' starting angle random
  rock(i,7) = rock(n,7)   ' rotation speed
End If
End Sub

Sub Drawbullet
Local i
For i=0 To 5
  If bult(i,0) Then Pixel bult(i,1),bult(i,2)
Next
End Sub

Sub DrawShip
Local x(4),y(4)
'off = (mot > timer) * 6624
'this is the ship
Math scale shpx(),1,x()
Math scale shpy(),1,y()
Math v_rotate 0,0,ph,x(),y(),x(),y()
Math add x(),px,x()  ' position ship
Math add y(),py,y()
Polygon 5,x(),y(),RGB(green)
'this is the exhaust flame
If mot > Timer Then
  Math scale flmx(),1,x()
  Math scale flmy(),1,y()
  Math v_rotate 0,0,ph,x(),y(),x(),y()
  Math add x(),px,x()  ' position rocket flame
  Math add y(),py,y()
  Polygon 5,x(),y(),RGB(brown)
EndIf
End Sub

' Go through the list of rocks and draw any that exist
Sub DrawRocks
Local i
Local x(14),y(14)

For i = 0 To MAXROCKS
  If trock(i) Then   ' rock exists
    Inc rock(i,6),rock(i,7) ' spin rock
    If rock(i,6) > 360 Then Inc rock(i,6),-360
    If rock(i,6) < 0 Then Inc rock(i,6),360

    Select Case trock(i) ' what shape of rock is it?
      Case 1
        Math scale r1x(),rock(i,0),x()
        Math scale r1y(),rock(i,0),y()
      Case 2
        Math scale r2x(),rock(i,0),x()
        Math scale r2y(),rock(i,0),y()
      Case 3
        Math scale r3x(),rock(i,0),x()
        Math scale r3y(),rock(i,0),y()
      Case 4
        Math scale r4x(),rock(i,0),x()
        Math scale r4y(),rock(i,0),y()
    End Select
    Math v_rotate 0,0,rock(i,6),x(),y(),x(),y()
    Math add x(),rock(i,2),x()  ' position rock
    Math add y(),rock(i,3),y()
    Polygon 15,x(),y()
  EndIf
Next i
End Sub

Sub drawfire
Local i
If fire Then
  For i=0 To 5
    If bult(i,0)=0 Then
      bult(i,0)=1:bult(i,1)=px:bult(i,2)=py:bult(i,3)=ph
      fire=0:Exit For
    End If
  Next
End If
End Sub                                                                                                                              

Edited 2024-07-26 16:04 by Martin H.
'no comment
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 9110
Posted: 07:34am 26 Jul 2024
Copy link to clipboard 
Print this post

Is the mod file posted anywhere?
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4223
Posted: 07:43am 26 Jul 2024
Copy link to clipboard 
Print this post

Hi Peter,

Here the MOD file and the changes from Martin patched in my own newer version.
You can fly 6 ships, and you respawn after death.
Not totally happy about how the asteroids break in pieces, but that will settle over time....
The text most likely will be a custom font. I thougth about vector painting it, but that slows down too much if I recalculate text on the fly. Currently trying to create a data set for the whole vector font but it is HUGE in memory usage (each character needs a individual x() and y() arrays).
So I may create a font that mimicks the vectors.

rocks5.zip

Volhout
Edited 2024-07-26 17:46 by Volhout
PicomiteVGA PETSCII ROBOTS
 
Martin H.

Guru

Joined: 04/06/2022
Location: Germany
Posts: 1113
Posted: 08:48am 26 Jul 2024
Copy link to clipboard 
Print this post

  Quote  The text most likely will be a custom font. I thougth about vector painting it, but that slows down too much if I recalculate text on the fly. Currently trying to create a data set for the whole vector font but it is HUGE in memory usage (each character needs a individual x() and y() arrays).
So I may create a font that mimicks the vectors.

A Font like this?



' asteroid Style
' Font type    : 64 Characters
' Font size    : 8x8 pixels
' Memory usage : 512
DefineFont #9
40200808
00000000 00000000 10101010 00100010 00482424 00000000 247E2400 00247E24
3C483E08 00107C12 1048A440 00044A24 32404830 003A444A 00100808 00000000
20201008 00081020 08081020 00201008 38541000 00001054 7C101000 00001010
00000000 20101000 7C000000 00000000 00000000 00101000 10080402 00804020
4242427E 007E4242 08080808 00080808 7E02027E 007E4040 7E02027E 007E0202
7E424242 00020202 7E40407E 007E0202 7E404040 007E4242 0202027E 00020202
7E42427E 007E4242 7E42427E 00020202 00101000 00101000 00101000 20101000
40300C00 00000C30 007E0000 0000007E 020C3000 0000300C 0C02423C 00100010
AA9A423C 003C409C 42422418 0042427E 7C42427C 007C4242 4040407E 007E4040
42424478 00784442 7C40407E 007E4040 7C40407E 00404040 4040423C 007E4246
7E424242 00424242 1010107E 007E1010 04040404 00384404 60605048 00444850
40404040 007C4040 425A6642 00424242 5A525262 00464A4A 4242423C 003C4242
7E42427E 00404040 4444447C 00764854 7E42427E 00424448 7E40407E 007E0202
1010107C 00101010 44444444 007C4444 24242442 00181824 42424242 0042665A
10386CC6 00C66C38 10386CC6 00101010 0804027E 007E2010 20202038 00382020
10204080 00020408 08080838 00380808 44282810 00000000 00000000 FF000000
End DefineFont

'no comment
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 4223
Posted: 10:21am 26 Jul 2024
Copy link to clipboard 
Print this post

Wauw ! That is fast.... 64 characters is fine.

However.. there is a drawback to your font. It is 8x8 pixels. To match it in the game it should be 16 or 20 pixels high.
But when you use the scale in the TEXT command, it also double the line width, making it very different from the "vector" style in the game.

See these screenshots (not very clear, but they did for me). I guess the font should be something like 20x12 or 16x10. Note also the somewhat strange "G".

as.zip

Volhout
PicomiteVGA PETSCII ROBOTS
 
     Page 3 of 7    
Print this page
© JAQ Software 2024