Flyer Invasion - Just for fun :)

Post your Gambas programming questions here.
Post Reply
User avatar
jornmo
Site Admin
Posts: 224
Joined: Wednesday 21st September 2016 1:19pm
Location: Norway

Flyer Invasion - Just for fun :)

Post by jornmo »

:D
FlyerIvasion-0.0.1.tar.gz
(6.82 MiB) Downloaded 644 times
User avatar
jornmo
Site Admin
Posts: 224
Joined: Wednesday 21st September 2016 1:19pm
Location: Norway

Re: Flyer Invasion - Just for fun :)

Post by jornmo »

You might want to set this line
.Resize(1600, 900)
to your screen resolution, or it will look awkward!
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Flyer Invasion - Just for fun :)

Post 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
User avatar
jornmo
Site Admin
Posts: 224
Joined: Wednesday 21st September 2016 1:19pm
Location: Norway

Re: Flyer Invasion - Just for fun :)

Post 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.
User avatar
jornmo
Site Admin
Posts: 224
Joined: Wednesday 21st September 2016 1:19pm
Location: Norway

Re: Flyer Invasion - Just for fun :)

Post 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
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Flyer Invasion - Just for fun :)

Post 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)?
User avatar
jornmo
Site Admin
Posts: 224
Joined: Wednesday 21st September 2016 1:19pm
Location: Norway

Re: Flyer Invasion - Just for fun :)

Post 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 :)
User avatar
jornmo
Site Admin
Posts: 224
Joined: Wednesday 21st September 2016 1:19pm
Location: Norway

Re: Flyer Invasion - Just for fun :)

Post by jornmo »

And I also find it to keep the code more clean and easy to read and understand.
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Flyer Invasion - Just for fun :)

Post by cogier »

The latest version seems to work well. Fullscreen works now as well.
User avatar
jornmo
Site Admin
Posts: 224
Joined: Wednesday 21st September 2016 1:19pm
Location: Norway

Re: Flyer Invasion - Just for fun :)

Post 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 :)
Post Reply