Jump to content



0

How to create a solid object in Batari Basic?


6 replies to this topic

#1 JorgeLiborinho OFFLINE  

JorgeLiborinho

    Space Invader

  • 17 posts
  • Location:Americana SP, Brazil

Posted Wed Feb 9, 2011 6:50 PM

What codes I use to leave the playfield solid player does not pass?
Look at the code:

set kernel_options player1colors
set kernel_options pfcolorscolors

player1x = 50
player1y = 50

main

pfcolors:
$80
$82
$84
$86
$88
$8A
$8C
$8E
$8C
$8A
$88
end

playfield:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XX.............XX.............XX
XX.............XX.............XX
XX...XXXXXX....XX....XXXXXX...XX
XX...X....................X...XX
XX...X....................X...XX
XX............................XX
XX.......XX..........XX.......XX
XX.......XXXXXXXXXXXXXX.......XX
XX............................XX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
end


COLUBK = 5

player1:
%01101100
101000
111000
%10111010
%11111110
111000
111000
111000
end

player1color:
$00
$F4
$F4
$88
$98
$F6
$F6
$F6
end

if joy0right then player1x = player1x + 1
if joy0left then player1x = player1x - 1
if joy0up then player1y = player1y - 1
if joy0down then player1y = player1y + 1

drawscreen
goto main

I want to leave the playfield solid, how?
What codes do I use?

#2 Random Terrain ONLINE  

Random Terrain

    Visual batari Basic User

  • 20,918 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Wed Feb 9, 2011 6:54 PM

View Postdiogoandrei, on Wed Feb 9, 2011 2:30 PM, said:

It's really better if you also attach your files in here, so someone can open them up and post a correction or something like that.

By the way, have you checked this thread?

Related links:

How to Attach a File at AtariAge

Code Snippets & Samples for bB Beginners

Collision Detection

Edited by Random Terrain, Wed Feb 9, 2011 6:56 PM.


#3 JorgeLiborinho OFFLINE  

JorgeLiborinho

    Space Invader

  • 17 posts
  • Location:Americana SP, Brazil

Posted Wed Feb 9, 2011 7:28 PM

Here is the game:

File .bas
Attached File  Jogo.bas   1003bytes   22 downloads

File .bin
Attached File  Jogo.bin   4K   37 downloads

I did not know how to attach files.

#4 JorgeLiborinho OFFLINE  

JorgeLiborinho

    Space Invader

  • 17 posts
  • Location:Americana SP, Brazil

Posted Wed Feb 9, 2011 7:49 PM

It did not help much!
I did exactly as told and still did not work!

Look at the codes:

set kernel_options player1colors
set kernel_options pfcolorscolors

player1x = 50
player1y = 50

main

pfcolors:
$80
$82
$84
$86
$88
$8A
$8C
$8E
$8C
$8A
$88
end

playfield:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XX.............XX.............XX
XX.............XX.............XX
XX...XXXXXX....XX....XXXXXX...XX
XX...X....................X...XX
XX...X....................X...XX
XX............................XX
XX.......XX..........XX.......XX
XX.......XXXXXXXXXXXXXX.......XX
XX............................XX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
end


COLUBK = 5

player1:
%01101100
101000
111000
%10111010
%11111110
111000
111000
111000
end

player1color:
$00
$F4
$F4
$88
$98
$F6
$F6
$F6
end

if joy0right then player1x = player1x + 1
if joy0left then player1x = player1x - 1
if joy0up then player1y = player1y - 1
if joy0down then player1y = player1y + 1

drawscreen

if collision(playfield,player1) then a = a + 1

goto main

See also the file .bas!
Attached File  Jogo.bas   1.03K   24 downloads

#5 Random Terrain ONLINE  

Random Terrain

    Visual batari Basic User

  • 20,918 posts
  • Controlled Randomness
    Replay Value
    Nonlinear
  • Location:North Carolina (USA)

Posted Wed Feb 9, 2011 8:54 PM

Here's a quick and kind of primitive way to do collision detection:

Attached File  jogo_2011y_02m_09d_2147t.bas   1.59K   35 downloads

Attached File  jogo_2011y_02m_09d_2147t.bin   4K   28 downloads


As you can see, the simple examples on the bB page are just that, examples. You can't copy "if collision(playfield,player0) then a = a + 1" and paste it into a program and expect anything to happen unless you change it to fit your program.

Edited by Random Terrain, Wed Feb 9, 2011 8:56 PM.


#6 SeaGtGruff OFFLINE  

SeaGtGruff

    River Patroller

  • 4,545 posts
  • Location:Georgia, USA

Posted Wed Feb 9, 2011 10:15 PM

View PostJorgeLiborinho, on Wed Feb 9, 2011 6:50 PM, said:

What codes I use to leave the playfield solid player does not pass?
I haven't tried out your code, but if I understand your question correctly, you want the players to pass behind the playfield rather than in front of it?

To do that you need to turn on bit 2 of the CTRLPF register (i.e., set it to 1).

Note that the CTRLPF register also controls whether the playfield is repeated or reflected, whether the "playfield score mode" is on or off, and the size (i.e., width) of the ball sprite, as follows:

CTRLPF bit 0 = playfield draw mode
off (0) = draw a repeated playfield
on (1) = draw a reflected playfield

CTRLPF bit 1 = playfield score mode
off (0) = draw the playfield using the color in the COLUPF register
on (1) = draw the left half of the playfield using the color in the COLUP0 register, and draw the right half of the playfield using the color in the COLUP1 register

CTRLPF bit 2 = playfield priority
off (0) = draw the players in front of the playfield
on (1) = draw the playfield in front of the players

CTRLPF bits 4 and 5 = ball width
= draw the ball 1 color clock wide
%01 = draw the ball 2 color clocks wide
%10 = draw the ball 4 color clocks wide
%11 = draw the ball 8 color clocks wide

Since batari Basic draws an asymmetrical playfield using a reflected playfield, you should be careful when setting the CTRLPF register to a given value, because you might end up messing up the playfield's appearance by inadvertently setting it to the repeated mode. When you want to change the value of a register that has multiple functions (as the CTRLPF register does), you can either add up the values of all the bits you want to turn on and then set the register to the total, or you can turn the bits on or off individually.

That is, each bit of a byte corresponds to a particular decimal value, as follows:

bit 0 -- off = +0, on = +1
bit 1 -- off = +0, on = +2
bit 2 -- off = +0, on = +4
bit 3 -- off = +0, on = +8
bit 4 -- off = +0, on = +16
bit 5 -- off = +0, on = +32
bit 6 -- off = +0, on = +64
bit 7 -- off = +0, on = +128

If you want a particular bit to be off, don't add its value into the total (i.e., add 0 for that bit). But if you want the bit to be on, then add its value into the total. For example, suppose you want to get the following results:

- Draw a reflected playfield.
- Draw the playfield with the COLUPF color.
- Draw the players behind the playfield (or draw the playfield in front of the players).
- Draw the ball 4 color clocks wide.

To do that you would want bit 0 to be on (+1), bit 1 to be off (+0), bit 2 to be on (+4), bit 4 to be off (+0), and bit 5 to be off (+32), so the total is 1+0+4+0+32 = 37. Thus, you could add the following line of code to your program somewhere before the "drawscreen" command:

   CTRLPF = 37

The other way to do it would be to turn the desired bits on or off individually. For example, if all you really want to do is make the players move behind the playfield, without messing up any of batari Basic's default settings, you could just turn on bit 2 of the CTRLPF register by adding the following line of code to your program somewhere before the "drawscreen" command:

   CTRLPF{2} = 1
Michael

#7 SeaGtGruff OFFLINE  

SeaGtGruff

    River Patroller

  • 4,545 posts
  • Location:Georgia, USA

Posted Wed Feb 9, 2011 10:20 PM

View PostJorgeLiborinho, on Wed Feb 9, 2011 6:50 PM, said:

What codes I use to leave the playfield solid player does not pass?
Er, on the other hand, if you mean you want the playfield to act as an obstacle that the players can't move past, then you want to know about collision detection. (I don't know why I thought you were talking about the playfield priority! Oh well, at least now you know how to do that, too, if you ever want to try it!)

Michael Posted Image




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users