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

Username:   Password: 
 RegisterRegister   
 If there a better way to make a fighting Game moves for characters besides a ton of processes?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
isaiahk9




PostPosted: Sun May 11, 2008 11:18 am   Post subject: If there a better way to make a fighting Game moves for characters besides a ton of processes?

I am making a fighting game for Turing, and I have to make some moves for characters. The best way to do that (of what I can think of is to use a ton of processes. For example :
There are two processes for the characters
In those is the input key for the moves. Each move has its own process
In a move process, there is a process for the animation, a process for the sound and a process for the effect on the enemy

If I have to do that for every move, it will mean a . . . lot of processes.
Does anyone know a better way?
Sponsor
Sponsor
Sponsor
sponsor
Saad




PostPosted: Sun May 11, 2008 11:24 am   Post subject: Re: If there a better way to make a fighting Game moves for characters besides a ton of processes?

Yes, there is a much better way.

Basically what you want to do is put them all together into 1 main loop

Turing:
loop
    %% Update every thing by one frame
    %% Draw everything
end loop


For example
Turing:
View.Set ("offscreenonly")
var x, y := 250
loop
    %% Here is my main update code for one frame
    var keyboardState : array char of boolean
    Input.KeyDown (keyboardState)
    if (keyboardState (KEY_UP_ARROW)) then
        y += 1
    end if
    if (keyboardState (KEY_DOWN_ARROW)) then
        y -= 1
    end if
    if (keyboardState (KEY_RIGHT_ARROW)) then
        x += 1
    end if
    if (keyboardState (KEY_LEFT_ARROW)) then
        x -= 1
    end if

    %% Here is where I draw everything
    Draw.FillOval (x, y, 50, 50, black)
    View.Update
    Time.DelaySinceLast (1)
    cls
end loop
isaiahk9




PostPosted: Sun May 11, 2008 11:50 am   Post subject: RE:If there a better way to make a fighting Game moves for characters besides a ton of processes?

Yeah, Saad that's what I'm doing right now with one character. So I need a process per each character, and then my main question was whether there was a better way to do moves (animation, sound, effect on enemy) than a ton of processes.
Expirant




PostPosted: Sun May 11, 2008 12:11 pm   Post subject: Re: If there a better way to make a fighting Game moves for characters besides a ton of processes?

You should be doing what Saad has shown. To do it with multiple characters, you should have an array of the characters, and instead of just running the one character in that main loop, run the whole array. Here's an example with what Saad did:

Turing:

type Coordinate :
    record
        x : int
        y : int
    end record

var NumCircles : int := 5
var Circles : array 1 .. 5 of Coordinate
for i : 1 .. NumCircles
    Circles (i).x := Rand.Int (10, maxx - 10)
    Circles (i).y := Rand.Int (10, maxy - 10)
end for

View.Set ("offscreenonly")
loop
    Time.DelaySinceLast (10)
    cls
    %% Here is my main update code for one frame
    var keyboardState : array char of boolean
    Input.KeyDown (keyboardState)
    if (keyboardState (KEY_UP_ARROW)) then
        for i : 1 .. NumCircles
            Circles (i).y += 1
        end for
    end if
    if (keyboardState (KEY_DOWN_ARROW)) then
        for i : 1 .. NumCircles
            Circles (i).y -= 1
        end for
    end if
    if (keyboardState (KEY_RIGHT_ARROW)) then
        for i : 1 .. NumCircles
            Circles (i).x += 1
        end for
    end if
    if (keyboardState (KEY_LEFT_ARROW)) then
        for i : 1 .. NumCircles
            Circles (i).x -= 1
        end for
    end if

    %% Here is where I draw everything
    for i : 1 .. NumCircles
        Draw.FillOval (Circles (i).x, Circles (i).y, 10, 10, black)
    end for
    View.Update
end loop


So all animations should be done in this main loop.
Sound is the only thing that should be done using a process.
CodeMonkey2000




PostPosted: Sun May 11, 2008 12:19 pm   Post subject: RE:If there a better way to make a fighting Game moves for characters besides a ton of processes?

For sound you have to use a process. But for animation, you need to remember what frame you are on at each iteration, and draw that frame. Effects is the same deal, remember what frame of the effects you are on. What I would do is make a player class that remembers its own effects and states, and has a single method that draws and computes that character. From here you can do what Expirant did, but in the for loop call the method that computes and draws.
isaiahk9




PostPosted: Sun May 11, 2008 12:21 pm   Post subject: RE:If there a better way to make a fighting Game moves for characters besides a ton of processes?

thanx everyone, that's exactly what i needed.
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  [ 6 Posts ]
Jump to:   


Style:  
Search: