
-----------------------------------
Wasabicheese
Wed Apr 29, 2009 12:11 pm

Sprite movement help
-----------------------------------
Im making a zelda game. How do you make it so that link loses health if hes hit by an arrow? The XXXXX part shows where i need help.

%"Legend of Zelda : The Turing Quest" By Ryan Shannon

%Music File
process DoMusic
    loop
        Music.PlayFile ("LostWoods.mp3")
    end loop
end DoMusic
fork DoMusic

% Health Bar
var dmg, hp: int
hp := 8- dmg
dmg := 1

%Movement Input
var x, y : int
x := 100
y := 100
var chars : array char of boolean
loop
    Input.KeyDown (chars)

    if chars (KEY_UP_ARROW) then
        y := y + 6
    end if

    if chars (KEY_RIGHT_ARROW) then
        x := x + 7
    end if

    if chars (KEY_LEFT_ARROW) then
        x := x - 7
    end if

    if chars (KEY_DOWN_ARROW) then
        y := y - 6
    end if

% Health Bar
var dmg, hp: int
hp := 8- dmg
dmg := 1
if XXXXXXX
dmg := dmg +1

%Picture File
var mypic1 : int := Pic.FileNew ("link.bmp")
Pic.Draw (mypic1, x, y, 0)
drawoval (x + 35, y + 23, 4, 4, blue)
delay (20)
cls
Pic.Free (mypic1)

end loop


Mod Edit: Remember to use syntax tags! Thanks :) Code Here

-----------------------------------
Tony
Wed Apr 29, 2009 12:50 pm

RE:Sprite movement help
-----------------------------------
first -- you shouldn't be loading and reloading the same picture inside the loop.

second -- you already know that Link is facing left, whenever he moves to the left
[code]
x:=x-5 
[/code]
but you are not currently making use of that information.

-----------------------------------
tjmoore1993
Wed Apr 29, 2009 4:59 pm

RE:Sprite movement help
-----------------------------------
I will help you out a bit, I will contact you in a bit with a copy of the code finalized. It should have what you want and it will be setup to be efficient.

-----------------------------------
Tony
Wed Apr 29, 2009 5:00 pm

RE:Sprite movement help
-----------------------------------
@tjmoore1993 -- don't do that.

-----------------------------------
tjmoore1993
Wed Apr 29, 2009 5:34 pm

Re: RE:Sprite movement help
-----------------------------------
@tjmoore1993 -- don't do that.

Why not?

-----------------------------------
Tony
Wed Apr 29, 2009 5:44 pm

RE:Sprite movement help
-----------------------------------
The idea is to help students understand the concepts and gain skills necessary to complete the assignments on their own, not just do it for them. If they'll simply take your solution now, they'll have even more difficulty catching up for the next assignment or project.

-----------------------------------
tjmoore1993
Wed Apr 29, 2009 5:56 pm

RE:Sprite movement help
-----------------------------------
Tony is right. However I have made a base to work from. Everything is almost included but the problem is you need to figure out collision on your own.


var cHP : int := 1000
var mDamage : int
var mypic1 : int := Pic.FileNew ("C:\\Character.bmp")
var mypic2 : int := Pic.FileNew ("C:\\Enemy.bmp")
var x1, y1, x2, y2 : int
var chars : array char of boolean

x1 := % Characters X value (Horizontal Axis)
y1 := % Characters Y value (Verticle Axis
x2 := % Monsters X value (Horizontal Axis)
y2 := % Monsters Y value (Verticle Axis)

process BgmSound
    loop
        Music.PlayFile ("C:\\CokeTown.mp3")
    end loop
end BgmSound

procedure mDamageHandler
    mDamage := Rand.Int (1, 60)
end mDamageHandler

procedure cHealthHandler
    mDamageHandler
    cHP := cHP - mDamage
    if cHP 