Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
QB64 program rewritten to Android
#1
Hello ! I want to make programs for android. Unfortunately, I've been programming in Basic for 30 years, and it's hard for my brain to switch to object-oriented programming. I don't see and understand at all how they are built on each other, how things can be connected. A week ago, I tried the development system called B4A (https://www.b4x.com), which is in principle written in Basic, but in practice it could be anything due to the lack of simplicity.

I made a program in QB64 in a couple of hours, and then converted it to B4A. I suffered with it for almost 2 days before I rewrote it properly and it finally started.
I have attached APK file. This should be launched on Android and the program will be installed. Pretty much the same as the code here.

In the qb64 version, the mouse behaves like the touchscreen on the phone. The left mouse button simulates touching the touchscreen, and the move button simulates moving the mouse.


.zip   fps2_apk.zip (Size: 128.38 KB / Downloads: 51)

Code: (Select All)
'Randomize Timer

Dim Shared map_dat(9)
Dim Shared map(99, 99)
Dim Shared map_p(9999, 9), map_pc
Dim Shared map_s(9999, 4), map_sc
Dim Shared map_l(9999, 9), map_lc
Dim Shared cam(9)
Dim Shared iranyitas(9)


mon = _NewImage(_DesktopWidth, _DesktopHeight, 32): Screen mon: _FullScreen
cam(0) = 10
cam(1) = 10
cam(2) = .7
cam(8) = _Width / 2
cam(9) = _Height / 2
cam(7) = 8 'latohatar
cam(6) = cam(7) * cam(7)
cam(5) = 1 / cam(7)

createtrack 30, 30, .5

create_textsq


Do: _Limit 30

    control
    cam(3) = iranyitas(0) * .01



    '  cam(0) = cam(0) + Sin(cam(3)) * (iranyitas(2) - iranyitas(1)) * .06
    '  cam(1) = cam(1) + Cos(cam(3)) * (iranyitas(2) - iranyitas(1)) * .06


    lepes = (iranyitas(2) - iranyitas(1)) * .06
    For t1 = 0 To 80
        For t2 = 0 To 1
            ang = cam(3) + t1 * (t2 * 2 - 1) * (3.1415 / 180)
            lepes = (iranyitas(2) - iranyitas(1)) * .06 / 80 * (80 - t1)
            x = cam(0) + Sin(ang) * lepes
            y = cam(1) + Cos(ang) * lepes
            If map(x - .5, y - .5) = 0 Then cam(0) = x: cam(1) = y: GoTo 88
        Next t2
    Next t1

    88:




    rot

    For t = 0 To map_lc - 1
        If map_p(map_l(t, 0), 5) And map_p(map_l(t, 1), 5) Then
            x1 = map_p(map_l(t, 0), 3)
            y1 = map_p(map_l(t, 0), 4)
            x2 = map_p(map_l(t, 1), 3)
            y2 = map_p(map_l(t, 1), 4)
            temp = 127 * (map_p(map_l(t, 0), 6) + map_p(map_l(t, 1), 6))
            Line (x1, y1)-(x2, y2), _RGB32(temp, temp, temp)
        End If

    Next t
    _Display
    Cls

Loop

Sub rot '(x, y, z)


    For t = 0 To map_pc - 1
        x2 = map_p(t, 0) - cam(0)
        y2 = map_p(t, 1) - cam(1)
        z2 = map_p(t, 2) - cam(2)

        rotate_2d x2, y2, cam(3)
        map_p(t, 5) = 0
        If Abs(y2) < cam(7) Then
            If Abs(x2) < cam(7) Then
                dis = (x2 * x2 + y2 * y2)
                If dis < cam(6) Then
                    If y2 > 0 Then
                        temp = 800 / y2
                        x = x2 * temp
                        y = z2 * temp
                        map_p(t, 3) = x + cam(8)
                        map_p(t, 4) = -y + cam(9)
                        map_p(t, 5) = 1
                        map_p(t, 6) = 1 - cam(5) * Sqr(dis)
                    End If
                End If
            End If
        End If
    Next t

End Sub

Sub control
    mousex = 0: mousey = 0: mousew = 0: While _MouseInput: mousex = mousex + _MouseMovementX: mousey = mousey + _MouseMovementY: mousew = mousew + _MouseWheel: Wend

    iranyitas(2) = iranyitas(1)

    If _MouseButton(1) Then
        iranyitas(0) = iranyitas(0) + mousex
        iranyitas(1) = iranyitas(1) + mousey
    End If



End Sub



Sub rotate_2d (x, y, ang): x1 = x * Cos(ang) - y * Sin(ang): y1 = x * Sin(ang) + y * Cos(ang): x = x1: y = y1: End Sub
Function interpolate (a, b, x): interpolate = a + (b - a) * x: End Function




Sub add_sq (a, b, c, d, plan)
    map_s(map_sc, 0) = a
    map_s(map_sc, 1) = b
    map_s(map_sc, 2) = c
    map_s(map_sc, 3) = d
    map_s(map_sc, 4) = plan
    map_sc = map_sc + 1
    add_line a, b
    add_line a, c
    add_line c, d
    add_line b, d
End Sub

Sub add_line (a, b)
    find = -1
    If map_lc > 0 Then
        For t = 0 To map_lc - 1
            If (map_l(t, 0) = a And map_l(t, 1) = b) Or (map_l(t, 0) = b And map_l(t, 1) = a) Then find = t
        Next
    End If

    If find = -1 Then
        map_l(map_lc, 0) = a
        map_l(map_lc, 1) = b
        map_lc = map_lc + 1
    End If
End Sub



Function add_point (x, y, z)
    find = -1
    If map_pc > 0 Then
        For t = 0 To map_pc - 1
            If map_p(t, 0) = x And map_p(t, 1) = y And map_p(t, 2) = z Then find = t
        Next t
    End If

    If find = -1 Then
        map_p(map_pc, 0) = x
        map_p(map_pc, 1) = y
        map_p(map_pc, 2) = z
        add_point = map_pc
        map_pc = map_pc + 1
    Else
        add_point = find
    End If



End Function

Sub createtrack (qx, qy, qf)
    map_dat(0) = qx
    map_dat(1) = qy
    map_dat(2) = qf
    Dim d(1)

    Dim temp1
    For x = 0 To qx - 1: For y = 0 To qy - 1: map(x, y) = 1: Next: Next

    d(0) = Int(map_dat(0) / 2): d(1) = Int(map_dat(1) / 2)
    temp1 = 0

    Do
        temp1 = temp1 + map(d(0), d(1))
        map(d(0), d(1)) = 0
        t = Int(4 * Rnd)
        d(t And 1) = d(t And 1) + (t And 2) - 1
        If d(0) = 1 Or d(0) = map_dat(0) - 1 Or d(1) = 1 Or d(1) = map_dat(1) - 1 Then d(0) = Int(map_dat(0) / 2): d(1) = Int(map_dat(1) / 2)
        If temp1 > qx * qy * qf Then Exit Do
    Loop
End Sub



Sub create_textsq
    For x = 0 To map_dat(0) - 1
        For y = 0 To map_dat(1) - 1
            p0 = add_point(x, y, map(x, y))
            p1 = add_point(x + 1, y, map(x, y))
            p2 = add_point(x, y + 1, map(x, y))
            p3 = add_point(x + 1, y + 1, map(x, y))
            add_sq p0, p1, p2, p3, 2

            If map(x, y) = 0 Then
                If map(x - 1, y) = 1 Then
                    x1 = x
                    y1 = y
                    x2 = x
                    y2 = y + 1
                    create_textsq2 x1, y1, x2, y2, 0
                End If

                If map(x + 1, y) = 1 Then
                    x1 = x + 1
                    y1 = y
                    x2 = x + 1
                    y2 = y + 1
                    create_textsq2 x1, y1, x2, y2, 0
                End If

                If map(x, y - 1) = 1 Then
                    x1 = x
                    y1 = y
                    x2 = x + 1
                    y2 = y
                    create_textsq2 x1, y1, x2, y2, 0
                End If

                If map(x, y + 1) = 1 Then
                    x1 = x
                    y1 = y + 1
                    x2 = x + 1
                    y2 = y + 1
                    create_textsq2 x1, y1, x2, y2, 0
                End If


            End If
        Next
    Next
End Sub

Sub create_textsq2 (x1, y1, x2, y2, plan)
    p0 = add_point(x1, y1, 0)
    p1 = add_point(x1, y1, 1)
    p2 = add_point(x2, y2, 1)
    p3 = add_point(x2, y2, 0)
    add_sq p0, p1, p3, p2, plan
End Sub

https://drive.google.com/file/d/1Un1gAY4...drive_link
Reply
#2
Don't have an Android device to test. Perhaps this will run in Windows Subsystem for Android. I'll play with that later.

I researched the B4X suite before. The only reason it does not appeal to me is it's dependence on the Java VM and runtime. That was an instant turn off for me.
Reply
#3
I don't like a lot of things in b4a either, but for now I see this as the easiest solution to run basic on android with minor rewriting.

What do you mean ? 'don't have an android device for testing'. I tried it on several phones, it works on all of them.
Reply
#4
(03-16-2024, 05:59 PM)MasterGy Wrote: I don't like a lot of things in b4a either, but for now I see this as the easiest solution to run basic on android with minor rewriting.

What do you mean ? 'don't have an android device for testing'. I tried it on several phones, it works on all of them.

I know its hard to believe. But I do not have any Android phone. Big Grin I use an iPhone.

But I think your apk should run on Windows Subsystem for Android.
Reply
#5
I misunderstood because of the translation. It translated to me as "don't run it on an Android device". Instead you wrote "I don't have an Android device". I understand now. Smile
Reply
#6
(03-16-2024, 10:05 PM)MasterGy Wrote: I misunderstood because of the translation. It translated to me as "don't run it on an Android device". Instead, you wrote "I don't have an Android device". I understand now. Smile

No problem. And it works. Nicely done!


[Image: Screenshot-2024-03-17-234928.png]
Reply
#7
Here is another option for running on Android:

Reply
#8
Interesting. So since JavaScript can run on Android, I guess my question would be how to generate and install the JavaScript exe on my phone? There are install kits like INNO, and I know DosBox came out with an Android version a long time ago. It was a bit clumsy back then, but maybe by now it is less step ridden to use. Maybe there is a direct PC to phone file transfer method as well. 

Pete
Reply
#9
(03-20-2024, 04:46 PM)Pete Wrote: Interesting. So since JavaScript can run on Android, I guess my question would be how to generate and install the JavaScript exe on my phone? There are install kits like INNO, and I know DosBox came out with an Android version a long time ago. It was a bit clumsy back then, but maybe by now it is less step ridden to use. Maybe there is a direct PC to phone file transfer method as well. 

Pete
I tend to think of it more like this... Javascript IS the exe.  The web browser is the virtual OS that is already supported on every platform.
Reply
#10
Okay, using the browser as the display surface. So how do we load the JavaScript to the phone and get the browser to execute it?

Pete
Reply




Users browsing this thread: 1 Guest(s)