IGNORED

# A lack of "and" statements - subbing in constants instead?

## Recommended Posts

In the absence of an "and" statement I think I am stuck without using variables or constants, but I'm not totally clear on whether or not fixed coordinates can be used as variables or constants for missile placement.

Where I'm at is that I want a missile to appear on the playfield, when it collides with the player, it moves to a different location, when touched again it returns to the original.

In my mind it would look like:

if collision(missile0.player0) AND missile0x = 1 : missile0y = 1 then missile0x = 2 : missile0y = 2
if collision(missile0.player0) AND missile0x = 2 : missile0y = 2 then missile0x = 1 : missile0y = 1

Obviously that isn't possible with bB (or I just havent seen it / figured it out), but I keep spinning wheels on, how do I define those fixed positions as constants?

Is it better to do:

``` const _c_M01X = 1
const _c_M01Y = 1
const _c_M02X = 2
const _c_M02Y = 2

Or is it better to do:
const _c_position1 = missile0x = 1 : missile0y = 1
const _c_position2 = missile0x = 2 : missile0y = 2

Thinking that once thats ironed out it might be something like:

if collision(missile0.player0) _c_position1 then _c_position2
if collision(missile0.player0) _c_position2 then _c_position1

Has anyone ever done something similar? The idea is that the player will be forced to constantly move around the map to gain points by picking up the missile.
```
##### Share on other sites

'AND' and 'OR' do exist in batariBasic... they're just done using C-style syntax instead:

AND is done using &&

OR is done using ||

------

For your missile position implementation, it would probably be better to use data statements to create an array of coordinates.  And then have the IF/THEN collision statement increment the array index and load the coordinates that way.

Like so:

```
if collision(missile0,player0) then gosub MoveItem

;------------------------------------------
;---- somewhere else, place the following:

;--- define some object positions (4 locations, indexed by 0..3)
data itemXpos
10, 10, 50, 50
end
data itemYpos
10, 50, 10, 50
end

dim itemPosIdx = z
MoveItem
;-- move to next index (next location)
itemPosIdx = itemPosIdx + 1
if itemPosIdx = 4 then itemPosIdx = 0

;-- load missile0 object with new position
missile0x = itemXpos[itemPosIdx]
missile0y = itemYpos[itemPosIdx]
return```

• 1
• 1
##### Share on other sites

Omg I feel really silly…thank you! Looking forward to getting back into it tomorrow, thank you again!

##### Share on other sites

17 hours ago, splendidnut said:

'AND' and 'OR' do exist in batariBasic... they're just done using C-style syntax instead:

AND is done using &&

OR is done using ||

------

For your missile position implementation, it would probably be better to use data statements to create an array of coordinates.  And then have the IF/THEN collision statement increment the array index and load the coordinates that way.

Like so:

```
if collision(missile0,player0) then gosub MoveItem

;------------------------------------------
;---- somewhere else, place the following:

;--- define some object positions (4 locations, indexed by 0..3)
data itemXpos
10, 10, 50, 50
end
data itemYpos
10, 50, 10, 50
end

dim itemPosIdx = z
MoveItem
;-- move to next index (next location)
itemPosIdx = itemPosIdx + 1
if itemPosIdx = 4 then itemPosIdx = 0

;-- load missile0 object with new position
missile0x = itemXpos[itemPosIdx]
missile0y = itemYpos[itemPosIdx]
return```

That worked for getting the stick to move!

I put the dim in the beginning of the code, followed by an initial xy, and then the array.

I called the subroutine in the main loop and put the subroutine itself right at the end of bank2.

I must've done something wrong with placement or something though bc its throwing the missile/stick way outside of the coordinates in the array. Any thought on why that might be? Im going to continue poking at it.

##### Share on other sites

The arrays (itemXpos, itemYpos) need to be in the same bank as the subroutine, and wherever else they are used.

##### Share on other sites

20 minutes ago, splendidnut said:

The arrays (itemXpos, itemYpos) need to be in the same bank as the subroutine, and wherever else they are used.

Gotcha, I had spaced them out bc I couldnt get anything to appear on screen when I had them all together. Sounds like I need to work on placement more than anything, I really appreciate your help and patience!

##### Share on other sites

45 minutes ago, splendidnut said:

The arrays (itemXpos, itemYpos) need to be in the same bank as the subroutine, and wherever else they are used.

GOT IT!

Thank you again, this has been a really fun learning exercise and now that I have some of the fundamentals down I can get to work on adding little bits and bobs in!

Posting functional maze with lives and objects and enemy here in case it helps anyone else.

@Random Terrain @splendidnut @alfredtdk - thanks for your patience and sample code. I know its not really a full game, but cobbling bits together has been really satisfying.

##### Share on other sites

• 3 weeks later...

Can't  say I've tryed it but if you're just toggling between two positions you should be able to use an exclusive or

something like

```  const toggle_x = M01X ^ M02X
const toggle_y = M01Y ^ M02Y

if collision(missile0, player0) then missile0y = missile0y ^ toggle_y : missile0x = missile0x ^ toggle_x```

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.