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

Username:   Password: 
 RegisterRegister   
 i cant get my collision detection to work
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Womble




PostPosted: Wed Jan 17, 2018 12:54 pm   Post subject: i cant get my collision detection to work

so far im trying to make a game where your trying to doge balls coming at you and for some reason using the same method
on 2 different balls for collision detection doesn't want to work and im wondering how could i get collision detection to work for multiple enemys Very Happy

code:

setscreen ("graphics:800;600")
var chars : array char of boolean
var score, timealive : real
var enemyreset : int
var playerx, playery, circle_1_radius : int
var enemyy1, enemyy2, circle_2_radius : int
var enemyx1 : array 0 .. 10 of int
var distance_between_centres : real
%assigning values to the variables for the circules
playerx := 700
playery := 300
circle_1_radius := 10
circle_2_radius := 10
enemyy1 := Rand.Int (20, 600)
enemyy2 := Rand.Int (20, 600)
enemyx1 (0) := 0
enemyx1 (1) := 0
score := 0
timealive := 0
enemyreset := 900

%main game
loop
    Input.KeyDown (chars)
    % move character
    if chars (KEY_RIGHT_ARROW) then
        playery := playery + 5
    end if
    if chars (KEY_LEFT_ARROW) then
        playery := playery - 5
    end if
    cls
    %character
    drawfilloval (playerx, playery, circle_1_radius, circle_2_radius, red)
    %time alive
    put "TIME: ", timealive ..
    %score
    put " SCORE: ", score ..
    %enemy
    drawfilloval (enemyx1 (0), enemyy1, circle_1_radius, circle_2_radius, blue)
    drawfilloval (enemyx1 (1), enemyy2, circle_1_radius, circle_2_radius, brightblue)
    %Checks if enemy has past the player and resets at the start
    if enemyx1 (1) > enemyreset then
        enemyx1 (1) := 0
        enemyy2 := Rand.Int (20, 599)
    end if
    if enemyx1 (0) > enemyreset then
        enemyx1 (0) := 0
        enemyy1 := Rand.Int (20, 600)
    end if
    delay (20)
    %moves the enemys
    enemyx1 (0) := enemyx1 (0) + 3
    enemyx1 (1) := enemyx1 (1) + 3
    %calculate the distance between the centres of the circles
    distance_between_centres := sqrt ((playerx - enemyx1 (0)) ** 2 + (playery - enemyy1) ** 2)
    distance_between_centres := sqrt ((playerx - enemyx1 (1)) ** 2 + (playery - enemyy2) ** 2)
    %checks if the player got hit
    if distance_between_centres <= circle_1_radius + circle_2_radius then
        put " You got hit"
        exit
    end if
    %counts score
    score := score + 5
    %counts time alive
    timealive := timealive + 0.02
end loop
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Wed Jan 17, 2018 6:05 pm   Post subject: RE:i cant get my collision detection to work

distance_between_centres := sqrt ((playerx - enemyx1 (0)) ** 2 + (playery - enemyy1) ** 2)
distance_between_centres := sqrt ((playerx - enemyx1 (1)) ** 2 + (playery - enemyy2) ** 2)

What do you think these two lines are doing?
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: