Basically i have an image which is repeated 5 times and i am trying to make it so they cant go out of the window but no matter what i try i just cant get it to work.
Any help:
This is my full code, originally it was going to be a Snake game but the smooth change in direction absolutly baffled me. So at the min it is just 5 bxes inline that more up,down, left, right.
Any help:
This is my full code, originally it was going to be a Snake game but the smooth change in direction absolutly baffled me. So at the min it is just 5 bxes inline that more up,down, left, right.
PHP Code
<?php
function love.load()
love.graphics.setBackgroundColor(000,000,000)
segmentImage = love.graphics.newImage('images/segment.png')
startingPositionX = 200
startingPositionY = 200
bodyLength = 5;
count = 0
width = love.window.getWidth()
height = love.window.getHeight()
--load body segments image positions into table, call them later
segmentControl = {}
while count <= bodyLength do
startingPositionX = startingPositionX - 20
table.insert(segmentControl, {x=startingPositionX, y=startingPositionY})
count = count + 1
end
end
--MOVEMENT FUNCTIONS
function rightMove()
for seg = 1, bodyLength do
currentSegmentPosition_X = segmentControl[seg].x
if currentSegmentPosition_X <= 784 then
segmentControl[seg].x = currentSegmentPosition_X + 15
end
end
end
function downMove()
for seg = 1, bodyLength do
currentSegmentPosition_Y = segmentControl[seg].y
if currentSegmentPosition_Y <= 550 then
segmentControl[seg].y = currentSegmentPosition_Y + 15
end
end
end
function upMove()
for seg = 1, bodyLength do
currentSegmentPosition_Y = segmentControl[seg].y
if currentSegmentPosition_Y >= 15 then
segmentControl[seg].y = currentSegmentPosition_Y - 15
end
end
end
function leftMove()
for seg = 1, bodyLength do
currentSegmentPosition_X = segmentControl[seg].x
if currentSegmentPosition_X >= 200 then
segmentControl[seg].x = currentSegmentPosition_X - 15
end
end
end
--END OF MOVEMENT
function love.draw()
if love.keyboard.isDown("right") then
rightMove()
end
if love.keyboard.isDown("down") then
downMove()
end
if love.keyboard.isDown("up") then
upMove()
end
if love.keyboard.isDown("left") then
leftMove()
end
for i = 1, bodyLength do
love.graphics.draw(segmentImage, segmentControl[i].x, segmentControl[i].y)
end
if bodyLength == 0 then
love.graphics.setBackgroundColor(255, 0, 0)
end
end



