-- objects: s. http://www.lua.org/pil/16.4.html -- s. http://www.fh-wedel.de/~si/seminare/ws09/Ausarbeitung/09.lua/lua4.htm#Vererbung function creature (width,height) local self = love.graphics.newCanvas( width, height ) local w = width local h = height local xpos -- [0,800] local ypos -- [0,600] local xdir -- {-1,0,1} local ydir -- {-1,0,1} local speed -- [0.1,1] local init = function (xsrc,ysrc,x,y,xd,yd,sp) -- xsrc, ysrc = copy-position (out of .GIF) xpos = x -- center ypos = y -- center xdir = xd ydir = yd speed = sp self:renderTo(function() love.graphics.draw(creatures, xsrc,ysrc) love.graphics.rectangle( "line",0,0,w,h) end) end local getx = function() return xpos end local gety = function() return ypos end local getw = function() return w end local draw = function () love.graphics.draw(self, xpos-w/2, ypos-h/2) end local move = function () ypos = ypos+(ydir*speed) if ypos < 200 then ydir=1 end if ypos > 400 then ydir=-1 end end local moveto = function (x,y) ypos = y xpos = x end local collide = function (x,y) return ( (x>xpos-w/2) and (xypos-h/2) and (y 800 then xpos=5 end end local moveto = function(x,y) xpos=x ypos=y end local collide = function (x,y) return ( (x>xpos-w/2) and (xypos-h/2) and (y 0 then shotwait=shotwait-1 end if playerx<0 then playerx=800-5 end if playerx>800 then playerx=5 end if playery<0 then playery=600-5 end if playery>600 then playery=5 end end function funny_background() for i=0,30,1 do love.graphics.setColor(100+i*5,100+i*5,255) love.graphics.rectangle( "fill", 0, i*10, 800, 20 ) end for i=60,30,-1 do love.graphics.setColor(100+i*5,255,100+i*5) -- hier ist irgendwas komisch -> wenn ich i verändere, ändert sich ansch. auch die Höhe der rectangles !?! love.graphics.rectangle( "fill", 0, i*10, 800, 20 ) end end function love.draw() love.graphics.setCaption("evoLUTION alpha") love.graphics.setBackgroundColor( 255,255,255 ) funny_background() love.graphics.setColor(255,255,255) -- reset previous color changes !?! if player==1 then fish.moveto(playerx,playery) else fish.move() end if player==2 then seal.moveto(playerx,playery) else seal.move() end if player==3 then dog.moveto(playerx,playery) else dog.move() end if player==4 then man.moveto(playerx,playery) else man.move() end for i=0,10,1 do if true==shot[i].getshot() then shot[i].move() shot[i].draw() -- love.graphics.print("shot "..tostring(shot[i].getshot()), 10, i*10) end if fish.collide(shot[i].getx(),shot[i].gety()) then player=1 shot[i].moveto(0,0) shot[i].setshot(false) playerx=fish.getx() playery=fish.gety() else fish.draw() end if seal.collide(shot[i].getx(),shot[i].gety()) then player=2 shot[i].moveto(0,0) shot[i].setshot(false) playerx=seal.getx() playery=seal.gety() else seal.draw() end if dog.collide(shot[i].getx(),shot[i].gety()) then player=3 shot[i].moveto(0,0) shot[i].setshot(false) playerx=dog.getx() playery=dog.gety() else dog.draw() end if man.collide(shot[i].getx(),shot[i].gety()) then player=4 shot[i].moveto(0,0) shot[i].setshot(false) playerx=man.getx() playery=man.gety() else man.draw() end end love.graphics.setColor(0,0,0) love.graphics.print("FPS: "..tostring(love.timer.getFPS()), 730, 314) love.graphics.print("BBOX on", 730, 334) love.graphics.print("Press SPACE | arrow keys", 300, 580) end