Page 1 of 1

Flyer Invasion - Just for fun :)

Posted: Sunday 30th October 2016 5:16pm
by jornmo
:D
FlyerIvasion-0.0.1.tar.gz
(6.82 MiB) Downloaded 644 times

Re: Flyer Invasion - Just for fun :)

Posted: Sunday 30th October 2016 5:19pm
by jornmo
You might want to set this line
.Resize(1600, 900)
to your screen resolution, or it will look awkward!

Re: Flyer Invasion - Just for fun :)

Posted: Monday 31st October 2016 5:29pm
by cogier
If only all Linux systems were the same!

I found a solution to the screen size issue with the code below: -

Code: Select all

Public Sub ScreenSize() As String                                             'To capture current screen size
  Dim sData, sSize, sTemp As String                                           'Variables to store the result of the shelled command, the size of the screen and a Temp variable
  Dim siCount As Short                                                        'To store the position in the string (e.g.1920 x 1080) of the 'x'

  Shell "xrandr --current" To sData                                           'Shell the command and store the result in sData

  For Each sTemp In Split(sData, "\n")                                        'For each Newline in sData..
    siCount = InStr(sTemp, "current")                                         'See is the word 'current' exists
    If siCount Then                                                           'If it does then..
      sSize = Mid(sTemp, siCount + 8, InStr(sTemp, ",", siCount) - (siCount + 8))  'Capture only the size details (e.g. 1920 x 1080)
      Break                                                                    'Get out of the loop
    End If
  Next

  Return sSize                                                                'Return the size
  
End

Public Sub Main()
  Dim siSizeW, siSizeH As Short                                               'Variables to store the screen size Width and Height
  Dim sData As String                                                         'Variable to store the data from the ScreenSize() routine

  Randomize CInt(Now)

  $hWindow = New Window As "Window"

  sData = ScreenSize()                                                        'Get the current screen size
  siSizeW = Val(Trim(Mid(sData, 1, InStr(sData, "x") - 1)))                   'Capture the screen width only
  siSizeH = Val(Trim(Mid(sData, InStr(sData, "x") + 1)))                      'Capture the screen height only
  Print "Screen size is " & Str(siSizeW) & " x " & Str(siSizeH) & "\n"        'Print screen size

  With $hWindow
    .Resize(siSizeW, siSizeH)                                                 'Apply the collected data
    '.Resizable = True
    .FullScreen = True
    .FrameRate = FRAMERATE
    .Show()
  End With

  If Exist("highscore.ini") Then
    $iHighScore = CInt(File.Load("highscore.ini"))
  Else
    $iHighScore = 0
    File.Save(Application.Path &/ "highscore.ini", 0)
  Endif

  LevelUp()

  Mouse.Hide()

  $iPlayerX = $hWindow.H / 2 - $iPlayerW / 2

  Music.Load("Hero Immortal.mp3") 'By Trevor Lenz, http://opengameart.org/content/hero-immortal
  $hShootSound = Sound.Load("laser10.wav") 'By dklon, http://opengameart.org/content/laser-fire
  $hHitSound = Sound.Load("laser8.wav") 'By dklon, http://opengameart.org/content/laser-fire

End
For some reason the screen does not go to 'Fullscreen' and the display is a little small and sometimes it's got all sorts of things going on. Shutter failed to take a picture so I have had to take a photo on my phone! The writing is as you see on the photo.

Image

Re: Flyer Invasion - Just for fun :)

Posted: Tuesday 1st November 2016 7:57am
by jornmo
Thanks cogier! That should do it, and I will try to implement it soon :) I also had some issues to get the fullscreen to work to begin with, but then it resolved for some reason unbeknownst to me... perhaps it should be reported as a bug. From here on, I will publish the updates on the farm.

Re: Flyer Invasion - Just for fun :)

Posted: Tuesday 1st November 2016 3:19pm
by jornmo
This is what I did:
Public Sub GetResolution()

  Dim s As String

  Shell "whereis xrandr" To s
  If Not InStr(s, "/usr/bin/") Then
    Print "Could not detect screen resolution! xrandr seems to not be installed! Falling back to default and windowed mode"
    $hWindow.FullScreen = False
    Return
  Endif

  $hWindow.FullScreen = True

  Shell "xrandr --current | grep '*'" To s
  s = Split(Trim(s), " ")[0]
  $iDesktopW = Split(s, "x")[0]
  $iDesktopH = Split(s, "x")[1]

End

Re: Flyer Invasion - Just for fun :)

Posted: Thursday 3rd November 2016 10:22pm
by cogier
Yes I have looked at this and learnt a lot. I did not know you could do that. As usual - VERY IMPRESSIVE CODE! :geek:

I have one question. Why do you use a variable 's' and not sData or sResult (or Similar)?

Re: Flyer Invasion - Just for fun :)

Posted: Friday 4th November 2016 9:08am
by jornmo
Thank you! Glad it has helped you :) Whenever I need a variable to be used a bit here and a bit there just for temporary operations, I tend to use an i, s, f or whatever variable type I need. So, when it is just s I can reuse it all over and I do not have to declare lots of variables for each place I need a string that I really do not need to remember what's inside :)

Re: Flyer Invasion - Just for fun :)

Posted: Friday 4th November 2016 9:10am
by jornmo
And I also find it to keep the code more clean and easy to read and understand.

Re: Flyer Invasion - Just for fun :)

Posted: Sunday 6th November 2016 5:17pm
by cogier
The latest version seems to work well. Fullscreen works now as well.

Re: Flyer Invasion - Just for fun :)

Posted: Sunday 6th November 2016 6:43pm
by jornmo
Good! It is due a change I made based on a report from the Gambas mailing list. Resize must be set to True in order for fullscreen to work on some systems it seems. My laptop does not require it though... no idea why :)