Problem mit addelement (3.30)

Anfängerfragen zum Programmieren mit PureBasic.
Benutzeravatar
Milchshake
Beiträge: 166
Registriert: 30.01.2006 17:47
Wohnort: Zwischen dem Sessel und dem Computer

Problem mit addelement (3.30)

Beitrag von Milchshake »

Also
wenn ich das proggram starte,macht es zwei objekte,doch nur eines ist
eine richtige wand.
hier der code

Code: Alles auswählen

;TST 02
InitSprite()
InitKeyboard()
OpenScreen(1024,768,32,"TST 2")

CreateSprite(0,64,64)
  StartDrawing( SpriteOutput(0) )
    Circle(32,32,16,$ff0000)
  StopDrawing()
CreateSprite(2,64,64)
  StartDrawing( SpriteOutput(2))
    Box(2,2,60,60,$aa6666)
  StopDrawing()

Structure Mauer
 x.w
 y.w
 Image.w
EndStructure 
NewList Mauer .Mauer()

lvl = 1
playergo = 0
Repeat
  
  ExamineKeyboard()
  StartDrawing(ScreenOutput())
  FrontColor(225,225,225)
  DrawingMode(1)
  Locate(10,0)
  DrawText(Str(offX))
  Locate(10,10)
  DrawText(Str(offY))
  StopDrawing()
 Gosub iniobj
If lvl = 1
AddElement(Mauer())
Mauer()\x = 64
Mauer()\y = 128
Mauer()\Image = 2

AddElement(Mauer())
Mauer()\x = 64
Mauer()\y = 0
Mauer()\Image = 2

EndIf  

  Gosub steuerung
  Gosub collision
 
  DisplayTransparentSprite(0, offX,offY)


  FlipBuffers()
  ClearScreen(0,0,0)
  
Until KeyboardReleased(#PB_Key_Escape) 





steuerung :
  
  If KeyboardPushed(#PB_Key_Right) And playergo = 0
    offX+64
  playergo = 10
  go = 1
  EndIf
  If KeyboardPushed(#PB_Key_Left) And playergo = 0
    offX-64
  playergo = 10
  go = 2
  EndIf
  If KeyboardPushed(#PB_Key_Up) And playergo = 0
    offY-64
  playergo = 10
  go = 3
  EndIf
  If KeyboardPushed(#PB_Key_Down) And playergo = 0
    offY+64
  playergo = 10
  go = 4
  EndIf
  If offX < 0
  offX = 0
  EndIf  
  If offY < 0
  offY = 0
  EndIf 
  If offy > 704
  offY = 704
  EndIf 
  If offX > 960
  offX = 960
  EndIf 
  playergo - 1
  If playergo < 0
  playergo = 0
  EndIf 
  Return 


collision :
If SpriteCollision(0,offx,offy,Mauer()\Image,Mauer()\x,mauer()\y)
If go = 1 And Mauer()\x = offX And Mauer()\y = offY 
offx - 64
EndIf
If go = 2 And Mauer()\x = offX And Mauer()\y = offY 
offx + 64
EndIf
If go = 3 And Mauer()\x = offX And Mauer()\y = offY 
offy + 64
EndIf
If go = 4 And Mauer()\x = offX And Mauer()\y = offY 
offy - 64
EndIf
EndIf  
 Return
 
 
 iniobj :
 ResetList(Mauer())
  While NextElement(Mauer())
    DisplayTransparentSprite(Mauer()\Image,Mauer()\x, Mauer()\y)
   Wend 
   Return 
Help!!
Hab jetzt PB 4.02
Muhahaha!!!!
Jilocasin
Beiträge: 665
Registriert: 13.05.2006 16:04
Kontaktdaten:

Beitrag von Jilocasin »

so wie ich die sache sehen, müsstest du für jedes element "SpriteCollision" eben einzeln abfragen /:->

//edit:

veränder mal so:

Code: Alles auswählen

collision :
 ResetList(Mauer())
  While NextElement(Mauer())
If SpriteCollision(0,offx,offy,Mauer()\Image,Mauer()\x,mauer()\y)
If go = 1 And Mauer()\x = offX And Mauer()\y = offY
offx - 64
EndIf
If go = 2 And Mauer()\x = offX And Mauer()\y = offY
offx + 64
EndIf
If go = 3 And Mauer()\x = offX And Mauer()\y = offY
offy + 64
EndIf
If go = 4 And Mauer()\x = offX And Mauer()\y = offY
offy - 64
EndIf
EndIf 
Wend
 Return
Bild
Kaeru Gaman
Beiträge: 17389
Registriert: 10.11.2004 03:22

Beitrag von Kaeru Gaman »

lötzinn, sowas mit collision zu machen.
eine einfache koordinaten-abfrage reicht für sowas völlig aus,
zumal du auch bei der kollision alle daten zur verfügung haben musst,
die du für ne koordinaten-abfrage brauchst.

schau auch dort mal rein:
http://www.purebasic.fr/german/viewtopic.php?t=9093
Der Narr denkt er sei ein weiser Mann.
Der Weise weiß, dass er ein Narr ist.
Antworten