Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Foreign Languages > German Forum
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Ball in ein Kreis

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-21-2012, 06:27 PM
Filippo's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Location: Schwäb. Gmünd, Germany
Posts: 977
Awards Showcase
Beta Tester 
Total Awards: 1
Default Ball in ein Kreis

Hallo,

ich weis es sollte eigendlich einfach sein, aber ich bekomme es einfach nicht in!
Ich möchte das der schwarze Punkt nur innerhalb vom rote Kreis bleibt, bzw. den rote Kreis nicht übersteigt.
Weißt jemanden wie das funktioniert?

Code:
'AccelBall
Sub Process_Globals
    
Dim Sensor As PhoneSensors
End Sub

Sub Globals
    
Dim can As Canvas
    
Dim ballx,bally,ballsize As Float
    
Dim targetx,targety As Float
    
    
Dim pnlAuge As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
    pnlAuge.Initialize(
"")
    pnlAuge.Color=
Colors.White
    Activity.AddView(pnlAuge, 
100dip,100dip,100dip,100dip)

    Sensor.Initialize(Sensor.TYPE_ORIENTATION)
    can.Initialize(pnlAuge)

    ballx=pnlAuge.Width/
2 : bally=pnlAuge.Height/2
    ballsize=
20dip : targety=bally : targetx=ballx

End Sub

Sub Activity_Resume
    Sensor.StartListening(
"Sensor")
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    Sensor.StopListening
End Sub

Sub Sensor_SensorChanged(Values() As Float)
    targety=targety-Values(
1)
    
If targety<ballsize Then targety=ballsize
    
If targety>(pnlAuge.Height-ballsize) Then targety=(pnlAuge.Height-ballsize)

    targetx=targetx-Values(
2)
    
If targetx<ballsize Then targetx=ballsize
    
If targetx>(pnlAuge.Width-ballsize) Then targetx=(pnlAuge.Width-ballsize)

    
Log("Sensor: " & Values(0) & " ;" & Values(1) & " ;" & Values(2))

    can.DrawColor(
Colors.White)
    ballx=ballx+(targetx-ballx)/
2.0
    bally=bally+(targety-bally)/
2.0
    can.DrawCircle(pnlAuge.Width/
2,pnlAuge.Height/2,pnlAuge.Width/2,Colors.Red,False,2.0)
    can.DrawCircle(ballx,bally,ballsize,
Colors.Black,True,0.0)
    pnlAuge.Invalidate
    
Log(ballx & ";" & bally)
End Sub
Ciao,
Filippo
Attached Images
File Type: jpg sensor-test.jpg (10.1 KB, 3 views)
__________________
PPC: MDA Pro, 2GB SD
Device: HTC Desire , Android 2.2
______________________
Reply With Quote
  #2 (permalink)  
Old 01-21-2012, 07:53 PM
klaus's Avatar
Basic4ppc Expert
 
Join Date: Oct 2007
Location: Fully, Switzerland
Posts: 4,463
Awards Showcase
Forum Contributer Beta Tester Competition Winner 
Total Awards: 3
Default

Hallo Filippo.
Versuche diesen Code:
Code:
    can.DrawColor(Colors.White)
ballx=ballx+(targetx-ballx)/
2.0
bally=bally+(targety-bally)/
2.0
r = 
Sqrt((ballx - pnlAuge.Width/2) * (ballx - pnlAuge.Width/2) + (bally - pnlAuge.Width/2) * (bally - pnlAuge.Width/2))
If r <= pnlAuge.Width/2 - ballsize Then
    can.DrawCircle(pnlAuge.Width/
2,pnlAuge.Height/2,pnlAuge.Width/2,Colors.Red,False,2.0)
    can.DrawCircle(ballx,bally,ballsize,
Colors.Black,True,0.0)
    pnlAuge.Invalidate
End If
Log(ballx & ";" & bally)
Beste Grüsse.
__________________
Klaus
Switzerland

Beginner's Guide / User's Guide
Reply With Quote
  #3 (permalink)  
Old 01-22-2012, 12:17 PM
Filippo's Avatar
Basic4ppc Expert
 
Join Date: May 2007
Location: Schwäb. Gmünd, Germany
Posts: 977
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Hallo Klaus,

vielen Dank für deine Start-Hilfe, aber es funktioniert immer noch nicht wie es sein soll.
Ich habe jetzt auch noch ein paar Zeilen geändert, aber auch ohne Erfolg.
Code:
Sub Process_Globals
    
Dim Sensor As PhoneSensors
End Sub

Sub Globals
    
Dim can As Canvas
    
Dim ballx,bally,ballsize As Float
    
Dim targetx,targety As Float
    
Dim maxRadius As Float
    
Dim mitteX,mitteY As Int
    
    
Dim pnlAuge As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
    pnlAuge.Initialize(
"")
    pnlAuge.Color=
Colors.White
    Activity.AddView(pnlAuge, 
100dip,100dip,100dip,100dip)

    Sensor.Initialize(Sensor.TYPE_ORIENTATION)
    can.Initialize(pnlAuge)

    ballx=pnlAuge.Width/
2 : bally=pnlAuge.Height/2
    ballsize=
20dip : targety=bally : targetx=ballx
    maxRadius=(pnlAuge.Width/
2) - (ballsize / 2)
    mitteX=pnlAuge.Width/
2 : mitteY=pnlAuge.Height/2

End Sub

Sub Activity_Resume
    Sensor.StartListening(
"Sensor")
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    Sensor.StopListening
End Sub

Sub Sensor_SensorChanged(Values() As Float)
    
Dim r1,r2 As Float
    
    targety=targety-Values(
1)
    r1= 
Sqrt(Power(Abs(targetx)-mitteX,2) + Power(Abs(targety)-mitteY,2))
    
If r1 <= maxRadius Then
        ballx=ballx+(targetx-ballx)/
2.0
        bally=bally+(targety-bally)/
2.0    
    
Else
        targety=targety+Values(
1)
    
End If
    
    targetx=targetx-Values(
2)
    r2= 
Sqrt(Power(Abs(targetx)-mitteX,2) + Power(Abs(targety)-mitteY,2))
    
If r2 <= maxRadius Then
        ballx=ballx+(targetx-ballx)/
2.0
        bally=bally+(targety-bally)/
2.0
    
Else
        targetx=targetx+Values(
2)
    
End If
    
    can.DrawColor(
Colors.White)
    can.DrawCircle(mitteX,mitteY,mitteX,
Colors.Red,False,2.0)
    can.DrawCircle(ballx,bally,ballsize,
Colors.Black,True,0.0)
    pnlAuge.Invalidate

    
Log("targetx: " & targetx & " ;targety=" & targety)
    
Log("maxRadius=" & maxRadius & "; r1=" & r1 & "; r2=" & r2)
    
End Sub
__________________
PPC: MDA Pro, 2GB SD
Device: HTC Desire , Android 2.2
______________________
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Know It Ball (magic 8 ball) mistermentality Basic4android Share Your Creations 0 03-07-2011 05:46 PM
Linie im Kreis rotieren lassen Bobbes German Forum 2 12-05-2009 08:40 PM
Ball and skewness with sprite.dll VoDB Questions (Windows Mobile) 2 11-30-2009 07:01 PM
How to make a ball move round a circle? Stellaferox Questions (Windows Mobile) 5 01-07-2009 03:53 PM
Ball bouncing against the screensides Stellaferox Share Your Creations 0 05-18-2007 12:28 PM


All times are GMT. The time now is 06:50 PM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0