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

Username:   Password: 
 RegisterRegister   
 Collision Detection Help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Harrison.Kevin




PostPosted: Wed Apr 15, 2015 11:13 am   Post subject: Collision Detection Help

I have read through threads on collision detection, but I'm still having issues getting myself to understand how it works.

Here is the code to the current project I have:
Turing:

var chars : array char of boolean
var x1 : int := 1
var x2 : int := x1 + 10
var y1 : int := 1
var y2 : int := y1 + 10
var xv : real := 0
var yv : real := 0
var g : real := 1
var ground : boolean := true
setscreen ("graphics:450;450,offscreenonly,nobuttonbar,title:Testing Screen")
loop
    Input.KeyDown (chars)
    if chars ('w') and y2 < maxy and ground = true then
        yv += 8
    end if
    if chars ('a') and x1 > 0 then
        xv -= 1
    elsif chars ('d') and x2 < maxx then
        xv += 1
    elsif chars (KEY_ESC) then
        exit
    end if
    if y1 > 0 then
        yv -= g
    elsif y1 < 0 then
        yv := 0
        y1 := 0
    end if
    if xv > 0 then
        xv -= 0.5
    elsif xv < 0 then
        xv += 0.5
    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 = 0 then
        ground := true
    else
        ground := false
    end if
    x1 += round(xv)
    y1 += round(yv)
    x2 := x1 + 10
    y2 := y1 + 10
    Draw.FillBox (x1, y1, x2, y2, black)
    Draw.FillBox (0, 0, 450, 450, cyan)
    Draw.FillBox (70, 0, 120, 80, black)
    Draw.FillBox (200, 0, 250, 100, black)
    Draw.FillBox (320, 0, 450, 100, blue)
    var font : int
    font := Font.New("serif:18")
    Draw.Text ("FINISH", 350, 35, font, white)
    Font.Free(font)
    Draw.FillBox (x1 - 1, y1 - 1, x2 + 1, y2 + 1, white)
    locate(1, 1)
    View.Update
    delay (10)
    cls
end loop


I am trying to make it so when the last box declared touches the other 2 black boxes, the last box declared will be set back to 0.



Mod Edit: Change quote tag to use syntax="turing" tags.
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Wed Apr 15, 2015 1:05 pm   Post subject: RE:Collision Detection Help

What parts don't you understand?
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: