Page 1 of 2

Collaborative Coding Horror Experiment

Posted: Sun Jun 08, 2014 9:57 pm
by Sheepolution
Basically this. But I made a new thread since that one didn't take off, and now already has 4 useless pages. So unlike that thread, I want to start off right away.

Just like that ^ thread says, this idea is based on this: http://www.gamedev.net/topic/649258-the ... ts-are-in/
We'll be keeping the same rules which are:
  • I will post a basic skeleton main.lua file.
  • Posts here will act as a kind of revision (un)control system, each post a "commit"
  • You must attempt to amend the current version of the code
  • The code change for a single "commit" should be relatively small and cohesive - add or change a single feature at most
  • Posts should highlight what was changed
  • Posts should include the full source of the program so far
  • The program will be in a single file only
  • Dependencies are limited to the standard library and the multimedia library only. No OS-specific calls
  • Assets may be attached to your post, they should be free of copyright restrictions
  • You can only add new code, not alter or remove existing code
  • You may, however, alter numeric or string constants in existing code
  • You may add code into existing lines:
  • Add a new clause to a condition
  • Add to an existing expression
  • Add parameters to existing function declaration/definition/call sites
  • Adding -- at the start of a line is allowed by this rule (?) (but keep it limited to 1 or 2 per commit?)
  • You may also "insert" a newline after a --, thus uncommenting such code
  • The code must not crash, to the best of your ability
  • Bad commits are ignorable under the "amend the current version" rule
It should be only the main.lua file. No images, audio, or fonts.

So, I will start:

Code: Select all

--Collaborative Coding Horror Experiment
--Commit 1

function love.load()
	player = Player(100,100)
end


function love.update(dt)

end


function love.draw()
	player.draw()
end

function love.keypressed(key)
	
end

function love.keyreleased(key)
	
end

function love.mousepressed(x,y,button)
	
end

function love.mousereleased(x,y,button)
	
end


function Player(x,y)
	local self = {x=x,y=y}
	function self.draw()
		love.graphics.setColor(30,80,120)
		love.graphics.circle("fill",self.x,self.y,50,50)
		love.graphics.setColor(255,255,255)
		love.graphics.circle("fill",self.x-25,self.y-15,5,50)
		love.graphics.circle("fill",self.x+25,self.y-15,5,50)
		love.graphics.arc("fill",self.x,self.y+10,20,-0,math.pi)
	end

	return self
end
For the newest version, check the latest post in this thread, or the github page. I try to merge all pullrequests as soon as possible.
Github

Don't be afraid to join this because you're not 'good enough'. Who cares if your code is bad? That's the whole idea of your project anyway. As long as your code works, it's never a bad for this experiment.

Let's make something horrible and fun!

Re: Collaborative Coding Horror Experiment

Posted: Sun Jun 08, 2014 10:17 pm
by josefnpat
Ok, adding something now. Expect an update soon.

Re: Collaborative Coding Horror Experiment

Posted: Sun Jun 08, 2014 10:18 pm
by christiankolding
Great idea! I will start with something simple. Player is now repositioned upon left mouse click!

Change:

Code: Select all

function love.mousepressed(x,y,button)
    if button == "l" then
        player = Player(x, y)
    end
end
Full code:

Code: Select all

--Collaborative Coding Horror Experiment
--Commit 2

function love.load()
   player = Player(100,100)
end


function love.update(dt)
end


function love.draw()
   player.draw()
end

function love.keyboard(key)
   
end

function love.keyreleased(key)
   
end

function love.mousepressed(x,y,button)
    if button == "l" then
        player = Player(x, y)
    end
end

function love.mousereleased(x,y,button)
   
end


function Player(x,y)
   local self = {x=x,y=y}
   function self.draw()
      love.graphics.setColor(30,80,120)
      love.graphics.circle("fill",self.x,self.y,50,50)
      love.graphics.setColor(255,255,255)
      love.graphics.circle("fill",self.x-25,self.y-15,5,50)
      love.graphics.circle("fill",self.x+25,self.y-15,5,50)
      love.graphics.arc("fill",self.x,self.y+10,20,-0,math.pi)
   end

   return self
end

Re: Collaborative Coding Horror Experiment

Posted: Sun Jun 08, 2014 10:25 pm
by josefnpat
Ok, merged changes.

I have added health and a fantastic (read annoying) background.

Code: Select all

--Collaborative Coding Horror Experiment
--Commit 1

function love.load()
   player = Player(100,100)
end


function love.update(dt)

   player:update(dt)
end


function love.draw()
   local rumble = 10
   local c = healthcolor(player.health/player.health_max)
   love.graphics.setColor(c[1],c[2],c[3])
   local offset = {
      x=math.random(0,rumble),
      y=math.random(0,rumble)
   }
   local size = {
        w=love.window.getWidth()-offset.x-math.random(0,rumble),
        h=love.window.getHeight()-offset.y-math.random(0,rumble)
   }
   love.graphics.rectangle("fill",offset.x,offset.y,size.w,size.h)
   player.draw()
end

function love.keypressed(key)
   
end

function love.keyreleased(key)
   
end

function love.mousepressed(x,y,button)
    if button == "l" then
        player = Player(x, y)
    end
end

function love.mousereleased(x,y,button)
   
end


function Player(x,y)
   local self = {x=x,y=y}
   self.health = 100
   self.health_max = 100
   self.health_dt = 0
   self.health_dt_t = 0.1
   self.update = function(self,dt)
      self.health_dt = self.health_dt + dt
      if self.health_dt > self.health_dt_t then
         self.health_dt = self.health_dt - self.health_dt_t
         self:upkeep()
      end
   end
   self.upkeep = function(self)
     self.health = self.health - 1
   end
   function self.draw()
      love.graphics.setColor(30,80,120)
      love.graphics.circle("fill",self.x,self.y,50,50)
      love.graphics.setColor(255,255,255)
      love.graphics.circle("fill",self.x-25,self.y-15,5,50)
      love.graphics.circle("fill",self.x+25,self.y-15,5,50)
      love.graphics.arc("fill",self.x,self.y+10,20,-0,math.pi)
   end

   return self
end

function healthcolor(i)
   -- Clamp
   if i > 1 then i = 1 end
   if i < 0 then i = 0 end
   -- 0 -> 0.5: 255
   -- 0.5 -> 1: 255 .. 0
   local r = 255*2 - 255*2*i
    if r > 255 then r = 255 end
   -- 0 -> 0.5: 0 .. 255
   -- 0.5 -> 1: 255
    local g = 255*2*i
   if g > 255 then g = 255 end
   -- 0 -> 1: 0
   local b = 0
   return {r,g,b}
end

Re: Collaborative Coding Horror Experiment

Posted: Mon Jun 09, 2014 8:49 am
by Kingdaro
Now he spins.

Code: Select all

function Player(x,y)
   ...
      self:spin(dt)
   ...
      love.graphics.push()
      love.graphics.translate(self.x, self.y)
      love.graphics.rotate(self.rotation)
      love.graphics.translate(-self.x, -self.y)
   ...
      love.graphics.pop()
   ...
   self.rotation = 0
   function self.spin(self, dt)
      self.rotation = self.rotation + math.pi * 4 * dt
   end
   ...
end
Full code:

Code: Select all

--Collaborative Coding Horror Experiment
--Commit 3

function love.load()
   player = Player(100,100)
end


function love.update(dt)

   player:update(dt)
end


function love.draw()
   local rumble = 10
   local c = healthcolor(player.health/player.health_max)
   love.graphics.setColor(c[1],c[2],c[3])
   local offset = {
      x=math.random(0,rumble),
      y=math.random(0,rumble)
   }
   local size = {
      w=love.window.getWidth()-offset.x-math.random(0,rumble),
      h=love.window.getHeight()-offset.y-math.random(0,rumble)
   }
   love.graphics.rectangle("fill",offset.x,offset.y,size.w,size.h)
   player.draw()
end

function love.keypressed(key)
   
end

function love.keyreleased(key)
   
end

function love.mousepressed(x,y,button)
   if button == "l" then
      player = Player(x, y)
   end
end

function love.mousereleased(x,y,button)
   
end


function Player(x,y)
   local self = {x=x,y=y}
   self.health = 100
   self.health_max = 100
   self.health_dt = 0
   self.health_dt_t = 0.1

   self.update = function(self,dt)
      self.health_dt = self.health_dt + dt
      if self.health_dt > self.health_dt_t then
         self.health_dt = self.health_dt - self.health_dt_t
         self:upkeep()
      end
      self:spin(dt)
   end
   self.upkeep = function(self)
     self.health = self.health - 1
   end
   function self.draw()
      love.graphics.push()
      love.graphics.translate(self.x, self.y)
      love.graphics.rotate(self.rotation)
      love.graphics.translate(-self.x, -self.y)

      love.graphics.setColor(30,80,120)
      love.graphics.circle("fill",self.x,self.y,50,50)
      love.graphics.setColor(255,255,255)
      love.graphics.circle("fill",self.x-25,self.y-15,5,50)
      love.graphics.circle("fill",self.x+25,self.y-15,5,50)
      love.graphics.arc("fill",self.x,self.y+10,20,-0,math.pi)

      love.graphics.pop()
   end

   self.rotation = 0
   function self.spin(self, dt)
      self.rotation = self.rotation + math.pi * 4 * dt
   end

   return self
end

function healthcolor(i)
   -- Clamp
   if i > 1 then i = 1 end
   if i < 0 then i = 0 end
   -- 0 -> 0.5: 255
   -- 0.5 -> 1: 255 .. 0
   local r = 255*2 - 255*2*i
   if r > 255 then r = 255 end
   -- 0 -> 0.5: 0 .. 255
   -- 0.5 -> 1: 255
   local g = 255*2*i
   if g > 255 then g = 255 end
   -- 0 -> 1: 0
   local b = 0
   return {r,g,b}
end

Re: Collaborative Coding Horror Experiment

