Quote: " Lukas, use Sparky's dll for that. It returns the bounce angle."
yes, but mine is 2d. it have the same graphical feel as the original
here it is:
REM Project: pong
REM Created: 10.08.2006 11:33:16
REM
REM ***** Main Source File *****
REM
Sync On : Sync Rate 60 : hide mouse
type tdata
x as integer
y as integer
height as integer
width as integer
score as integer
ismoving as integer
speed as integer
direction as integer
endtype
global player as tdata
global enemy as tdata
global ball as tdata
ball.x = 320-(ball.width/2)
ball.y = 240-(ball.height/2)
enemy.y = 240-(enemy.height/2)
player.y = 240-(player.height/2)
ball.speed = 2
ball.ismoving = 0
makeMedia()
set text font "system" : set text size 72
_paused=1
Do
if _paused=0
` player physics
player.x = screen width()-40
inc player.y, (downkey()-upkey())*1
if player.y <= 5 then player.y = 5
if player.y >= (screen height()-1)-55 then player.y = (screen height()-1)-55
` enemy physics
if ball.ismoving = 1
enemymid = enemy.y+(enemy.height/2)
if enemymid < ball.y then inc enemy.y, 1
if enemymid > ball.y then dec enemy.y, 1
endif
enemy.x = 40
if enemy.y <= 5 then enemy.y = 5
if enemy.y >= (screen height()-1)-55 then enemy.y = (screen height()-1)-55
` ball physics
if ball.ismoving = 0
ball.x = 320-(ball.width/2)
ball.y = 240-(ball.height/2)
if spacekey()=1
ball.ismoving = 1
ball.direction = rnd(3)
if ball.direction = 0 then ball.direction = wrapvalue( 45 )
if ball.direction = 1 then ball.direction = wrapvalue( 315 )
if ball.direction = 2 then ball.direction = wrapvalue( 225 )
if ball.direction = 3 then ball.direction = wrapvalue( 135 )
endif
else
if ball.y < ball.height then ball.direction = wrapvalue( ball.direction *-1 ) : ball.y = 10
if ball.y > (screen height()-1)-ball.height then ball.direction = wrapvalue( ball.direction *-1 ) : : ball.y = 465
ball.x = ball.x + cos( ball.direction ) * ball.speed
ball.y = ball.y + sin( ball.direction ) * ball.speed
if ball.x <= (enemy.x+10)
if (ball.y >= enemy.y and ball.y <= (enemy.y+enemy.height)) or (ball.y+ball.height >= enemy.y) and (ball.y+ball.height < enemy.y+enemy.height)
ball.direction = 180 - ball.direction
ball.x = (enemy.x+20)
endif
endif
if (ball.x-ball.width) >= (player.x-10)
if (ball.y >= player.y and ball.y < player.y+player.height) or (ball.y+ball.height >= player.y and ball.y+ball.height < player.y+player.height)
ball.direction = 180 - ball.direction
playmid = player.y+(player.height/2)
if playmid < ball.y then ball.direction = ball.direction - sqrt( (playmid-ball.y)^2 )
if playmid > ball.y then ball.direction = ball.direction + sqrt( (playmid-ball.y)^2 )
ball.x = (player.x-20)
endif
endif
if ball.x < 35 then ball.ismoving = 0 : player.score = player.score + 1
if ball.x > screen width()-35 then ball.ismoving = 0 : enemy.score = enemy.score + 1
endif
` update
Paste Image 4, 0, 0
Paste Image 1, player.x, player.y
Paste Image 2, enemy.x, enemy.y
Paste Image 3, ball.x, ball.y
center text 160, 0, str$( enemy.score )
center text 480, 0, str$( player.score )
else
paste image 100, 0, 0
endif
` help
if controlkey() and _latch=0
_latch=1
if _paused=1 then _paused=0 else _paused=1
endif
if controlkey() = 0 then _latch=0
Sync : Loop
Function makeMedia()
rem Paddle
cls 0 : ink rgb( 255, 255, 255 ), 0
box 0, 0, 10, 50
get image 1, 0, 0, 10, 50
get image 2, 0, 0, 10, 50
player.height = 50
enemy.height = 50
rem Background
cls 0
ink rgb( 255, 255, 255 ), 0 : box 0, 0, screen width()-1, screen height()-1
ink rgb( 000, 000, 000 ), 0 : box 5, 5, screen width()-6, screen height()-6
ink rgb( 255, 255, 255 ), 0
for x = 1 to 40
line 320, (x*15)-10, 320, (x*15)
next x
get image 4, 0, 0, 640, 480
rem Ball
cls 0 : ink rgb( 255, 255, 255 ), 0
box 0, 0, 10, 10
get image 3, 0, 0, 10, 10
ball.height = 10
ball.width = 10
rem Help Screen
cls 0
ink rgb( 255, 255, 255 ), 0 : box 100, 100, 540, 380
ink rgb( 000, 000, 000 ), 0 : box 105, 105, 535, 375
ink rgb( 255, 255, 255 ), 0
center text 320, 150, "Pong"
center text 320, 200, "control key - show/hide this message"
center text 320, 215, "up key - move paddle up"
center text 320, 230, "down key - move paddle down"
center text 320, 245, "space key - start game when ball freeze"
center text 320, 300, "programmed by Lukas W (www.lukasw.com)"
center text 320, 315, ""
get image 100, 0, 0, 640, 480
EndFunction
come to think of it,
this is my first 2d game in darkbasic/dbpro
Gil,
i've been uh... busy.. it's not like i am avoiding you or popr at all or anything like that
no seriously, i think i forgot that we had a forum, i do that once in a while.
and i have work and my band, and other projects of my own.
basically i am just waiting for *that* moment when i want to do something cool in dbp/popr.