Hi,
sorry for the long wait, been a little busy lately, anyhoo, les get on to moving the ball around the screen.
First of all I'm just going to mention a little about variables, you can give a variable any value you want but even the slightest difference can make all the difference. When moving our ball we want it to go fast enough to be a challenge for the player but not so fast you can never get to it. I find a good speed is 0.75 if you want to use a decimal (0.75, 1.435., 78.123 etc) the name of the variable has to be followed by a #
We want to move our ball so first of all we need to make variables for its x and y positions, place this piece of code with your other varibles outside of the loop.....
ball_x#=100, ball_y#=100
You can see here I've added a # to the end of the variable names because I plan on increasing these by a decimal number.
You now need to add these variabls to the sprite command just like we did for the bat/paddle, so change......
to......
sprite 6,ball_x#,ball_y#,6
sprite 6,ball_x#,ball_y#,6
This is just the same as we did for the bat/paddle, I am telling the computer to associate ball_x# and ball_y# with the ball sprite.
Now we actually want to see the ball moving. For the bat/paddle we only wanted it to move if one of the arrow keys was pressed, which is why we used the IF command, we want the ball to always be moving so in the loop we put......
ball_x#=ball_x#+0.75
ball_y#=ball_y#+0.75
We don't put an IF command for this, whenever the computer sees this it will move the ball 0.75 right and 0.75 up no matter what is happening.
Finally we need to remind the computer that ball_x# and ball_y# are connected to the ball, just like we did with the bat/paddle, put.....
sprite 6,ball_x#,ball_y#,6
near the end of your code.
Your completed code should now look something like this.....
set display mode 800,600,32
backdrop on
color backdrop rgb(0,0,0)
player_x=50
player_y=240
ball_x#=100
ball_y#=100
load image "player_bat.bmp",1
sprite 1,player_x,player_y,1
load image "enemy_bat.bmp",2
sprite 2,750,240,2
load image "horizontal_wall_top.png",3
sprite 3,0,30,3
load image "horizontal_wall_bottom.png",4
sprite 4,0,570,4
load image "vertical_wall.png",5
sprite 5,400,30,5
load image "ball.bmp",6
sprite 6,ball_x#,ball_y#,6
rem start loop
do
ball_x#=ball_x#+0.75
ball_y#=ball_y#+0.75
rem move bat up when upkey is pressed
if upkey()=1 and player_y>0 then player_y=player_y-1
rem move bat down when downkey is pressed
if downkey()=1 and player_y<580 then player_y=player_y+1
rem remind computer that player_y belongs to sprite 1
sprite 1,player_x,player_y,1
sprite 6,ball_x#,ball_y#,6
rem end loop
loop
Run your code and you can see the ball move up diagonally, delete the
ball_y#=ball_y#+0.75 command and see what happens, you should then be able to work out what happens if you delete the
ball_x#=ball_x#+0.75 command and why.
If you need help with any of this just say. In the next tut we'll concentrate on stopping the ball from passing through the walls.
Formely code2kill
To tell you the truth, I'm just glad I DON'T enjoy playng The Sims.
the
play2kill fan club