Author Topic: Gl Money  (Read 1619 times)

0 Members and 1 Guest are viewing this topic.

Peter

  • Guest
Gl Money
« on: November 24, 2015, 12:06:09 PM »
Hello,
Code: [Select]
include "ogl.inc"
Window 800, 600, 1

sys anzahl=1000,xscreen=800,yscreen=600 
sys xmitte= 400,ymitte =300 
single aSpeed,v
bmpload 1,"bmp/coin_strip.bmp"

dim phase(1000) as sys
dim x(1000)     as single
dim y(1000)     as single
dim winkl(1000) as single
dim speed(1000) as single
dim sinus(360)  as single
dim cosin(360)  as single

for i=0 to anzahl-1
    x(i) = xmitte
    y(i) = ymitte
    winkl(i)= rand(1,360)
    speed(i)= rand(1,3)
next

for i=0 to 999
    phase(i) = rand(0,7)
next
for i=0 to 360
    sinus(i)= sin(rad(i))
    cosin(i)= cos(rad(i))
next

Function xMove(single x,w,speed) as single
    return x + Cosin(w)*speed
End Function

Function yMove(single y,w,speed) as single
    return y + Sinus(w)*speed
End Function

Function Distance(single x1,y1,x2,y2) as single
    sys dx, dy
    dx = x1-x2: dy = y1-y2
    return abs(sqr(dx*dx+dy*dy))
End Function

while Key(27)=0
cls 255,255,255
for i=0 to anzahl-1
    aSpeed = Distance (xmitte, ymitte, x(i), y(i)) /200 * speed(i)+1
    x(i) = xMove(x(i), winkl(i), aSpeed)
    y(i) = yMove(y(i), winkl(i), aSpeed)
    if x(i) < -32 Or x(i) > xscreen Or y(i) < -32 Or y(i) > yscreen
       x(i) = xmitte
       y(i) = ymitte
       winkl(i) = rand(1,360)
       speed(i) = rand(1,3)
    end if
SpriteAnimate 1,x(i),y(i),32,32,phase(i)
next
v +=.2
if v >=1 then
   v = 0
for i=1 to 1000
    phase[i] +=1
    if phase[i]=6 then phase[i]=0
next
end if
xmitte = xMouse
ymitte = yMouse
redraw
wait 10
Wend
winEnd

 

.

Mike Lobanovsky

  • Guest
Re: Gl Money
« Reply #1 on: November 24, 2015, 01:19:22 PM »
Cool! :D

I wouldn't however say that my re-implementation of same in FBSL BASIC's simple GDI graphics is much worse in terms of speed or quality, at least on my PC. :)

Code: OxygenBasic
  1. ' !!! FBSL BASIC !!!
  2. #Option Implicit
  3. #Include "mingfx.inc"
  4.  
  5. xscreen = 800
  6. yscreen = 600
  7.  
  8. xmittel = xscreen \ 2
  9. ymittel = yscreen \ 2
  10.  
  11. anzahl  = 1000
  12. v       = 0.0
  13.  
  14. Dim %phase[anzahl], %winkel[anzahl], %speed[anzahl], x[anzahl], y[anzahl]
  15.  
  16. For i = 0 To anzahl
  17.   x[i] = xmittel
  18.   y[i] = ymittel
  19.   winkel[i] = Rnd() * 360
  20.   speed[i]  = Rnd() * 3
  21.   phase[i]  = Rnd() * 7
  22. Next
  23.  
  24. money = LoadSprite("coin_strip.bmp", 192, 32, 6)
  25.  
  26. Window(xscreen, yscreen, FALSE, "Money, Money, Money ... Must Be Funny!")
  27.  
  28. While Not Esc
  29.   Screen(100, 0, 100)
  30.   For i = 0 To anzahl
  31.     aSpeed = Distance(xmittel, ymittel, x[i], y[i]) / 200 * speed[i] + 3
  32.     x[i] = xMove(x[i], winkel[i], aSpeed)
  33.     y[i] = yMove(y[i], winkel[i], aSpeed)
  34.     If x[i] < -32 OrElse x[i] > xscreen OrElse y[i] < -32 OrElse y[i] > yscreen Then
  35.       x[i] = xmittel
  36.       y[i] = ymittel
  37.       winkel[i] = Rnd() * 360
  38.       speed[i]  = Rnd() * 3
  39.     End If
  40.     Sprite(money, x[i], y[i], 32, 32, phase[i])
  41.   Next
  42.   If Incr(v, .2) >= 1 Then
  43.     v = 0.0
  44.     For i = 0 To anzahl
  45.       phase[i] = phase[i] + 1
  46.       If phase[i] = 6 Then phase[i] = 0
  47.     Next
  48.   End If
  49.   xmittel = MouseX()
  50.   ymittel = MouseY()
  51.   Redraw()
  52.   Wait(10)
  53. WEnd
  54.  
  55. Function xMove(x, w, speed)
  56.   Return x + Cos(w) * speed
  57. End Function
  58.  
  59. Function yMove(y, w, speed)
  60.   Return y + Sin(w) * speed
  61. End Function
  62.  
  63. Function Distance(x1, y1, x2, y2)
  64.   dx = x1 - x2: dy = y1 - y2
  65.   Return SqRt(dx * dx + dy * dy)
  66. End Function
  67.  

.
« Last Edit: November 24, 2015, 07:09:53 PM by Mike Lobanovsky »

Peter

  • Guest
Re: Gl Money
« Reply #2 on: November 24, 2015, 04:19:41 PM »
Hi Mike,

I wouldn't say that's bad. On the contrary,  very good result.
Thanks for so many coins.   :)

Here's Gdi version:
Code: [Select]
include "asm.inc"
Window 800, 600, 1

sys anzahl=1000,xscreen=800,yscreen=600 
sys xmitte= 400,ymitte =300 
single aSpeed,v
LoadSprite "bmp/coin_strip.bmp",6

dim phase(1000) as sys
dim x(1000)     as single
dim y(1000)     as single
dim winkl(1000) as single
dim speed(1000) as single
dim sinus(360)  as single
dim cosin(360)  as single

for i=0 to anzahl-1
    x(i) = xmitte
    y(i) = ymitte
    winkl(i)= rand(1,360)
    speed(i)= rand(1,3)
next

for i=0 to 999
    phase(i) = rand(0,7)
next
for i=0 to 360
    sinus(i)= sin(rad(i))
    cosin(i)= cos(rad(i))
next

Function xMove(single x,w,speed) as single
    return x + Cosin(w)*speed
End Function

Function yMove(single y,w,speed) as single
    return y + Sinus(w)*speed
End Function

Function Distance(single x1,y1,x2,y2) as single
    sys dx, dy
    dx = x1-x2: dy = y1-y2
    return abs(sqr(dx*dx+dy*dy))
End Function

while Key(27)=0
cls 0,0,255
for i=0 to anzahl-1
    aSpeed = Distance (xmitte, ymitte, x(i), y(i)) /200 * speed(i)+1
    x(i) = xMove(x(i), winkl(i), aSpeed)
    y(i) = yMove(y(i), winkl(i), aSpeed)
    if x(i) < -32 Or x(i) > xscreen Or y(i) < -32 Or y(i) > yscreen
       x(i) = xmitte
       y(i) = ymitte
       winkl(i) = rand(1,360)
       speed(i) = rand(1,3)
    end if
    Sprite 1,x(i),y(i),32,32,phase(i)
next
v +=.3
if v >=1 then
   v = 0
for i=1 to 1000
    phase[i] +=1
    if phase[i]=6 then phase[i]=0
next
end if
xmitte = xMouse
ymitte = yMouse
redraw
wait 10
Wend
winExit

.
« Last Edit: November 24, 2015, 04:47:41 PM by Peter »