Collaborative Coding Horror Experiment

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
Sheepolution
Party member
Posts: 264
Joined: Mon Mar 04, 2013 9:31 am
Location: The Netherlands
Contact:

Collaborative Coding Horror Experiment

Post 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!
Last edited by Sheepolution on Mon Jun 09, 2014 9:56 pm, edited 2 times in total.
User avatar
josefnpat
Inner party member
Posts: 955
Joined: Wed Oct 05, 2011 1:36 am
Location: your basement
Contact:

Re: Collaborative Coding Horror Experiment

Post by josefnpat »

Ok, adding something now. Expect an update soon.
Missing Sentinel Software | Twitter

FORCIBLY IGNORED.
<leafo> when in doubt delete all of your code
<bartbes> git rm -r *
<bartbes> git commit -m "Fixed all bugs"
<bartbes> git push
christiankolding
Prole
Posts: 17
Joined: Sun Jul 22, 2012 11:15 am
Location: Copenhagen, Denmark
Contact:

Re: Collaborative Coding Horror Experiment

Post 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
User avatar
josefnpat
Inner party member
Posts: 955
Joined: Wed Oct 05, 2011 1:36 am
Location: your basement
Contact:

Re: Collaborative Coding Horror Experiment

Post 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
Missing Sentinel Software | Twitter

FORCIBLY IGNORED.
<leafo> when in doubt delete all of your code
<bartbes> git rm -r *
<bartbes> git commit -m "Fixed all bugs"
<bartbes> git push
User avatar
Kingdaro
Party member
Posts: 395
Joined: Sun Jul 18, 2010 3:08 am

Re: Collaborative Coding Horror Experiment

Post 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
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Collaborative Coding Horror Experiment

Post by Roland_Yonaba »

Just a small suggestion...Won't it be better to handle everything with a proper github repository and pull requests ?
User avatar
Sheepolution
Party member
Posts: 264
Joined: Mon Mar 04, 2013 9:31 am
Location: The Netherlands
Contact:

Re: Collaborative Coding Horror Experiment

Post 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
User avatar
chezrom
Citizen
Posts: 59
Joined: Tue May 28, 2013 11:03 pm
Location: France

Re: Collaborative Coding Horror Experiment

Post 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 ...
User avatar
Sheepolution
Party member
Posts: 264
Joined: Mon Mar 04, 2013 9:31 am
Location: The Netherlands
Contact:

Re: Collaborative Coding Horror Experiment

Post 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)
User avatar
Kingdaro
Party member
Posts: 395
Joined: Sun Jul 18, 2010 3:08 am

Re: Collaborative Coding Horror Experiment

Post by Kingdaro »

You're not allowed to remove or alter any lines.
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests