BASIC

Author Topic: Help for NEWBIES. NOTE: I am a newbie so I cant really help.  (Read 7965 times)

Offline blackout12

  • Mc. Print
  • *
  • Posts: 39
    • View Profile
I fixed it

Offline blackout12

  • Mc. Print
  • *
  • Posts: 39
    • View Profile
well, thank you guys so much for your advice and help, but it seems that all I had to do was delete the file I was using and redo everything for it to work. I will never know what was wrong with it originally but its fixed now. =D :D =D :D =D :D =D :D =D :D :D =D :D =D =D :D :D =D

Offline blackout12

  • Mc. Print
  • *
  • Posts: 39
    • View Profile
Code: GLBasic [Select]
Main:  
 DIM baty[2]
 DIM batx[2]
 DIM score[2]

 //pre-settings
 GOSUB Init
 MainLoop:
  GOSUB MoveAll
  GOSUB ShowAll
 GOTO Main
 

SUB Init:
 GOSUB ResetBall
 BLACKSCREEN
 DRAWRECT 0,0, 640, 16,  RGB(255, 255, 255)
 DRAWRECT 0, 464, 640, 480, RGB(255, 255, 255)
 DRAWRECT 312, 0, 16, 480, RGB(255, 255, 255)
 USEASBMP
 
 
 baty[0]=240; baty[1]=240
 
 batx[0]=16; batx[1]=600
ENDSUB

SUB ResetBall:

    ballx=320
    bally=240
   
    IF ballsx<0
     ballsx=1
    ELSE
     ballsx=-1
    ENDIF  
   
    ballsy=1
ENDSUB



SUB ShowAll:
 FOR num=0 TO 1
  DRAWRECT batx[num], baty[num], 16, 64, RGB (255, 255, 255)
  PRINT score[num], num*320 + 32, 16
 NEXT
 DRAWRECT ballx, bally, 16, 16, RGB(255, 255, 255)
 SHOWSCREEN
ENDSUB




SUB MoveAll:
  FOR num=0 TO 1
  IF KEY(30) THEN baty[0]=baty[0]-2
  IF KEY(44) THEN baty[0]=baty[0]+2
 
  IF KEY(200) THEN baty[1]=baty[1]-2
  IF KEY(208) THEN baty[1]=baty[1]+2
 
  IF baty[num]<0  THEN baty[num]=0
  IF baty[num]>416  THEN baty[num]=416
 NEXT
ENDSUB
 
this code makes the bats move but only like a milimeter and then it cant go any further. any suggestions why it would do this?

Offline erico

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 4179
    • View Profile
    • Portfolio
Blackout12, I feel you are trying to create a program by adding blocks of code expecting it to work out of the box.
I see your code has some advanced things, like functions and types.

You can´t do a game by adding pieces of code from here and there, you must understand what is going on per line and command.
It seems to me you want to try a huge step instead of going on slowly.

Again, I´m no god coder, I can´t use types or functions yet, I´m learning.
But with the VERY little I know of GLBasic, I can reach what I want.
It may take a huge code and it may be un-optimized, but I can make what I want, and that is what matters.

So to make it clear, you can start coding on GLBasic with very little knowledge on commands (as I do).
But it is important that you know about these few commands AND language structure.

You seem to have the needed perseverance, and that is great!
You will get there, did you try the PONG tutorial?

Offline fuzzy70

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 828
  • Look left, Look right, LOOK OUT!!
    • View Profile
I'm not at my main pc at the moment but the error looks like the following, you have
Code: GLBasic [Select]
GOTO Main
 
in your code which means it sets up everything, does the game loop once then starts from the beginning. Try replacing the above with
Code: GLBasic [Select]
GOTO MainLoop
& try that. so the top part of your code looks like the following

Code: GLBasic [Select]
Main:  
 DIM baty[2]
 DIM batx[2]
 DIM score[2]

 //pre-settings
 GOSUB Init
 MainLoop:
  GOSUB MoveAll
  GOSUB ShowAll
GOTO MainLoop
 

That way it will initialize everything as normal & run the game loop rather that starting from the beginning every time.

Lee
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)

Offline blackout12

  • Mc. Print
  • *
  • Posts: 39
    • View Profile
I have Finished programming Pong but I have a midi file I want to play in the game, where in the code wuold I have to put it?
Code: GLBasic [Select]
main:
 DIM bat_y[2]
 DIM bat_x[2]
 DIM score[2]
  GOSUB Init
  MainLoop:
    GOSUB MoveAll
    GOSUB ShowAll
  GOTO MainLoop



// ------------------------------------------------------------- //
// ---  INIT  ---
// ------------------------------------------------------------- //
SUB Init:

 GOSUB ResetBall

 BLACKSCREEN
 DRAWRECT 0,0, 640, 16,  RGB(255, 255, 255)
 DRAWRECT 0, 464, 640, 480, RGB(255, 255, 255)
 DRAWRECT 312, 0, 16, 480, RGB(255, 255, 255)
 USEASBMP


 bat_y[0]=240; bat_y[1]=240

 bat_x[0]=16;  bat_x[1]=600
ENDSUB // INIT




// ------------------------------------------------------------- //
// ---  RESETBALL  ---
// ------------------------------------------------------------- //
SUB ResetBall:


    ball_x=320
    ball_y=240

    IF ball_sx<0
     ball_sx=1
    ELSE
     ball_sx=-1
    ENDIF

    ball_sy=1
ENDSUB // RESETBALL




// ------------------------------------------------------------- //
// ---  SHOWALL  ---
// ------------------------------------------------------------- //
SUB ShowAll:
 FOR num=0 TO 1
  DRAWRECT bat_x[num], bat_y[num], 16, 64, RGB(255, 255, 255)
  PRINT score[num], num*320 + 32, 16
 NEXT
 DRAWRECT ball_x, ball_y, 16, 16, RGB(255, 255, 255)
 SHOWSCREEN
ENDSUB // SHOWALL




// ------------------------------------------------------------- //
// ---  MOVEALL  ---
// ------------------------------------------------------------- //
SUB MoveAll:
FOR num=0 TO 1

 IF KEY(30) THEN bat_y[0]=bat_y[0]-2
 IF KEY(44) THEN bat_y[0]=bat_y[0]+2

 IF KEY(200) THEN bat_y[1]=bat_y[1]-2
 IF KEY(208) THEN bat_y[1]=bat_y[1]+2

 IF bat_y[num]<0  THEN bat_y[num] =0
 IF bat_y[num]>416  THEN bat_y[num] =416
NEXT
    ball_x=ball_x+ball_sx
    ball_y=ball_y+ball_sy
   
 IF ball_y>464
  ball_y=464
  ball_sy= -ball_sy
 ENDIF
 
 IF ball_y<0
  ball_y=0
  ball_sy= -ball_sy
  ENDIF
 
 IF ball_x<0
  score[1]=score[1]+2
  GOSUB ResetBall
 ENDIF
 IF ball_x>624
  score[0]=score[0]+2
  GOSUB ResetBall
 ENDIF
 
 FOR num=0 TO 1
 IF (ball_sx<0 AND num = 0) OR (ball_sx>0 AND num=1)
 col=BOXCOLL(bat_x[num], bat_y[num], 16, 64, ball_x, ball_y, 16, 16)
 IF col=TRUE
 ball_sx = -ball_sx
 ball_sx = ball_sx * 1.2
 ball_sy = ball_sy *1.05
 NEXT
 ENDIF
 ENDIF
ENDSUB
 
« Last Edit: 2013-Jan-18 by blackout12 »

Offline blackout12

  • Mc. Print
  • *
  • Posts: 39
    • View Profile
I have figured out where to put the music and it works. but how do I make a playlist?

Offline fuzzy70

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 828
  • Look left, Look right, LOOK OUT!!
    • View Profile
I could give you the code to do that but feel you would learn more from doing it yourself (that's the best way to learn as far as I concerned). So I will tell you the steps involved & you should have enough info to work it out.

  • Create a string array to hold the filenames of the songs that you want to play (eg Song$[])
  • Create a variable to keep track of the current song playing (eg CurrSong)
  • Use PLAYMUSIC as usual but pass it the Song$[CurrSong] array rather than the one filename as before
  • During your MainLoop check to see if the song has ended using ISMUSICPLAYING(), if so then increase CurrSong by one
  • Go back to step 3

You will also have to make sure to check that CurrSong does not go above the amount of songs in the list & if it does set it back to 0. Don't forget arrays start at zero & not 1, example
Code: GLBasic [Select]
DIM Song$[0]="Song1.mid"
DIM Song$[1]="Song2.mid"

IF CurrSong > 1 then CurrSong = 0
 

Lee
"Why don't you just make ten louder and make ten be the top number and make that a little louder?"
- "These go to eleven."

This Is Spinal Tap (1984)

Offline blackout12

  • Mc. Print
  • *
  • Posts: 39
    • View Profile
please define step 1 and 2 further please

Offline Slydog

  • Prof. Inline
  • *****
  • Posts: 930
  • KodeSource
    • View Profile
    • KodeSource
If it helps, here's my music library I created a couple of years back.
I don't know if I left it functional or not, it's been a while.
I do recall that when the Play List started the next song, it paused the entire game for a short second, before playing.
I think this is a GLBasic issue, as it pauses while it loads the song from disk, as there is no way to pre-load a song.
(At least that was a problem back then!)

Initialize:
It uses global constants for the sound effect IDs, and global ints for the music IDs.
Code: GLBasic [Select]
CONSTANT SOUND_MENU% = 2
CONSTANT SOUND_MOVE% = 3
CONSTANT SOUND_MOVE_UP% = 4
CONSTANT SOUND_MOVE_DN% = 5
CONSTANT SOUND_STAR% = 6

GLOBAL MUSIC_INTRO%
GLOBAL MUSIC_MENU%
GLOBAL MUSIC_GAMEOVER%
GLOBAL MUSIC_SONG1%
GLOBAL MUSIC_SONG2%
GLOBAL MUSIC_SONG3%
GLOBAL MUSIC_SONG4%

FUNCTION Sound_Initialize:
        // MUSIC
        MUSIC_INTRO =           _Sound.Music_Add("intro")
        MUSIC_MENU =            _Sound.Music_Add("menu")
        MUSIC_GAMEOVER =        _Sound.Music_Add("gameover")
        MUSIC_SONG1 =           _Sound.Music_Add("song_01")
        MUSIC_SONG2 =           _Sound.Music_Add("song_02")
        MUSIC_SONG3 =           _Sound.Music_Add("song_03")
        MUSIC_SONG4 =           _Sound.Music_Add("song_04")
        _Sound.Music_PlaylistSetFirst(MUSIC_SONG1)

        // EFFECTS
        _Sound.Effect_Add(SOUND_MENU,           "ting",         1)
        _Sound.Effect_Add(SOUND_MOVE,           "move_01",      2)
        _Sound.Effect_Add(SOUND_MOVE_UP,        "move_02",      2)
        _Sound.Effect_Add(SOUND_MOVE_DN,        "move_03",      2)
        _Sound.Effect_Add(SOUND_STAR,           "flag_01",      1)
ENDFUNCTION
 

Usage:
Code: GLBasic [Select]
Somewhere in you main game loop, call:
_Sound.Music_PlayList()

// To play a specific song:
_Sound.Music_Play(MUSIC_INTRO, TRUE)

// To play a specific sound effect:
_Sound.Effect_Play(SOUND_MOVE_UP)
 

Sound Library:
Code: GLBasic [Select]
CONSTANT SOUND_PATH_MUSIC$ = "Sounds/Music/"
CONSTANT SOUND_PATH_EFFECTS$ = "Sounds/Effects/"

?IFDEF IPHONE
CONSTANT SOUND_MUSIC_EXT$ =     ".m4a"
CONSTANT SOUND_EFFECTS_EXT$ =   ".caf"
?ELSE
CONSTANT SOUND_MUSIC_EXT$ =     ".mp3"
CONSTANT SOUND_EFFECTS_EXT$ =   ".wav"
?ENDIF

GLOBAL _volume_music# = 0.5
GLOBAL _volume_effects# = 0.75

//==============================================================================
//  S O U N D
//==============================================================================

TYPE TSoundEffect
        id%
        channel%
        volume#
        pan#
        is_playing%
ENDTYPE

TYPE TSound
        music_ix%
        music_playlist_first%
        music$[]
        effects[] AS TSoundEffect

        FUNCTION Music_Add%: fn$
                fn$ = SOUND_PATH_MUSIC$ + fn$ + SOUND_MUSIC_EXT$
                DIMPUSH self.music$[], fn$
                LOG(">Music Add: [" + fn$ + "] | ix:[" + BOUNDS(self.music$[], 0) - 1 + "]")
                RETURN BOUNDS(self.music$[], 0) - 1
        ENDFUNCTION

        FUNCTION Music_PlaylistSetFirst%: first%
                self.music_playlist_first = first
                RETURN TRUE
        ENDFUNCTION

        FUNCTION Music_PlayList%:
                IF self.music_ix < self.music_playlist_first
                        self.Music_Stop()
                        self.music_ix = self.music_playlist_first
                ENDIF
                IF self.Music_IsPlaying() = TRUE THEN RETURN
                INC self.music_ix
                IF self.music_ix >= BOUNDS(self.music$[], 0)
                        self.music_ix = self.music_playlist_first
                ENDIF
                LOG(">MUSIC :: Now Playing: [" + self.music$[self.music_ix] + "]")
                PLAYMUSIC self.music$[self.music_ix], FALSE
                self.Music_Volume(0.5)
                RETURN TRUE
        ENDFUNCTION

        FUNCTION Music_Play%: song%, b_loop%=FALSE
                IF song >= BOUNDS(self.music$[], 0) THEN RETURN
                IF (self.music_ix = song) AND (self.Music_IsPlaying()) THEN RETURN

                self.music_ix = song
                self.Music_Stop()
                PLAYMUSIC self.music$[self.music_ix], b_loop
                self.Music_Volume(1.0)
                RETURN TRUE
        ENDFUNCTION

        FUNCTION Music_IsPlaying%:
                RETURN ISMUSICPLAYING()
        ENDFUNCTION

        FUNCTION Music_Volume: volume#
                MUSICVOLUME volume * _volume_music
        ENDFUNCTION

        FUNCTION Music_Stop%:
                STOPMUSIC
        ENDFUNCTION

        FUNCTION Effect_Add%: id%, fn$, buffers%=1, b_preload%=FALSE, volume#=1.0, pan#=0.0
                LOCAL effect AS TSoundEffect
                effect.id = id
                effect.volume = volume
                effect.pan = pan
                effect.channel = BLANK
                effect.is_playing = FALSE
                fn$ = SOUND_PATH_EFFECTS$ + fn$ + SOUND_EFFECTS_EXT$
                LOG(">Sound Add: [" + fn$ + "] | id:[" + id + "]")
                LOADSOUND fn$, effect.id, buffers
                DIMPUSH self.effects[], effect
                IF b_preload = TRUE THEN self.Effect_Play(id, 0.0)
                RETURN TRUE
        ENDFUNCTION

        FUNCTION Effect_Play%: id%, volume#=BLANK, pan#=BLANK
                LOCAL ex%
                ex = self.Effect_Find(id)
                IF ex < 0 THEN RETURN FALSE
                IF volume = BLANK THEN volume = self.effects[ex].volume
                IF    pan = BLANK THEN    pan = self.effects[ex].pan
                self.effects[ex].channel = PLAYSOUND(id, pan, 1.0)//_volume_effects * volume)
                LOG("Effect_Play: [" + id + "]")
                RETURN TRUE
        ENDFUNCTION

        FUNCTION Effect_IsPlaying%: id%
                LOCAL ex%
                ex = self.Effect_Find(id)
                IF ex < 0 THEN RETURN FALSE
                RETURN SOUNDPLAYING(self.effects[ex].channel)
        ENDFUNCTION

        FUNCTION Effect_Find%: id%
                LOCAL ex%
                FOR ex = 0 TO BOUNDS(self.effects[], 0) - 1
                        IF self.effects[ex].id = id THEN RETURN ex
                NEXT
                RETURN BLANK
        ENDFUNCTION

        FUNCTION Sound_Mute%:
                self.Music_Volume(0.0)
                HUSH
                RETURN TRUE
        ENDFUNCTION

        FUNCTION Sound_GetNextId%: b_reset% = FALSE
                STATIC id% = 1000
                IF b_reset = TRUE THEN id = 0
                INC id
                RETURN id
        ENDFUNCTION
ENDTYPE

FUNCTION LOG: message$, add_linefeed% = TRUE, show_time% = TRUE
        STATIC datetime% = -1                                                                   // Log timer
        LOCAL elapsed#                                                                                  // How much time has elapsed since program start (or manual reset)
        IF datetime < 0 THEN datetime = GETTIMERALL()                   // Initialize log timer if not already set
        IF message$ = "RESET" THEN datetime = GETTIMERALL()             // Manually reset log timer
        elapsed = (GETTIMERALL() - datetime) / 1000.0
        ?IFDEF WIN32
                IF show_time = TRUE THEN DEBUG "[" + FORMAT$(8, 3, elapsed) + "] "
                DEBUG message$
                IF add_linefeed THEN DEBUG "\n"
        ?ELSE
                INLINE
                        STDOUT(message_Str);
                ENDINLINE
        ?ENDIF
ENDFUNCTION
 
« Last Edit: 2013-Jan-21 by Slydog »
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1773
    • View Profile
    • Homepage
please define step 1 and 2 further please
If you have a look at the post above yours, he already specified step 1 and 2 by doing them for you :-)

Offline blackout12

  • Mc. Print
  • *
  • Posts: 39
    • View Profile
Code: GLBasic [Select]
SETCURRENTDIR ("Media")



LOADSPRITE "person1.bmp" ,0

LOADSPRITE "bullet.bmp" ,1

LOADSPRITE "Desert.bmp" ,2





WHILE TRUE

MOUSESTATE mx, my, b1, b2

DRAWRECT 0,0,640, 480,RGB(255,255,255)

DRAWSPRITE 0, 100,100

DRAWSPRITE 1, mx, my

    IF b1 = TRUE THEN
   
DRAWSPRITE  2, 0,0

SHOWSCREEN

WEND
  this is my code, all it does is if you click, it loads a new image, how would I make it so that it only loads the image when i click on "person1"?

Offline Sokurah

  • Mr. Polyvector
  • ***
  • Posts: 177
    • View Profile
this is my code, all it does is if you click, it loads a new image, how would I make it so that it only loads the image when i click on "person1"?
No, you currently already load all the images. What you want to say is "what do you need to do to show another image".

Here's a bit of pseudo code to get you going.

Quote
Load image1
Load image2
Repeat
   thisvariable=1
   if imagecollide (mouse, image) then thisvariable=2
   if thisvariable=1 then showimage image1
   if thisvariable=2 then showimage image2
Until something

..it's really all there is to it. ;)
« Last Edit: 2013-Feb-13 by Sokurah »
Website: Tardis remakes / Mostly remakes of Arcade and ZX Spectrum games. All freeware. :-)
Twitter: Sokurah