Computer Science Canada

Dragonball Z Project

Author:  Prince Pwn [ Wed Jan 17, 2007 6:29 pm ]
Post subject:  Dragonball Z Project

I started my final project a couple days ago. I'm trying to figure out how to shoot my "energy ball" using a procedure without having a delay, so I can move the same time it is shooting.

Lots of the code may seem a bit messed up, but I am least worried about that right now. Some is there for further use.

Turing:

View.Set ("graphics:700;400;offscreenonly")

%%% Types %%%
type Data :
    record
        Pic, LeftPic, RightPic, PowerUpLeft, PowerUpRight, FacingLeftSS1, FacingRightSS1 : int
        X, Y, MovingRight, MovingLeft, Speed, DuckRightSS1, DuckLeftSS1, PowerLevel : int
        ShootingRightSS1, ShootingLeftSS1, KickRightSS1, KickLeftSS1 : int
        PunchLeftSS1, PunchRightSS1 : int
        RequiredSS1 : int
    end record

var stick : boolean := true

%%% Data %%%
var Broly : Data
var Default : Data

%%% Variables Needed %%%
var keys : array char of boolean
var firstReached : int := 0
var SS1 : boolean := false
var increasePower : int := 1000
var ballSpeed : int := 10
var Floor : int := 50
var charge : int
var direction : string := "right"
var font : int := Font.New ("Comic Sans MS:30")
var powerFont : int := Font.New ("Comic Sans MS:15")

%%% Pictures / Data %%%
var PowerUp := Pic.FileNew ("powerUp.bmp")
var energyBall := Pic.FileNew ("energyBall.bmp")
%var backgroundPic := Pic.FileNew ("Background.jpg")

Broly.LeftPic := Pic.FileNew ("Broly/brolyFacingLeft.bmp")
Broly.RightPic := Pic.FileNew ("Broly/brolyFacingRight.bmp")
Broly.PowerUpLeft := Pic.FileNew ("Broly/brolyPowerUpLeftSS1.bmp")
Broly.PowerUpRight := Pic.FileNew ("Broly/brolyPowerUpRightSS1.bmp")
Broly.FacingLeftSS1 := Pic.FileNew ("Broly/brolyFacingLeftSS1.bmp")
Broly.FacingRightSS1 := Pic.FileNew ("Broly/brolyFacingRightSS1.bmp")
Broly.MovingRight := Pic.FileNew ("Broly/brolyRightSS1.bmp")
Broly.MovingLeft := Pic.FileNew ("Broly/brolyLeftSS1.bmp")
Broly.DuckRightSS1 := Pic.FileNew ("Broly/brolyDuckRightSS1.bmp")
Broly.DuckLeftSS1 := Pic.FileNew ("Broly/brolyDuckLeftSS1.bmp")
Broly.ShootingLeftSS1 := Pic.FileNew ("Broly/brolyShootingLeftSS1.bmp")
Broly.ShootingRightSS1 := Pic.FileNew ("Broly/brolyShootingRightSS1.bmp")
Broly.KickRightSS1 := Pic.FileNew ("Broly/brolyKickRightSS1.bmp")
Broly.KickLeftSS1 := Pic.FileNew ("Broly/brolyKickLeftSS1.bmp")
Broly.PunchRightSS1 := Pic.FileNew ("Broly/brolyPunchRightSS1.bmp")
Broly.PunchLeftSS1 := Pic.FileNew ("Broly/brolyPunchLeftSS1.bmp")

Default.Pic := Broly.RightPic
Default.X := 50
Default.Y := Floor
Default.PowerLevel := 0
Default.RequiredSS1 := 0
Default.Speed := 1


process Sfx (directory : string)
    Music.PlayFile (directory)
end Sfx
fork Sfx ("Sounds/Dragon Ball Z Theme.mp3")

procedure Refresh
    %Pic.Draw (backgroundPic, 0, 0, picCopy)
    Font.Draw ("Broly's Power Level: " + intstr (Default.PowerLevel), 100, maxy - 50, powerFont, brightred)
    Font.Draw (intstr (charge), 10, 10, font, black)
    Pic.Draw (Default.Pic, Default.X, Default.Y, picMerge)
end Refresh

procedure EnergyBall (power : int, col : int)
    Default.PowerLevel -= power
    if direction = "right" then
        for i : Default.X .. maxx by ballSpeed
            Refresh
            Pic.Draw (energyBall, 55 + i, Default.Y + 75, picMerge)
            View.Update
            cls
        end for
    elsif direction = "left" then
        for decreasing i : Default.X .. 0 - Pic.Width (energyBall) * 2 by ballSpeed
            Refresh
            Pic.Draw (energyBall, i, Default.Y + 75, picMerge)
            View.Update
            cls
        end for
    end if
end EnergyBall

charge := 0
loop
    Input.KeyDown (keys)
    %charge := parallelget
    Refresh
    if keys ('a') or charge = 104 then
        Default.X -= Default.Speed
        Default.Pic := Broly.LeftPic
    elsif keys ('d') or charge = 88 then
        Default.X += Default.Speed
        Default.Pic := Broly.RightPic
    end if
    if keys ('w') then
        Default.Y += Default.Speed
    elsif keys ('s') then
        Default.Y -= Default.Speed
    end if

    if keys ('q') or charge = 248 or keys (KEY_UP_ARROW) then
        if direction = "right" then
            Default.Pic := Broly.PowerUpRight
        elsif direction = "left" then
            Default.Pic := Broly.PowerUpLeft
        end if
        Pic.Draw (PowerUp, Default.X - 15, Default.Y - 10, picMerge)

        Default.PowerLevel += increasePower
        if Default.PowerLevel > Default.RequiredSS1 then
            SS1 := true
            firstReached += 1
            Default.Speed := 4
            if firstReached = 1 then
                fork Sfx ("Sounds/Kakarotto.wav")
            end if
        end if
    else
        if SS1 then
            %Broly.PowerLevel := Broly.RequiredSS1

            if direction = "right" then
                Default.Pic := Broly.FacingRightSS1
            elsif direction = "left" then
                Default.Pic := Broly.FacingLeftSS1
            end if

        else
            if direction = "right" then
                Default.Pic := Broly.RightPic
            elsif direction = "left" then
                Default.Pic := Broly.LeftPic
            end if
        end if
    end if
    if SS1 and keys ('d') or SS1 and charge = 88 then
        Default.Pic := Broly.MovingRight
        Broly.Speed := 4
    elsif SS1 and keys ('a') or SS1 and charge = 104 then
        Default.Pic := Broly.MovingLeft
        Broly.Speed := 4
    elsif SS1 and keys ('s') and Default.Y <= Floor then
        if direction = "right" then
            Default.Pic := Broly.DuckRightSS1
        elsif direction = "left" and Default.Y <= Floor then
            Default.Pic := Broly.DuckLeftSS1
        end if
        Broly.Speed := 1
    end if

    if SS1 and keys (KEY_RIGHT_ARROW) then
        direction := "right"
        Default.Pic := Broly.KickRightSS1
    elsif SS1 and keys (KEY_LEFT_ARROW) then
        direction := "left"
        Default.Pic := Broly.KickLeftSS1
    elsif SS1 and keys (KEY_DOWN_ARROW) and direction = "right" then
        Default.Pic := Broly.PunchRightSS1
    elsif SS1 and keys (KEY_DOWN_ARROW) and direction = "left" then
        Default.Pic := Broly.PunchLeftSS1
    end if

    if keys (' ') or charge = 112 and Broly.PowerLevel > 1000 then
        if direction = "right" then
            Default.Pic := Broly.ShootingRightSS1
        elsif direction = "left" then
            Default.Pic := Broly.ShootingLeftSS1
        end if
        EnergyBall (increasePower * 10, white)
    end if
   
    if Default.X <= 0 then
        Default.X += Default.Speed
    elsif Default.X >= maxx - Pic.Width (Default.Pic) then
        Default.X -= Default.Speed
    end if
    if Default.Y <= Floor then
        Default.Y += Default.Speed
    elsif Default.Y >= maxy - Pic.Height (Default.Pic) then
        Default.Y -= Default.Speed
    end if

    Pic.Draw (Default.Pic, Default.X, Default.Y, picMerge)
    View.Update
    cls
    %Pic.Draw (backgroundPic, 0, 0, picCopy)
    if keys ('d') or charge = 88 then
        direction := "right"
    elsif keys ('a') or charge = 104 then
        direction := "left"
    end if
end loop

Author:  ericfourfour [ Wed Jan 17, 2007 9:21 pm ]
Post subject:  RE:Dragonball Z Project

Try to think of your problem this way: How does one keep track of the ball's position as it moves in sync with the character.


: