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

Username:   Password: 
 RegisterRegister   
 Sprite movement help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Wasabicheese




PostPosted: Wed Apr 29, 2009 12:11 pm   Post subject: 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.

Turing:
%"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 Smile
code:
[syntax="turing"]Code Here[/syntax]
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Wed Apr 29, 2009 12:50 pm   Post subject: 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

but you are not currently making use of that information.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
tjmoore1993




PostPosted: Wed Apr 29, 2009 4:59 pm   Post subject: 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




PostPosted: Wed Apr 29, 2009 5:00 pm   Post subject: RE:Sprite movement help

@tjmoore1993 -- don't do that.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
tjmoore1993




PostPosted: Wed Apr 29, 2009 5:34 pm   Post subject: Re: RE:Sprite movement help

Tony @ Wed Apr 29, 2009 5:00 pm wrote:
@tjmoore1993 -- don't do that.


Why not?
Tony




PostPosted: Wed Apr 29, 2009 5:44 pm   Post subject: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
tjmoore1993




PostPosted: Wed Apr 29, 2009 5:56 pm   Post subject: 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.

Turing:

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 <= 0 then
        put "You have died."
    end if
end cHealthHandler

procedure CollisionDetection
/*
It was requested by Tony that I did not fully help you so I what I did was
simply adjust your code so it runs nicer. It may need some tweaking though.
The program should run cleaner and I fixed the flicker a bit.

Pic.Free was not needed because you were reusing the image in a loop. It was
a waste of processing and it causes lag with loading of an image. Hope
this helps a bit and all I can suggest now is to find a guide on Collision
*/

end CollisionDetection

fork BgmSound
loop
    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) then
        y1 := y1 + 6
    end if
    if chars (KEY_RIGHT_ARROW) then
        x1 := x1 + 7
    end if
    if chars (KEY_LEFT_ARROW) then
        x1 := x1 - 7
    end if
    if chars (KEY_DOWN_ARROW) then
        y1 := y1 - 6
    end if
    CollisionDetection
    Pic.Draw (mypic2, x2, y2, 0)
    Pic.Draw (mypic1, x1, y1, 0)
    delay (20)
    cls
end loop


63 line(s) of code

This demonstrates a procedure structure that should be used. I will give you a link to a guide that has helped me with collision and it should help you.

http://compsci.ca/v3/viewtopic.php?t=13661

Good luck.
tjmoore1993




PostPosted: Wed Apr 29, 2009 6:11 pm   Post subject: RE:Sprite movement help

@ Wasabicheese

If you are having problems with Collision then post another topic. Make sure when posting a topic you atleast show members that you tried to solve your problem. Also inform us on what techniques you have tried.

When you are finish the game don't forget to submit it and let us users check it out. Smile
Sponsor
Sponsor
Sponsor
sponsor
Wasabicheese




PostPosted: Wed Apr 29, 2009 10:40 pm   Post subject: Re: Sprite movement help

thanks a lot for your help! I'll be sure to post this in submissions when im finished!
Wasabicheese




PostPosted: Fri May 01, 2009 12:05 pm   Post subject: Re: Sprite movement help

I've been having another problem. on the "pic.draw" lines near the bottom, i receive the error message "Illegal Picture ID number '0'" does anyone know how to fix this?

Turing:
var cHP : int := 1000
var mDamage : int
var mypic1 : int := Pic.FileNew ("Link.bmp")
var mypic2 : int := Pic.FileNew ("Knight.bmp")
var x1, y1, x2, y2 : int
var chars : array char of boolean

x1 := 50 % Characters X value (Horizontal Axis)
y1 := 50 % Characters Y value (Verticle Axis
x2 := 200 % Monsters X value (Horizontal Axis)
y2 := 200 % Monsters Y value (Verticle Axis)

process BgmSound
    loop
        Music.PlayFile ("LostWoods.mp3")
    end loop
end BgmSound

procedure mDamageHandler
    mDamage := Rand.Int (1, 60)
end mDamageHandler

procedure cHealthHandler
    mDamageHandler
    cHP := cHP - mDamage
    if cHP <= 0 then
        put "You have died."
    end if
end cHealthHandler

procedure CollisionDetection
/*
It was requested by Tony that I did not fully help you so I what I did was
simply adjust your code so it runs nicer. It may need some tweaking though.
The program should run cleaner and I fixed the flicker a bit.

Pic.Free was not needed because you were reusing the image in a loop. It was
a waste of processing and it causes lag with loading of an image. Hope
this helps a bit and all I can suggest now is to find a guide on Collision
*/

end CollisionDetection

fork BgmSound
loop
    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) then
        y1 := y1 + 6
    end if
    if chars (KEY_RIGHT_ARROW) then
        x1 := x1 + 7
    end if
    if chars (KEY_LEFT_ARROW) then
        x1 := x1 - 7
    end if
    if chars (KEY_DOWN_ARROW) then
        y1 := y1 - 6
    end if
    CollisionDetection
    Pic.Draw (mypic2, x2, y2, 0)  %HERE
    Pic.Draw (mypic1, x1, y1, 0)  %HERE
    delay (20)
    cls
end loop
BigBear




PostPosted: Fri May 01, 2009 4:14 pm   Post subject: RE:Sprite movement help

The Picture isn't being create make sure the picture file and this source file are in the same folder
tjmoore1993




PostPosted: Fri May 01, 2009 4:30 pm   Post subject: RE:Sprite movement help

Try looking over this guide
http://compsci.ca/v3/viewtopic.php?t=191

The guide is kind of crusty, but it should help though. Any questions feel free to "pm" me or simply post in this topic.
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  [ 12 Posts ]
Jump to:   


Style:  
Search: