So I haven't programmed BASIC since the Commodore days. Lately I've been tinkering with UDK and NWN2 scripting, along with doing 3d models and making short animated films.
I started with the simple Pong game and after 2 days here is what I have. I think I've commented it pretty good. Thanks to the community for all the help on the forums.
//////////////////////
////ball variables////
//////////////////////
BallPosX# = 0.0 //for the left-right position - 0 to 90
BallPosY# = 0.0 //for the up-down position - 0 to 90
BallDirX# = 300.0 //current direction and speed in the X direction
BallDirY# = 300.0 //current direction and speed in the Y direction
paddle1Y# = 300.0 //variable for paddle 1 up-down poistion
paddle2Y# = 300.0 //variable for paddle 2 up-down poistion
score1 = 0 //player 1 score
score2 = 0 //player 2 score
movingright =1
movingdown =1
GOSUB _Init
GOSUB _Sprites
hide_sprites()
GOSUB _menu
show_sprites()
CLS
SET TEXT OPAQUE
//////////////////////
////Main Game Loop////
//////////////////////
Do
Gosub _readkeys
Gosub _player1move
Gosub _player2move
Gosub _ballmove
Gosub _collision
Gosub _scores
Gosub _checkwin
sync
Loop
End
///////////////////////////////////////
////player input for moving paddles////
///////////////////////////////////////
_readkeys:
/////////////////////////
////1 player controls////
/////////////////////////
if playeramount = 1
if upkey()=1
inc paddle1Y#, -10
if paddle1Y# <= 0
paddle1Y# = 0
endif
endif
if downkey()=1
inc paddle1Y#, 10
if paddle1Y# >= 470
paddle1Y# = 470
endif
endif
///////////////
////AI Code////Very Simple!!!!!
///////////////
if BallDirX# >= 300
paddle2Y#=curvevalue(BallDirY#,paddle2Y#,AILevel)+0.10
endif
endif ////1 player controls end////
/////////////////////////
////2 player controls////
/////////////////////////
if playeramount = 2
if upkey()=1 //1st player controls
inc paddle1Y#, -10
if paddle1Y# <= 0
paddle1Y# = 0
endif
endif
if downkey()=1
inc paddle1Y#, 10
if paddle1Y# >= 470
paddle1Y# = 470
endif
endif
if keystate(17)=1 //2nd player controls
inc paddle2Y#, -10
if paddle2Y# <= 0
paddle2Y# = 0
endif
endif
if keystate(31)=1
inc paddle2Y#, 10
if paddle2Y# >= 470
paddle2Y# = 470
endif
endif
endif
RETURN
////////////////////////////////////////
////updates player 1 paddle movement////
////////////////////////////////////////
_player1move:
SPRITE 2, 50, paddle1Y#, 2
RETURN
////////////////////////////////////////
////updates player 2 paddle movement////
////////////////////////////////////////
_player2move:
SPRITE 3, 730, paddle2Y#, 2
RETURN
/////////////////////////////
////updates ball movement////
/////////////////////////////
_ballmove:
SPRITE 1, BallDirX#, BallDirY#, 1
RETURN
///////////////////////
////collision check////
//////////////////////
_collision:
if BallDirX# <= 0 //if it hits the left wall
inc score2, 1
movingright=1
movingleft =0
endif
if BallDirX# >= 780 //if it hits the right wall
inc score1, 1
movingleft=1
movingright =0
endif
if BallDirY# >=600 //if it hits the bottom wall
movingdown=0
movingup=1
endif
if BallDirY# <=0 //if it hits the top wall
movingdown=1
movingup=0
endif
///////////////////////////////////////////////
////check for sprite collision with paddles////
///////////////////////////////////////////////
if SPRITE HIT(1, 2)=1
movingright=1
movingleft =0
endif
if SPRITE HIT(1, 3)=1
movingright=0
movingleft =1
endif
//////////////////////////
////ball movement code////
//////////////////////////
if movingright = 1 then inc BallDirX#,10
if movingleft = 1 then inc BallDirX#,-10
if movingdown = 1 then inc BallDirY#,10
if movingup = 1 then inc BallDirY#,-10
RETURN
////////////////////////////////////
////updating and printing scores////
////////////////////////////////////
_scores:
TEXT 10,10,"Player 1:"
TEXT 120,10,Str$(score1)
TEXT 650,10,"Player 2:"
TEXT 760,10,Str$(score2)
RETURN
////////////////////////////
////shows the start menu////
////////////////////////////
_menu:
//load sound "media\music\Belmont Theme.wav",1
//play sound 1
sync
SET TEXT FONT "verdana"
SET TEXT SIZE 30
SET TEXT TRANSPARENT
while playeramount <1 or playeramount >2
cls
LOAD BITMAP "title_screen.png",0
SET CURSOR 300,500
INPUT "How many players:"; playeramount
endwhile
while difficulty <1 or difficulty >3
cls
LOAD BITMAP "title_screen.png",0
SET CURSOR 275,500
INPUT "Choose a difficulty setting 1-3:"; difficulty
endwhile
if difficulty = 1 then AILevel = 10
if difficulty = 2 then AILevel = 8
if difficulty = 3 then AILevel = 2
RETURN
//////////////////////////
////check for a winner////
//////////////////////////
_checkwin:
if score1 >= 10
while returnkey() <>1
cls
hide_sprites()
TEXT 150,200,"Player 1 Wins!!! Congrats!!! Hit ENTER to quit"
sync
endwhile
END
endif
if score2 >= 10
while returnkey() <>1
cls
hide_sprites()
TEXT 150,200,"Player 2 Wins!!! Congrats!!! Hit ENTER to quit"
sync
endwhile
END
endif
RETURN
/////////////////////////////////////////
////sets up screen, sync, camera, etc////
/////////////////////////////////////////
_Init:
set display mode 800,600,32
color backdrop rgb(0,0,0)
sync on
sync rate 60
hide mouse
autocam off
RETURN
///////////////////////////
////sets up our sprites////
///////////////////////////
_Sprites:
LOAD IMAGE "ball.png",1
LOAD IMAGE "paddle.png",2
SET SPRITE 1, 1, 1
SET SPRITE 2, 1, 1
SET SPRITE 3, 1, 1
SCALE SPRITE 1, 20 //shrink the ball down
RETURN
/////////////////
////functions////
/////////////////
function show_sprites()
SHOW ALL SPRITES
endfunction
function hide_sprites()
HIDE ALL SPRITES
endfunction