(Vain) neljä suuntainen objecti.

Voit pyytää apua ohjelmointiongelmiin täältä.
Post Reply
phons
Guru
Posts: 1056
Joined: Wed May 14, 2008 10:11 am

(Vain) neljä suuntainen objecti.

Post by phons »

Eli siis semmoinen objekti jolla on vain neljä suuntaa eli jos painan ylös-näppäintä niin se katsoo sinne ja liikku sinne ja jos taas alas se katsoo alas ja likkuu sinne päin ja jne. Ongelma on siinä että en vaan oikein saanut tommosta tehtyä. Apuja!!! :|
Image
phons
Guru
Posts: 1056
Joined: Wed May 14, 2008 10:11 am

Re: (Vain) neljä suuntainen objecti.

Post by phons »

Ai niin ei tarvii tehä mitään semmost et jos painaa samaan aikaan vasen- ja alas-näppäintä niin se liikkuu viistosti alas ja vasemmalle. Mut kunhan saan sen kattomaan niihin suuntin. :|
Image
koodaaja
Moderator
Moderator
Posts: 1583
Joined: Mon Aug 27, 2007 11:24 pm
Location: Otaniemi - Mikkeli -pendelöinti

Re: (Vain) neljä suuntainen objecti.

Post by koodaaja »

"tehä" :o Ei (esimerkki)koodi ole mikään oleusarvo.

Ensin lataat objektin. Laita pyörimisarvoksi vähintään neljä, sillä pitäisi jo toimia. Sitten tarkistat jokaisen nuolinäppäimen. Jos näppäintä painetaan, käännetään rotateobjectilla objekti oikeaan kulmaan ja liikutetaan sitä joko moveobjectilla tai translateobjectilla.
Koodiapina
Forum Veteran
Posts: 2396
Joined: Tue Aug 28, 2007 4:20 pm

Re: (Vain) neljä suuntainen objecti.

Post by Koodiapina »

Pikasesti väännettyä purkkaa. Käyttää kuvia (Vihaan objekteja). Koodi siis estää, että vinoittain ei voi mennä.

Code: Select all

 
    Dim dirx    ' Suunta
    Dim diry
    
    plx = 10    ' Sijainti
    ply = 10
    
    Dim rot(4)
    löl = LoadImage("media/car.bmp")
    
    For i = 1 To 4
        rot(i) = CloneImage(löl)
        RotateImage rot(i),90*i
    Next i
    
    dirx = 1

    While True
        If KeyHit(cbkeyleft) Or KeyHit(cbkeyright)
            If dirx <> (KeyHit(cbkeyright)-KeyHit(cbkeyleft)) Then
                dirx = (KeyHit(cbkeyright)-KeyHit(cbkeyleft))
                diry = 0
            Else
                plx = plx + dirx
            EndIf 
        ElseIf KeyHit(cbkeyup) Or KeyHit(cbkeydown)
            If diry <> (KeyHit(cbkeydown)-KeyHit(cbkeyup)) Then
                diry = (KeyHit(cbkeydown)-KeyHit(cbkeyup))
                dirx = 0
            Else
                ply = ply + diry
            EndIf 
        EndIf 
        If dirx = 1 Then
            DrawImage rot(4),plx*16,ply*16
        ElseIf dirx = -1
            DrawImage rot(2),plx*16,ply*16
        ElseIf diry = 1
            DrawImage rot(1),plx*16,ply*16
        ElseIf diry = -1
            DrawImage rot(3),plx*16,ply*16
        EndIf 
        DrawScreen 
    Wend 
koodaaja
Moderator
Moderator
Posts: 1583
Joined: Mon Aug 27, 2007 11:24 pm
Location: Otaniemi - Mikkeli -pendelöinti

Re: (Vain) neljä suuntainen objecti.

Post by koodaaja »

Grandi wrote:Pikasesti väännettyä purkkaa.
Pikaisesti väännetty vähempi purkkaisa näkemys.

Code: Select all

car = LoadImage("Media\car.bmp")

x = 200
y = 150

Dim rot(3)

For i = 0 To 3
    rot(i) = CloneImage(car)
    RotateImage rot(i), 90*i
Next i

While True
    
    If KeyHit(205) Then
        If dir<>0 Then dir = 0 Else x = x + 20
    ElseIf KeyHit(208) Then
        If dir<>1 Then dir = 1 Else y = y + 20
    ElseIf KeyHit(203) Then
        If dir<>2 Then dir = 2 Else x = x - 20
    ElseIf KeyHit(200) Then
        If dir<>3 Then dir = 3 Else y = y - 20
    EndIf
    
    DrawImage rot(dir), x, y    
    
    DrawScreen
Wend
KeyHitit voi vaihtaa KeyDowneiksi, jos ei tykkää rämpyttämisestä.
phons
Guru
Posts: 1056
Joined: Wed May 14, 2008 10:11 am

Re: (Vain) neljä suuntainen objecti.

Post by phons »

Okei joo ihan hyvä mutta toivoin kyllä objekteja... :roll:
Image
koodaaja
Moderator
Moderator
Posts: 1583
Joined: Mon Aug 27, 2007 11:24 pm
Location: Otaniemi - Mikkeli -pendelöinti

Re: (Vain) neljä suuntainen objecti.

Post by koodaaja »

Selitin sinulle kyllä, kuinka se hoituu objekteilla. Et sinä muiden koodeja käyttämällä opi itse tekemään mitään, mutta väännän nyt jotain.

Code: Select all

car = LoadObject("Media\car.bmp", 4)

While True
    
    If KeyDown(205) Then
        RotateObject car, 0
        MoveObject car, 5
    ElseIf KeyDown(200) Then
        RotateObject car, 90
        MoveObject car, 5
    ElseIf KeyDown(203) Then
        RotateObject car, 180
        MoveObject car, 5
    ElseIf KeyDown(208) Then
        RotateObject car, 270
        MoveObject car, 5
    EndIf
    
    DrawScreen
Wend
phons
Guru
Posts: 1056
Joined: Wed May 14, 2008 10:11 am

Re: (Vain) neljä suuntainen objecti.

Post by phons »

Juu tein itekkin objekteilla ton. En vaan sanonu siit mittää. :oops:
Image
phons
Guru
Posts: 1056
Joined: Wed May 14, 2008 10:11 am

Re: (Vain) neljä suuntainen objecti.

Post by phons »

Kiitos paljon kaikille auttajille. ;)
Image
Post Reply