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

Username:   Password: 
 RegisterRegister   
 Combat Game
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Monojoe




PostPosted: Wed Mar 29, 2006 5:32 pm   Post subject: Combat Game

Ok im new to turing this year so bare with me.

ive been trying to make this 2 player fighting game where each person is on a side (and its a side view game) and has a gun. i have the movement down and im just wondering how i would go about making the guys shoot.

heres my Code so far:

(sorry if theres some variables not doing anyhting thats from trying different things and failing, if anyone has any ideas or tips it would make my life a whole lot easier.)

code:

import weapon in "item.tu"
var P1Posx, P1Fistx, P1Fisty, P1Headx, P1Heady, P2Posx, P2Fistx, P2Fisty, P2Headx,
    P2Heady, Player1Health, Player2Health, P1eye, P2eye,P1body,P2body,Thick1,Thick2,p1b,p2b : int

%Music.PlayFileReturn ("Theme.MID")
%Player 1 Parameters
P1Posx := 50
P1Fistx := P1Posx + 35
P1Fisty := 40
P1Headx := P1Posx
P1Heady := 60
Player1Health := 100000
P1body:=30
Thick1:=20
p1b:=P1Fistx







%Player 2 Parameters
P2Posx := 585
P2Fistx := P2Posx- 35
P2Fisty := 40
P2Headx := P2Posx
P2Heady := 60
Player2Health := 100000
p2b:=P2Fistx
P2body:=30
Thick2:=20
View.Set ("offscreenonly")
loop
    put "Player 1 Health ", Player1Health, "                           Player 2 Health ", Player2Health



    %Player 1 Controls
    var chars : array char of boolean
    Input.KeyDown (chars)
    if chars ('x') then
        P1Posx := P1Posx + 5
        P1Fistx := P1Fistx + 5
    elsif chars ('z') then
        P1Posx := P1Posx - 5
        P1Fistx := P1Fistx - 5
 
        elsif chars (KEY_ALT) then
       
        P1Fisty := P1Fisty - 20
        P1body:=P1body-10
        Thick1:=Thick1-10
        P1Heady:=P1Heady-25
          elsif chars (KEY_SHIFT) then
       
     

    end if

    %Player 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    if chars (KEY_RIGHT_ARROW) then
        P2Posx := P2Posx + 5
        P2Fistx := P2Fistx + 5


    elsif chars (KEY_LEFT_ARROW) then
        P2Posx := P2Posx - 5
        P2Fistx := P2Fistx - 5
   elsif chars (KEY_DOWN_ARROW) then
       
        P2Fisty := P2Fisty - 20
        P2body:=P2body-10
        Thick2:=Thick2-10
        P2Heady:=P2Heady-25
 elsif chars (KEY_CTRL) then
 
 
 
    end if



    if P1Posx >= 257 then
        P1Posx := P1Posx - 5
         P1Fistx := P1Fistx - 5
    end if
    if P2Posx <= 317 then
        P2Posx := P2Posx + 5
          P2Fistx := P2Fistx + 5
    end if


    %Damage Engine Player 1
    if P1Posx + 10 > P2Fistx and P1Posx - 10 < P2Fistx and P2Fisty = 40 then

        Player1Health := Player1Health - 15

    else
        Player1Health := Player1Health

    end if
    %Damage Engine Player 2
    if P2Posx + 10 > P1Fistx and P2Posx - 10 < P1Fistx and P1Fisty = 40 then

        Player2Health := Player2Health - 15

    else
        Player2Health := Player2Health

    end if

    %Player 1 Image
    Draw.FillOval (P1Posx, P1body, 10, Thick1, blue)
    Draw.FillOval (P1Posx, P1Heady, 10, 10, blue)
    Draw.ThickLine (P1Posx, Thick1+10, P1Posx, 0, 10, blue)
    Draw.ThickLine (P1Posx, P1Fisty, P1Fistx, P1Fisty, 10, blue)
    weapon.handgun (P2Fistx, P2Fisty)

    %Player 2 Image
    Draw.FillOval (P2Posx, P2body, 10, Thick2, red)
    Draw.FillOval (P2Posx, P2Heady, 10, 10, red)
    Draw.ThickLine (P2Posx, Thick2+10, P2Posx, 0, 10, red)
    Draw.ThickLine (P2Posx, P2Fisty, P2Fistx, P2Fisty, 10, red)
   
 weapon.handgun2 (P1Fistx, P1Fisty)

    %Player 1 Parameters

    P1Fistx := P1Posx+35
    P1Fisty := 40
    P1Headx := P1Posx
    P1Heady := 60
    Thick1:=20
    P1body:=30
   
    %Player 2 Parameters

    P2Fistx := P2Posx - 35
    P2Fisty := 40
    P2Headx := P2Posx
    P2Heady := 60
P2body :=30
Thick2:=20

    if Player1Health = 0 then
    elsif Player2Health = 0 then
        exit
    end if
    View.Update
    delay (15)
    cls

end loop
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Wed Mar 29, 2006 7:37 pm   Post subject: (No subject)

Hello Monojoe. Please resize your avatar - it's too wide.

On to your code:
Glad to see you have some of the ideas down. Now, you need to streamline that by incorporating Types and Records. Look at the [Turing Walkthrough] for further details.
You say you're new, that's no problem. There's always room for learning.
As for Shooting - this may be a little challenging for you, since it will mean that you'll have to work with elementary objects. Essentially, you'll have a group of variables (packaged in a Record) that will hold information about a 'bullet'. These will include things like its position, speed, direction, etc.
In your main movement loop, you can check for the occurence of a particular key, for instance Space. When it is pressed, you will initiate a sequence of procedures/functions that will create the 'bullet' and each iteration of the loop, some of its properties will change (for instance its position).

Read up on the following topics in the Tutorials:
- Procedures, Functions, Processes (leave the latter alone for now though)
- Records and Types
- Arrays, single-dimensional is fine for now
- View.Update
These topics will take just a short time to read, but will take a while to get used to. The good news is you seem to be thinking in the right way about approaching programming, so just trust your intuition and experiment.

Questions? Post 'em up.
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  [ 2 Posts ]
Jump to:   


Style:  
Search: