Moving a pic, plz help
Author |
Message |
kasqit
|
Posted: Wed Jun 11, 2008 8:17 am Post subject: Moving a pic, plz help |
|
|
I need help making a pic im using of a spaceship sprite to move witht he arrow keyes. i know how to make a circle or box move, but not a pic.
this is how i make the circle move
var key : string (1)
var x, y : int
x := 100
y := 200
loop
getch (key)
cls
if ord (key) = 200 then
y := y + 5
drawfilloval (x, y, 50, 50, black)
delay (10)
elsif ord (key) = 208 then
y := y - 5
drawfilloval (x, y, 50, 50, black)
delay (10)
elsif ord (key) = 205 then
x := x + 5
drawfilloval (x, y, 50, 50, black)
delay (10)
elsif ord (key) = 203 then
x := x - 5
drawfilloval (x, y, 50, 50, black)
delay (10)
end if
end loop
if someone could help me out by showing me how to make a picture move in place of the circle, that would be great, Thanks
<---lol |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
kasqit
|
Posted: Wed Jun 11, 2008 8:39 am Post subject: Re: Moving a pic, plz help |
|
|
these are some revisions of my program i made, and it kind of workes now,
%playy proc
proc playy
var key : string (1)
var x, y : int
x := 100
y := 200
loop
getch (key)
cls
if ord (key) = 200 then
y := y + 5
pic := Pic.FileNew ("spaceship2.jpg")
Pic.Draw (pic, y, -150, picMerge)
Pic.Free (pic)
delay (10)
elsif ord (key) = 208 then
y := y - 5
pic := Pic.FileNew ("spaceship2.jpg")
Pic.Draw (pic, y, -150, picMerge)
Pic.Free (pic)
delay (10)
elsif ord (key) = 205 then
x := x + 5
pic := Pic.FileNew ("spaceship2.jpg")
Pic.Draw (pic, -150, x, picMerge)
Pic.Free (pic)
delay (10)
elsif ord (key) = 203 then
x := x - 5
pic := Pic.FileNew ("spaceship2.jpg")
Pic.Draw (pic, -150, x, picMerge)
Pic.Free (pic)
delay (10)
end if
end loop
end playy
it kind of teleports, and the movement keyes are mixed up maybe? any help would be awesome, thanks
Kasqit |
|
|
|
|
![](images/spacer.gif) |
jeffgreco13
![](http://compsci.ca/v3/uploads/user_avatars/21290830414888dd996a022.jpg)
|
Posted: Wed Jun 11, 2008 9:07 am Post subject: Re: Moving a pic, plz help |
|
|
God damn, for some reason my Turing documentation went for a sh*t and I can't access it.
But if yours still works bring it up, using F10, and look at the Input.KeyDown method. You'll be able to implement that and create a little better of a "listener" than the getch you're using above. |
|
|
|
|
![](images/spacer.gif) |
kasqit
|
Posted: Wed Jun 11, 2008 9:15 am Post subject: Re: Moving a pic, plz help |
|
|
Thanks man, now i'll take some time and try to figure out this new stuff =P |
|
|
|
|
![](images/spacer.gif) |
kasqit
|
Posted: Wed Jun 11, 2008 9:25 am Post subject: Re: Moving a pic, plz help |
|
|
lol, it kind of helped me, it made the flashing go away which is nice, but now i have two ships when i try to move, and it leaves the ship behind and it goes, so it smears across the page. also the movements are all backwards too, here is the code i used, and help would be greatly apreciated
%playy proc
proc playy
/******MOVEMENT******/
var key : string (1)
var x, y : int
var chars : array char of boolean
x := 100
y := 100
loop
Input.KeyDown (chars)
locate (1, 1)
if chars (KEY_UP_ARROW) then
y := y + 5
pic := Pic.FileNew ("spaceship3.jpg")
Pic.Draw (pic, y, 0, picMerge)
Pic.Free (pic)
delay (10)
else
put " " ..
end if
if chars (KEY_RIGHT_ARROW) then
x := x + 5
pic := Pic.FileNew ("spaceship3.jpg")
Pic.Draw (pic, 0, x, picMerge)
Pic.Free (pic)
delay (10)
else
put " " ..
end if
if chars (KEY_LEFT_ARROW) then
x := x - 5
pic := Pic.FileNew ("spaceship3.jpg")
Pic.Draw (pic, 0, x, picMerge)
Pic.Free (pic)
delay (10)
else
put " " ..
end if
if chars (KEY_DOWN_ARROW) then
y := y - 5
pic := Pic.FileNew ("spaceship3.jpg")
Pic.Draw (pic, y, 0, picMerge)
Pic.Free (pic)
delay (10)
else
put " " ..
end if
end loop
end playy
this is the first time i used this function, so bear with me =P |
|
|
|
|
![](images/spacer.gif) |
jeffgreco13
![](http://compsci.ca/v3/uploads/user_avatars/21290830414888dd996a022.jpg)
|
Posted: Wed Jun 11, 2008 9:35 am Post subject: Re: Moving a pic, plz help |
|
|
it smears because you have to clear the screen and redraw it each time the ship moves...
Head back to your Turing documentation and look for the 'View' method. Pay close attention to View.Set("offscreenonly") and View.Update
The View method is important because it will tell your program to do the animating in the background rather than up front, if you don't use the View mehtod and you just clear the screen continuously it will be really choppy and flashy.
[url=http://compsci.ca/v3/viewtopic.php?t=12533]CHECK THIS OUT TOO[/syntax] |
|
|
|
|
![](images/spacer.gif) |
kasqit
|
Posted: Wed Jun 11, 2008 9:51 am Post subject: Re: Moving a pic, plz help |
|
|
Im sorry, im a total N00b at turing, and the teacher never taught that stuff.... so its just confusing the hell out of me and when i put it in, it messed around with the title screen, didnt show up until i hit the x, etc.
This is the whole program
View.Set ("graphics:640;480")
colourback (black)
var pic : int
var font1, font2, font3, font4 : int
var prompt1, prompt2, prompt3, key : string (1)
font1 := Font.New ("Comic Sans MS:20")
font2 := Font.New ("Comic Sans MS:17")
font3 := Font.New ("Comic Sans MS:30")
font4 := Font.New ("Comic Sans MS:15")
%Space ship
proc ship
end ship
%playy proc
proc playy
/******MOVEMENT******/
var key : string (1)
var x, y : int
var chars : array char of boolean
x := 100
y := 100
loop
Input.KeyDown (chars)
locate (1, 1)
if chars (KEY_UP_ARROW) then
y := y + 5
pic := Pic.FileNew ("spaceship3.jpg")
Pic.Draw (pic, y, 0, picMerge)
Pic.Free (pic)
delay (10)
else
put " " ..
end if
if chars (KEY_RIGHT_ARROW) then
x := x + 5
pic := Pic.FileNew ("spaceship3.jpg")
Pic.Draw (pic, 0, x, picMerge)
Pic.Free (pic)
delay (10)
else
put " " ..
end if
if chars (KEY_LEFT_ARROW) then
x := x - 5
pic := Pic.FileNew ("spaceship3.jpg")
Pic.Draw (pic, 0, x, picMerge)
Pic.Free (pic)
delay (10)
else
put " " ..
end if
if chars (KEY_DOWN_ARROW) then
y := y - 5
pic := Pic.FileNew ("spaceship3.jpg")
Pic.Draw (pic, y, 0, picMerge)
Pic.Free (pic)
delay (10)
else
put " " ..
end if
end loop
end playy
%Instructions Proc
proc instructions (var pic : int)
cls
Font.Draw ("Instructions", 250, 440, font2, brightred)
Font.Draw ("Welcome to the most epic space game ever made.", 4, 360, font2, brightred)
Font.Draw ("You're objective here is to avoid any on-coming obstacles.", 4, 340, font2, brightred)
Font.Draw ("If you come in contact with any of the obstacles ", 4, 320, font2, brightred)
Font.Draw ("on the map you will die!", 4, 300, font2, brightred)
pic := Pic.FileNew ("spaceship.jpg")
Pic.Draw (pic, -150, -150, picMerge)
Pic.Free (pic)
getch (key)
end instructions
%Map proc
proc map
end map
%Main Menu
proc menu
pic := Pic.FileNew ("alienship.jpg")
Pic.Draw (pic, 1, 1, picMerge)
Pic.Free (pic)
var font5 : int
font5 := Font.New ("Comic Sans MS:20")
assert font5 > 0
Font.Draw ("Epic Advanced Man Of Space Man", 185, 440, font5, brightred)
delay (250)
Font.Draw ("1. Play", 250, 350, font1, brightred)
delay (250)
Font.Draw ("2. Instructions", 250, 300, font1, brightred)
delay (250)
Font.Draw ("3. Exit", 250, 250, font1, brightred)
end menu
%mainline
loop
menu
getch (key)
if key = "1" then
playy
elsif key = "2" then
instructions (pic)
elsif key = "3" then
cls
Font.Draw ("Deserter...", 250, 350, font1, brightred)
delay (999)
quit
end if
cls
end loop
im just trying to get the movement down for now
Thanks a lot
Kasqit |
|
|
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Wed Jun 11, 2008 3:14 pm Post subject: RE:Moving a pic, plz help |
|
|
I don't think you can call yourself a noob; you've been doing this for a good portion of the semester now (unless you're in engineering, they do very little with turing). Perhaps your teacher is a bit...odd, like mine, or maybe you haven't been paying attention/trying very hard. I know most people in my class don't.
Movement is easy, though I have never actually used getch for it. I suppose you could use sprites (a favourite for me) but they can be a pain and are a smidgeon complicated.
I guess I should also mention, picture movement is exactly the same as circle and box movement; you are manipulating exactly the same variables. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
S_Grimm
![](http://compsci.ca/v3/uploads/user_avatars/18926424384e6d86e5cf4d6.jpg)
|
Posted: Thu Jun 12, 2008 12:24 pm Post subject: RE:Moving a pic, plz help |
|
|
change View.Set ("graphics")
to
View.Set ("offscreenonly")
it has to be spelled the exact way it is now or it will not work
edit: could you also post the pictures in a zippfile or spmething? i can't run the program w\o them |
|
|
|
|
![](images/spacer.gif) |
|
|