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

Username:   Password: 
 RegisterRegister   
 Collision and Flickering in my Turing game [Help a complete noob out please]
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Ins3ktz




PostPosted: Mon May 14, 2012 5:37 pm   Post subject: Collision and Flickering in my Turing game [Help a complete noob out please]

What is it you are trying to achieve?
I'm trying to create a two player asteroid dodging game. So far I've got the menus down, and two sprites taken from the internet.

What is the problem you are having?
I have quite a few:

A) I don't know how I'm going to make the asteroids fall randomly and take the player to a game over screen when the player is hit. Basically I'm a complete Turing noob. But I'm a noob that's willing to learn Smile

B) My characters disappear when they're not moving. When they are moving seperately they are fine. When they are moving in unison their movement speeds are very slow and they flicker enough to give blind people epilepsy.

Describe what you have tried to solve this problem
Well for A I just don't understand. For B, I've tried View.Updates, cls, etc. but it doesn't work (Though I'm pretty sure it's a human error).


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Here's my game code

Turing:


setscreen ("Graphics:641;420")
colourback (255)


var picMENU: int:= Pic.FileNew ("Galaxy.jpg")
if picMENU=0 then
    put "Unable to load the JPEG: ",Error.LastMsg
    return
    end if
Pic.Draw (picMENU,0,0,picCopy)
var chars : array char of boolean
var i: int
var pichumanMENU: int:= Pic.FileNew ("HumanMenu.jpg")
if pichumanMENU=0 then
    put "Unable to load the JPEG: ",Error.LastMsg
    return
    end if

var picMENUs: int:= Pic.FileNew ("Galaxy3.jpg")
if picMENUs=0 then
    put "Unable to load the JPEG: ",Error.LastMsg
    return
    end if
var picMENU2: int:= Pic.FileNew ("Galaxy4.jpg")
if picMENU2=0 then
    put "Unable to load the JPEG: ",Error.LastMsg
    return
    end if
var picMENUC: int:= Pic.FileNew ("Credits.jpg")
if picMENUC=0 then
    put "Unable to load the JPEG: ",Error.LastMsg
    return
    end if
var picGAME: int:= Pic.FileNew ("PlanetSurface.jpg")
if picGAME=0 then
    put "Unable to load the JPEG: ", Error.LastMsg
    return
    end if
var picALIEN: int:= Pic.FileNew ("elite.jpg")
if picALIEN=0 then
    put "Unable to load the JPEG: ", Error.LastMsg
    return
    end if
var picHUMAN: int:= Pic.FileNew ("human.jpg")
if picHUMAN=0 then
    put "Unable to load the JPEG: ",Error.LastMsg
    return
    end if
var picASTEROID: int:= Pic.FileNew ("188.jpg")
if picASTEROID=0 then
    put "Unable to load the JPEG: ",Error.LastMsg
    return
    end if
var x, y : int
x := 0
y := 0
var a, b : int
a := 0
b := 0

loop
Input.KeyDown (chars)
locate (1, 1)
if chars (KEY_ENTER) then
cls
Pic.Draw (picGAME, 0, 0, picCopy)
loop
    Input.KeyDown (chars)
    Pic.Draw (picGAME, 0, 0, picCopy)
    if chars ('d') then
        a := a + 10
        Pic.Draw (picALIEN, a, b, picCopy)
        View.Update
        Pic.Draw (picGAME, 0, 0, picCopy)       
        Pic.Draw (picALIEN, a, b, picCopy)
        View.Update
        delay (25)
        View.Update       
        Pic.Draw (picALIEN, a, b, picCopy)
        View.Update
    end if
    if chars ('a') then
        a := a - 10
        Pic.Draw (picALIEN, a, b, picCopy)
        View.Update
        Pic.Draw (picGAME, 0, 0, picCopy)       
        Pic.Draw (picALIEN, a, b, picCopy)
        View.Update
        delay (25)
        View.Update       
        Pic.Draw (picALIEN, a, b, picCopy)
        View.Update
    end if
    View.Update
    Input.KeyDown (chars)
    if chars (KEY_RIGHT_ARROW) then
        x := x + 10
        Pic.Draw (picHUMAN, x, y, picCopy)
        View.Update
        Pic.Draw (picGAME, 0, 0, picCopy)       
        Pic.Draw (picHUMAN, x, y, picCopy)
        View.Update
        delay (25)
        View.Update
        Pic.Draw (picGAME, 0, 0, picCopy)
        Pic.Draw (picHUMAN, x, y, picCopy)
        View.Update
    end if
    if chars (KEY_LEFT_ARROW) then
        x := x - 10
        Pic.Draw (picHUMAN, x, y, picCopy)
        View.Update
        Pic.Draw (picGAME, 0, 0, picCopy)       
        Pic.Draw (picHUMAN, x, y, picCopy)
        View.Update
        delay (25)
        View.Update
        Pic.Draw (picGAME, 0, 0, picCopy)
        Pic.Draw (picHUMAN, x, y, picCopy)
        View.Update
    end if
end loop
end if
if chars (KEY_BACKSPACE) then
cls
Pic.Draw (picMENUs, 0, 0, picCopy)
end if
if chars (KEY_SHIFT) then
cls
Pic.Draw (pichumanMENU,0,0,picCopy)
end if
if chars (KEY_ALT) then
cls
Pic.Draw (picMENU, 0, 0, picCopy)
end if
if chars (KEY_CTRL) then
cls
Pic.Draw (picMENU2, 0, 0, picCopy)
end if
if chars (KEY_TAB) then
cls
Pic.Draw (picMENUC, 0, 0, picCopy)
end if
end loop





Please specify what version of Turing you are using
I am currently using Turing 4.1.1.

Also, may I request that whoever would be kind enough to answer please explain it to me? I'd like to understand, not just blatantly copy off someone. And yes, I've looked at the guides, but either I'm doing something wrong while I'm implementing what I've learned, or I'm just not understanding.

Appreciate the help Smile
Sponsor
Sponsor
Sponsor
sponsor
Amarylis




PostPosted: Mon May 14, 2012 6:25 pm   Post subject: RE:Collision and Flickering in my Turing game [Help a complete noob out please]

For the flickering, it's a simple solution:

You tried View.Update, but you haven't followed it up with the command that tells it to not update the screen until View.Update. That's placed in the setscreen string. Just make it look like this:

Turing:
setscreen ("graphics:641;420,offscreenonly")    % Or View.Set ("graphics:641;420, offscreenonly")


And the second one I'd have to actually take a closer look at your code than just scrolling through it, so I'll get back to you in a bit
Ins3ktz




PostPosted: Mon May 14, 2012 6:33 pm   Post subject: RE:Collision and Flickering in my Turing game [Help a complete noob out please]

Thanks for the reply!

I get it!

So I should delete all the extra View.Updates I put in?

Appreciate the help!
Amarylis




PostPosted: Mon May 14, 2012 6:44 pm   Post subject: RE:Collision and Flickering in my Turing game [Help a complete noob out please]

Okay, so I took a look at the code, and I find that a lot of the stuff in your if statements for handling pressing the keys is, well... Irrelevant.

A few tips:
If no coordinates have changed, drawing two identical copies of the same picture will do nothing for the user, and will only make the program slower

Since we do not have access to the pictures you are using for the game, I'm going with the assumption of you wanting the picture of the game and of the players to blend in pretty well. Take a look at things such as picMerge for the picture effects.

For the asteroids, consider using the Rand module to make the coordinates for the asteroids.

Question: Are the asteroids falling straight down, or at an angle?
Ins3ktz




PostPosted: Mon May 14, 2012 6:45 pm   Post subject: RE:Collision and Flickering in my Turing game [Help a complete noob out please]

Straight down.
Amarylis




PostPosted: Mon May 14, 2012 6:46 pm   Post subject: RE:Collision and Flickering in my Turing game [Help a complete noob out please]

Oh, whoops, wrong link for the Rand module


This is the right one
Ins3ktz




PostPosted: Mon May 14, 2012 6:53 pm   Post subject: RE:Collision and Flickering in my Turing game [Help a complete noob out please]

Thank you!

I'm sorry but I have to go offline for today. I greatly appreciate your help, and if you would continue to do so in my absence I would be extremely grateful.

Thanks again!
Amarylis




PostPosted: Mon May 14, 2012 6:55 pm   Post subject: RE:Collision and Flickering in my Turing game [Help a complete noob out please]

Okay, a few tips on that then...

You'll probably be wanting to box off the area that the character occupies (i.e. the size of the character pictures), making sure that the the asteroid's (assuming they'll just be red circles drawn with the Draw.Oval or FillOval procedures) edges don't touch the box, as opposed to not allowing the circle's center to touch the box.

Make sure to always stop drawing the circles after they hit the "floor" of the game- less things to draw, less chances it'll lang.

Timers would be effective here- they can be used to randomize the frequency of falling asteroids.

Consider how many asteroids you want on the screen at any given time, that will influence how much coding you'll have to do for them, and how long it'll take Turing to draw all the pictures you want on screen at once
Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: Tue May 15, 2012 1:12 pm   Post subject: RE:Collision and Flickering in my Turing game [Help a complete noob out please]

This is how your code should be set up, to be faster and cleaner

Turing:

loop
     Update positions, statuses and such
     Draw stuff
     View.Update
     cls
end loop


Notice how I only viewupdate ONCE. If you do it multiple times, it actually doesnt make it any better; the point of that thing is so that you can just draw everything once, instead of everything separately. In fact, you can use View.UpdateArea (0, 0, max, maxy) to make it even faster.
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  [ 9 Posts ]
Jump to:   


Style:  
Search: