Jump to content

# Ricochet

## Recommended Posts

I have been studying bb and reading these forums for my game that I am working on. I kind of have 2 - a standard kernel and a multisprite kernel game for the purpose of practicing and learning code.

I haven't been able to find a thread or example of source code for a sprite/missile/ball ricochet but I am trying to have a sprite basically move one direction depending on the playfield and then when it meets a wall, ricochet in an opposite direction.

I am trying to wrap my brain around this. I feel this is easier than I am making it out to be...

#### Share this post

##### Share on other sites

Similar to this?

randomterrain.com/atari-2600-memories-batari-basic-commands.html#sprite_ball_miss_coll_example

#### Share this post

##### Share on other sites

I just read that and by the description I couldn't quite determine if that is exactly what I was thinking of but I was gonna check it out when I get home.

#### Share this post

##### Share on other sites

Yes. This looks like it is what I was thinking. I will have to do some reading on bits and work to understand the code a little bit better. I know what I have been programming is probably very simplistic but I am going to try and integrate something like this in my game. This will be a good exercise. Thanks!

#### Share this post

##### Share on other sites

Hey 2018 Kevin! I was revisiting this as I started messing with this effect when I first started and when I moved to DPC+ I abandoned this game mechanic since I wasn't really using it in the newer program.  But since I was practicing doing all sorts of things recently, I figured I would give an update to my past self!

I was trying to make a bouncing ball(really missile sprite) in a portion of the playfield but then as playfield pixels are drawn on the screen I wanted the ball to switch direction.  This was the little code I had came up with today as I was playing around with bitwise operations.

```    const _Top = 13
const _Bottom = 74
const _Left = 22
const _Right = 116

missile1height=2
if missile1x<=_Left  then k{2}=0
if missile1x>=_Right then k{2}=1
if missile1y<= _Top then k{3}=0
if missile1y>= _Bottom then k{3}=1
if !k{2} then missile1x=missile1x+1:if missile1x>=_Right && k{2} then missile1y=66:k=k^%00000100
if k{2} then missile1x=missile1x-1:if missile1x<=_Left && !k{2} then missile1y=23:k=k^%00000100
if k{3} then missile1y=missile1y-1:if missile1y>=_Bottom && k{3} then missile1x=25:k=k^%00001000
if !k{3} then missile1y=missile1y+1:    if missile1y<=_Top && !k{3} then missile1x=116:k=k^%000010001
if collision(playfield,missile1) then missile1y=missile1y-2:k=k^%00001100```

I may try to add something in there to give a little bit less predictability if it gets stuck in a rut but I don;t think that would be too much of an issue in what I was programming. It may not be the cleanest or best code in the world, but I am proud of it. Especially since I remember first looking at the sample program and being somewhat lost. Thanks Random Terrain and everyone else who had posted in these forums or who had helped me along the way!

And as an added bonus, my first grader was watching me playing around with this and had a blast asking me to change the value of the constants to see how it impacts the program.  Maybe we have a future homebrewer on our hands!

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

• ### Recently Browsing   0 members

No registered users viewing this page.

×
×
• Create New...