Posted: Thu Dec 24, 2009 12:31 pm Post subject: Re: Collision Problem in Array
Um, I just fixed it up now, and I decided to add a power bar for a superjump. I used the formula, percentage * pixel distance of the starting part of the bar to the end. I read that somewhere here, but I can't find it now. Anyway, first of all, the bar is way too high at the beginning, and then goes below the bottom when it depletes. I'm very confused right now. Can anyone shed some light on this? I wasn't sure if I was supposed to make this another topic because it is a different problem, so I just put it in here. Here is the new code. I'm going to copy and paste the whole thing since it's fairly different from the first one.
%Fonts and options variables var font2, font4 :int var answer :string
font2 :=Font.New("serif:12") assert font2 > 0
font4 :=Font.New("Algerian:20") assert font4 > 0 %%%%%%%%%%%%%%%%%%%%%%
%Constants for platforms const bnum :=4%Total number of moving platforms at once const gnum :=3%Total number of still boxes type Platform : record
bplatx, bplaty, speed :real%Blue platforms (moveable)
gplatx, gplaty :int%Green platforms (still) endrecord var platforms :array1.. bnum of Platform
var gplatforms :array1.. gnum of Platform
%%%%%%%%%%%%%%%%%%%%%% setscreen("offscreenonly") var keys :arraycharofboolean %%%%%%%%%%%%%%%%%%%%%%
% player position and velocity var dx, dy :int var velx, vely, powery :real % bottom platform position var px, py, inc, bplatx, bplaty, gplatx, gplaty :int % points system and jump power if it fully recharged or not var points, power :int
dx :=200
velx :=0
dy :=400
vely :=0
bplatx :=100
bplaty :=30
px :=100
py :=10
inc :=2
gplatx :=100
gplaty :=30
power :=250
powery :=250* power / 250%The power bar %%%%%%%%%%%%%%%%%%%%%%
%Randomizes starting locations for still platforms for ii :1.. gnum
gplatforms (ii).gplatx := Rand.Int (100, maxx - 100)
gplatforms (ii).gplaty := Rand.Int (20, 300) endfor %%%%%%%%%%%%%%%%%%%%%%
%Sets up the replay, and return to GUI options. r : Replay, q : MainMenu
answer :="r" %%%%%%%%%%%%%%%%%%%%%%
%Instructions for the game procedure doodlejumpinstructions
setscreen("no echo, no cursor") locate(1, 20) colour(green) put"Doodlejump - Turing" putskip put"Did you ever play Doodlejump on the iPhone or iPod Touch?" put"This is a crossover version of it. Although it does not look" put"like it, it is basically the same concept. You control the" put"green box with 3 legs. All you have to do is keep jumping" put"upwards from platform to platform. Everytime the platforms" put"go below the screen, you will score 50 points. Unfortunately," put"there are gaps too large for you to jump, which is where the" put"superjump comes into play. You have a skill called 'SuperJump'" put"which would allow you to jump a lot higher than normal. However," put"it takes time to charge, allowing you only to use it at certain" put"times. Have fun and good luck!" put"Press any key to continue~" View.Update Input.Pause cls end doodlejumpinstructions
%Starts the game procedure doodlejump
points :=0 if answer ="r"then loop Input.KeyDown(keys) % to make the player move if keys (KEY_LEFT_ARROW)and dx - 30 > 100then
velx := -movement
elsif keys (KEY_RIGHT_ARROW)and dx + 30 < maxx - 100then
velx := movement
elsif keys (KEY_UP_ARROW)and power =250then
vely +=30%Because jump is a constant, then the extra power must be added to the velocity
power :=0 else
velx :=0 endif %Two side borders drawfillbox(0, 0, 100, maxy, black) drawfillbox(maxx - 100, 0, maxx, maxy, black) %The collision check if dy <= bottom then
vely := jump
endif % constantly subtracting gravity from the dy position
vely -= grav
dx +=round(velx)
dy +=round(vely) %Draws platforms for i :1.. bnum
if platforms (i).bplatx < 100then
platforms (i).speed *= -1 elsif platforms (i).bplatx + 100 > maxx - 100then
platforms (i).speed *= -1 endif
platforms (i).bplatx += platforms (i).speed
drawfillbox(round(platforms (i).bplatx),round(platforms (i).bplaty),round(platforms (i).bplatx + 50),round(platforms (i).bplaty + 50),1) %Checks if the player hits any platforms ifView.WhatDotColour(dx - 10, dy - 15)=1orView.WhatDotColour(dx, dy - 15)=1orView.WhatDotColour(dx + 10, dy - 15)=1or(View.WhatDotColour(dx - 10, dy - 15)=1and View.WhatDotColour(dx, dy - 15)=1andView.WhatDotColour(dx + 10, dy - 15)=1)orView.WhatDotColour(dx - 10, dy - 8)=1orView.WhatDotColour(dx, dy - 8)=1or View.WhatDotColour(dx + 10, dy
- 8)=1or(View.WhatDotColour(dx - 10, dy - 8)=1andView.WhatDotColour(dx, dy - 8)=1andView.WhatDotColour(dx + 10, dy
- 8)=1)then
vely := jump
endif %Checks if the player is moving up on the screen if dy + 30 >= 300then
platforms (i).bplaty -= grav *4 endif %Checks if the platforms go below screen, then randomizes them again if they do. Player scores 50 points for every platform that resets if platforms (i).bplaty + 50 < 0then
platforms (i).bplatx := Rand.Int (100, maxx - 200)
platforms (i).bplaty := Rand.Int (350, maxy + 50)
platforms (i).speed := Rand.Int (1, 5)
points +=50 endif %Draws bottom blue platform that never leaves the screen if px > maxx - 200then
inc *= -1 elsif px < 100then
inc *= -1 endif
px += inc
drawfillbox(px, py - 30, px + 100, py + 20, 1) for ii :1.. gnum
%Checks if the platforms go below screen, then randomizes them again if they do. Player scores 50 points for every platform that resets if gplatforms (ii).gplaty + 50 < 0then
gplatforms (ii).gplatx := Rand.Int (100, maxx - 200)
gplatforms (ii).gplaty := Rand.Int (300, maxy)
points +=50 endif %Checks if the player is moving up on the screen, moves everything else down if dy + 30 >= 300then
gplatforms (ii).gplaty -= grav *2 endif drawfillbox(gplatforms (ii).gplatx, gplatforms (ii).gplaty, gplatforms (ii).gplatx + 60, gplatforms (ii).gplaty + 50, green) endfor endfor %Checks if the player hits the green platforms ifView.WhatDotColour(dx - 10, dy - 15)=greenorView.WhatDotColour(dx, dy - 15)=greenorView.WhatDotColour(dx + 10, dy - 15)=greenor(View.WhatDotColour(dx - 10, dy -
15) = green and View.WhatDotColour(dx, dy - 15)=greenandView.WhatDotColour(dx + 10, dy - 15)=green)orView.WhatDotColour(dx - 10, dy - 8)=greenorView.WhatDotColour(dx, dy -
8)= green or View.WhatDotColour(dx + 10, dy
- 8)=greenor(View.WhatDotColour(dx - 10, dy - 8)=greenandView.WhatDotColour(dx, dy - 8)=greenandView.WhatDotColour(dx + 10, dy
- 8)=green)then
vely := jump
endif % collision check to see if the player died if dy < bottom then loop Font.Draw("Game Over!",200, 300, font2, red) Font.Draw("Press any 'q' to return to MainMenu or 'r' to play again.",130, 270, font2, red) %Randomizes starting locations of moving platforms for i :1.. bnum
platforms (i).bplatx := Rand.Int (100, maxx - 200)
platforms (i).bplaty := Rand.Int (20, 350)
platforms (i).speed := Rand.Int (1, 5) endfor
dx :=200
dy :=400 %%%%%%%%%%%%%%%%%%%%%% %Randomizes starting locations for still platforms for ii :1.. gnum
gplatforms (ii).gplatx := Rand.Int (100, maxx - 100)
gplatforms (ii).gplaty := Rand.Int (20, 300) endfor %%%%%%%%%%%%%%%%%%%%%% put"POINTS: ", points
points :=0
power :=250 View.Update get answer
exitwhen answer ="q"or answer ="r" endloop endif if dy + 20 > top then
vely :=0 endif %Shows how many points the player has put"POINTS: ", points
put power %ERASE THIS AFTER TESTING
powery := power *250 / 100%The power bar Font.Draw("S",5, 340, font4, brightred) Font.Draw("U",5, 310, font4, brightred) Font.Draw("P",5, 280, font4, brightred) Font.Draw("E",5, 250, font4, brightred) Font.Draw("R",5, 220, font4, brightred)%Says SUPERJUMP off to the side Font.Draw("J",5, 190, font4, brightred) Font.Draw("U",5, 160, font4, brightred) Font.Draw("M",5, 130, font4, brightred) Font.Draw("P",5, 100, font4, brightred) drawfillbox(40, 100, 75, 350, red) drawfillbox(40, 100, 75, round(powery),yellow) %%%%%%%%%%
%This is the power recharging part if power < 250then
power +=1 endif %Draws player drawfillbox(dx - 20, dy - 10, dx + 20, dy + 10, green) Draw.ThickLine(dx - 10, dy - 8, dx - 10, dy - 15, 5, black) Draw.ThickLine(dx, dy - 8, dx, dy - 15, 5, black) Draw.ThickLine(dx + 10, dy - 8, dx + 10, dy - 15, 5, black) exitwhen answer ="q" View.Update delay(30) cls endloop endif end doodlejump
%%%%%%%%%%%%%%%%%%%%%%
%Calls the procedures
doodlejumpinstructions
doodlejump
Sponsor Sponsor
TheGuardian001
Posted: Thu Dec 24, 2009 12:51 pm Post subject: Re: Collision Problem in Array
Lets start with it being too high up. Now, your power bar maxes out at 250. Normally, you'd have to calculate a percentage and draw based on that. But the height of the graphical power bar is also 250. So you actually don't need to do any calculations at all, since they are both the same size.
Now, as for it going too low, when you draw the yellow bar, you draw it with this:
code:
drawfillbox (40, 100, 75,round (powery), yellow)
you tell the box to draw from a starting height of 100, and to finish at powery with absolutely no relation to the starting height. If you want it to draw a certain amount above the starting height, you'll need to relate the two.
landfarm
Posted: Thu Dec 24, 2009 1:08 pm Post subject: RE:Collision Problem in Array
You're the best man! I fixed it now, and the 250 think was a coincidence. I just had to add 100 to the powery. Actually, I could just remove that variable because powery = power.
landfarm
Posted: Thu Dec 24, 2009 1:21 pm Post subject: RE:Collision Problem in Array
Wait, I just realized that my collision checks were still inside one of the for loops, so I moved them out. Unfortunately, now it's no longer working. What happened?
Turing:
for i :1.. bnum
if platforms (i).bplatx < 100then
platforms (i).speed *= -1 elsif platforms (i).bplatx + 100 > maxx - 100then
platforms (i).speed *= -1 endif
platforms (i).bplatx += platforms (i).speed
drawfillbox(round(platforms (i).bplatx),round(platforms (i).bplaty),round(platforms (i).bplatx + 50),round(platforms (i).bplaty + 50),1) %Checks if the player is moving up on the screen if dy + 30 >= 300then
platforms (i).bplaty -= jump div2 endif %Checks if the platforms go below screen, then randomizes them again if they do. Player scores 50 points for every platform that resets if platforms (i).bplaty + 50 < 0then
platforms (i).bplatx := Rand.Int (100, maxx - 200)
platforms (i).bplaty := Rand.Int (350, maxy + 50)
platforms (i).speed := Rand.Int (1, 5)
points +=50 endif endfor %Draws bottom blue platform that never leaves the screen if px > maxx - 200then
inc *= -1 elsif px < 100then
inc *= -1 endif
px += inc
drawfillbox(px, py - 30, px + 100, py + 20, 1) if points < 4000then for ii :1.. gnum
%Checks if the platforms go below screen, then randomizes them again if they do. Player scores 50 points for every platform that resets if gplatforms (ii).gplaty + 50 < 0then
gplatforms (ii).gplatx := Rand.Int (100, maxx - 200)
gplatforms (ii).gplaty := Rand.Int (300, maxy)
points +=50 endif %Checks if the player is moving up on the screen, moves everything else down if dy + 30 >= 300then
gplatforms (ii).gplaty -= jump div2 endif drawfillbox(gplatforms (ii).gplatx, gplatforms (ii).gplaty, gplatforms (ii).gplatx + 60, gplatforms (ii).gplaty + 50, green) endfor endif % collision check to see if the player died if dy < bottom then loop Font.Draw("Game Over!",200, 300, font2, red) Font.Draw("Press any 'q' to return to MainMenu or 'r' to play again.",130, 270, font2, red) %Randomizes starting locations of moving platforms for i :1.. bnum
platforms (i).bplatx := Rand.Int (100, maxx - 200)
platforms (i).bplaty := Rand.Int (20, 350)
platforms (i).speed := Rand.Int (1, 5) endfor
dx :=200
dy :=400 %%%%%%%%%%%%%%%%%%%%%% %Randomizes starting locations for still platforms for ii :1.. gnum
gplatforms (ii).gplatx := Rand.Int (100, maxx - 100)
gplatforms (ii).gplaty := Rand.Int (20, 300) endfor %%%%%%%%%%%%%%%%%%%%%% put"POINTS: ", points
points :=0
power :=250 View.Update get answer
exitwhen answer ="q"or answer ="r" endloop endif if dy + 20 > top then
vely :=0 endif %Shows how many points the player has put"POINTS: ", points
put power %ERASE THIS AFTER TESTING Font.Draw("S",5, 340, font4, brightred) Font.Draw("U",5, 310, font4, brightred) Font.Draw("P",5, 280, font4, brightred) Font.Draw("E",5, 250, font4, brightred) Font.Draw("R",5, 220, font4, brightred)%Says SUPERJUMP off to the side Font.Draw("J",5, 190, font4, brightred) Font.Draw("U",5, 160, font4, brightred) Font.Draw("M",5, 130, font4, brightred) Font.Draw("P",5, 100, font4, brightred) drawfillbox(40, 100, 75, 350, red) drawfillbox(40, 100, 75, round(power + 100),yellow) %%%%%%%%%% %This is the power recharging part if power < 250then
power +=1 endif %Draws player drawfillbox(dx - 20, dy - 10, dx + 20, dy + 10, green) Draw.ThickLine(dx - 10, dy - 8, dx - 10, dy - 15, 5, black) Draw.ThickLine(dx, dy - 8, dx, dy - 15, 5, black) Draw.ThickLine(dx + 10, dy - 8, dx + 10, dy - 15, 5, black) %Checks if the player hits the green platforms ifView.WhatDotColour(dx - 10, dy - 15)=greenorView.WhatDotColour(dx, dy - 15)=greenorView.WhatDotColour(dx + 10, dy - 15)=greenor(View.WhatDotColour(dx - 10, dy -
15) = green and View.WhatDotColour(dx, dy - 15)=greenandView.WhatDotColour(dx + 10, dy - 15)=green)orView.WhatDotColour(dx - 10, dy - 8)=greenorView.WhatDotColour(dx, dy -
8)= green or View.WhatDotColour(dx + 10, dy
- 8)=greenor(View.WhatDotColour(dx - 10, dy - 8)=greenandView.WhatDotColour(dx, dy - 8)=greenandView.WhatDotColour(dx + 10, dy
- 8)=green)then
vely := jump
endif %Checks if the player hits any blue platforms ifView.WhatDotColour(dx - 10, dy - 15)=1orView.WhatDotColour(dx, dy - 15)=1orView.WhatDotColour(dx + 10, dy - 15)=1or(View.WhatDotColour(dx - 10, dy - 15)=1and View.WhatDotColour(dx, dy - 15)=1andView.WhatDotColour(dx + 10, dy - 15)=1)orView.WhatDotColour(dx - 10, dy - 8)=1orView.WhatDotColour(dx, dy - 8)=1or View.WhatDotColour(dx + 10, dy
- 8)=1or(View.WhatDotColour(dx - 10, dy - 8)=1andView.WhatDotColour(dx, dy - 8)=1andView.WhatDotColour(dx + 10, dy
- 8)=1)then
vely := jump
endif exitwhen answer ="q" View.Update delay(30) cls endloop
TheGuardian001
Posted: Thu Dec 24, 2009 1:32 pm Post subject: Re: Collision Problem in Array
I could be wrong, but I believe your collision check is hitting the character. Try drawing the character after the hit checks and see if that fixes anything.
landfarm
Posted: Thu Dec 24, 2009 1:46 pm Post subject: RE:Collision Problem in Array
Um, I put it at the very bottom, after everything is drawn, including the player. In fact, the drawing of the player is right above the collision checks. This is strange. I'm going to keep them in the for loops for now, since it works. EDIT: Ohh, nvm, I see what you mean. It works now, but there doesn't seem to be any logic in that.
TheGuardian001
Posted: Thu Dec 24, 2009 2:10 pm Post subject: Re: Collision Problem in Array
landfarm wrote:
Um, I put it at the very bottom, after everything is drawn, including the player.
Which is exactly the problem. If your character is drawn, and the detection is looking at the area occupied by one of his legs, it's going to be seeing black, not blue or green, since your character is drawn last and will be on top of everything else.
landfarm
Posted: Thu Dec 24, 2009 2:14 pm Post subject: RE:Collision Problem in Array
Oh, I see now. That logic stuff is getting to me. Thanks again.