Re: microA interpreter

Started by Zlatko Vid, February 08, 2021, 09:28:38 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Zlatko Vid

  •  

Zlatko Vid

I add..recompile micro(A) with new function frac(expr)
then i try same algo , and again not work...hmm
then i look again into facebook page where one guy used AmstradCPC
yes you read properly ...of course emulator when he show how he do that in Amstrad basic..
so i connect two and two ..and try with 2 while loops ..and finally work ...voila

'prime numbers using fn fraction() - micro(A) by Aurel
var k,max,c,y,fr,p,n,pk,i
wcolor 0,0,0 : fcolor 230,230,130
print 10,5,"prime numbers micro(A) by Aurel"
print 10,25,"num      prime     fraction"
fcolor 130,220,220
n=0 : max = 20 : y=20 : c=0

'pseudo do loop
while n < max
y=y+20 : print 10,y,n
n=n+1

c=0:i=0
while i < n
'---------------------------------
i=i+1
fr = frac(n/i) : print 200,y,fr
if fr = 0
  c=c+1
endif
wend
'----------------------------------
if c = 2
   p = n
   print 100,y,p
endif
wend
'-------------------
func prime()
  p=n
  y=y+20
  print 100,y,p
endfn
'--------------------
print 300,4,"Primes Over..."
  •  

Zlatko Vid

First time tested windows messages processing in microA

  •  

Zlatko Vid

example with tracking mouse x,y and drawing
  •  

Zlatko Vid

#4
Thank you Anthon !
here is binary version

Micro(A) interpreter and AEmicro039 - code editor are created using Oxygen Basic!

and here is small example about how to use win messages in micro(A)
'windows messages test
var r,g,b
var mx , my, wp
ptr wmMouseMove ,wmKeyDown
r = 255 : g = 255 : B = 255
wcolor r,g,b : fcolor 40,80,100
print 100,10,"testing WM_MOUSEMOVE and WM_KEYDOWN in micro(A)"
print 6,10,"mx"
print 6,40,"my"

WinMsg wmMOUSEMOVE

   mousex mx
   mousey my

   fcolor 0,0,0 :rect 24,5,68,24   
   fcolor 100,160,220 : print 30,10,mx
   fcolor 0,0,0 :rect 24,35,68,24   
   fcolor 100,160,220 : print 30,40,my

   fcolor 30,170,100 : pset mx,my

EndWm

WinMsg wmKEYDOWN

hWparam wp
'vkLEFT ?
if wp = 37
   fcolor 100,100,230 : rect mx,my,16,16
endif

'vkRIGHT ?
if wp = 39
   fcolor 100,160,130 : circle mx,my,16
endif
EndWm


  •  

Zlatko Vid

and here is my attempt to make primitive game in primitive
but modern interpreter  ;D

'primitive game in microA
var r,g,b , mx , my, ax,ay, wp ,tmp
var bf, bx, by ,bs
ptr wmKeyDown
ay = 176 : ax = 128
wcolor 0,0,0 : fcolor 140,180,200
print 20,410,"primitive game in micro(A)"
print 20,430,"move 'A' with LEFT<->RIGHT arrow keys"
print 20,450,"Shoot with SPACE bar"
print 506,10,"ax" : print 506,40,"by"
updateScreen() : fcolor 220,10,10 : print ax,ay,"A"


WinMsg wmKEYDOWN

hWparam wp
'vkLEFT ?-----------------------------------
if wp = 37
  ' tmp = ax  :  print tmp,ay," "
   if ax > 17 : ax = ax - 10 :endif
   'fcolor 100,210,230 : print ax,ay,"A"
    'updateScreen()   
endif

'vkRIGHT ?---------------------------------
if wp = 39
   tmp = ax 
   if ax < 229 : ax = ax + 10 : endif
  ' fcolor 100,210,230 : print ax,ay,"A"
   'updateScreen()
endif

'vkSpace ?----------------------------------
if wp =32
     if bf = 0
        bf = 1
bx = ax
by = ay-10
     endif
endif

'empty loop
while wp ! 27
    fcolor 180,180,120 : rect 1,1,256,192
    updateScreen()
    updateBullet()
    swap
wend

EndWm

func updateScreen()
    'cls
'fcolor 180,180,120 : rect 1,1,256,192
'update ax position
fcolor 80,80,100 :rect 524,5,68,24   
fcolor 100,160,220 : print 530,10,ax

'display player
    'print ax,ay," "
    fcolor 100,210,230 : print ax,ay,"A"

    ' Display bullet
   
if bf = 1
fcolor 255,255,0 : print bx, by,"^"
        'update by position
    fcolor 80,80,100 :rect 524,35,68,24 
fcolor 245,118,0 : print 530,40,by
endif

     swap
endfn

func updateBullet()

if bf = 1
        by = by - 1
' Bullet has left the screen.
' fire to 0 - now you can fire.
       if by < 0 : bf=0 : endif
endif

endfn


  •  

Zlatko Vid

aka game better version with score
'primitive game in microA with Johnno help
var r,g,b , mx , my, ax,ay, wp ,p,score
var bf, bx, by ,bs, ex,ey
ptr wmKeyDown, wmTimer
ay = 175 : ax = 120 : ex = 5 : ey = 10
wcolor 0,0,0 : fcolor 140,180,200
print 20,410,"primitive game in micro(A)"
print 20,430,"move 'A' with LEFT<->RIGHT arrow keys"
print 20,450,"Shoot with SPACE bar"
print 20,470,"Pause with ESC key"
print 456,10,"player" : print 456,40,"bullet" : print 456,70,"enemy"
print 456,100,"score"
updateScreen() : fcolor 220,10,10 : print ax,ay,"A"


WinMsg wmKEYDOWN

hWparam wp
'vkLEFT ?-----------------------------------
if wp = 37
   if ax > 11 : ax = ax - 5 :endif
endif

'vkRIGHT ?----------------------------------
if wp = 39
   if ax < 229 : ax = ax + 5 : endif
endif

'vkSpace ?----------------------------------
if wp =32
     if bf = 0
        bf = 1
bx = ax
by = ay
     endif
endif

'empty loop ---------------------------------
while wp ! 27
    fcolor 180,180,120 : rect 1,1,256,192
    updateScreen()
    updateBullet()
    updateEnemy()
    testCollision()
    'delay loop
    p=0
    while p < 800
     p=p+0.1
    wend
    swap
wend

EndWm

'--------------------------------------------------
func updateScreen()
'update ax position
fcolor 80,80,100 :rect 524,5,68,24   
fcolor 100,160,220 : print 530,10,ax

'display player
    fcolor 100,210,230 : print ax,ay,"A"

    'Display bullet 
if bf = 1
fcolor 255,255,0 : print bx, by,"^"
        'update by bullet position
    fcolor 80,80,100 :rect 524,35,68,24 
fcolor 235,218,100 : print 530,40,by
endif
   
    'display enemy
     fcolor 0,150,100 : rect ex,ey,10,6
     'update ex enemy position
fcolor 80,80,100 :rect 524,65,68,24 
fcolor 100,160,100 : print 530,70,ex
     'update score
      fcolor 80,80,100 :rect 524,95,68,24 
fcolor 245,118,0 : print 530,100,score     

    swap

endfn
'----------------------------------------------------------------
func updateBullet()
if bf = 1
        by = by - 5
' Bullet has left the screen.
       if by < 0 : bf=0 : endif
endif
endfn
'----------------------------------------------------------------
func updateEnemy()
   if ex < 250 : ex=ex+5 : endif
   if ex = 240 : ex=5    : endif
   fcolor 0,150,100 : rect ex,ey,10,6
endfn

func testCollision()
if ey = by
       if ex = bx
          fcolor 220,100,100: print ex,ey,"-XX-": score = score + 10         
       endif
    endif
endfn
  •  

Zlatko Vid

Hello
This is the first time i am movin graphic object in micro(A)
'test load image
ptr img,img2
ptr wmKeyDown, wmTimer
var wp,ix,iy
wcolor 200,200,210
fcolor 180,60,100 : print 110,10,"Test Load Bitmap Image into handler"
'syntax-> LoadImg (1)hImg , (3)str "img.bmp" ,(5)imgType , (7)w , (9)h, (11)colorFlags
LoadImg img,"spaceMoon.bmp" , 0, 646, 438,16
'print value of img handler  / if value not null -> OK!
print 10,440,"image handler value:"
print 10,460,img
'show img on window
ShowImg img,0,0,646,438
'load another image
LoadImg img2,"craft1.bmp" , 0, 116, 48,16
'ShowImg img2,0,0,116,48

'events...
WinMsg wmKEYDOWN

hWparam wp
'vkLEFT -----------------------------------
if wp = 37
   if ix > 0 : ix = ix - 6 :endif
  updateScreen()
endif

'vkRIGHT ?----------------------------------
if wp = 39
   if ix < 500 : ix = ix + 6 : endif
   updateScreen()
