Welcome, Guest |
You have to register before you can post on our site.
|
|
|
Expanding Horizons using MCUs |
Posted by: nunzi8 - 09-06-2024, 08:54 AM - Forum: GitHub Discussion
- Replies (2)
|
|
I have just recently come across "QB64PE" (a very great project)
I don't know its internals and I was wondering:
if it was possible to run it on a MCU like "Rasperry pi pico", "ESP32" "STM32", ...
Obviously making some compromises, for example without compiling to machine code... or without OpenGL.
Best Regards.
Nunzio
|
|
|
Bumper ball game (like plinko). |
Posted by: Dav - 09-05-2024, 04:13 PM - Forum: Games
- Replies (3)
|
|
This is more of a prototype for a bigger game, but it works enough to play and try out. It's like a plinko game, you position the ball, let it drop and try to make it stop on the winning area.
Use arrow keys to move the ball left/right. When ready to drop the ball press ENTER. The ball will bounce off the bumpers. The goal is to make the ball stop on the green winners pad at the bottom.
Right now the bumpers are positioned random, not always good, but it would be easy to design a screen, make shapes (lines with slopes) out of the bumpers too.
- Dav
Code: (Select All)
'==============
'BUMPERBALL.BAS
'==============
'Simple drop the ball on the pad game.
'Coded by Dav, SEP/2024
'Use left/right arrows to move the ball.
'Press the ENTER key to drop the ball.
'Try to make the ball stop on the pad.
'ESC key quits.
Randomize Timer
Screen _NewImage(1000, 800, 32)
bumps = 25 'number of bumpers on the screen
Dim bumpx(bumps), bumpy(bumps), bumpsize(bumps), ballclr~&(bumps)
'===========
restartgame:
'===========
'make random bumper values
For b = 1 To bumps
bumpsize(b) = 15 'bumper size
bumpx(b) = 30 + (Rnd * (_Width - 30)) 'x position
'bumpy(b) = 60 + (Rnd * (_Height - 190))
bumpy(b) = 60 + (b * 25)
ballclr~&(b) = _RGBA(0, 0, 255, 255)
Next
'init puck to drop
pucksize = 30 'puck size
puckclr~& = _RGBA(255, 64, 64, 255) 'puck color
puckx = _Width / 2 'x position
pucky = pucksize 'y position
puckxv = 0 'x speed
puckyv = 0 'y speed
gravity = 0.5 'gravity value
'for timing bouncing stopping
puckytimer = 0
'random location for a winning pad
padx = Rnd * (_Width - 200)
padx2 = padx + 200
pady = _Height - 3
pady2 = 3
'=== loop to move puck until Enter key pressed
Do
Cls , _RGB(45, 45, 45)
'controls
key$ = InKey$
If key$ = Chr$(0) + Chr$(75) Then puckx = puckx - 8 ' Left Arrow
If key$ = Chr$(0) + Chr$(77) Then puckx = puckx + 8 ' Right Arrow
If key$ = Chr$(13) Then Exit Do 'enter drop puck
If key$ = Chr$(27) Then End
'make sure puck stays on screen
If puckx < pucksize Then puckx = pucksize
If puckx > _Width - pucksize Then puckx = _Width - pucksize
'draw puck
fc puckx, pucky, pucksize, puckclr~&, 1
'draw all the bumpers
For b = 1 To bumps
fc bumpx(b), bumpy(b), bumpsize(b), ballclr~&(b), 1
Next
'draw winning pad
Line (padx, pady)-(padx2, pady + pady2), _RGBA(0, 255, 0, 255), BF
_Limit 30
_Display
Loop
'loop for dropping the puck
Do
Cls , _RGB(45, 45, 45)
'apply gravity
puckyv = puckyv + gravity
puckx = puckx + puckxv
pucky = pucky + puckyv
'if hits bottom, bounce off
If pucky > _Height - pucksize Then
If puckyv > .3 Then Play "mbt200l32o1d"
pucky = _Height - pucksize
puckyv = -puckyv * 0.7
End If
'bounce puck off screen edges
If puckx < pucksize Then
Play "mbt200l32o1b"
puckx = pucksize
puckxv = -puckxv * 0.7
End If
If puckx > _Width - pucksize Then
Play "mbt200l32o1b"
puckx = _Width - pucksize
puckxv = -puckxv * 0.7
End If
'draw the puck
fc puckx, pucky, pucksize, puckclr~&, 1
'draw all the bumpers
For b = 1 To bumps
fc bumpx(b), bumpy(b), bumpsize(b), ballclr~&(b), 1
'check for puck collisions with bumpers
If ((puckx - bumpx(b)) ^ 2 + (pucky - bumpy(b)) ^ 2) < (pucksize + bumpsize(b)) ^ 2 Then
fc bumpx(b), bumpy(b), bumpsize(b), _RGBA(255, 255, 0, 255), 1
Play "mbt200o5l32ef"
x = (puckx - bumpx(b)): y = (pucky - bumpy(b))
dis = Sqr(x * x + y * y)
If dis > 0 Then
x = x / dis: y = y / dis
End If
vr = puckxv * x + puckyv * y
puckxv = puckxv - 2 * vr * x
puckyv = puckyv - 2 * vr * y
over = (pucksize + bumpsize(b)) - Sqr((puckx - bumpx(b)) ^ 2 + (pucky - bumpy(b)) ^ 2)
puckx = puckx + x * over
pucky = pucky + y * over
End If
Next
'reduce x velocity so ball doesn't roll on bottom too long
If pucky >= _Height - pucksize Then
puckxv = puckxv * 0.88 'reduce x velocity
End If
'I'm using a timer to see if ball has stopped moving much.
'check if puck is near bottom, and if puckyv hasn't changed since timer
If Abs(pucky - (_Height - pucksize)) < 10 Then
If Abs(puckyv - lastPuckyv) < .1 Then
puckytimer = puckytimer + 0.033
Else
puckytimer = 0
End If
lastPuckyv = puckyv
'if it's been 2 seconds since puckyv was stable
If puckytimer >= 2.0 Then
'if puck is on winning pad
If puckx >= padx And puckx <= padx2 Then
Line (0, 0)-(_Width, _Height), _RGBA(0, 255, 0, 25), BF
Play "mbt120l16o2c,e e,g e,g,o3c"
Else
Line (0, 0)-(_Width, _Height), _RGBA(255, 0, 0, 25), BF
Play "mbt120l16o2b,f e b,f"
End If
_Display
Exit Do
End If
Else
puckytimer = 0 'Reset timer otherwise
lastPuckyv = puckyv
End If
' Draw winning pad
Line (padx, pady)-(padx2, pady + pady2), _RGBA(0, 255, 0, 255), BF
_Limit 30
_Display
If InKey$ = Chr$(27) Then End
Loop
_Delay 2
GoTo restartgame
Sub fc (cx, cy, radius, clr~&, grad)
If radius = 0 Then Exit Sub ' safety bail
If grad = 1 Then
red = _Red32(clr~&)
grn = _Green32(clr~&)
blu = _Blue32(clr~&)
alpha = _Alpha32(clr~&)
End If
r2 = radius * radius
For y = -radius To radius
x = Int(Sqr(r2 - y * y))
' If doing gradient
If grad = 1 Then
For i = -x To x
dis = Sqr(i * i + y * y) / radius
red2 = red * (1 - dis) + (red / 2) * dis
grn2 = grn * (1 - dis) + (grn / 2) * dis
blu2 = blu * (1 - dis) + (blu / 2) * dis
clr2~& = _RGBA(red2, grn2, blu2, alpha)
Line (cx + i, cy + y)-(cx + i, cy + y), clr2~&, BF
Next
Else
Line (cx - x, cy + y)-(cx + x, cy + y), clr~&, BF
End If
Next
End Sub
|
|
|
console only OR screen only |
Posted by: mdijkens - 09-04-2024, 07:47 PM - Forum: Help Me!
- Replies (2)
|
|
I'm building a small console utility.
If a parameter is given, the utility should run in the console and print the result there.
But if no parameter is given, a screen interface should be shown where user can enter parameter(s) and play with result.
This basically means, I want console:only when command$<>"" ELSE Screen:only
Code: (Select All)
$Console
If Command$ <> "" Then
_ScreenHide
_Console On
_Dest _Console
Else
_Console Off
_ScreenShow
_Dest 0
End If
Print "this is it"
If I run this program a very brief flickering can be observed in both cases:
- when doubleclick the exe, I see briefly a console window before the screen is shown and console window disappears
- when at commandprompt including parameter, a screen briefly comes up and disappears. (brief window focus change)
Anyone a good idea/approach to have 1 and only one of them from the very first beginning?
|
|
|
The Space Globe |
Posted by: NakedApe - 09-03-2024, 11:01 PM - Forum: Works in Progress
- Replies (4)
|
|
@Dav kindly thought I should put this in its own thread. A little 3D thing I was fooling around with over the long weekend. There's a single sound file below just for fun. I've been writing little bits for a new game I'm thinking about.
Code: (Select All)
Option _Explicit ' << SPACE GLOBE >>
Screen _NewImage(1280, 720, 32) ' by Ted Kluger
_MouseHide: _ScreenMove _Middle ' v.1.0
Type globe
x As Single '
y As Single
radius As Single
frameCol As _Unsigned Long
dotCol As _Unsigned Long
End Type
Dim As Long scanSnd
Dim globe(10) As globe
Dim As Integer i, j, k, bright, fCol(11), pSpot(11)
Dim As Single percent, radAdder, iOAspect(4), tempAsp(4), xScroller
Dim As _Byte grow, scan, signer, played
Dim Shared As Long starScape, starScape2
scanSnd = _SndOpen("fuzzyNoise.wav"): _SndVol scanSnd, .5
i = 1 ' it's all about the 1st globe right now
globe(i).radius = 5 ' start values
globe(i).x = _Width / 2
globe(i).y = _Height / 2
Data 1.15,1.4,1.8,2.7,5.8
For j = 0 To 4: Read iOAspect(j): Next ' store aspect data (inner Oval Aspects)
Data 60,90,110,130,160,181,190,182,160,137,100,70
For j = 0 To 11: Read fCol(j): Next ' store globe section fill greys
Data -122,-102,-82,-57,-35,-10,13,35,60,81,102,123
For j = 0 To 11: Read pSpot(j): Next ' store paint locations
grow = -1: scan = 0 ' flags
radAdder = .75: signer = 1 ' radius adder value & sign for scan
setStars ' create backdrop, software image
restart:
For j = 0 To 4: tempAsp(j) = iOAspect(j): Next ' initial aspects for inner ovals
Do ' --------------------------------------------------- * MAIN *
Cls
_Limit 120
xScroller = xScroller - .2 ' scroll stars to the left
_PutImage (0 + xScroller, 0), starScape
_PutImage (1281 + xScroller, 0), starScape2
If xScroller < -1280 Then xScroller = 0
radAdder = globe(i).radius * .0075 * Sgn(radAdder) ' rate of change is a factor of size
percent = globe(i).radius / 130 ' adjust paint points by radius / orig size
bright = globe(i).radius * 1.7 + 150 ' brightness = function of size
If bright > 254 Then bright = 255 ' mind the max
globe(i).frameCol = _RGB32(150) ' grey frame
globe(i).dotCol = _RGB32(255, 255, 0, bright) ' variable brightness for paint dot locs
Print "arrows to steer": Print "spacebar to stop/start"
Print "<s> to scan": Print "<esc> to exit" ' user inputs & controls
If _KeyDown(19200) Then globe(i).x = globe(i).x - 2.5 + globe(i).radius / 200 ' steers more when it's small, less when big
If _KeyDown(19712) Then globe(i).x = globe(i).x + 2.5 - globe(i).radius / 200
If _KeyDown(18432) Then globe(i).y = globe(i).y - 2 + globe(i).radius / 200
If _KeyDown(20480) Then globe(i).y = globe(i).y + 2 - globe(i).radius / 200
If _KeyHit = 32 Then ' space bar stops / starts movement
If grow <> 0 Then
grow = 0
_KeyClear
ElseIf grow = 0 Then grow = -1
_KeyClear
End If
End If
If grow Then ' size control
globe(i).radius = globe(i).radius + radAdder
If globe(i).radius > 250 Then radAdder = -radAdder
If globe(i).radius < 1 Then radAdder = -radAdder
End If
If _KeyDown(115) Or _KeyDown(83) Then scan = -1: _KeyClear ' scan = quick wiggle, show paint spots, move/color globe sections
If scan Then
j = 0
Do ' scan control
k = k + 1
If Not played And scanSnd > 0 Then _SndPlay scanSnd: played = -1
If k = 160 Or k = 320 Or k = 480 Then signer = -signer
globe(i).x = globe(i).x + .25 * signer
tempAsp(j) = tempAsp(j) + .08 ' was .05
j = j + 1
If tempAsp(j) > 5.5 Then tempAsp(j) = 1.15
Loop Until j = UBound(tempAsp)
If k > 600 Then
scan = 0: k = 0 ' scan resets itself
If _SndPlaying(scanSnd) Then _SndStop scanSnd: played = 0
GoTo restart
End If
End If ' ------------------------------
' draw globe
If scan And globe(i).radius > 10 Then ' if scan, paint inside of globe 1st
Circle (globe(i).x, globe(i).y), globe(i).radius - 3, _RGB32(255, 10, 0), , , 1
Paint (globe(i).x, globe(i).y), _RGB32(200, 100, 200, bright), _RGB32(255, 10, 0)
End If
Circle (globe(i).x, globe(i).y), globe(i).radius, globe(i).frameCol, , , 1 ' draw main circle
For j = 0 To 4
Circle (globe(i).x, globe(i).y), globe(i).radius, globe(i).frameCol, , , tempAsp(j) ' draw inside ovals
Next
Line (globe(i).x, globe(i).y - globe(i).radius)-(globe(i).x, globe(i).y + globe(i).radius), globe(i).frameCol ' middle line
If globe(i).radius > 8 Then ' was 10 paint globe sections
For j = 0 To 11
Paint (globe(i).x + (percent * pSpot(j)), globe(i).y), _RGB32(fCol(j), fCol(j), fCol(j), bright), globe(i).frameCol '
Next
If scan Then
For j = 0 To 11 ' draw paint spots during scan
If globe(i).radius < 30 Then ' was 80
PSet (globe(i).x + (percent * pSpot(j)), globe(i).y), globe(i).dotCol ' paint locs based on % of orig 130 radius @ x = 200
Else Circle (globe(i).x + (percent * pSpot(j)), globe(i).y), globe(i).radius / 102, globe(i).dotCol ' draw dots more to scale, sorta
End If
Next
End If
End If
_Display
Loop Until _KeyDown(27)
_SndClose scanSnd
System ' * END *
' ---------------------------------------------------------------
Sub setStars () ' starscape backdrop
Dim c As Integer
Dim As Long virtual
virtual = _NewImage(1280, 720, 32) '
_Dest virtual
c = 0
Do: c = c + 1
PSet ((Int(Rnd * _Width)), Int(Rnd * _Height)), _RGB32(190 + Rnd * 20) ' whites
Loop Until c = 2000
c = 0
Do: c = c + 1
PSet ((Int(Rnd * _Width)), Int(Rnd * _Height)), _RGB32(100 + Rnd * 22) ' grays
Loop Until c = 6000 '
starScape = _CopyImage(virtual, 32) ' software image
starScape2 = _CopyImage(virtual, 32) ' another copy to allow sideways scrolling
_Dest 0: _FreeImage virtual
End Sub
|
|
|
Is there a _GETALPHA kind of method? |
Posted by: Dav - 09-01-2024, 11:06 PM - Forum: Help Me!
- Replies (3)
|
|
I am adding alpha transparency parameter to a SUB using _SETALPHA to change the image, was wondering if there is a way to retrieve current alpha state of that image before I change it, so I can restore it what it was before after calling the SUB.
Thanks!
- Dav
|
|
|
The World Prototype |
Posted by: WriterHash - 08-31-2024, 08:12 AM - Forum: Works in Progress
- Replies (6)
|
|
So, i made a progress with the codding, it is not so well so i was wondering if y'all got any proper fixes for it, let me share it
Code: (Select All)
Dim money As Integer
Dim strength As Integer
Dim speed As Integer
Dim babes As Integer
Dim balls As Integer
Dim cash As Integer
Dim directions As Integer
Dim knowledge As Integer
'intro
Screen 0
Color 4, 0
Locate 8, 37
Print "The World"
Sleep 5
Cls
Locate 8, 37
Print "Is Loading"
_Delay 5
'opening
Cls
Print "You finally got released from Prison at Kulai Headquarters"
Print "you looked at the sky and the people below it, you began"
Print "wondering, that you can become rich and powerfull"
Print "so you began your journey."
_Delay 10
MainPart
Sub MainPart
Cls
Print "Whats your name?"
Input name$
Sleep 2
Cls
MainPart2
End Sub
Sub MainPart2
Print "You are outside of Kulai Headquarters,"
Print "Where will you go?"
Print "(N)"
Print "(S)"
Input x
If x = N Then
North
End If
If x = S Then
South
End If
End Sub
Sub South
Cls
Print "You found a Police Headquarters"
Print "What will you do?"
Print "Ask For Job"
Print "Leave"
_Delay 4
Input x
If x = 1 Then Police
If x = 2 Then MainPart2
End Sub
Sub Police
Print "You need at least 50iq and 20 strength"
Print "50 stamina and 10 balls"
Print "Do you have what it takes?"
Input x
If knowledge >= 50 And strength >= 20 And stamina >= 50 And balls >= 10 Then Police2
If knowledge <= 50 And strength <= 20 And stamina <= 50 And balls <= 10 Then South
If x = No Then South
End Sub
Sub Police2
Print "Under Construction"
End Sub
Sub North
Print "Under Construction"
End Sub
|
|
|
|