It is currently Fri Oct 18, 2019 7:41 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Old windows-code does not work on mac
PostPosted: Fri Apr 18, 2014 3:52 pm 
Offline
User
User
User avatar

Joined: Mon Aug 13, 2012 6:12 pm
Posts: 89
Location: Berlin, Germany
Hi,

i have some old code, which i used on Windows a few years ago. Now i want to go on with this little project, but meanwhile i use a Mac instead of Windows. I looks like there is maybe something Windows-specific code in there, which does not work on my Mac.

What happens if i start the code? The Window is opening but nothing in there, no sprites at all. The sound-file is playing.

Any Mac-user out there who can try my code?

Code:
; Project   : Dungeon
; Filename  : dungeon.pb

AppPath.s = GetPathPart(ProgramFilename())
Enumeration
; Sprites
#Rasen
#Wasser
#Spieler1
#Spieler2
; Sounds
#Musik1
EndEnumeration

#ScreenWidth = 1024
#ScreenHeight = 768
#MapWidth= 15
#MapHeight = 20

; Unterstützung für Bildformat PNG
UsePNGImageDecoder()

; Unterstützung für Soundformat OGG
UseOGGSoundDecoder()

; Sprite und Tastatur initialisieren
If InitSprite() = 0 : MessageRequester("Fehler", "Sprite konnte nicht initialisiert werden!") : End : EndIf
If InitKeyboard() = 0 : MessageRequester("Fehler", "Tastatur konnte nicht initialisiert werden!") : End : EndIf

; Geschwindigkeitskonstante
#SPEED = 2

; Diese Funktion prüft ob eine Kollision vorliegt
Procedure Collision(x.f, y.f)
  Result = 0
; Gehe alle Tiles durch
  Restore Map   
  For my = 0 To #MapWidth - 1
    For mx = 0 To #MapHeight - 1
      a.b
      Read .b a
;     Wenn der Tile-Typ 1(#Rasen) ist, so prüfe auf eine Kollision mit diesem Tile...
      If a = 1
;       ... mit den entsprechenden Tile-Koordinaten(IndexX * TileBreite, IndexY * TileBreite)...
;       ... und den entsprechenden Spieler-Koordinaten(SpielerX, SpielerY)...
        If SpriteCollision(#Rasen, Int(x), Int(y), #Spieler1, mx * 50, my * 50)
;         Wenn ja: gib 1(True) zurück
          Result = 1
;         und springe aus beiden Schleifen(Anzahl: 2) raus
          Break 2
        EndIf
      EndIf     
    Next
  Next
 
  ProcedureReturn Result
EndProcedure

; Screen öffnen
If OpenWindow(0, 0, 0, 340, 285, "Dungeon!", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)

  If OpenWindowedScreen(WindowID(0), 10, 70, 320, 200, 0, 0, 0)
    LoadSprite(#Spieler1, "res/michael_kopf.png")
  Else
    MessageRequester("Error", "Can't open windowed screen!", 0)
    End
  EndIf

EndIf

; Sprites laden
LoadSprite(#Rasen, "res/rasen.png")
LoadSprite(#Wasser,"res/wasser.png")
LoadSprite(#Spieler1,"res/michael_kopf.png")
LoadSprite(#Spieler2,"res/alexandra_kopf.png")

; Spielerposition in der Mitte des Bildschirms
X.f = #ScreenWidth / 2
Y.f = #ScreenHeight / 2

; Framerate auf 30 setzen
SetFrameRate(30)

; Hintergrundmusik laden und endlos abspielen
If InitSound() = 0 : MessageRequester("Fehler", "Soundwiedergabe konnte nicht initialisiert werden!") : End : EndIf

LoadSound(#Musik1, "res/background.ogg")
PlaySound(#Musik1, 1)

; Hauptschleife
Repeat
; Keyboardstatus erneuern und abfragen
  ExamineKeyboard()
 
  If KeyboardPushed(#PB_Key_Up)     ; laufe hoch
    If Collision(X, Y - #SPEED) = 0
      Y - #SPEED
    EndIf
  EndIf
  If KeyboardPushed(#PB_Key_Down)   ; laufe runter
    If Collision(X, Y + #SPEED) = 0
      Y + #SPEED
    EndIf
  EndIf
  If KeyboardPushed(#PB_Key_Left)   ; laufe links
    If Collision(X - #SPEED, Y) = 0
      X - #SPEED
    EndIf
  EndIf
  If KeyboardPushed(#PB_Key_Right)  ; laufe rechts
    If Collision(X + #SPEED, Y) = 0
      X + #SPEED
    EndIf
  EndIf
 
; Beenden?
  If KeyboardPushed(#PB_Key_Escape)
    Quit = 1
  EndIf
 
; Screeninhalt löschen und mit Schwarz überdecken
  ClearScreen(0)
   
; Spieler anzeigen
   DisplaySprite(#Spieler1, X, Y)

; Mapdaten durchgehen
  Restore Map
  For my = 0 To #MapWidth - 1
    For mx = 0 To #MapHeight - 1
      a.b
      Read.b a
      Select a
         Case 1 ; Rasen
           DisplaySprite(#Rasen, mx * 50, my * 50)
         Case 2 ; Wasser
           DisplaySprite(#Wasser, mx * 50, my * 50)
         Case 3 ; Spieler2
           DisplaySprite(#Spieler2, mx * 50, my * 50)
      EndSelect
    Next
  Next
   
; Gefüllten Backbuffer zum Frontbuffer bringen
; FlipBuffers()
 
; Eine kleine Verzögerung um den Prozessor nicht vollständig auszulasten
  Delay(5)
Until Quit = 1
End

; Mapdaten
DataSection
  Map:
  Data.b 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
  Data.b 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
  Data.b 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1
  Data.b 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1
  Data.b 1, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1
  Data.b 1, 0, 0, 2, 2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1
  Data.b 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
  Data.b 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1
  Data.b 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1
  Data.b 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1
  Data.b 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
  Data.b 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
  Data.b 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 1
  Data.b 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
  Data.b 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
EndDataSection


Thanks

Michael

_________________
Michael

PureBasic 5.51, macOS 10.12.2 Sierra


Top
 Profile  
Reply with quote  
 Post subject: Re: Old windows-code does not work on mac
PostPosted: Sat Apr 19, 2014 12:21 am 
Offline
Addict
Addict
User avatar

Joined: Sat Apr 26, 2003 8:26 am
Posts: 2924
Location: Planet Earth
thinkitsimple wrote:
What happens if i start the code? The Window is opening but nothing in there, no sprites at all. The sound-file is playing.

You out-commented FlipBuffers(), so screen buffers do not switch. Also, you need to check
all incoming WindowEvent() in windowed screen mode. Can't test here without the sprites.


Top
 Profile  
Reply with quote  
 Post subject: Re: Old windows-code does not work on mac
PostPosted: Sat Apr 19, 2014 7:53 am 
Offline
User
User
User avatar

Joined: Mon Aug 13, 2012 6:12 pm
Posts: 89
Location: Berlin, Germany
Hi Danilo,

found the FlipBuffers() by myself, already tested the code without uncommenting this. Same result, no sprites are shown.

Strange enough, after changing the screen-width and -height of the window, some (rasen, wasser, michael_kopf), but not all (alexandra_kopf) sprites are shown.

How do i check the incoming Window Events?

I have uploaded the sprites and sound to this location: http://www.thinkitsimple.de/public/project/dungeon.zip.

Thanks for helping.

_________________
Michael

PureBasic 5.51, macOS 10.12.2 Sierra


Top
 Profile  
Reply with quote  
 Post subject: Re: Old windows-code does not work on mac
PostPosted: Sat Apr 19, 2014 8:25 am 
Offline
Addict
Addict
User avatar

Joined: Sat Apr 26, 2003 8:26 am
Posts: 2924
Location: Planet Earth
thinkitsimple wrote:
How do i check the incoming Window Events?

Replace the Delay(5) with:
Code:
; Eine kleine Verzögerung um den Prozessor nicht vollständig auszulasten
Delay(5)
Repeat
    event = WindowEvent()
    If event = #PB_Event_CloseWindow
        Quit = 1
    EndIf
Until event = 0

thinkitsimple wrote:
Strange enough, after changing the screen-width and -height of the window, some (rasen, wasser, michael_kopf), but not all (alexandra_kopf) sprites are shown.

Map value 3 is outside of the screen here. When I place a 3 somewhere else, it works fine.


EDIT:
Code:
; Project   : Dungeon
; Filename  : dungeon.pb
; Copyright : 2007-2014 Michael Bzdega
; Comment   : A tile-based 2-D Adventure-Game

AppPath.s = GetPathPart(ProgramFilename())
Enumeration
    ; Sprites
    #Rasen
    #Wasser
    #Spieler1
    #Spieler2
    ; Sounds
    #Musik1
EndEnumeration

#ScreenWidth = 800
#ScreenHeight = 600
#MapWidth= 15
#MapHeight = 20

; Unterstützung für Bildformat PNG
UsePNGImageDecoder()

; Unterstützung für Soundformat OGG
UseOGGSoundDecoder()

; Sprite und Tastatur initialisieren
If InitSprite() = 0 : MessageRequester("Fehler", "Sprite konnte nicht initialisiert werden!") : End : EndIf
If InitKeyboard() = 0 : MessageRequester("Fehler", "Tastatur konnte nicht initialisiert werden!") : End : EndIf

; Geschwindigkeitskonstante
#SPEED = 2

; Diese Funktion prüft ob eine Kollision vorliegt
Procedure Collision(x.f, y.f)
    Result = 0
    ; Gehe alle Tiles durch
    Restore Map   
    For my = 0 To #MapWidth - 1
        For mx = 0 To #MapHeight - 1
            a.b
            Read .b a
            ;     Wenn der Tile-Typ 1(#Rasen) ist, so prüfe auf eine Kollision mit diesem Tile...
            If a = 1
                ;       ... mit den entsprechenden Tile-Koordinaten(IndexX * TileBreite, IndexY * TileBreite)...
                ;       ... und den entsprechenden Spieler-Koordinaten(SpielerX, SpielerY)...
                If SpriteCollision(#Rasen, Int(x), Int(y), #Spieler1, mx * 50, my * 50)
                    ;         Wenn ja: gib 1 (True) zurück
                    Result = 1
                    ;         und springe aus beiden Schleifen (Anzahl: 2) raus
                    Break 2
                EndIf
            EndIf     
        Next
    Next
   
    ProcedureReturn Result
EndProcedure

; Screen öffnen
If OpenWindow(0, 0, 0, #ScreenWidth, #ScreenHeight, "Dungeon!", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
   
    If OpenWindowedScreen(WindowID(0), 0, 0, #ScreenWidth, #ScreenHeight, 0, 0, 0)
        LoadSprite(#Spieler1, "res/michael_kopf.png")
    Else
        MessageRequester("Error", "Can't open windowed screen!", 0)
        End
    EndIf
   
EndIf

; Sprites laden
LoadSprite(#Rasen, "res/rasen.png")
LoadSprite(#Wasser,"res/wasser.png")
LoadSprite(#Spieler1,"res/michael_kopf.png")
LoadSprite(#Spieler2,"res/alexandra_kopf.png")

; Spielerposition in der Mitte des Bildschirms
X.f = #ScreenWidth / 2
Y.f = #ScreenHeight / 2

; Framerate auf 30 setzen
SetFrameRate(30)

; Hintergrundmusik laden und endlos abspielen
If InitSound() = 0 : MessageRequester("Fehler", "Soundwiedergabe konnte nicht initialisiert werden!") : End : EndIf

LoadSound(#Musik1, "res/background.ogg")
PlaySound(#Musik1, 1)

; Hauptschleife
Repeat
    ; Keyboardstatus erneuern und abfragen
    ExamineKeyboard()
   
    If KeyboardPushed(#PB_Key_Up)     ; laufe hoch
        If Collision(X, Y - #SPEED) = 0
            Y - #SPEED
        EndIf
    EndIf
    If KeyboardPushed(#PB_Key_Down)   ; laufe runter
        If Collision(X, Y + #SPEED) = 0
            Y + #SPEED
        EndIf
    EndIf
    If KeyboardPushed(#PB_Key_Left)   ; laufe links
        If Collision(X - #SPEED, Y) = 0
            X - #SPEED
        EndIf
    EndIf
    If KeyboardPushed(#PB_Key_Right)  ; laufe rechts
        If Collision(X + #SPEED, Y) = 0
            X + #SPEED
        EndIf
    EndIf
   
    ; Beenden?
    If KeyboardPushed(#PB_Key_Escape)
        Quit = 1
    EndIf
   
    ; Screeninhalt löschen und mit Schwarz überdecken
    ClearScreen(0)
   
    ; Spieler anzeigen
    DisplaySprite(#Spieler1, X, Y)
   
    ; Mapdaten durchgehen
    Restore Map
    For my = 0 To #MapWidth - 1
        For mx = 0 To #MapHeight - 1
            a.b
            Read.b a
            Select a
                Case 1 ; Rasen
                    DisplaySprite(#Rasen, mx * 50, my * 50)
                Case 2 ; Wasser
                    DisplaySprite(#Wasser, mx * 50, my * 50)
                Case 3 ; Spieler2
                    DisplaySprite(#Spieler2, mx * 50, my * 50)
            EndSelect
        Next
    Next
   
    ; Gefüllten Backbuffer zum Frontbuffer bringen
    FlipBuffers()
   
    ; Eine kleine Verzögerung um den Prozessor nicht vollständig auszulasten
    Delay(5)
    ; Events abfragen
    Repeat
        event = WindowEvent()
        If event = #PB_Event_CloseWindow
            Quit = 1
        EndIf
    Until event = 0
   
Until Quit = 1
End

; Mapdaten
DataSection
    Map:
    Data.b 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
    Data.b 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
    Data.b 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1
    Data.b 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1
    Data.b 1, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1
    Data.b 1, 0, 0, 2, 2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1
    Data.b 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
    Data.b 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1
    Data.b 1, 0, 0, 3, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1
    Data.b 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1
    Data.b 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
    Data.b 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
    Data.b 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 1
    Data.b 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
    Data.b 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
EndDataSection

With the following values you see the whole map:
Code:
#ScreenWidth = 1000
#ScreenHeight = 750


Top
 Profile  
Reply with quote  
 Post subject: Re: Old windows-code does not work on mac
PostPosted: Sat Apr 19, 2014 10:22 am 
Offline
User
User
User avatar

Joined: Mon Aug 13, 2012 6:12 pm
Posts: 89
Location: Berlin, Germany
Hi Danilo,

thanks, this works as it should. Very nice, now i can go and make a bit more out this.

Maybe you can help in another small problem?

When i run this in the IDE, all runs fine now. But when i compile it as mac app, the sprites and sound seems not be be included in the app. It opens a black window, no sprites, no music, no error-message.

How can i include these resources within the compiled app? Or is this a matter of path-definition? How do i set the file-pathes, to run the code within the IDE and as compiled app with a res-folder nearby?

_________________
Michael

PureBasic 5.51, macOS 10.12.2 Sierra


Top
 Profile  
Reply with quote  
 Post subject: Re: Old windows-code does not work on mac
PostPosted: Sat Apr 19, 2014 11:15 am 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2011 3:47 am
Posts: 2213
Location: Singapore
thinkitsimple wrote:
...When i run this in the IDE, all runs fine now. But when i compile it as mac app, the sprites and sound seems not be be included in the app...
Hi thinkitsimple. Just make sure that the res folder which contains the michael_kopf.png, rasen.png, wasser.png, background.ogg, etc. files is in the same directory as the compiled app.

thinkitsimple wrote:
How can i include these resources within the compiled app?...
For this, you could either use resource files, or simply include the resources within the application itself, using the CatchImage(), CatchSprite(), CatchMusic() and CatchSound() functions.

_________________
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too!


Top
 Profile  
Reply with quote  
 Post subject: Re: Old windows-code does not work on mac
PostPosted: Sat Apr 19, 2014 11:46 am 
Offline
Addict
Addict
User avatar

Joined: Sat Apr 26, 2003 8:26 am
Posts: 2924
Location: Planet Earth
thinkitsimple wrote:
When i run this in the IDE, all runs fine now. But when i compile it as mac app, the sprites and sound seems not be be included in the app. It opens a black window, no sprites, no music, no error-message.

Your .app is a directory/package only. Right-click the app and choose "Paketinhalt anzeigen" (german Mac OS X).

Copy your 'res' folder to Dungeon.app/Contents/, so you get Dungeon.app/Contents/res/background.ogg etc.
"Contents" is the main directory within your .app


Top
 Profile  
Reply with quote  
 Post subject: Re: Old windows-code does not work on mac
PostPosted: Sat Apr 19, 2014 3:36 pm 
Offline
User
User
User avatar

Joined: Mon Aug 13, 2012 6:12 pm
Posts: 89
Location: Berlin, Germany
Danilo wrote:
Your .app is a directory/package only. Right-click the app and choose "Paketinhalt anzeigen" (german Mac OS X).

Copy your 'res' folder to Dungeon.app/Contents/, so you get Dungeon.app/Contents/res/background.ogg etc.
"Contents" is the main directory within your .app


Thanks, this solves my problem.

_________________
Michael

PureBasic 5.51, macOS 10.12.2 Sierra


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye