fb:porticula NoPaste
Mein Spielansatz mit logging funktion
Uploader: | flo |
Datum/Zeit: | 15.11.2007 19:26:21 |
'Programmiert von Florian Jung (icq 305-487-969)
'Dieser Code ist zum Testen gedacht... ausschließlich!
'Wenn ihr ihn selbst verwenden wollt, fragt mich bitte per PN oder ICQ
'Fehler postet bitte im Forum ^^
'Achtung: nach ca 15 sekunden ist die log so um die 80 kb groß...
'nach möglichkeit SOFORT den fehler finden und dann beenden,
'wenn euch eure festplatte lieb ist xD
#define false 0
#define true not false
#include "fbgfx.bi"
#define decs declare sub
#define decf declare function
const xlen=24,ylen=24,gravity=75,jump=110
decs FigurZeichnen()
decf deltaT as double
decs xstop
decs ystop
type TPhysics 'Alles was man f�r die
x as double 'Berechnungen braucht:
y as double 'x- und y-Koordinaten,
ax as double 'Beschleunigung in
ay as double 'beide Richtungen
vx as double 'Jetzige und vorherige
vy as double 'Geschwindigkeiten
vxalt as double
vyalt as double
xalt as double
yalt as double
width as integer
height as integer
end type
dim shared Figur as TPhysics
with Figur
.x=600
.y=460
.ax=0
.ay=0
.vx=0
.vy=0
end with
dim as double dT
dim shared as fb.image ptr FigurSprite(1 to 1, 0 to 1)
dim shared as fb.image ptr FigurHG
screenres 800,600,8,2
screenset 1,0
FigurSprite(1,0)=imagecreate (20,20)
FigurSprite(1,1)=imagecreate (20,20)
FigurHG=imagecreate (20,20)
'bload "gfx\test1.bmp", FigurSprite (1,0)
'bload "gfx\test2.bmp", FigurSprite (1,1)
dim shared as byte block(1 to 34, 1 to 25)
dim as byte rstop,lstop,ustop,dstop
dim shared as integer bx,by,obx,oby
by=1
for by=20 to 1 step -1
for bx=21-by to 32-20+by
block (bx,by)=-1
next
?bx,by
'for bx=5 to 10
' block (bx,19)=-1
'next
next
block (15,2)=-1
sleep
open "log.txt" for output as #2
?#2,"x";"y";"c";"FPS","x-koordinate","y-koordinate","vx","vy"
for bx=1 to 34
for by=1 to 25
line(bx*24-24,by*24-24)-step(24,24),7,B
if block (bx,by) then line(bx*24-24,by*24-24)-step(24,24),1,BF else line(bx*24-24,by*24-24)-step(24,24),4,B
next
next
pcopy 1,0
get (Figur.x,Figur.y)-step(19,19),FigurHG
'put (1,1),Figursprite(1,1),pset
dT=deltaT
with Figur
.x=200
.y=200
end with
bx=fix(figur.x/24)+1
by=fix(figur.y/24)+1
obx=bx:oby=by
do
sleep 10
dT=deltaT
FigurZeichnen
if multikey(&h48) and Figur.ay=0 then Figur.ay=gravity:Figur.vy=-jump
if multikey(&h4b) then Figur.vx=-50 else if multikey(&h4d) then Figur.vx=50 else Figur.vx=0
do until inkey="" : loop
with Figur
.vx=.vx+.ax*dT
.vy=.vy+.ay*dT
.xalt=.x
.yalt=.y
.x=.x+(.vxalt+.vx)/2*dT
.y=.y+(.vyalt+.vy)/2*dT
.vxalt=.vx
.vyalt=.vy
bx=fix(fix(.x)/24)+1
by=fix(fix(.y)/24)+1
if bx=obx and by=oby then ?#2," ";" ";" ";
if bx<>obx and by=oby then
xstop
bx=fix(fix(.x)/24)+1
obx=bx
?#2,"*";" ";" ";
elseif bx=obx and by<>oby then
ystop
by=fix(fix(.y)/24)+1
oby=by
?#2," ";"*";" ";
elseif obx <> by and oby <>by then
if bx>obx then
if block (bx+1,by)=-1 and block (bx+1,by-1)=-1 then rstop=true else rstop=false
elseif bx<obx then
if block (bx,by) =-1 and block (bx,by-1)=-1 then lstop=true else lstop=false
end if
if by>oby then
if block(bx,by)=-1 and block (bx+1,by)=-1 then dstop=true else dstop=false
elseif by<oby then
if block(bx,by-1)=-1 and block (bx+1,by-1)=-1 then ustop=true else ustop=false
end if
if (rstop=false and lstop=false and ustop=false and dstop=false) or ((rstop=true or lstop=true) and (ustop=true or dstop=true)) then
if abs(.vx)<abs(.vy) then
?#2," ";" ";"<";
ystop
xstop
else
?#2," ";" ";">";
xstop
ystop
end if
rstop=0:lstop=0:ustop=0:dstop=0
end if
if rstop or lstop then xstop:?#2," ";" ";"x";
if ustop or dstop then ystop:?#2," ";" ";"y";
endif
obx=bx:oby=by
if .ay=0 then
if block(bx,by+1)=0 and block (bx+1,by+1)=0 then .ay=gravity
end if
end with
locate 1,1:?bx,by,figur.vy;" ";,figur.ay;" "
locate 2,1:?fix(1/dT) ; "FPS"
pcopy 1,0
?#2,fix(1/dT),fix(figur.x),fix(figur.y),fix(figur.vx),fix(figur.vy)
'screensync
'vsync
loop
function deltaT as double
static altezeit as double
deltaT=timer-altezeit
altezeit=timer
end function
sub FigurZeichnen
put (Figur.xalt,Figur.yalt-24),FigurHG,pset
get (Figur.x,Figur.y-24)-step(23,23),FigurHG
' put (Figur.x,Figur.y-24),FigurSprite(1,1),or
' put (Figur.x,Figur.y-24),FigurSprite(1,0),and
line(figur.x,figur.y-24)-step(23,23),3,BF
end sub
sub xstop
with Figur
if (Block(bx+1,by) =-1 or Block (bx+1,by-1)=-1) then
.x=bx*24-25
.vx=0:.ax=0:.vxalt=0
bx=fix(fix(.x)/24)+1
end if
if (Block(bx,by) =-1 or Block (bx,by-1)=-1) then
.x=bx*24+1
.vx=0:.ax=0:.vxalt=0
bx=fix(fix(.x)/24)+1
end if
end with
end sub
sub ystop
with figur
if (Block(bx,by-1) =-1 or Block (bx+1,by-1)=-1) and .vy<0 then
.y=by*24
.vy=0:.ay=gravity:.vyalt=0
by=fix(fix(.y)/24)+1
end if
if (Block(bx,by) =-1 or Block (bx+1,by)=-1) and .vy>0 then
.y=by*24-25
.vy=0:.ay=0:.vyalt=0
by=fix(fix(.y)/24)+1
end if
end with
end sub