Mehrere collisionen mit or??

Übersicht BlitzBasic Beginners-Corner

Neue Antwort erstellen

grafe

Betreff: Mehrere collisionen mit or??

BeitragDo, Dez 04, 2008 22:58
Antworten mit Zitat
Benutzer-Profile anzeigen
Der titel sagt eigentlich schon alles kann man mehrere collisionen hintereinander mit or schreiben. bei mir klappt es eben nicht

Code: [AUSKLAPPEN]
      For f.feind= Each feind
      
         If ImagesCollide (shots,xshot,yshot,0,feind,f\feindx,f\feindy,0) Or ImagesCollide(player,mx,my,0,feind,f\feindx,f\feindy,0) Or ImagesCollide (shots,x1shot,y1shot,0,feind,f\feindx,f\feindy,0) Or ImagesCollide (shots,x1shot,y1shot,0,feind,f\feindx,f\feindy,0)
            
            points1=points1+shotspeed/10
            kabumvarif=1
                     
         EndIf
      
         If kabumvarif >10
            Delete f.feind
            kabumvarif=0
         EndIf
      Next


bei mir funktioniert die kollision immer nur beim ersten Evil or Very Mad
SpaceThreat 3D Multiplayer Spaceshooter
 

da_poller

BeitragDo, Dez 04, 2008 23:03
Antworten mit Zitat
Benutzer-Profile anzeigen
zur not frage alle 3 kollsisionen ab und setze x(oder eine andere variable) auf 1 wenn kollision vorhanden danach

if x=1 then blabla..

grafe

BeitragDo, Dez 04, 2008 23:09
Antworten mit Zitat
Benutzer-Profile anzeigen
aber ich brauche eine möglichst sparsame variante(bcc)
SpaceThreat 3D Multiplayer Spaceshooter

Xeres

Moderator

BeitragDo, Dez 04, 2008 23:11
Antworten mit Zitat
Benutzer-Profile anzeigen
Sind die letzten beiden ImagesCollide nicht identisch?
Win10 Prof.(x64)/Ubuntu 16.04|CPU 4x3Ghz (Intel i5-4590S)|RAM 8 GB|GeForce GTX 960
Wie man Fragen richtig stellt || "Es geht nicht" || Video-Tutorial: Sinus & Cosinus
T
HERE IS NO FAIR. THERE IS NO JUSTICE. THERE IS JUST ME. (Death, Discworld)

grafe

BeitragDo, Dez 04, 2008 23:14
Antworten mit Zitat
Benutzer-Profile anzeigen
ja,
habs verbessert und es geht immer noch nicht...

die ersten zwei collisionen gehen

[edit]

hier mal mein spiel

Code: [AUSKLAPPEN]
Graphics 800,600,0,1

;images
   Global shots=CreateImage(10,10)
   Global feind=CreateImage(20,20)
   Global player=CreateImage(20,30)
   Global explosion=CreateImage(30,30)
   Global sternen=CreateImage(10,10)
   Global strahl=CreateImage(10,1000)
   Global schutz=CreateImage(30,40)
   Global i=CreateImage(10,10)
   Global i1=CreateImage(10,10)
   Global i2=CreateImage(10,10)
   
;--

SetBuffer BackBuffer()



;variablen
   ;player
      x=0
      Global playerx=mx
      Global playery=my
      Global playerda=150
      shoti=0
      Global xshot=0
      Global x1shot=0
      Global x2shot=0
      Global yshot=5
      shotspeed=30
      superstrahl=1000
      suberstrahldown=0
      sperstrahlanzeige=superstrahl/20
      strahlx=-100
      strahly=0
      strahlgibpunkt=0
      collided=0
      pld=0
      ss=1
   ;feind
      feindx=Rnd(0,1000)
      feindy=10
      feindpos=0   
      feindspeed=5
      feindda=1
      Global feindkomm=10000
      Global feindzeit=10000
      Global kabumvarif=0
      
      ;feindschuss
         xfshot=0
         yfshot=0
         feindschuss=0
         
   ;sonstiges
      points=0
      points1=0
      lp=5
      lp1=5
      sternenvari=0
      Global kabumvari=0
      sda=0
      sda1=0


   ;player

   ;timer
      Global feindtim
      Global fshottim
      Global itim
;---------------------

;grafik schuss
   SetBuffer ImageBuffer(shots)
      Color 0,255,0
      Oval 0,0,10,10
;-----------------------------
;grafik player
   SetBuffer ImageBuffer(player)
      Color 0,0,255
      Oval 0,0,20,30
;-----------------------------
;grafik schussnormal
   SetBuffer ImageBuffer(feind)
      Color 255,0,0
      Oval 0,0,20,20
;-----------------------------
;grafik explosion
   SetBuffer ImageBuffer(explosion)
      Color 255,0,0
      Oval 0,0,30,30
      Color 255,255,0
      Oval 5,5,20,20
      Color 255,255,255
      Oval 10,10,10,10
;-----------------------------
;grafik sternen
   SetBuffer ImageBuffer(sternen)
      Color 255,255,255
      Oval 0,0,Rnd(5,15),Rnd(5,15)
;-----------------------------   
;grafik strahler
   SetBuffer ImageBuffer(strahl)
      Color 0,255,0
      Rect 0,0,10,1000
      Color 255,0,0
      Rect 2.5,0,5,1000
;-----------------------
;grafik schutz
   SetBuffer ImageBuffer(schutz)
      Color 0,255,0
      Oval 0,0,30,40,0
      
;grafik i
   SetBuffer ImageBuffer(i)
      Color 255,0,0
      Rect 0,0,10,10,0

;grafik i
   SetBuffer ImageBuffer(i1)
      Color 0,255,0
      Oval 0,0,10,10,0

;grafik i
   SetBuffer ImageBuffer(i2)
      Color 0,0,255
      Oval 0,0,10,10,0
      
SetBuffer BackBuffer()
 


;timer
   Global sternetimer

;types
   Type sterne
      Field sternegrosse
      Field sternespeed
      Field sternex
      Field sterney
      Field sternefarbe
   End Type
   
   Type kabum
      Field kabumx
      Field kabumy
      Field kabumcolor
      Field kabumspeedx
      Field kabumspeedy
   End Type
   
   Type feind
      Field feindx
      Field feindy
      Field feindspeed
      Field feindshotx
      Field feindshoty
      Field feindshotspeed
      Field feindkabumx
      Field feindkabumy
      Field feindkabumcolor
      Field feindkabumspeed
   End Type
   
   Type items
      Field ix
      Field iy
      Field is
      Field im
   End Type
   
   Type s
      Field sx
      Field sy
      Field ssp
      Field sspx
   End Type

;sounds

   blitz=LoadSound("blast.mp3")
   strahls=LoadSound("strahler.mp3")

;--------------------
;hauptschleife
;--------------------
While Not KeyHit(1)
Cls
   
   ; graphicen
   sterneerstellen()
   sterneposition()
   explosiondaten()
   explosionmachen()
   feinddaten()
   feindmachen()
   idata()
   imachen()
   ;variablen

      mx=MouseX()
      my=MouseY()

   ;----------------------------
   
   ;feind
      
      feindpos=feindpos+feindspeed
      
      If feindpos >500 Then
         feindx=feindx-feindspeed
      EndIf
      
      If feindpos <500 Then
         feindx=feindx+feindspeed
      EndIf
      
      If feindpos >1000
         feindpos=0
      EndIf
   ;--------------------------------
   
   ;schuss spieler
   If MouseHit(1)=1 And pld=0 Then
      PlaySound blitz
      yshot = my : xshot=mx
      yshot= my:x1shot=mx
      yshot= my:x2shot=mx
   EndIf



   If superstrahl <2000
      If superstrahldown=0
         superstrahl=superstrahl+shotspeed/2
      EndIf   
   EndIf

   If MouseDown(2) And pld=0 Then
      superstrahldown=1
      SoundVolume strahls,0.5
      
      If superstrahl >1000
         superstrahl=superstrahl-shotspeed
         strahlx=mx+5
         strahly=my-1000
      EndIf   
      
      If superstrahl <1050 And superstrahl >0
         strahlx=-100
         strahly=0
         superstrahl=superstrahl-1000
      EndIf
   EndIf
   
   If Not MouseDown(2)
      SoundVolume strahls,0
   EndIf
   
   If superstrahl <1050
      superstrahlanzeige=0
   EndIf
   
   If superstrahl >1050
      superstrahlanzeige=superstrahl/20
   EndIf

   
   If Not MouseDown(2) Then
      superstrahldown=0
      strahlx=-100
      strahly=0
      strahlgibpunkt=0
   EndIf
   
   For f.feind= Each feind
   If ImagesCollide (strahl,strahlx,strahly,0,feind,f\feindx,f\feindy,0)
      strahlgibpunkt=strahlgibpunkt+shotspeed
      If strahlgibpunkt <60
         Delete f.feind
         points1=points1+shotspeed/10
      EndIf
   EndIf
   Next
   
   
   yshot=yshot-shotspeed
      
   If shot >1
      shot=0
   EndIf
   
   If shot=0
      shoti=0
   EndIf
   
   If shot=1 Then
      xshot=mx
      yshot=my-10
      x1shot=mx
      x2shot=mx
   EndIf
   

   ;schuss
      If ss=1
      DrawImage shots,xshot+5,yshot
      EndIf
      
      If ss=2
      DrawImage shots,xshot,yshot
      DrawImage shots,x1shot+10,yshot
      x1shot=x1shot+shotspeed/2
      EndIf
      
      If ss=3
      DrawImage shots,xshot,yshot
      DrawImage shots,x1shot+10,yshot
      DrawImage shots,x2shot-10,yshot
      x1shot=x1shot+shotspeed/2
      x2shot=x2shot-shotspeed/2
      EndIf
      
      DrawImage strahl,strahlx,strahly
   ;player
      
      For f.feind=Each feind
         
         kollisionzwpf=ImagesCollide (shots,f\feindshotx,f\feindshoty,0,player,mx,my,0)  Or ImagesCollide (feind,f\feindx,f\feindy,0,player,mx,my,0)  And sda=0                                   
            
         If kollisionzwpf=1 And collided=0
            lp=pl-1
            kabumvari=kabumvari+shotspeed/10
            playerda=350
            pld=1
            collided=1   
         ElseIf kollisionzwpf=0 And collided=1
            collided=0
         EndIf
      
      Next
      


      
      If playerda <350
         DrawImage player,mx,my
      EndIf
      
      If sda >0 Or sda1 >0
         DrawImage schutz,mx-5,my-5
      EndIf
      
   ;feind
      
      For f.feind= Each feind
         
         
         
         If ImagesCollide (shots,xshot,yshot,0,feind,f\feindx,f\feindy,0) Or ImagesCollide(player,mx,my,0,feind,f\feindx,f\feindy,0) Or ImagesCollide (shots,x1shot,y1shot,0,feind,f\feindx,f\feindy,0) Or ImagesCollide (shots,x2shot,y2shot,0,feind,f\feindx,f\feindy,0)
            
            points1=points1+shotspeed/10
            kabumvarif=1
            

            
         
         EndIf
      
         If kabumvarif >10
            Delete f.feind
            kabumvarif=0
         EndIf
      Next
      

      
   ;punkte
      
      If points1>0
         points=points+1
      EndIf
      
      If points1>2.1
         points1=0
      EndIf
      
      ;If points=10
      ;   RuntimeError "Du hast gewonnen!!"
      ;EndIf
      
   ;feindschuss

      
      If playerda >349 Then playerda=playerda+shotspeed/10
      
      If playerda >750 Then playerda=0
      
      If playerda <320 Then playerda=playerda+shotspeed/10
      
      If playerda >300 And playerda<320
       playerda=300
       pld=0
       sda=0
      EndIf
      If playerda <300
      sda=1
      pld=0
      EndIf
            
      
   ;items
      
      For d.items=Each items
         
         If d\im=2
            If ImagesCollide (player,mx,my,0,i1,d\ix,d\iy,0) Then
               playerda=-300
               Delete d.items
            EndIf
         EndIf
         

         
         
      Next
   
         
      For d.items=Each items
         If d\im=1
            If ImagesCollide (player,mx,my,0,i,d\ix,d\iy,0) Then
               ss=ss+1
               Delete d.items
            EndIf
         EndIf
      Next
      
      
      
      ;If lp=0 Then
      ;   RuntimeError "Haha"
      ;EndIf
      
   ;sinnloser text
      
      Color 100,100,0
      Rect 0,570,800,30
      Color 1,1,1
      Text 10,570,"punkte = "+points
      Text 200,570,"Lebenspunkte"+lp
      Text 400,570,"Superstrahl = "+superstrahlanzeige,"%"
      Text 600,570,""+ss


Flip
Wend
End


Function sterneerstellen()

   sternetimer=sternetimer+1
   
   If sternetimer >10 Then
      sternetimer=0
   
      info.sterne=New sterne
         info\sternespeed=Rnd (1,10)
         info\sternex=Rnd(0,800)
         info\sterney=-5
         info\sternegrosse=Rnd(2,7)
         info\sternefarbe=Rnd(100,255)
   EndIf


End Function

Function sterneposition()

   For info.sterne=Each sterne
   
      info\sterney=info\sterney+info\sternespeed
   
      Color info\sternefarbe,info\sternefarbe,info\sternefarbe:Oval info\sternex,info\sterney,info\sternegrosse,info\sternegrosse

      If info\sterney >600 Then Delete info.sterne
   
   Next

End Function

Function explosiondaten()
   
   mx=MouseX()
   my=MouseY()
   
   If kabumvari >100 Then kabumvari=0
   
   If kabumvari >0 Then kabumvari=kabumvari+1
   
   If kabumvari >0 And kabumvari <20

      ex.kabum=New kabum
         ex\kabumx=mx
         ex\kabumy=my
         ex\kabumspeedx=Rnd(-10,10)
         ex\kabumspeedy=Rnd(-10,10)
         ex\kabumcolor=Rnd(0,255)
   EndIf
   
   For f.feind=Each feind
   
   ;If kabumvarif =16 Then kabumvarif=0

   If kabumvarif >0  And kabumvarif <17 Then
   kabumvarif=kabumvarif+1

   
      e.kabum=New kabum
         e\kabumx=f\feindx
         e\kabumy=f\feindy
         e\kabumspeedx=Rnd(-10,10)
         e\kabumspeedy=Rnd(-10,10)
         e\kabumcolor=Rnd(0,255)
   EndIf
   Next
End Function

Function explosionmachen()
   
   For ex.kabum= Each kabum
   
      ex\kabumx=ex\kabumx+ex\kabumspeedx
      ex\kabumy=ex\kabumy+ex\kabumspeedy
      
      Color ex\kabumcolor,ex\kabumcolor,100 : Rect ex\kabumx,ex\kabumy,5,5
      
      If ex\kabumx >800 Or ex\kabumx   <0 Or ex\kabumy <0 Or ex\kabumy >600 And kabumvari >30 Then Delete ex.kabum
      
   Next
   
   For e.kabum= Each kabum
   
      e\kabumx=e\kabumx+e\kabumspeedx
      e\kabumy=e\kabumy+e\kabumspeedy
      
      Color e\kabumcolor,e\kabumcolor,100 : Rect e\kabumx,e\kabumy,5,5
      
      If e\kabumx >800 Or e\kabumx <0 Or e\kabumy <0 Or e\kabumy >600  Then Delete e.kabum
      
   Next
   
End Function

Function feinddaten()
   
   If feindkomm >1000
   feindkomm=feindkomm -1
   EndIf
   
   feindzeit=feindzeit+1
   
   feindtim=feindtim+1
   
   If feindtim > feindkomm/50
   
   feindtim=0   
   
      f.feind=New feind
         f\feindx=Rnd (0,800)
         f\feindy=-5
         f\feindspeed=Rnd(5,feindzeit/2000)
         f\feindshotx=f\feindx
         f\feindshoty=f\feindy
         f\feindshotspeed=30
         
   EndIf
         
   If feindkomm <9000 And feindkomm >8990
   Color 255,255,0
   Text 350,290,"Level 2"
   
   EndIf
   
   If feindkomm=8990
   Delay 2000
   EndIf
   
End Function

Function feindmachen()






   
   For f.feind=Each feind
      
      f\feindy=f\feindy+f\feindspeed
      
      DrawImage feind,f\feindx,f\feindy
      
      f\feindshoty=f\feindshoty+f\feindshotspeed
      
      DrawImage shots,f\feindshotx,f\feindshoty

      
      
      If f\feindy >600 Then Delete f.feind
      

   Next
   
   
End Function
   
   
Function idata()

   itim=itim+1
   If itim >400 Then itim=0

   If itim >399
   d.items=New items
      d\ix=Rnd(0,800)
      d\iy=-5
      d\is=Rnd(5,8)
      d\im=Rnd(1,3)
   EndIf
End Function   

Function imachen()

   For d.items=Each items
   
      d\iy=d\iy+d\is
      
   If d\im=1   
      DrawImage i ,d\ix,d\iy
   EndIf   
   
   If d\im=2
      DrawImage i1,d\ix,d\iy
   EndIf
   
   If d\im=3
      DrawImage i2 ,d\ix,d\iy
   EndIf   
   
      
   Next
   
End Function

Function sd()
   
   
   If MouseHit(1) And ss=1
   s.s=New s
   ;If ss=1
      s\sx=MouseX()
      s\sy=MouseY()
      s\ssp=30
      s\sspx=0
   EndIf
   If ss=2
      s\sx=MouseX()
      s\sy=MouseY()
      s\ssp=30
      s\sspx=10
   EndIf
   If ss=3
      s\sx=MouseX()
      s\sy=MouseY()
      s\ssp=30
      s\sspx=-10
   EndIf

End Function

Function sm()
   
   For s.s=Each s
      
      s\sy=s\sy+s\ssp
      s\sx=s\sx+s\sspx
      
      DrawImage shots,s\sx,s\sy
   
   Next
   
End Function
   
   
   
   
   


ist noch ein bischen gross und noch nicht fertig

aber bei dem schuss funktioniert nur ein schuss und nicht 2 und 3

Xeres

Moderator

BeitragDo, Dez 04, 2008 23:33
Antworten mit Zitat
Benutzer-Profile anzeigen
Platzsparender wäre in jedem Falle eine reine Distanzmessung, also Kreis-Kreis Kollision wenn du so willst.

Edit:
Wenn du dir um den Platz Gedanken machst, würde ich mal bei der grauenhaften Benennung von Types und den dazugehörigen Feldern anfangen...
Win10 Prof.(x64)/Ubuntu 16.04|CPU 4x3Ghz (Intel i5-4590S)|RAM 8 GB|GeForce GTX 960
Wie man Fragen richtig stellt || "Es geht nicht" || Video-Tutorial: Sinus & Cosinus
T
HERE IS NO FAIR. THERE IS NO JUSTICE. THERE IS JUST ME. (Death, Discworld)
  • Zuletzt bearbeitet von Xeres am Do, Dez 04, 2008 23:35, insgesamt einmal bearbeitet

grafe

BeitragDo, Dez 04, 2008 23:34
Antworten mit Zitat
Benutzer-Profile anzeigen
wie geht das??

sry bin noch ein noob
SpaceThreat 3D Multiplayer Spaceshooter

Xeres

Moderator

BeitragDo, Dez 04, 2008 23:38
Antworten mit Zitat
Benutzer-Profile anzeigen
Die Distanz ermittelst du mit dem guten alten Pythagoras, ist diese kleiner als die Summe der Radien der Kreise, findet eine Kollision statt.
Tafelwerk und Forensuche bieten da mehr als genügend Infos zu.
Win10 Prof.(x64)/Ubuntu 16.04|CPU 4x3Ghz (Intel i5-4590S)|RAM 8 GB|GeForce GTX 960
Wie man Fragen richtig stellt || "Es geht nicht" || Video-Tutorial: Sinus & Cosinus
T
HERE IS NO FAIR. THERE IS NO JUSTICE. THERE IS JUST ME. (Death, Discworld)

grafe

BeitragDo, Dez 04, 2008 23:45
Antworten mit Zitat
Benutzer-Profile anzeigen
könnte man es nicht so machen:

Code: [AUSKLAPPEN]
if imagescollide(shot,xshot or x1shot or x2shot,yshot,0,feind,f\feindx,f\feindy)
SpaceThreat 3D Multiplayer Spaceshooter

Xeres

Moderator

BeitragFr, Dez 05, 2008 0:13
Antworten mit Zitat
Benutzer-Profile anzeigen
Or, And und Xor sind zur Logischen Verknüpfung und keine Grammatikalischen "Tue das oder das wie es gerade gut passt". Koordinaten so zu Verknüpfen führt zu keinem Sinnvollen Ergebnis.
Win10 Prof.(x64)/Ubuntu 16.04|CPU 4x3Ghz (Intel i5-4590S)|RAM 8 GB|GeForce GTX 960
Wie man Fragen richtig stellt || "Es geht nicht" || Video-Tutorial: Sinus & Cosinus
T
HERE IS NO FAIR. THERE IS NO JUSTICE. THERE IS JUST ME. (Death, Discworld)

Neue Antwort erstellen


Übersicht BlitzBasic Beginners-Corner

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group