|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
Corroder Grandmaster Cheater Supreme Reputation: 75
Joined: 10 Apr 2015 Posts: 1667
|
Posted: Fri Jul 12, 2019 4:44 am Post subject: Collision Check |
|
|
From this topic: https://forum.cheatengine.org/viewtopic.php?t=610317
Code: | function onCollision(obj1,obj2)
obj1x = obj1.left
obj1y = obj1.top
obj1w = obj1.width
obj1h = obj1.height
obj2x = obj2.left
obj2y = obj2.top
obj2w = obj2.width
obj2h = obj2.height
if obj2x + obj2w >= obj1x and obj2y + obj2h >= obj1y and obj2y <= obj1y + obj1h and obj2x <= obj1x + obj1w then
return true
end
end
if onCollision(obj1, obj2) then
obj2.destroy()
end |
The collision check function return error if one or both objects are destroyed. So, I did modification:
Code: | function onCollision(obj1,obj2)
if obj1 == nil or obj2 == nil then obj1 = nil obj2 = nil end
obj1x = obj1.left
obj1y = obj1.top
obj1w = obj1.width
obj1h = obj1.height
obj2x = obj2.left
obj2y = obj2.top
obj2w = obj2.width
obj2h = obj2.height
if obj2x + obj2w >= obj1x and obj2y + obj2h >= obj1y and obj2y <= obj1y + obj1h and obj2x <= obj1x + obj1w then
return true
end
end |
Now I want to test colliding with objects created using array table.
Code: | local bricks = {}
local isBricksEnabled = {}
local brickWidth = 70
local brickHeight = 25
local brickRows = 8
local brickColumns = 8
local width, height = 70, 25
local gap = 5
form = createForm()
form.setSize(640.480)
--- create object panels as bricks
for row = 1, brickRows do
bricks[row] = {}
for col = 1, brickColumns do
local x = (col - 1) * (width + gap) -- x offset
local y = (row - 1) * (height + gap) -- y offset
local newBrick = createPanel(form)
newBrick.width = brickWidth
newBrick.height = brickHeight
newBrick.top = y + 15
newBrick.left = x + 15
newBrick.BorderStyle = 'bsNone'
bricks[row][col] = newBrick
end
end
|
let say I have created a game ball as 'gameBall'. I did make the game ball bouncing, etc.
My question, how to check and destroy the bricks when the ball hits it?.
So far this is the script but didn't work, the bricks didn't detect by the ball.
Code: | -- Check for bricks colliding
for rows = 1, brickRows do
for columns = 0, brickColumns do
if not isBrickEnabled[rows][columns] then repeat
if onCollision(gameBall,bricks[rows][columns]) then
isBrickEnabled[rows][columns] = false
if gameBall.Left + 10 < bricks[rows][columns].Left or
gameBall.Left > bricks[rows][columns].Left + bricks[rows][columns].Width then
xVel = -xVel
else
yVel = -yVel
end
end
end
end
end
|
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
Back to top |
|
|
AylinCE Grandmaster Cheater Supreme Reputation: 32
Joined: 16 Feb 2017 Posts: 1260
|
Posted: Fri Jul 12, 2019 7:39 am Post subject: |
|
|
If you're not offended me: I will ask a correction.
Regarding the following topic.
Can you code the jump logic for all the panels?
The code you share is valid only for "Form" limits,
If you apply the same code to all Panels, the solution will work.
https://forum.cheatengine.org/viewtopic.php?t=610429
I have no idea for the problem.
However, 64 panels one by one, it will not be difficult to encode.
_________________
|
|
Back to top |
|
|
Corroder Grandmaster Cheater Supreme Reputation: 75
Joined: 10 Apr 2015 Posts: 1667
|
Posted: Fri Jul 12, 2019 9:31 am Post subject: |
|
|
Aylin wrote: | ..I will ask a correction.
....
Can you code the jump logic for all the panels?
The code you share is valid only for "Form" limits,
If you apply the same code to all Panels, the solution will work.
https://forum.cheatengine.org/viewtopic.php?t=610429
I have no idea for the problem.
However, 64 panels one by one, it will not be difficult to encode. |
1. ...I will ask the correction.
Did you mean, you will correcting my script and give solutions?.
2. ...the jump logic for all the panels?
Did you mean to make all panel 'Jump"
3. ...However, 64 panels one by one, it will not be difficult to encode.
I have made 100 panels on the form with a "normal" way (just use createPanel(form), etc...etc 100 times) and all work properly.
But, I don't want this way and that is why I post a topic with the title "Collision Check" With objects created and stores on an array table.
EDITED
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Last edited by Corroder on Fri Jul 12, 2019 7:16 pm; edited 2 times in total |
|
Back to top |
|
|
AylinCE Grandmaster Cheater Supreme Reputation: 32
Joined: 16 Feb 2017 Posts: 1260
|
Posted: Fri Jul 12, 2019 12:49 pm Post subject: |
|
|
Yes, I understand, I'm making an absolute translation error.
The following is the code that you created: valid for "form".
Is it possible to edit this code for all "Panels"?
Code: | local objWidth
local objHeight=50
local objX,objY,volX,volY
function bounced()
volX=math.random(1,4)
volY=math.random(1,4)
objX=lbbounce.Left
objY=lbbounce.Top
objWidth=lbbounce.Width
objX=math.random(0,frm.Width-objWidth)
objX=math.random(0,frm.Height-objHeight)
frm.DoubleBuffer=true
timer1.Enabled=true
end
function timer1_Tick(sender)
lbbounce.Left=objX
lbbounce.Top=objY
objX=objX+volX
if (objX<0) then
volX=-volX
lbbounce.Font.Color=math.random(255,255)
elseif (objX+objWidth>frm.Width) then
volX=-volX
lbbounce.Font.Color=math.random(0,255)
end
objY=objY+volY
if (objY<0) then
volY=-volY
lbbounce.Font.Color=math.random(0,255)
elseif (objY+objHeight>frm.Height) then
volY=-volY
lbbounce.Font.Color=math.random(0,255)
end
end |
The game you created with VB: I've tried later in CE.
He shoots the panels, but doesn't jump when the ball hits the panel.
It only bounces when the form hits the walls.
That's what I wanted to say.
Is it possible to apply the above code for all panels?
also, thanks for replying.
_________________
|
|
Back to top |
|
|
Corroder Grandmaster Cheater Supreme Reputation: 75
Joined: 10 Apr 2015 Posts: 1667
|
Posted: Fri Jul 12, 2019 6:46 pm Post subject: |
|
|
First, please check in the Turkish language, which is different between "atlama" and "sıįrayan". So, I think you ask about "sıįrayan" not "atlama".
From my code you ask for, this is the explanation:
Code: | -- check for left side form
if (objX<0) then volX=-volX end
-- check for right side form
if (objX+objWidth>frm.Width) then volX=-volX end
-- check for top side form
if (objY<0) then volY=-volY end
-- check for bottom side
if (objY+objHeight>frm.Height) then volY=-volY end
-- check for Panel
-- do something
|
And for the I made using VB, this is a demo video about the same game created using CE.
In the game CE Version, I used a different script but with the same logic with the script you ask for.
Demo:
https://youtu.be/LFBOFV3Ge2Q
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
Back to top |
|
|
AylinCE Grandmaster Cheater Supreme Reputation: 32
Joined: 16 Feb 2017 Posts: 1260
|
Posted: Fri Jul 12, 2019 7:23 pm Post subject: |
|
|
I do not want the code you already have.
It makes more sense that this remains private to you.
I just wanted to see if it was possible.
And I'm convinced. Thanks.
Inspired for similar topics.
Note: Many masters can not do this coding.
That makes you privileged.
Congratulations again. and thanks for your patience.
_________________
|
|
Back to top |
|
|
Corroder Grandmaster Cheater Supreme Reputation: 75
Joined: 10 Apr 2015 Posts: 1667
|
Posted: Fri Jul 12, 2019 8:45 pm Post subject: Re: Collision Check |
|
|
Corroder wrote: | From this topic: https://forum.cheatengine.org/viewtopic.php?t=610317
Now I want to test colliding with objects created using array table.
Code: | local bricks = {}
local isBricksEnabled = {}
local brickWidth = 70
local brickHeight = 25
local brickRows = 8
local brickColumns = 8
local width, height = 70, 25
local gap = 5
form = createForm()
form.setSize(640.480)
--- create object panels as bricks
for row = 1, brickRows do
-- do something
end
|
So far this is the script but didn't work, the bricks didn't detect by the ball.
Code: | -- Check for bricks colliding
for rows = 1, brickRows do
for columns = 0, brickColumns do
if not isBrickEnabled[rows][columns] then repeat
if onCollision(gameBall,bricks[rows][columns]) then
isBrickEnabled[rows][columns] = false
if gameBall.Left + 10 < bricks[rows][columns].Left or
gameBall.Left > bricks[rows][columns].Left + bricks[rows][columns].Width then
xVel = -xVel
else
yVel = -yVel
end
end
end
end
end
|
|
[SOLVED]
I just need to add a new table, let say is as 'brickArray = {}' and this table used to store all bricks has created before.
Then to check collision between the ball and brickArray[x]:
Code: | local numEnemies = #brickArray
for x = 1, numEnemies do
if onCollision(gameBall, brickArray[x]) then
if gameBall.Left + 10 < brickArray[x].Left or gameBall.Left > brickArray[x].Left + brickArray[x].Width then
xVel = -xVel else yVel = -yVel
end
-- code to remove the collided brick here
end
end
|
Now, the last thing is how to remove/destroy the collided bricks, so it does not return an error after removed.
Aylin wrote: | ...
I just wanted to see if it was possible.
|
Yes, it is possible. I have proved it.
EDIT AND SOLVED
The full game has done. Using CE Lua. (See how, NOT JUST VB)
Demo: https://youtu.be/_E5NxseE15Y
_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|