fb:porticula NoPaste
PingPong - Teil3 ...
Uploader: | Kirodema |
Datum/Zeit: | 08.07.2008 23:24:27 |
#define oben chr(255,72)
#define unten chr(255,80)
screenres 800,600
dim shared as integer sw, sh
screeninfo sw, sh
'===============================================================================
' Paddel - Anfang
'===============================================================================
type Paddel
public:
declare constructor()
declare sub drawPaddel(xpos as integer, ypos as Integer)
declare sub movePaddel(richtung as String, ByRef buffer As Byte Ptr)
Declare Sub destroyImg()
private:
as integer xgr, ygr, xpos, ypos
As Byte Ptr ein, aus
end type
constructor Paddel()
this.xgr = 15
this.ygr = 75
ein = ImageCreate(this.xgr + 1, this.ygr + 1)
aus = ImageCreate(this.xgr + 1, this.ygr + 1)
If ein = 0 Or aus = 0 Then
?"speicherreservierung fehlgeschlagen"
If ein Then ImageDestroy ein
If aus Then ImageDestroy aus
Sleep
EndIf
end constructor
sub Paddel.movePaddel(richtung as String, ByRef buffer As Byte ptr)
GET buffer, (this.xpos, this.ypos)-(this.xpos+this.xgr, this.ypos+this.ygr), this.ein
Dim As Integer oldx = this.xpos
Dim As Integer oldy = this.ypos
if richtung = "rauf" Then
ypos -= 5
if ypos < 100 then ypos = 100
drawPaddel(xpos, ypos)
end if
if richtung = "runter" Then
ypos += 5
if (ypos + ygr) > sh then ypos = sh - ygr
drawPaddel(xpos, ypos)
end if
Put this.ein, (oldx, oldy), buffer
end sub
sub Paddel.drawPaddel(xpos as integer, ypos as Integer)
this.xpos = xpos
this.ypos = ypos
line (xpos, ypos) - (xpos + xgr, ypos + ygr),,BF
end Sub
Sub Paddel.destroyImg()
ImageDestroy ein
ImageDestroy aus
End Sub
'===============================================================================
' Paddel - Ende
'===============================================================================
dim as Paddel p1, p2
dim taste as String
Dim bgr As Byte Ptr
bgr = ImageCreate(sw, sh)
line bgr, (0, 100)-(sw, 100)
line bgr, (sw\2, 100) - (sw\2, sh)
circle bgr, (sw\2, 350), 100
Put (0,0), bgr
p1.drawPaddel(50,300)
p2.drawPaddel(sw - 50, 300)
Do
taste = inkey
Put (0, 0), bgr
If taste = oben then p1.movePaddel ("rauf", bgr)
if taste = unten then p1.movePaddel ("runter", bgr)
ScreenSync
loop until taste = chr(27)
ImageDestroy bgr
p1.destroyImg()
p2.destroyImg()
end