endif

'vkUP --------------------------------------
if wp = 38
     if iy > 0 : iy = iy - 6 :endif
     updateScreen()
endif

'vkDOWN --------------------------------------
if wp = 40
    if iy < 420 : iy = iy + 6 :endif
    updateScreen()
endif

while wp ! 27
   ' fcolor 180,180,120 : rect 1,1,256,192
   ' updateScreen()
   ' updateShip()
    'updateBullet()
   ' updateEnemy()
    'testCollision()
    'delay loop
   ' p=0
   ' while p < 800
    ' p=p+0.1
    'wend

wend

EndWm

func updateScreen()
   fcolor 80,80,100   : rect 524,5,68,24   
   fcolor 100,160,220 : print 530,10,ix
   fcolor 80,80,100   : rect 524,34,68,24
   fcolor 100,160,220  : print 530,38,iy
   'updateShip()
ShowImg img2,ix,iy,116,48
endFn

'func updateShip()
'  ShowImg img2,ix,iy,116,48
'endFn

  •  

Zlatko Vid

I add hdc handler for each loaded image ..similar like Peter Wirbelauer do in his
window api include functions using this time TransparentBlt function.
And i can say that work ,still need to test time and ordinary "game loop" to try make simple 2d
gdi game.
  •  

Zlatko Vid

When space theme become boring then here is fine jungle theme
This time i add moving sprite run by loop.
'test demo in gdi
ptr img,img2,img3
ptr wmKeyDown, wmTimer
var wp,ix,iy,p,ex,ey
wcolor 200,200,210
fcolor 180,60,100 : print 110,10,"Test Load Bitmap Image into handler"
'syntax-> LoadImg (1)hImg , (3)str "img.bmp" ,(5)imgType , (7)w , (9)h, (11)colorFlags
LoadImg img,"Jungle.bmp" , 0, 640, 360,16
'print value of img handler  / if value not null -> OK!
print 10,440,"Jungle Life m(A)"
'show img on window
ShowImgT img,0,0,640,360
'load another image
LoadImg img2,"craft2.bmp" , 0, 116, 48,16
LoadImg img3,"satelite2.bmp" , 0, 40, 40,24
ShowImgT img3,300, 300, 40, 40
ex = 300 : ey = 300
updateScreen()

'events...
WinMsg wmKEYDOWN

hWparam wp
'vkLEFT -----------------------------------
if wp = 37
   if ix > 0 : ix = ix - 6 :endif
endif

'vkRIGHT ?----------------------------------
if wp = 39
   if ix < 500 : ix = ix + 6 : endif
endif

'vkUP --------------------------------------
if wp = 38
     if iy > 0 : iy = iy - 6 :endif
endif

'vkDOWN --------------------------------------
if wp = 40
    if iy < 420 : iy = iy + 6 :endif
endif

while wp ! 27

updateBack()
  updateScreen() 
   updateShip() 
   
    'updateBullet()
    updateEnemy()
    'testCollision()
    'delay loop
   '  p=0
   ' while p < 800
    ' p=p+0.01
   'wend
swap
'ShowImg img,0,0,646,438
wend

EndWm

func updateScreen()
   fcolor 80,80,100   : rect 524,5,68,24   
   fcolor 100,160,220 : print 530,10,ix
   fcolor 80,80,100   : rect 524,34,68,24
   fcolor 100,160,220  : print 530,38,iy
ShowImgT img3, ex, ey, 40, 40
ShowImgT img2,ix,iy,116,48
endfn

func updateBack()
ShowImgT img,0,0,640,360
endFn

func updateShip()
  ShowImgT img2,ix,iy,116,48   
endFn

func updateEnemy()
   if ex < 600 : ex = ex + 1 : endif
   if ex = 598 : ex = 10 : endif
endfn

  •  

Zlatko Vid

And i finally made simple shooter progie in microA
  •  

Zlatko Vid

#11
not a big step ...but working

here is simple test of strs() aka STR$() basic function inside loop

'aka fill string array with while loop conversion
var i,max
str ts,nt : ts = ">"
i = 0 : max = 1025
wcolor 0,0,0 :fcolor 220,180,150 : print 10,10,"FAKE FILL STRING micro(A)"
swap

while i < max
i=i+1
    fcolor 100,150,100 : rect 8,98,20,24
    print 10,100,ts

    fcolor 100,150,150 : rect 38,98,100,24
    nt = strs(i)
    print 40,100,nt

swap
wend 

  •