Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Street Fighter Game - How to Jump With Sprites?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Lawlly




PostPosted: Thu Dec 20, 2007 1:08 am   Post subject: Street Fighter Game - How to Jump With Sprites?

Alright well I've managed to work sprites and enable walking and punching. Though still, the jumping thing stumps me once again. I'm aware I need to use booleans of course, and I tried 2 methods of jumping though still no luck with sprites.

Btw, I've already created the pictures and sprites for the jumping. I've also created the procedure that does the jump animation called Player1Jump.

And for now I've set the Up and Down arrow keys to only shift the picture, not jump.

So here's my game in its testing stages...



RyuAnimate.rar
 Description:
Controls:

Right Arrow Key- Move Right
Left Arrow Key- Move left

UpArrowKey- Shift Picture Up
DownArrowKey- Shift Picture Down

Spacebar- Punch

Download
 Filename:  RyuAnimate.rar
 Filesize:  30.94 KB
 Downloaded:  174 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Jestar




PostPosted: Thu Dec 20, 2007 9:08 am   Post subject: Re: Street Fighter Game - How to Jump With Sprites?

to jump you would need to change the y co ordinate, instead of the x. so when you press up then...

code:

%moving up
loop
Sprite y = sprite y + 1
exit when sprite y = 5
end loop

%coming back down
loop
sprite y= sprite y - 1
exit when sprite y = 0
end loop


something like that
xdanielx98




PostPosted: Thu Dec 20, 2007 12:17 pm   Post subject: Re: Street Fighter Game - How to Jump With Sprites?

I would really like to help but as I cant see your program I cant tell you for sure what you would have to do... what i would suggest is that you input the fallowing code into your program with the coordinating variables with it, I use this code to animate my sprites but it is rather complicated


    if key (KEY_UP_ARROW) then
    jump := 1
    end if

    if jump = 1 then
    y := round (y3 + velocity * tim * sind (theta) - 0.5 * gravity * tim * tim)
    tim := tim + 1


and for your variables I would suggest that you go with something down these lines



    var velocity, tim, tim2, theta, gravity, x2, y2, x3, y3 : real
    var key : array char of boolean
    var jump : int

    velocity := 2
    tim := 0
    tim2 := 0
    theta := 90
    gravity := 0.02
    y2 := 1
    y3 := 1


so as far as all of this goes, as long as you place it in your program at the right spots, it will give you a very nice looking program that simulates gravity and angles of jumps. Very Happy
Lawlly




PostPosted: Thu Dec 20, 2007 12:39 pm   Post subject: Re: Street Fighter Game - How to Jump With Sprites?

Alright well here's my code if you cannot download.

code:
%***********************
%  Created By: Lawlly  *
%  December, 2007      *
%***********************

%**************************************************************************************************
%*************************************** Variable Declaration *************************************
%**************************************************************************************************

%Ryu Player 1 Punch
var pic1 : int := Pic.FileNew ("RyuPunch1.jpg")
var pic2 : int := Pic.FileNew ("RyuPunch2.jpg")
var pic3 : int := Pic.FileNew ("RyuPunch3.jpg")

%Ryu Player 1 Walk
var PicWalk1 : int := Pic.FileNew ("RyuWalk1.jpg")
var PicWalk2 : int := Pic.FileNew ("RyuWalk2.jpg")
var PicWalk3 : int := Pic.FileNew ("RyuWalk3.jpg")
var PicWalkL1 : int := Pic.FileNew ("RyuWalkL1.jpg")
var PicWalkL2 : int := Pic.FileNew ("RyuWalkL2.jpg")

%Ryu Player 1 Jump

var PicJump1 : int := Pic.FileNew ("RyuJump1.jpg")
var PicJump2 : int := Pic.FileNew ("RyuJump2.jpg")
var PicJump3 : int := Pic.FileNew ("RyuJump3.jpg")

%Ryu Punch Create Sprites
var sprite1 : int := Sprite.New (pic1)
var sprite2 : int := Sprite.New (pic2)
var sprite3 : int := Sprite.New (pic3)

%Ryu Walk Create Sprites
var SpriteWalk1 : int := Sprite.New (PicWalk1)
var SpriteWalk2 : int := Sprite.New (PicWalk2)
var SpriteWalk3 : int := Sprite.New (PicWalk2)
var SpriteWalkL1 : int := Sprite.New (PicWalkL1)
var SpriteWalkL2 : int := Sprite.New (PicWalkL2)

%Ryu Jump Create Sprites
var SpriteJump1 : int := Sprite.New (PicJump1)
var SpriteJump2 : int := Sprite.New (PicJump2)
var SpriteJump3 : int := Sprite.New (PicJump3)

% Declare other variables
var x, y : int := 50
var centered : boolean := false
var chars : array char of boolean

%**************************************************************************************************
%******************************************* Set Sprite Height ************************************
%**************************************************************************************************

%Ryu Player 1 Sprite Height
Sprite.SetHeight (sprite1, 1)
Sprite.SetHeight (sprite2, 1)
Sprite.SetHeight (sprite3, 1)

%Ryu Player 1 Walk Sprite Height
Sprite.SetHeight (SpriteWalk1, 1)
Sprite.SetHeight (SpriteWalk2, 1)
Sprite.SetHeight (SpriteWalk3, 1)

Sprite.SetHeight (SpriteWalkL1, 1)
Sprite.SetHeight (SpriteWalkL2, 1)

%Ryu Player 1 Jump Sprite Height
Sprite.SetHeight (SpriteJump1, 1)
Sprite.SetHeight (SpriteJump2, 1)
Sprite.SetHeight (SpriteJump3, 1)

Sprite.SetPosition (sprite1, x, y, centered)
Sprite.Show (sprite1)

%**************************************************************************************************
%******************************************* Procedure Creation ***********************************
%**************************************************************************************************

proc Player1Punch
    Sprite.Hide (sprite1)

    Sprite.Animate (sprite2, pic2, x, y, centered)
    Sprite.Show (sprite2)
    delay (120)

    Sprite.Animate (sprite3, pic3, x, y, centered)
    Sprite.Hide (sprite2)
    Sprite.Show (sprite3)
    delay (120)

    Sprite.Hide (sprite3)
    Sprite.Show (sprite2)
    delay (120)

    Sprite.Hide (sprite2)
    Sprite.Show (sprite1)
    delay (120)
end Player1Punch

proc Player1Walk
    Sprite.Hide (sprite1)

    Sprite.Animate (SpriteWalk1, PicWalk1, x, y, centered)
    Sprite.Show (SpriteWalk1)
    delay (120)

    Sprite.Animate (SpriteWalk2, PicWalk2, x, y, centered)
    Sprite.Hide (SpriteWalk1)
    Sprite.Show (SpriteWalk2)
    delay (120)

    Sprite.Animate (SpriteWalk3, PicWalk3, x, y, centered)
    Sprite.Hide (SpriteWalk2)
    Sprite.Show (SpriteWalk3)
    delay (120)

    Sprite.Hide (SpriteWalk3)
    Sprite.Show (sprite1)
end Player1Walk

proc Player1WalkL
    Sprite.Hide (sprite1)

    Sprite.Animate (SpriteWalkL1, PicWalkL1, x, y, centered)
    Sprite.Show (SpriteWalkL1)
    delay (120)

    Sprite.Animate (SpriteWalkL2, PicWalkL2, x, y, centered)
    Sprite.Hide (SpriteWalkL1)
    Sprite.Show (SpriteWalkL2)
    delay (120)

    Sprite.Hide (SpriteWalkL2)
    Sprite.Show (sprite1)

end Player1WalkL

proc Player1Jump
Sprite.Hide (sprite1)

Sprite.Animate (SpriteJump1, PicJump1, x, y, centered)
Sprite.Show (SpriteJump1)
delay(120)

Sprite.Animate (SpriteJump2, PicJump2, x, y, centered)
Sprite.Hide (SpriteJump1)
Sprite.Show (SpriteJump2)
delay(120)

Sprite.Animate (SpriteJump3, PicJump3, x, y, centered)
Sprite.Hide (SpriteJump2)
Sprite.Show (SpriteJump3)
delay(120)

Sprite.Hide (SpriteJump3)
Sprite.Show (sprite1)
end Player1Jump

%*************************************************************************************************
%******************************************** Key Controls ***************************************
%*************************************************************************************************

loop
    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) then
        y += 1
        Sprite.SetPosition (sprite1, x, y, centered)
        delay (10)

    elsif chars (KEY_DOWN_ARROW) then
        y -= 1
        Sprite.SetPosition (sprite1, x, y, centered)
        delay (10)

    elsif chars (KEY_RIGHT_ARROW) then
        x += 15

        Sprite.SetPosition (sprite1, x, y, centered)
        Sprite.SetPosition (SpriteWalk1, x, y, centered)
        Sprite.SetPosition (SpriteWalk2, x, y, centered)
        Sprite.SetPosition (SpriteWalk3, x, y, centered)

        delay (10)
        Player1Walk

    elsif chars (KEY_LEFT_ARROW) then
        x -= 15

        Sprite.SetPosition (sprite1, x, y, centered)
        Sprite.SetPosition (SpriteWalkL1, x, y, centered)
        Sprite.SetPosition (SpriteWalkL2, x, y, centered)

        delay (10)
        Player1WalkL

    elsif chars (' ') then
        Player1Punch
    end if
    View.Update
end loop

Sprite.Free (sprite1)
Sprite.Free (sprite2)
Sprite.Free (sprite3)
Sprite.Free (SpriteWalk1)
Sprite.Free (SpriteWalk2)
Sprite.Free (SpriteWalk3)
Sprite.Free (SpriteWalkL1)
Sprite.Free (SpriteWalkL2)
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: