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

Username:   Password: 
 RegisterRegister   
 unable to see words and gravity does not work on ball
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Weapon X




PostPosted: Mon May 02, 2005 6:51 pm   Post subject: unable to see words and gravity does not work on ball

code:

setscreen ("graphics")
setscreen ("offscreenonly")
var option : string
var score1, score2, ballx, ballx2, bally, bally2, xmod, xmod2, ymod, ymod2 : int
var chars : array char of boolean
var chars2 : array char of boolean
var slimex, slimey, slimex2, slimey2, vy, vy2, vy3 : real
var background : int
slimex := 530
slimey := 0
slimex2 := 110
slimey2 := 0
vy := 0
vy2 := 0
vy3 := 0
const jumpVelocity := 5
const speedX := 2  %speed of horizontal movement
const gravity := 0.15
var inAir := false
const jumpVelocity2 := 5
const speedX2 := 2  %speed of horizontal movement
const gravity2 := 0.15
var inAir2 := false
const jumpVelocity3 := 5
const speedX3 := 2  %speed of horizontal movement
const gravity3 := 0.15
var inAir3 := false
ballx := 320
bally := 0
xmod := 1
ymod := 1
xmod2 := 1
ymod2 := 1
score1 := 0
score2 := 0
put "Pick a number: 1, 2, 3, 4."
get background
put "You Picked The Number ", background, ". Excellent Choice!"
if background = 1 then
background := Pic.FileNew ("slimegamebackground.jpg")
end if
if background = 2 then
background := Pic.FileNew ("slimegamebackground2.jpg")
end if
if background = 3 then
background := Pic.FileNew ("slimegamebackground3.jpg")
end if
if background = 4 then
background := Pic.FileNew ("slimegamebackground4.jpg")
end if
put "Do you want a fast game or a slow game? (Type fast or slow)"
get option
loop
Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) and not inAir then
        vy := jumpVelocity
        inAir := true
    end if
    if inAir then
        slimey += vy
        vy -= gravity
        if slimey <= 0 then
            inAir := false
            vy := 0
        end if
    end if
    if chars (KEY_RIGHT_ARROW) then
        slimex += 10
    end if
    if chars (KEY_LEFT_ARROW) then
        slimex -= 10
    end if
    Input.KeyDown (chars2)
    if chars2 ('w') and not inAir2 then
        vy2 := jumpVelocity2
        inAir2 := true
    end if
    if inAir2 then
        slimey2 += vy2
        vy2 -= gravity2
        if slimey2 <= 0 then
            inAir2 := false
            vy2 := 0
        end if
    end if
    if chars2 ('d') then
        slimex2 += 10
    end if
    if chars2 ('a') then
        slimex2 -= 10
    end if
    Pic.Draw (background, 0, 0, picCopy)

if option = 'fast' then
delay (5)
end if
if option = 'slow' then
delay (10)
end if
   
    drawfillarc (round (slimex), round (slimey), -50, -50, 180, 0, blue)
    drawfillarc (round (slimex), round (slimey), -40, -40, 180, 0, blue)
    drawfillarc (round (slimex), round (slimey), -30, -30, 180, 0, blue)
    drawfillarc (round (slimex), round (slimey), -20, -20, 180, 0, blue)
    drawfillarc (round (slimex), round (slimey), -10, -10, 180, 0, blue)
    drawfillarc (round (slimex), round (slimey), -9, -9, 180, 0, blue)
    drawfillarc (round (slimex), round (slimey), -8, -8, 180, 0, blue)
    drawfillarc (round (slimex), round (slimey), -7, -7, 180, 0, blue)
    drawfillarc (round (slimex2), round (slimey2), -50, -50, 180, 0, blue)
    drawfillarc (round (slimex2), round (slimey2), -40, -40, 180, 0, blue)
    drawfillarc (round (slimex2), round (slimey2), -30, -30, 180, 0, blue)
    drawfillarc (round (slimex2), round (slimey2), -20, -20, 180, 0, blue)
    drawfillarc (round (slimex2), round (slimey2), -10, -10, 180, 0, blue)
    drawfillarc (round (slimex2), round (slimey2), -9, -9, 180, 0, blue)
    drawfillarc (round (slimex2), round (slimey2), -8, -8, 180, 0, blue)
    drawfillarc (round (slimex2), round (slimey2), -7, -7, 180, 0, blue)
    drawfilloval (round (slimex2 + 27), round (slimey2 + 30), 7,7, yellow)
    drawfilloval (round (slimex - 27), round (slimey + 30), 7,7, yellow)
    drawline (0, 126, 107, 126, blue)     %|net 1 top
    drawline (0, 125, 100, 125, black)     %|
    drawline (0, 124, 100, 124, black)     %|
    drawline (0, 123, 100, 123, black)     %|
    drawline (0, 122, 100, 122, black)     %|net 1
    drawline (0, 121, 100, 121, black)     %|
    drawline (0, 120, 100, 120, black)     %|
    drawline (0, 119, 100, 119, black)     %|
    %____________________________________________

    drawline (100, 0, 100, 125, black)     %|net 1
    drawline (101, 0, 101, 125, black)     %|net 1
    drawline (102, 0, 102, 125, black)     %|net 1
    drawline (103, 0, 103, 125, black)     %|net 1
    drawline (104, 0, 104, 125, black)     %|net 1
    drawline (105, 0, 105, 125, black)     %|net 1
    drawline (106, 0, 106, 125, black)     %|net 1
    drawline (107, 0, 107, 125, black)     %|net 1
    %____________________________________________

    drawline (0, 110, 100, 110, black)     %|net 1
    drawline (0, 100, 100, 100, black)     %|net 1
    drawline (0, 90, 100, 90, black)     %|net 1
    drawline (0, 80, 100, 80, black)     %|net 1
    drawline (0, 70, 100, 70, black)     %|net 1
    drawline (0, 60, 100, 60, black)     %|net 1
    drawline (0, 50, 100, 50, black)     %|net 1
    drawline (0, 40, 100, 40, black)     %|net 1
    drawline (0, 30, 100, 30, black)     %|net 1
    drawline (0, 20, 100, 20, black)     %|net 1
    drawline (0, 10, 100, 10, black)     %|net 1

    %____________________________________________

    drawline (90, 0, 90, 119, black)     %|net 1
    drawline (80, 0, 80, 119, black)     %|net 1
    drawline (70, 0, 70, 119, black)     %|net 1
    drawline (60, 0, 60, 119, black)     %|net 1
    drawline (40, 0, 40, 119, black)     %|net 1
    drawline (39, 0, 39, 119, blue)     %|net 1
    drawline (28, 0, 28, 119, black)     %|net 1
    drawline (20, 0, 20, 119, black)     %|net 1
    drawline (10, 0, 10, 119, black)     %|net 1

    %______________________________END OF NET 1________________________________________________________________________________________________

    drawline (640, 126, 534, 126, blue)     %|net 2 top
    drawline (640, 125, 540, 125, black)     %|net 2
    drawline (640, 124, 540, 124, black)     %|net 2
    drawline (640, 123, 540, 123, black)     %|net 2
    drawline (640, 122, 540, 122, black)     %|net 2
    drawline (640, 121, 540, 121, black)     %|net 2
    drawline (640, 120, 540, 120, black)     %|net 2
    drawline (640, 119, 540, 119, black)     %|net 2
    %____________________________________________

    drawline (541, 0, 541, 125, black)     %|net 2
    drawline (540, 0, 540, 125, black)     %|net 2
    drawline (539, 0, 539, 125, black)     %|net 2
    drawline (538, 0, 538, 125, black)     %|net 2
    drawline (537, 0, 537, 125, black)     %|net 2
    drawline (536, 0, 536, 125, black)     %|net 2
    drawline (535, 0, 535, 125, black)     %|net 2
    drawline (534, 0, 534, 125, black)     %|net 2

    %____________________________________________

    drawline (640, 110, 540, 110, black)     %|net 2
    drawline (640, 100, 540, 100, black)     %|net 2
    drawline (640, 90, 540, 90, black)     %|net 2
    drawline (640, 80, 540, 80, black)     %|net 2
    drawline (640, 70, 540, 70, black)     %|net 2
    drawline (640, 60, 540, 60, black)     %|net 2
    drawline (640, 50, 540, 50, black)     %|net 2
    drawline (640, 40, 540, 40, black)     %|net 2
    drawline (640, 30, 540, 30, black)     %|net 2
    drawline (640, 20, 540, 20, black)     %|net 2
    drawline (640, 10, 540, 10, black)     %|net 2

    %____________________________________________

    drawline (550, 0, 550, 125, black)     %|net 2
    drawline (560, 0, 560, 125, black)     %|net 2
    drawline (570, 0, 570, 125, black)     %|net 2
    drawline (580, 0, 580, 125, black)     %|net 2
    drawline (590, 0, 590, 125, black)     %|net 2
    drawline (611, 0, 611, 125, blue)     %|net 2
    drawline (620, 0, 620, 125, black)     %|net 2
    drawline (630, 0, 630, 125, black)     %|net 2

    %_________________________________END OF NET 2_____________________________________________________________________________________________

    Draw.FillOval (ballx, bally, 10, 10, 12)

    ballx += xmod
    bally += ymod
    if ballx >= maxx then
        xmod := -xmod
    elsif ballx <= 0 then
        xmod := -xmod
    end if
    if bally >= 380 then
        ymod := -ymod
    elsif bally <= 0 then
        ymod := -ymod
    end if
    if bally + xmod and not inAir3 then
        vy3 := jumpVelocity3
        inAir3 := true
    end if
    if inAir3 then
        bally += vy3
        vy3 -= gravity3
        if bally <= 0 then
            inAir3 := false
            vy3 := 0
        end if
    end if
    if whatdotcolour (ballx + 11, bally) = blue or whatdotcolour (ballx - 11, bally) = 1 then
        xmod := -xmod
    end if
    if whatdotcolour (ballx, bally + 11) = blue or whatdotcolour (ballx, bally - 11) = 1 then
        ymod := -ymod
    end if
    if ballx <= 50 and bally <= 119 then
        score2 += 1
    end if
    if ballx >= 600 and bally <= 119 then
        score1 += 1
    end if
    if slimex >= maxx then
        slimex -= 10
    elsif slimex <= 0 then
        slimex += 10
    end if
    if slimex2 >= maxx then
        slimex2 -= 10
    elsif slimex2 <= 0 then
        slimex2 += 10
    end if
    if score1 <= 1 then
        locatexy (0, 400)
        put "", score1, ""
    elsif score1 >= 1 then
        locatexy (0, 400)
        put "", score1, ""
    end if
    if score2 <= 1 then
        locatexy (620, 400)
        put "", score2, ""
    elsif score2 >= 1 then
        locatexy (620, 400)
        put "", score2, ""
    end if

    View.Update


end loop


well, i typed this code and when the program starts (that is, if i can get the ball gravit working with some help) the persons choice does not show. the ball also does not work when i add gravity.



slime soccer.rar
 Description:

Download
 Filename:  slime soccer.rar
 Filesize:  672.17 KB
 Downloaded:  167 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
jamonathin




PostPosted: Tue May 03, 2005 6:16 am   Post subject: (No subject)

Ok, here are your problems. The text wont show up because you're using offscreenonly, so you can either put "nooffscreenonly" or make the game "offscreenonly" after your option menu, either way you still need to put "offscreenonly" after your menu.

For the gravity, you need to round the number in order to add it to an int. An integer cannot have a decimal place, so we use bally += round (vy3)

Also, you have an error on line 225. It reads this.
Quote:
if bally + xmod and not inAir3 then
if bally + modx = what? Nothing, so you need to make it <= something, >= or =.

If there's anything, juss ask away Smile
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  [ 2 Posts ]
Jump to:   


Style:  
Search: