First of, I am new to programming, obviously new to Lua and Lo[e]ve
I am dreaming, as I read on the board as some of you, of a zelda-esque game. You know, some dungeons, a worldmap, some events, bosses and some weapons, a save function and so on.
I know, pretty high aim for a beginner, nevertheless not unreachable. So I decided to create a little game. Learning by doing. After completing some starting tutorials for basic Lo[e]ve functions, I thought it might be a good start, using the first tutorial (moving an image) to go to a "higher" level. Still small breads...
So I ended up with GHOSTLY.
First of all I describe what I intended, then I post you the code and last but not least, the problem that occured .
GHOSTLY
You have a friendly ghost that's soaring through the night. You can move, left,right and up. The controls are left key for left, right key for right and up key for... well .. up. However by pressing down, the ghost constantly soars down and the game will restart, after the ghost reached the bottom (so it's your duty to keep that little ghost flying ).
That's all it should do by now. Later on I want to add collission, enemies and a sidescrolling level, but well, as I said, I am a beginner and I want to expand my knowledge by creating and expanding this game step by step.
Problems that occured so far
Well, I don't get the ghost to soar down. I used true / false and repeat - until loop, however nothing happens at all, but I think the game is getting stuck in the loop (and I see no problem there) and well doesn't react at all.
Here is the code.
Code: Select all
-- GHOSTLY Demo by F. Bingart aka GHOSTLY
-- Want to learn more about Lua and Lo[e]ve
-- I would be grateful if you want to help me out
-- Thanks in advance for all suggestions, tipps and helpful comments
---------------------------------------------------------------------------------------------------------------------------------------------------
-- I'm a absolute beginner to coding, lua and Lo[e]ve, however I am eager to learn
-- I want to start small, so I can really learn things, then just asking for code, code, code. I really want to understand where I messed up
function load()
-- Variables
ghostly_r = -- loading right looking ghost, isn't he cute, done by me, using gimp
love.graphics.newImage("images/ghost_right.png")
ghostly_l = -- loding left looking ghost, isn't he cute, done by me, using gimp
love.graphics.newImage("images/ghost_left.png")
ghostlypicture = -- to alter the picture, according to the buttons pressed, I guess it's easier using another variable
ghostly_r
ghostlyx = -- start x variable, centers the ghost
400
ghostlyy = -- start y variable, centers the ghost
300
ghostlyspeed = -- high velocity, baby
5
ghostlygravity = -- if the gravity is true, the ghost shall fall permanently, look further down the code. thanks.
false
-- Backgroundcolor
love.graphics.setBackgroundColor(50, 5 , 185) -- I lo[e]ve me some blue, also I was able test the transparacy of the .png files
end
function update(dt)
-- Setting end of game
if ghostlyy > 600 then
restart() -- later on the ghost shall hit things and causes a game over screen,
end -- but since I am in the "beginning class" this shall do it for now
-- Movement controls and triggering gravity
if love.keyboard.isDown(love.key_right) then
ghostlygravity = true -- triggers "ghostlygravity", if that's the fist button you press
ghostlyx = ghostlyx + (ghostlyspeed * dt) -- movement right
ghostlypicture = ghostly_r -- sets "ghostlypicture" to ghost_right.png
elseif love.keyboard.isDown(love.key_left) then
ghostlygravity = true -- triggers "ghostlygravity", if that's the fist button you press
ghostlyx = ghostlyx - (ghostlyspeed * dt) -- movement left
ghostlypicture = ghostly_l -- Sets "ghostlypicture" to ghost_left.png
end
if love.keyboard.isDown(love.key_up) then
ghostlygravity = true -- triggers "ghostlygravity", if that's the fist button you press
ghostlyy = ghostlyy - (ghostlyspeed * dt * 1.5) -- movement up, * 1.5 for giving you the opportunity to raise again, slowly, but you'll raise
end
-- Gravitycheck and what to do
if ghostlygravity == true then -- basicly, the Ghost shall drop down, until "ghostlygravity" is false again
repeat
ghostlyy = ghostlyy + (ghostlyspeed * dt)
until ghostlygravity == false
end
end
function draw()
love.graphics.draw(ghostlypicture, ghostlyx, ghostlyy)
end
- GHOSTLY / F. Bingart
Oh.. and before I forget, here is the Love