user123
Anmeldungsdatum: 13.02.2009 Beiträge: 11
|
Verfasst am: 13.02.2009, 18:05 Titel: Collision beschleunigen |
|
|
Den unteren Code habe ich aus einem Forum und mal mit zusätzlichen Körpern erweitert und er überprüft den ganzen Screen auf 800x600 für die Collision. Erstmal, es ist ein tolles Ding und jetzt schon schnell.
1. Wie kann ich bei meiner Demo die Farben auslesen? Die Farben bei der Collison möchte ich auch als Print ausgeben.
2. Wie könnten welche Programmzeilen noch mit ASM-Inline schneller machen?
Danke.
Code: |
screenres 800,600,32,2
SCREENSET 1,0
TYPE obj
x AS INTEGER
y AS INTEGER
w AS INTEGER
h AS INTEGER
ox AS INTEGER
oy AS INTEGER
END TYPE
DIM AS obj ufo,baum
WITH ufo
.x=0
.y=0
.w=140
.h=140
END WITH
WITH baum
.x=0
.y=0
.w=800
.h=600
END WITH
DIM AS UINTEGER PTR img_ufo,img_baum
img_ufo = IMAGECREATE(ufo.w,ufo.h)
img_baum= IMAGECREATE(baum.w,baum.h)
PAINT img_ufo,(2,2),RGB(255,0,255)
CIRCLE img_ufo,(19,19),15,RGB(100,100,255),,,,F
PAINT img_baum,(2,2),RGB(255,0,255)
CIRCLE img_baum,(44,44),40,RGB(0,160,0),,,,F
line img_baum,(0,0)-(10,150),rgb(160,160,0),bf
circle img_baum,(244,244),70,rgb(0,160,255),,,,F
line img_baum,(100,200)-(130,440),rgb(160,255,0),bf
circle img_baum,(544,144),70,rgb(0,0,255),,,,F
line img_baum,(450,200)-(500,460),rgb(160,255,0),bf
line img_baum,(600,100)-(700,200),rgb(255,0,0),bf
DIM AS INTEGER mx,my,osX,osY,px,py,collision
DIM AS UINTEGER pufo,pbaum
DO
GETMOUSE mx,my
ufo.x=mx-20
ufo.y=my-20
'die Hochkomma bitte entfernen
PUT (baum.X,baum.y),img_baum,TRANS
PUT (ufo.X,ufo.y),img_ufo,TRANS
If(((ufo.x >= baum.x And ufo.x <= baum.x+baum.w) Or _
(baum.x >= ufo.x And baum.x <= ufo.x+ufo.w)) And _
((ufo.y >= baum.y And ufo.y <= baum.y+baum.h) Or _
(baum.y >= ufo.y And baum.y <= ufo.y+ufo.h))) Then
ufo.ox=0
ufo.oy=0
baum.ox=0
baum.oy=0
osX=ufo.w
osY=ufo.h
If(osX > baum.w) Then osX = baum.w
If(osY > baum.h) Then osX = baum.h
If ufo.x < baum.x Then
ufo.ox = baum.x - ufo.x
If baum.x+baum.w > ufo.x+ufo.w Then osX=ufo.x+ufo.w-baum.x
Else
baum.ox = ufo.x - baum.x
If ufo.x + ufo.w > baum.x + baum.w Then osX=baum.x+baum.w-ufo.x
End If
If(ufo.y < baum.y) Then
ufo.oy = baum.y - ufo.y
If(baum.y+baum.h > ufo.y+ufo.h) Then osY=ufo.y+ufo.h-baum.y
Else
baum.oy = ufo.y - baum.y
If(ufo.y + ufo.h > baum.y + baum.h) Then osY=baum.y+baum.h-ufo.y
End If
'POINT liefert hier (32bpp) einen Farbwert mit ALPHA-channel(hat mit Transparenz zu tun) vorne dran
'also &HFFFF00FF
'aus diesem Grund sind puo und pbaum auch UINTEGER
FOR px=0 TO osX-1
FOR py=0 TO osY-1
pufo=POINT(ufo.ox + px,ufo.oy + py,img_ufo)
pbaum=POINT(baum.ox + px,baum.oy + py,img_baum)
IF pufo<>&HFFFF00FF AND pbaum<>&HFFFF00FF AND collision=0 THEN collision=1
NEXT py
NEXT px
IF collision THEN
LOCATE(3,1):PRINT "!!!!!! Kollision !!!!!"
END IF
collision=0
ELSE
LOCATE(1,1):PRINT " "
LOCATE(3,1):PRINT " "
END IF
screencopy
cls
LOOP UNTIL INKEY <>""
IMAGEDESTROY img_ufo
IMAGEDESTROY img_baum
END
|
|
|