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

Username:   Password: 
 RegisterRegister   
 collision detection on a scrolling game?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Spiicyice




PostPosted: Sat Jan 18, 2014 9:03 pm   Post subject: collision detection on a scrolling game?

What is it you are trying to achieve?
Make "barriers" on my map, while having the screen able to scroll.


What is the problem you are having?
When I set my barriers, it doesn't make it at only one position on the whole map. Every time I keep moving and the screen begins to scroll, the barrier I set will still be there. Is it possible to have multiple collision detections on a scrolling screen?


My Code:
Turing:

%Variables
var pic : int := 0
var picnum : int := 0
var win := Window.Open ("graphics:1260;720,offscreenonly,title: Sonic Generations")
var background : int := Pic.FileNew ("greenhillcrop2.jpg")
var sonic : int := Pic.FileNew ("Sonic1.bmp")
var sonicflip : int := Pic.Mirror (sonic)
var sega : int := Pic.FileNew ("Sega.jpg")
var input : array char of boolean
var face : int := 1
var offsetx, x, y : int := 0
x := 0
y := 76
var x1 : int := 50
var x2 : int := x1 + 10
var y1 : int := 250
var y2 : int := 70
var xv : real := 0
var yv : real := 0
var g : real := 1
var ground : boolean := true

%Music Processes

%This process plays the Sega song
process SegaMusic
    Music.PlayFile ("Sega.wav")
end SegaMusic

%This process plays Game song
process Gamemusic
    Music.PlayFile ("Song1.mp3")
end Gamemusic

%This process plays Game song
process MenuMusic
    Music.PlayFile ("Introsong.mp3")
end MenuMusic

%This process plays Game song
process EndgameMusic
    Music.PlayFile ("EndMusic.mp3")
end EndgameMusic

%This process plays Game song
process BeatlevelMusic
    Music.PlayFile ("LevelBeat.mp3")
end BeatlevelMusic

%This process plays Game song
process GameoverMusic
    Music.PlayFile ("GameOver.mp3")
end GameoverMusic

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Animating the Intro
/*for i : 1 .. 28
 pic := Pic.FileNew ("Sega (" + intstr (i) + ").bmp")
 Pic.Draw (pic, picnum, 0, picCopy)
 View.Update
 Pic.Free (pic)
 delay (35)
 end for

 %Playing Sega music
 fork SegaMusic

 %Animating the Intro
 for i : 29 .. 215
 pic := Pic.FileNew ("Sega (" + intstr (i) + ").bmp")
 Pic.Draw (pic, picnum, 0, picCopy)
 View.Update
 Pic.Free (pic)
 delay (35)
 end for

 %Playing Menu music
 fork MenuMusic

 %Animating the Intro
 for i : 216 .. 422
 pic := Pic.FileNew ("Sega (" + intstr (i) + ").bmp")
 Pic.Draw (pic, picnum, 0, picCopy)
 View.Update
 Pic.Free (pic)
 delay (35)
 end for

 %Playing Game music
 fork Gamemusic

 %Animating the Intro
 for i : 423 .. 504
 pic := Pic.FileNew ("Sega (" + intstr (i) + ").bmp")
 Pic.Draw (pic, picnum, 0, picCopy)
 View.Update
 Pic.Free (pic)
 delay (35)
 end for
 */

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Main Game
loop
    %Initializing
    Input.KeyDown (input)
    if input (KEY_UP_ARROW) and y2 > 69 and ground = true then
        yv += 8
    end if
    % Move left if you press the left arrow
    if input (KEY_LEFT_ARROW) and x1 > 0 then
        xv -= 1
        face := 0
    end if
    % Move right if you press the right arrow
    if input (KEY_RIGHT_ARROW) and x2 < maxx then
        xv += 1
        face := 1
        % If player gets close to the edge, move screen instead of player
        if x1 > 800 then
            x1 := 800
            offsetx -= 5
        end if
    end if
    if y1 > 70 then
        yv -= g
    elsif y1 < 70 then
        yv := 0
        y1 := 70
    end if

    if xv > 0 then
        xv -= 0.9
    elsif xv < 0 then
        xv += 0.9
    end if

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    if x1 < 0 then
        x1 := 0
        xv := 0
    elsif x2 > maxx then
        x1 := maxx - 10
        xv := 0
    end if


    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    if y2 > maxy then
        y1 := maxy - 10
        yv := 0
    end if

    if y1 = 70 then
        ground := true
    else
        ground := false
    end if

    if offsetx < -65 and offsetx > -66 and x1 > maxx div 2 and x1 < maxx div 2 + 40 then
        y1 := 70 + 5
        yv := yv + 1
    elsif offsetx < -65 and x1 > maxx div 2 + 40 and x1 < maxx div 2 + 80 then
        y1 := 70 + 5
    end if

    if offsetx < -200 and offsetx > -201 and x1 > maxx div 2 and x1 < maxx div 2 + 40 then
       
    elsif offsetx < -200 and x1 > maxx div 2 + 40 and x1 < maxx div 2 + 80 then
    end if



    x1 += round (xv)
    y1 += round (yv)

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    delay (10)
    Pic.Draw (background, offsetx, 0, 0)
    if face = 0 then
        Pic.Draw (sonic, x1, y1, picMerge)
    elsif face = 1 then
        Pic.Draw (sonicflip, x1, y1, picMerge)
    end if
    View.Update

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

end loop




If someone wants the whole thing with all of the pictures so they can fool around with it, just tell me.

Thanks! Very Happy
Sponsor
Sponsor
Sponsor
sponsor
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  [ 1 Posts ]
Jump to:   


Style:  
Search: