Seite 1 von 1

sechseck statt kreis!

Verfasst: 22.10.2007 22:21
von R4z0r1989
wieso macht mein kreis wenn ich zB. links und oben drücke keinen kreis sondern ein sechseck?

Code: Alles auswählen

; PureBasic Visual Designer v3.95 build 1485 (PB4Code)

Procedure Playerdraw(p_x,p_y,angle)
  p_a_a.f=6.29/360*angle-0.79
  p_x_a.f = 20*Cos(p_a_a.f) + 20*Sin(p_a_a.f)
  p_y_a.f = 20*Sin(p_a_a.f) - 20*Cos(p_a_a.f)
  Circle(p_x, p_y, 10 , $0000FF)
  LineXY(p_x, p_y, p_x+p_x_a.f, p_y+p_y_a.f, $0000FF)
EndProcedure

;- Window Constants
;
Enumeration
  #Window_0
EndEnumeration

;- Gadget Constants
;
Enumeration
  #Image_field
  #String_send
  #Button_send
EndEnumeration

;- Image Plugins

Image0 = CreateImage(0, 500, 500)

Procedure Open_Window_0()
  If OpenWindow(#Window_0, 216, 0, 500, 530, "Chat",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
    If CreateGadgetList(WindowID(#Window_0))
      ImageGadget(#Image_field, 0, 0, 500, 500, Image0)
      StringGadget(#String_send, 10, 500, 420, 20, "")
      ButtonGadget(#Button_send, 440, 500, 50, 20, "send")
      
    EndIf
  EndIf
EndProcedure

Open_Window_0()

Repeat

  If GetAsyncKeyState_(37)
    angle - 1
  EndIf
  If GetAsyncKeyState_(38)
    p_a_a.f=6.29/360*angle-0.79
    p_x_a.f = 1*Cos(p_a_a.f) + 1*Sin(p_a_a.f)
    p_y_a.f = 1*Sin(p_a_a.f) - 1*Cos(p_a_a.f)
    p_x = p_x + p_x_a.f
    p_y = p_y + p_y_a.f
  EndIf
  If GetAsyncKeyState_(39)
    angle + 1
  EndIf
  If GetAsyncKeyState_(40)
    p_a_a.f=6.29/360*angle-0.79
    p_x_a.f = 1*Cos(p_a_a.f) + 1*Sin(p_a_a.f)
    p_y_a.f = 1*Sin(p_a_a.f) - 1*Cos(p_a_a.f)
    p_x = p_x - p_x_a.f
    p_y = p_y - p_y_a.f
  EndIf
  
  StartDrawing(ImageOutput(0))
    Box(0,0,500,500,$FFBABA)
    Playerdraw(p_x,p_y,angle)
  StopDrawing()
  SetGadgetState(#Image_field,ImageID(0))

  Event = WindowEvent() 
    If Event = #PB_Event_CloseWindow 
      Quit = 1 
    ElseIf Event = #PB_Event_Gadget Or Event = #PB_Event_Menu 
    
      Select EventGadget()
    
        Case #Button_send
  
      EndSelect 
    EndIf 
  
    Delay(5)
  
  Until Quit 

Verfasst: 22.10.2007 22:37
von STARGÅTE
weil p_x und p_y auch .f sein MUSSEN, auch wenns keine 0,.. Pixel gibt, aber da du dich ja immer nur im 0,... Pixel bewegst muss es auch .f sein.

PS: das ist kein sechseck sonder ein 8-Eck ... Horizontal, Vertikal, Diagonal

Verfasst: 23.10.2007 01:05
von R4z0r1989
1.Warum wird sind die vier variablen pointu pointo pointl und pointr so unterschiedlich aufgeführt?

2. ich hab schon gemerkt dass ich ein prob mit dem stengel bei der kolisionsabfrage bekomme, aber wie kann ich das trozdem lösen?

Code: Alles auswählen

Procedure Playerdraw(p_x,p_y,angle,Name$)
  p_a_a.f=6.29/360*angle-0.79
  p_x_a.f = 7*Cos(p_a_a.f) + 7*Sin(p_a_a.f)
  p_y_a.f = 7*Sin(p_a_a.f) - 7*Cos(p_a_a.f)
  DrawingMode(1)
  DrawText(p_x-20,p_y-TextWidth(Name$)/2,Name$, $0000FF)
  Circle(p_x, p_y, 5 , $0000FF)
  LineXY(p_x, p_y, p_x+p_x_a.f, p_y+p_y_a.f, $0000FF)
EndProcedure

Enumeration
  #Window_0
EndEnumeration

Enumeration
  #Image_field
  #String_send
  #Button_send
EndEnumeration

Image0 = CreateImage(0, 500, 500)

Procedure Open_Window_0()
  If OpenWindow(#Window_0, 216, 0, 500, 530, "Chat",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
    If CreateGadgetList(WindowID(#Window_0))
      ImageGadget(#Image_field, 0, 0, 500, 500, Image0)
      StringGadget(#String_send, 10, 500, 420, 20, "")
      ButtonGadget(#Button_send, 440, 500, 50, 20, "send")
      
    EndIf
  EndIf
EndProcedure

Open_Window_0()

Name$ = "R4z0r"

Repeat

  If GetAsyncKeyState_(37)
    angle - 1
    motion = 1
  EndIf
  If GetAsyncKeyState_(38)
    p_a_a.f=6.29/360*angle-0.79
    p_x_a.f = 0.2*Cos(p_a_a.f) + 0.2*Sin(p_a_a.f)
    p_y_a.f = 0.2*Sin(p_a_a.f) - 0.2*Cos(p_a_a.f)
    p_x.f = p_x.f + p_x_a.f
    p_y.f = p_y.f + p_y_a.f
    motion = 1
  EndIf
  If GetAsyncKeyState_(39)
    angle + 1
    motion = 1
  EndIf
  If GetAsyncKeyState_(40)
    p_a_a.f=6.29/360*angle-0.79
    p_x_a.f = 0.2*Cos(p_a_a.f) + 0.2*Sin(p_a_a.f)
    p_y_a.f = 0.2*Sin(p_a_a.f) - 0.2*Cos(p_a_a.f)
    p_x.f = p_x.f - p_x_a.f
    p_y.f = p_y.f - p_y_a.f
    motion = 1
  EndIf
  
  If p_x.f < 5
    p_x.f = 5
  ElseIf p_x.f > 495
    p_x.f = 495
  EndIf
  
  If p_y.f < 5
    p_y.f = 5
  ElseIf p_y.f > 495
    p_y.f = 495
  EndIf
  
  StartDrawing(ImageOutput(0))
    pointr = Point(p_x.f+5, p_y.f)
    pointl = Point(p_x.f-5, p_y.f)
    pointu = Point(p_x.f, p_y.f+5)
    pointo = Point(p_x.f, p_y.f-5)
  StopDrawing()
  
  SetGadgetText(#String_send,Str(pointr)+"  "+Str(pointl)+"  "+Str(pointu)+"  "+Str(pointo))
  
  If pointr = $00FF00
    p_x.f - 1
  EndIf
  If pointl = $00FF00
    p_x.f + 1
  EndIf
  If pointu = $00FF00
    p_y.f - 1
  EndIf
  If pointo = $00FF00
    p_y.f + 1
  EndIf
  
  StartDrawing(ImageOutput(0))
    Box(0,0,500,500,$FFBABA)
    Box(50,50,50,50,$00FF00)
    Playerdraw(p_x.f,p_y.f,angle,Name$)
  StopDrawing()
  SetGadgetState(#Image_field,ImageID(0))

  Event = WindowEvent() 
    If Event = #PB_Event_CloseWindow 
      Quit = 1 
    ElseIf Event = #PB_Event_Gadget Or Event = #PB_Event_Menu 
    
      Select EventGadget()
    
        Case #Button_send
  
      EndSelect 
    EndIf 
  
    motion = 0
  
    Delay(5)
    
  Until Quit
Vielen dank im Voraus!