Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
my third game, simple arkanoid
#4
Very nice, very retro Smile

It's kind of hard to get the ball where you want it, lots of waiting. Nothing wrong with that. If I rememeber correctly, that's the way it worked in the good old days too! But I've modified your collision_ball function (player.n7) so that it's possible to aim a little.

If the ball bounces on the left part of the paddle, the ball goes left. The more left on the paddle, the more left it goes. Same thing with the right side. If the ball hits the absolute center of the paddle, the ball goes straight up. That's how I usually make the controls for breakout games.

I don't think it's the "spin" thing you asked for, because I didn't quite understand what you meant.

Code:
    player.collision_ball = function()
        if collision_rect(this.x,this.y,this.Width,this.Height,this.ball.x,this.ball.y+this.ball.velocity_y,this.ball.Width,this.ball.Height)
            play sound sound_bounce,0.7
            ' Marcus.
            'this.ball.velocity_y = abs(this.ball.velocity_y)
            ' Calculate the current speed.
            speed = sqr(this.ball.velocity_x^2 + this.ball.velocity_y^2)
            ' Distance in x from ball center to paddle center, dx will be ~[-0.5..0.5].
            dx = (this.ball.x + this.ball.Width/2 - (this.x + this.Width/2))/this.Width
            ' set dy to -0.4, so that you get a good range of possible bounces. You can
            ' experiment with different values. Lower values mean wider range of angles, it should
            ' be less than 0.5 though.
            dy = -0.4
            ' Create new velocities by normalizing (dx dy). That is, recalculate the length of
            ' (dx dy) so that it is 1 but still points in the exact same direction.
            k = 1/sqr(dx*dx + dy*dy)
            dx = k*dx
            dy = k*dy
            ' Now multiply dx and dy with speed, so that the speed of the ball doesn't change from
            ' what it was before.
            dx = dx*speed
            dy = dy*speed
            ' Set ball velocity (while testing this I noticed that the ball is moving with its
            ' negative direction, which made me confused :) ).
            this.ball.velocity_x = -dx
            this.ball.velocity_y = -dy
        endif
    endfunc
Reply


Messages In This Thread
my third game, simple arkanoid - by aliensoldier - 03-17-2024, 03:24 PM
RE: my third game, simple arkanoid - by johnno56 - 03-17-2024, 05:42 PM
RE: my third game, simple arkanoid - by Marcus - 03-18-2024, 06:19 PM
RE: my third game, simple arkanoid - by johnno56 - 03-18-2024, 10:22 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)