Posted: Mon Jun 09, 2014 9:12 am
by Roland_Yonaba
Just a small suggestion...Won't it be better to handle everything with a proper github repository and pull requests ?

Re: Collaborative Coding Horror Experiment

Posted: Mon Jun 09, 2014 11:03 am
by Sheepolution
Roland_Yonaba wrote:Just a small suggestion...Won't it be better to handle everything with a proper github repository and pull requests ?
Done. https://github.com/DaanHaaz/CCHE

But if people don't use git or don't know how to, they're free to post their version in this thread.
Of course it can go wrong sometimes, but I think it will work.

Current version:

Diff
Made the player's position change instead of making a whole new player instance.

Code: Select all

@@ -1,5 +1,4 @@
 --Collaborative Coding Horror Experiment
---Commit 3
 
 function love.load()
    player = Player(100,100)
@@ -38,7 +37,7 @@
 
 function love.mousepressed(x,y,button)
    if button == "l" then
-      player = Player(x, y)
+      player.x, player.y = player.setPlayerPosition(x, y)
    end
 end
 
@@ -86,6 +85,11 @@
       self.rotation = self.rotation + math.pi * 4 * dt
    end
 
+   function self.setPlayerPosition(x,y)
+      self.x, self.y = x, y
+      return self.x, self.y
+   end
+
    return self
 end

Code: Select all

--Collaborative Coding Horror Experiment

function love.load()
   player = Player(100,100)
end


function love.update(dt)

   player:update(dt)
end


function love.draw()
   local rumble = 10
   local c = healthcolor(player.health/player.health_max)
   love.graphics.setColor(c[1],c[2],c[3])
   local offset = {
      x=math.random(0,rumble),
      y=math.random(0,rumble)
   }
   local size = {
      w=love.window.getWidth()-offset.x-math.random(0,rumble),
      h=love.window.getHeight()-offset.y-math.random(0,rumble)
   }
   love.graphics.rectangle("fill",offset.x,offset.y,size.w,size.h)
   player.draw()
end

function love.keypressed(key)
   
end

function love.keyreleased(key)
   
end

function love.mousepressed(x,y,button)
   if button == "l" then
      player.x, player.y = player.setPlayerPosition(x, y)
   end
end

function love.mousereleased(x,y,button)
   
end


function Player(x,y)
   local self = {x=x,y=y}
   self.health = 100
   self.health_max = 100
   self.health_dt = 0
   self.health_dt_t = 0.1

   self.update = function(self,dt)
      self.health_dt = self.health_dt + dt
      if self.health_dt > self.health_dt_t then
         self.health_dt = self.health_dt - self.health_dt_t
         self:upkeep()
      end
      self:spin(dt)
   end
   self.upkeep = function(self)
     self.health = self.health - 1
   end
   function self.draw()
      love.graphics.push()
      love.graphics.translate(self.x, self.y)
      love.graphics.rotate(self.rotation)
      love.graphics.translate(-self.x, -self.y)

      love.graphics.setColor(30,80,120)
      love.graphics.circle("fill",self.x,self.y,50,50)
      love.graphics.setColor(255,255,255)
      love.graphics.circle("fill",self.x-25,self.y-15,5,50)
      love.graphics.circle("fill",self.x+25,self.y-15,5,50)
      love.graphics.arc("fill",self.x,self.y+10,20,-0,math.pi)

      love.graphics.pop()
   end

   self.rotation = 0
   function self.spin(self, dt)
      self.rotation = self.rotation + math.pi * 4 * dt
   end

   function self.setPlayerPosition(x,y)
      self.x, self.y = x, y
      return self.x, self.y
   end

   return self
end

function healthcolor(i)
   -- Clamp
   if i > 1 then i = 1 end
   if i < 0 then i = 0 end
   -- 0 -> 0.5: 255
   -- 0.5 -> 1: 255 .. 0
   local r = 255*2 - 255*2*i
   if r > 255 then r = 255 end
   -- 0 -> 0.5: 0 .. 255
   -- 0.5 -> 1: 255
   local g = 255*2*i
   if g > 255 then g = 255 end
   -- 0 -> 1: 0
   local b = 0
   return {r,g,b}
end

Re: Collaborative Coding Horror Experiment

Posted: Mon Jun 09, 2014 11:19 am
by chezrom
Err ... your last modification breaks one of your rules : you have deleted existing code.

The solution to avoid the remove of the line and the recreation of player instance is to add a parameter to Player, that can be nil, and is an already existing instance (we modify x and y and return) . It's crap but eh it's a Coding Horror ...

Re: Collaborative Coding Horror Experiment

Posted: Mon Jun 09, 2014 11:35 am
by Sheepolution
chezrom wrote:Err ... your last modification breaks one of your rules : you have deleted existing code.
Well actually not, I modified it, but I haven't removed a single existing character.

Original: player = Player(x, y)
New: player.x, player.y = player.setPlayerPosition(x, y)

Re: Collaborative Coding Horror Experiment

Posted: Mon Jun 09, 2014 12:07 pm
by Kingdaro
You're not allowed to remove or alter any lines.