Fighting game problem with Pic.Draw
Author |
Message |
jinjin
|
Posted: Sun May 11, 2008 12:24 pm Post subject: Fighting game problem with Pic.Draw |
|
|
Hey everybody,
I'm making a fighting game for my grade 10 ISU and I managed to make the first character (imported using the Pic functions) walk both ways, jump, and crouch, with the picture displayed based on his face direction. However, when I was trying to set his beginning stance (before the moving loops), the picture was displayed perfectly the first time but did not work when I tried stopping the program and executing it again. All that happened the second time was that the background was displayed but in order to display the character, I had to press one of the directional buttons. I have reviewed the code and do not see how this could happen.
Here's the source: (The code in question is marked in documentation and I've included minimal comments on the parts that might seem confusing).
Turing: |
setscreen ("offscreenonly")
setscreen ("graphics: max, max")
var pic1 := Pic.FileNew ("D:/left1.bmp")
var pic2 := Pic.FileNew ("D:/left2.bmp")
var pic3 := Pic.FileNew ("D:/left3.bmp")
var pic4 := Pic.FileNew ("D:/left4.bmp")
var pic5 := Pic.FileNew ("D:/left5.bmp")
var pic6 := Pic.FileNew ("D:/left6.bmp")
var pic7 := Pic.FileNew ("D:/left7.bmp")
var pic8 := Pic.FileNew ("D:/left8.bmp")
var pic9 := Pic.FileNew ("D:/left9.bmp")
var pic10 := Pic.FileNew ("D:/left10.bmp")
var pic11 := Pic.FileNew ("D:/right1.bmp")
var pic12 := Pic.FileNew ("D:/right2.bmp")
var pic13 := Pic.FileNew ("D:/right3.bmp")
var pic14 := Pic.FileNew ("D:/right4.bmp")
var pic15 := Pic.FileNew ("D:/right5.bmp")
var pic16 := Pic.FileNew ("D:/right6.bmp")
var pic17 := Pic.FileNew ("D:/right7.bmp")
var pic18 := Pic.FileNew ("D:/right8.bmp")
var pic19 := Pic.FileNew ("D:/right9.bmp")
var pic20 := Pic.FileNew ("D:/right10.bmp")
var pic21 := Pic.FileNew ("D:/stright.bmp")
var pic22 := Pic.FileNew ("D:/stleft.bmp")
var pic23 := Pic.FileNew ("D:/background2.bmp")
var pic24 := Pic.FileNew ("D:/jumps1l.bmp")
var pic25 := Pic.FileNew ("D:/jumps1r.bmp")
var pic26 := Pic.FileNew ("D:/jumps2l.bmp")
var pic27 := Pic.FileNew ("D:/jumps2r.bmp")
var pic28 := Pic.FileNew ("D:/jumps3l.bmp")
var pic29 := Pic.FileNew ("D:/jumps3r.bmp")
var pic30 := Pic.FileNew ("D:/jumps4l.bmp")
var pic31 := Pic.FileNew ("D:/jumps4r.bmp")
var pic32 := Pic.FileNew ("D:/jumps5l.bmp")
var pic33 := Pic.FileNew ("D:/jumps5r.bmp")
var x : int := 0
var y : int := 0
var facedir : string
var stepright := 1
var stepleft := 1
var ch : array char of boolean
%%%%%%%%%%%%% BEGINNING OF FLAWED SECTION %%%%%%%%%%%%%%%%%%%%%%
Pic.Draw (pic23, 0, 0, picCopy)
Pic.Draw (pic21, x, y, picCopy)
Pic.Draw (pic23, 0, 0, picCopy)
%% Merging pic with background
Pic.Draw (pic21, x, y, picMerge)
%%%%%%%%%%%%% END OF FLAWED SECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Starting Face direction (to make imported pics face the same way)
facedir := "right"
loop
Input.KeyDown (ch )
if ch (KEY_RIGHT_ARROW) then
facedir := "right"
%% Changing walking pic based on step
if stepright = 1 then
Pic.Draw (pic11, x, y, picCopy)
Pic.Draw (pic23, 0, 0, picCopy)
Pic.Draw (pic11, x, y, picMerge)
elsif stepright = 2 then
Pic.Draw (pic12, x, y, picCopy)
Pic.Draw (pic23, 0, 0, picCopy)
Pic.Draw (pic12, x, y, picMerge)
elsif stepright = 3 then
Pic.Draw (pic13, x, y, picCopy)
Pic.Draw (pic23, 0, 0, picCopy)
Pic.Draw (pic13, x, y, picMerge)
elsif stepright = 4 then
Pic.Draw (pic14, x, y, picCopy)
Pic.Draw (pic23, 0, 0, picCopy)
Pic.Draw (pic14, x, y, picMerge)
elsif stepright = 5 then
Pic.Draw (pic15, x, y, picCopy)
Pic.Draw (pic23, 0, 0, picCopy)
Pic.Draw (pic15, x, y, picMerge)
elsif stepright = 6 then
Pic.Draw (pic16, x, y, picCopy)
Pic.Draw (pic23, 0, 0, picCopy)
Pic.Draw (pic16, x, y, picMerge)
elsif stepright = 7 then
Pic.Draw (pic17, x, y, picCopy)
Pic.Draw (pic23, 0, 0, picCopy)
Pic.Draw (pic17, x, y, picMerge)
elsif stepright = 8 then
Pic.Draw (pic18, x, y, picCopy)
Pic.Draw (pic23, 0, 0, picCopy)
Pic.Draw (pic18, x, y, picMerge)
elsif stepright = 9 then
Pic.Draw (pic19, x, y, picCopy)
Pic.Draw (pic23, 0, 0, picCopy)
Pic.Draw (pic19, x, y, picMerge)
elsif stepright = 10 then
Pic.Draw (pic20, x, y, picCopy)
Pic.Draw (pic23, 0, 0, picCopy)
Pic.Draw (pic20, x, y, picMerge)
end if
View.Update
delay (50)
stepright := stepright + 1
x := x + 10
%% Resetting walking pic
if stepright = 11 then
stepright := 1
end if
elsif ch (KEY_LEFT_ARROW) then
facedir := "left"
if stepleft = 1 then
Pic.Draw (pic1, x, y, picCopy)
Pic.Draw (pic23, 0, 0, picCopy)
Pic.Draw (pic1, x, y, picMerge)
elsif stepleft = 2 then
Pic.Draw (pic2, x, y, picCopy)
Pic.Draw (pic23, 0, 0, picCopy)
Pic.Draw (pic2, x, y, picMerge)
elsif stepleft = 3 then
Pic.Draw (pic3, x, y, picCopy)
Pic.Draw (pic23, 0, 0, picCopy)
Pic.Draw (pic3, x, y, picMerge)
elsif stepleft = 4 then
Pic.Draw (pic4, x, y, picCopy)
Pic.Draw (pic23, 0, 0, picCopy)
Pic.Draw (pic4, x, y, picMerge)
elsif stepleft = 5 then
Pic.Draw (pic5, x, y, picCopy)
Pic.Draw (pic23, 0, 0, picCopy)
Pic.Draw (pic5, x, y, picMerge)
elsif stepleft = 6 then
Pic.Draw (pic6, x, y, picCopy)
Pic.Draw (pic23, 0, 0, picCopy)
Pic.Draw (pic6, x, y, picMerge)
elsif stepleft = 7 then
Pic.Draw (pic7, x, y, picCopy)
Pic.Draw (pic23, 0, 0, picCopy)
Pic.Draw (pic7, x, y, picMerge)
elsif stepleft = 8 then
Pic.Draw (pic8, x, y, picCopy)
Pic.Draw (pic23, 0, 0, picCopy)
Pic.Draw (pic8, x, y, picMerge)
elsif stepleft = 9 then
Pic.Draw (pic9, x, y, picCopy)
Pic.Draw (pic23, 0, 0, picCopy)
Pic.Draw (pic9, x, y, picMerge)
elsif stepleft = 10 then
Pic.Draw (pic10, x, y, picCopy)
Pic.Draw (pic23, 0, 0, picCopy)
Pic.Draw (pic10, x, y, picMerge)
end if
View.Update
delay (50)
stepleft := stepleft + 1
x := x - 10
if stepleft = 11 then
stepleft := 1
end if
elsif ch (KEY_UP_ARROW) then
if facedir = "right" then
%% Stance before jump
Pic.Draw (pic25, x, y, picCopy)
Pic.Draw (pic23, 0, 0, picCopy)
Pic.Draw (pic25, x, y, picMerge)
%% For loop when jumping up (I know Mazer's gravity method is a better way but I did not understand it so I used for loops)
for i : 0 .. 200 by 25
Pic.Draw (pic27, x, i, picCopy)
Pic.Draw (pic23, 0, 0, picCopy)
Pic.Draw (pic27, x, i, picMerge)
View.Update
cls
delay (50)
end for
%% For loop when jumping down
for decreasing i : 200 .. 0 by 25
Pic.Draw (pic31, x, i, picCopy)
Pic.Draw (pic23, 0, 0, picCopy)
Pic.Draw (pic31, x, i, picMerge)
View.Update
cls
delay (50)
end for
%% Stance after jump
Pic.Draw (pic21, x, y, picCopy)
Pic.Draw (pic23, 0, 0, picCopy)
Pic.Draw (pic21, x, y, picMerge)
View.Update
delay (50)
elsif facedir = "left" then
Pic.Draw (pic24, x, y, picCopy)
Pic.Draw (pic23, 0, 0, picCopy)
Pic.Draw (pic24, x, y, picMerge)
for i : 0 .. 200 by 25
Pic.Draw (pic26, x, i, picCopy)
Pic.Draw (pic23, 0, 0, picCopy)
Pic.Draw (pic26, x, i, picMerge)
View.Update
cls
delay (50)
end for
for decreasing i : 200 .. 0 by 25
Pic.Draw (pic30, x, i, picCopy)
Pic.Draw (pic23, 0, 0, picCopy)
Pic.Draw (pic30, x, i, picMerge)
View.Update
cls
delay (50)
end for
Pic.Draw (pic22, x, y, picCopy)
Pic.Draw (pic23, 0, 0, picCopy)
Pic.Draw (pic22, x, y, picMerge)
View.Update
delay (50)
end if
elsif ch (KEY_DOWN_ARROW) then
if facedir = "right" then
Pic.Draw (pic33, x, y, picCopy)
Pic.Draw (pic23, 0, 0, picCopy)
Pic.Draw (pic33, x, y, picMerge)
View.Update
delay (50)
end if
if facedir = "left" then
Pic.Draw (pic32, x, y, picCopy)
Pic.Draw (pic23, 0, 0, picCopy)
Pic.Draw (pic32, x, y, picMerge)
View.Update
delay (50)
end if
end if
end loop
|
Apologies if you find the code messy/inefficient as I wrote this based on my minimal knowledge. Any help on this issue is appreciated.
Edit: Sorry mod/admin, I didn't notice that I posted this in the VB section at first. Thanks for moving it.
Edit2: Never mind, I got it. I had to use PicUnderMerge instead for some reason. I still don't know why, but I don't want to try fixing something that isn't broken right now. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Dan
![](http://wiki.compsci.ca/images/archive/3/3c/20100325043407!Danspic.gif)
|
Posted: Sun May 11, 2008 7:56 pm Post subject: RE:Fighting game problem with Pic.Draw |
|
|
I know you solved your problem but i thought i would give you some helpfull tips for other things in it.
First of all you have a tone of variables for holding picture ids. You can make arrays to deal with it and load in the pictures with a for loop where the index is put in place of the number in the file name so it will dynamicly load the images. You would then have an array for left, right, and a few others rather then 23 variables.
If you do this you then don't need all thos ifs to pick the right pictures to display at a given stepright or stepleft. |
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! |
|
|
|
![](images/spacer.gif) |
jinjin
|
Posted: Wed May 14, 2008 10:38 pm Post subject: Re: Fighting game problem with Pic.Draw |
|
|
Thanks for the tip, Dan. That's definitely a helpful tip that will make my code cleaner/more efficient. However, at the moment, I'm tied up with simply trying to make the program work as best as possible as it is due to some time constraints. I am not very experienced with arrays so I do not want to tread into uncharted waters yet but it would definitely be something useful to look at for later.
Thanks
P.S. Sorry for the late reply; I've been busy with this ISU and other assignments coming up due to it being near the end of my high school semester. |
|
|
|
|
![](images/spacer.gif) |
|
|