Log In  


Can someone please help me. I am following lazy devs' breakout tutorial and I am having trouble
getting the bricks to work. I think the problem is my definition of the box variables but if I remove them the game breaks.



I have narrowed it down to the definition of the y. if I remove every other box variable it works but if I remove y it breaks


Please post your code in TEXT so we can run it here, @barking_dog. As the sourcecode you posted is only a picture with pixels it's difficult to ascertain the problem this way.


function game_update()

wall_collision()
movement()

local nextx, nexty

nextx=ball.x+ball.dx
nexty=ball.y+ball.dy

if
pad_collision(nextx,nexty,pad.x,pad.y,pad.w,pad.h)
then

if
  collision_advanced(ball.x,ball.y,ball.dx,ball.dy,pad.x,pad.y,pad.w,pad.h)

then
ball.dx=-ball.dx
score+=1
sfx(0)
else
ball.dy=-ball.dy
score+=1
sfx(0)
end

end

if
brick.v==true
and
pad_collision(nextx,nexty,brick.x,brick.y,brick.w,brick.h)
then

if
  collision_advanced(ball.x,ball.y,ball.dx,ball.dy,brick.x,brick.y,brick.w,brick.h)

then
ball.dx=-ball.dx
score+=10
brick.v=false
sfx(0)
else
ball.dy=-ball.dy
score+=10
brick.v=false
sfx(0)
end

end

if
lives==0
then
state="over"
sfx(4)
end

ball.x=nextx
ball.y=nexty

end

function pad_collision(box_x,box_y,box_w,box_h)

local nextx, nexty

nextx=ball.x+ball.dx
nexty=ball.y+ball.dy

if
nexty-ball.r > box_y+box_h
then
return false
end

if
nexty+ball.r < box_y
then
return false
end

if
nextx-ball.r > box_x+box_w
then
return false
end

if
nextx+ball.r < box_x
then
return false
end

return true

end


You're almost there, @barking_dog.

Please repost one more time putting [ code ] before you paste your source-code and
[ /code ] after you paste your source-code.

Leave out the spaces I've included above.

Then your code will look like this.

cls()
pset(64,64,7)

With proper tabulation, spacing, and it will ignore BBS commands.
Then the rest of us can go through it properly.


function pad_collision(box_x,box_y,box_w,box_h)

  local nextx, nexty

  nextx=ball.x+ball.dx
  nexty=ball.y+ball.dy

  if
    nexty-ball.r > box_y+box_h
  then
    return false
  end

  if
    nexty+ball.r < box_y
  then
    return false
  end

  if
    nextx-ball.r > box_x+box_w
  then
    return false
  end

  if
    nextx+ball.r < box_x
  then
    return false
  end

  return true

end

function game_update()

 wall_collision()
 movement()

 local nextx, nexty

 nextx=ball.x+ball.dx
 nexty=ball.y+ball.dy

 if
   pad_collision(nextx,nexty,pad.x,pad.y,pad.w,pad.h)
 then

    if
      collision_advanced(ball.x,ball.y,ball.dx,ball.dy,pad.x,pad.y,pad.w,pad.h)
   then
     ball.dx=-ball.dx
     score+=1
     sfx(0)
   else
     ball.dy=-ball.dy
     score+=1
     sfx(0)
   end

 end

 if
   brick.v==true
 and
   pad_collision(nextx,nexty,brick.x,brick.y,brick.w,brick.h)
 then

    if
      collision_advanced(ball.x,ball.y,ball.dx,ball.dy,brick.x,brick.y,brick.w,brick.h)
   then
     ball.dx=-ball.dx
     score+=10
     brick.v=false
     sfx(0)
   else
     ball.dy=-ball.dy
     score+=10
     brick.v=false
     sfx(0)
   end

 end

 if
   lives==0
 then
   state="over"
   sfx(4)
 end

 ball.x=nextx
 ball.y=nexty

end

Their you go sorry


Alright, good deal so far, @barking_dog. One more thing. I need the sprites that go with this.

In immediate mode type: save @clip then in a reply to this message, press CTRL+V.

Then we'll have the whole picture for your cart. The code listed online and the actual cart.

I also recommend you download LazyDev's own finished breakout and post it the same way here, save @clip and CTRL+V.

With these two codes can see what the difficulty is.


Cart #tudoniraki-0 | 2022-11-13 | Code ▽ | Embed ▽ | No License


Cart #fehudekupe-0 | 2022-11-13 | Code ▽ | Embed ▽ | No License


1

Just from glancing at them, @barking_dog, it appears as if the two codes are radically different from each other.

Here is what I suggest. Go to archive the code you've been working on. Don't worry about it for now.

Watch the tutorial again, this time, use HIS (LazyDev) code and confirm everything he is talking about is already in his own code which does work, I tried it.

Years ago I didn't just start in to writing machine-language from scratch. No, I took existing machine-language code and subroutines and and twiddled with them.

Changing a few values here and there. The first I did was Apple Invaders. I found all kinds of interesting things.

  1. Increase number of tanks I had to start with.
  2. Speed up the player's movement.
  3. Stop the invaders from shooting.
  4. Stop the invaders from descending.
  5. Stop the invaders from moving at all.
  6. Mess up the graphics.
  7. Do something bad in the code and the whole thing crashes, where I reloaded it and started messing with the code again.

Once I began to understand what changes I was making, it was then I very carefully started to write my own machine-code.

By watching his tutorial and matching it to his own code, you are bound to discover the very difficulty you are having in your own code - and you'll learn a lot more than just jumping in feet first. :)



[Please log in to post a comment]