Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trekn-mixer 0.2
#7
This is a rather silly program that simulates space vessels racing each other and sometimes crashing.

Code: (Select All)
const numtrekn = 3
type trktype
    as integer x, y, c, l, sx, sy
end type
dim shared e(1 to numtrekn) as trktype
dim as integer i, j
dim as long hv, fl, cred
dim afile$, ke$

randomize timer

afile$ = "trekn.bmp"
hv = _loadimage(afile$, 32)

for i = 1 to numtrekn
    inittrekn i
next

screen _newimage(640, 576, 32)
cred = _rgb(192, 0, 0)

_display
do
    _limit 15
    ke$ = inkey$
    if ke$ = chr$(27) then exit do

    cls
    fl = tert(fl, &hff00, &hff)
    for i = 0 to 576 step 64
        line(i, 0)-step(0, 575), cred, , fl
        line(i + 63, 0)-step(0, 575), cred, , fl
    next
    for i = 1 to numtrekn
        if Random1(3) = 1 then
            e(i).x = e(i).x - 64
            if e(i).x < 0 then e(i).x = 0
        elseif Random1(3) = 1 then
            e(i).x = e(i).x + 64
            if e(i).x > 576 then e(i).x = 576
        end if
        e(i).c = e(i).c + 1
        if e(i).c >= e(i).l then
            e(i).c = 1
            e(i).y = e(i).y + 32
            if e(i).y > 480 then
                inittrekn i
            end if
        end if
        if e(i).y >= 0 then
            _putimage(e(i).x, e(i).y), hv, 0, (e(i).sx, e(i).sy)-step(63, 95)
        end if
    next
    for i = 1 to numtrekn
        for j = i to numtrekn
            if i <> j then
                if e(i).y >= 0 then
                    if e(i).x = e(j).x and e(i).y = e(j).y then
                        polygonstar e(i).x + 32, e(i).y + 48, 48, 48, 4
                        inittrekn i
                        inittrekn j
                    end if
                end if
            end if
        next
    next
    _display
loop
_autodisplay
system

sub inittrekn (which as integer)
    e(which).x = (Random1(10) - 1) * 64
    e(which).y = -96
    e(which).c = 0
    e(which).l = Random1(5)
    e(which).sx = (Random1(8) - 1) * 64
    e(which).sy = (Random1(4) - 1) * 96
end sub

sub polygonstar (x as integer, y as integer, wd as integer, ht as integer, rr as integer)
    static s as integer, fl as _byte, time1 as _byte
    static as single x1, y1, x2, y2, dr, d, r
    static as long hh, cbred
    hh = _copyimage(0)
    fl = Random1(2) - 2
    time1 = 1
    for s = 3 to 24
        dr = 360 / s
        d = 0
        cbred = _rgb(224, (Random1(25) - 1) * 2, (Random1(32) - 1) * 4)
        do until fix(d) >= 360
            fl = not fl
            r = _d2r(d)
            x1 = x2
            y1 = y2
            if fl then
                x2 = x + cos(r) * rr
                y2 = y + sin(r) * rr
            else
                x2 = x + cos(r) * wd
                y2 = y + sin(r) * ht
            end if
            if time1 then
                time1 = 0
                pset(x2, y2), cbred
            else
                line(x1, y1)-(x2, y2), cbred
            end if
            d = d + dr
        loop
        _display
        _delay 0.05
        _putimage(0, 0), hh
    next
    _freeimage hh
end sub

function Random1& (maxval as long)
    Random1& = int(rnd * maxval + 1)
end function

function Rand& (minval as long, maxval as long)
    dim as long n, x
    n = minval
    x = maxval
    if n > x then swap n, x
    Rand& = int(rnd * (x - n)) + n
end function

function tert&& (valu as _integer64, one as _integer64, two as _integer64)
    if valu = one then tert&& = two : exit function
    tert&& = one
end function

It uses the program featured in this topic that creates sprite sheets.

On Windows follow the instructions provided in the code to create an image file.
Call it "trekn.bmp", must be 32-bit BMP, and place it in the same directory as this provided program's EXE file.

On Linux cannot paste into GIMP or like program, must run JDJ's program provided on the first post of this topic then use the "screenshot" feature.
Press [PRT SC] or similar key. If you're on an OS with KDE Plasma desktop environment, usually only the program window's area could be selected and could save the file as BMP.
Otherwise (like me on Spiral Cinnamon) must accept an entire screen "screenshot" saved either to the user's home folder or in "Pictures" folder.
The file created by the "screenshot" program should be opened in GIMP or other image editor and saved as BMP if it wasn't already.
If the "screenshot" is an entire screen then the image editor should be used to crop to contain only the program window's area of the "trekn" program.

Save to JPEG or PNG if you like, but I recommend BMP because the other formats do "dithering" which ruins the "pixel harmony" which is bad for arcade games. This is only a point of view.
The code then would have to be adjusted for an image file extension other than BMP.

This program creates no sound.
When two space crafts collide, the visual effect is rather very lame.
I couldn't do anything about the flickering while one craft is "on top of" the other, using "_CLEARCOLOR" turned out unpleasant.
At this moment a maximum of three space crafts at a time are active. This could be changed with "NUMTREKN" constant.
With more space craft this program might benefit from a much-larger screen but doesn't make a good screensaver LOL.
Reply


Messages In This Thread
Trekn-mixer 0.2 - by James D Jarvis - 12-05-2022, 01:03 AM
RE: Trekn-mixer 0.2 - by James D Jarvis - 12-05-2022, 09:03 PM
RE: Trekn-mixer 0.2 - by bplus - 12-05-2022, 11:41 PM
RE: Trekn-mixer 0.2 - by Pete - 12-05-2022, 11:56 PM
RE: Trekn-mixer 0.2 - by mnrvovrfc - 12-06-2022, 12:26 AM
RE: Trekn-mixer 0.2 - by James D Jarvis - 12-06-2022, 01:56 AM
RE: Trekn-mixer 0.2 - by mnrvovrfc - 12-08-2022, 01:10 AM
RE: Trekn-mixer 0.2 - by mnrvovrfc - 12-09-2022, 10:13 AM
RE: Trekn-mixer 0.2 - by mnrvovrfc - 12-06-2022, 01:44 PM
RE: Trekn-mixer 0.2 - by James D Jarvis - 12-06-2022, 05:47 PM
RE: Trekn-mixer 0.2 - by CharlieJV - 12-10-2022, 03:32 AM
RE: Trekn-mixer 0.2 - by James D Jarvis - 07-20-2023, 01:28 PM
RE: Trekn-mixer 0.2 - by johnno56 - 07-20-2023, 08:37 PM
RE: Trekn-mixer 0.2 - by James D Jarvis - 07-20-2023, 10:17 PM
RE: Trekn-mixer 0.2 - by johnno56 - 07-21-2023, 02:48 AM
RE: Trekn-mixer 0.2 - by James D Jarvis - 07-21-2023, 03:53 AM



Users browsing this thread: 10 Guest(s)