FAQ  •  Register  •  Login

Slot Machine Nexus

<<

sam686

User avatar

Posts: 468

Joined: Fri Oct 15, 2010 8:53 pm

Location: United States, South Dakota

Post Wed Nov 27, 2013 5:54 pm

Slot Machine Nexus

The level itself isn't very good, but it does make good way of coding levelgen.

You can put as many zones as you want without having to edit the levelgen at all.

Note, flags spawning are only useful in Nexus. You may need to change flags into something else for use in other game types.

(works for 019)
  Code:


MyObject = {}
function MyObject:New()
  local self = {}
  self.slotpos = nil
  self.slot1 = 0
  self.slot2 = 0
  self.slot3 = 0
  self.slot1obj = nil
  self.slot2obj = nil
  self.slot3obj = nil
  self.slottime = 0
  self.slotship = nil

  function self:onShipEnteredZone(ship, zone, zoneType, zoneId)
    if self.slottime == 0 then
      self.slotpos = zone:getLoc()
      self.slotship = ship
      self.slottime = 2000
    end
  end


  function self:onTick(timePassed)

    if self.slottime == 0 then return end

    if self.slottime > timePassed then
      self.slottime = self.slottime - timePassed
    else
      self.slottime = 0
      local shippos = self.slotship:getLoc()
      if shippos == nil then shippos = self.slotpos end
      if self.slot1 == self.slot2 and self.slot2 == self.slot3 then
        for a = 1, 13 * self.slot1 + 4 do
          local x = math.cos(a * 127) * 10
          local y = math.sin(a * 127) * 10
          local j = generateItem(self.slot1, shippos.x + x, shippos.y + y)
          j:setVel(point.new(x * 20, y * 20))
        end
      end
    end


    if self.slottime > 1000 + math.random(200) then
      self.slot1 = self.slot1 + 1
      if self.slot1 > 2 then self.slot1 = 0 end
      if self.slot1obj ~= nil then self.slot1obj:removeFromGame() end
      self.slot1obj = generateItem(self.slot1, self.slotpos.x - 200, self.slotpos.y - 150)
    end
    if self.slottime > 500 + math.random(200) then
      self.slot2 = self.slot2 + 1
      if self.slot2 > 2 then self.slot2 = 0 end
      if self.slot2obj ~= nil then self.slot2obj:removeFromGame() end
      self.slot2obj = generateItem(self.slot2, self.slotpos.x, self.slotpos.y - 150)
    end
    if self.slottime > 10 + math.random(200) then
      self.slot3 = self.slot3 + 1
      if self.slot3 > 2 then self.slot3 = 0 end
      if self.slot3obj ~= nil then self.slot3obj:removeFromGame() end
      self.slot3obj = generateItem(self.slot3, self.slotpos.x + 200, self.slotpos.y - 150)
    end
  end

  return self
end

slots = {}


function onShipEnteredZone(ship, zone, zoneType, zoneId)
  if zoneType == ObjType.Zone then
    if slots[zoneId] == nil then slots[zoneId] = MyObject:New() end
    slots[zoneId]:onShipEnteredZone(ship, zone, zoneType, zoneId)
  end
end

function generateItem(num, x, y)
  local obj1
  if     num == 0 then obj1 = Asteroid.new()
  elseif num == 1 then obj1 = Mine.new()
  elseif num == 2 then obj1 = FlagItem.new()
  end
  obj1:setLoc(point.new(x, y))
  levelgen:addItem(obj1)
  return obj1
end

function onTick(timePassed)
  for index, slot in pairs(slots) do
    slots[index]:onTick(timePassed)
  end

end

function main()
  subscribe(Event.tick)
  subscribe(Event.ShipEnteredZone)
end
 



(works for 018a but not 019)
  Code:

MyObject = {}
MyObject.__index = MyObject
function MyObject:New(Arg1)
  local t = {}
  setmetatable(t, MyObject )
  t.slotpos = nil
  t.slot1 = 0
  t.slot2 = 0
  t.slot3 = 0
  t.slot1obj = nil
  t.slot2obj = nil
  t.slot3obj = nil
  t.slottime = 0
  t.slotship = nil
  return(t)
end

slots = {}

function MyObject:onShipEnteredZone(ship, zone, zoneType, zoneId)
  if self.slottime == 0 then
    self.slotpos = zone:getLoc()
    self.slotship = ship
    self.slottime = 2000
  end
end

function generateItem(num, x, y)
  local obj1
  if     num == 0 then obj1 = Asteroid.new()
  elseif num == 1 then obj1 = Mine.new()
  elseif num == 2 then obj1 = FlagItem.new()
  end
  obj1:setLoc(point.new(x, y))
  levelgen:addItem(obj1)
  return obj1
end

function MyObject:onTick(timePassed)

  if self.slottime == 0 then return end

  if self.slottime > timePassed then
    self.slottime = self.slottime - timePassed
  else
    self.slottime = 0
    local shippos = self.slotship:getLoc()
    if shippos == nil then shippos = self.slotpos end
    if self.slot1 == self.slot2 and self.slot2 == self.slot3 then
      for a = 1, 13 * self.slot1 + 4 do
        local x = math.cos(a * 127) * 10
        local y = math.sin(a * 127) * 10
        local j = generateItem(self.slot1, shippos.x + x, shippos.y + y)
        j:setVel(point.new(x * 20, y * 20))
      end
    end
  end


  if self.slottime > 1000 + math.random(200) then
    self.slot1 = self.slot1 + 1
    if self.slot1 > 2 then self.slot1 = 0 end
    if self.slot1obj ~= nil then self.slot1obj:removeFromGame() end
    self.slot1obj = generateItem(self.slot1, self.slotpos.x - 200, self.slotpos.y - 150)
  end
  if self.slottime > 500 + math.random(200) then
    self.slot2 = self.slot2 + 1
    if self.slot2 > 2 then self.slot2 = 0 end
    if self.slot2obj ~= nil then self.slot2obj:removeFromGame() end
    self.slot2obj = generateItem(self.slot2, self.slotpos.x, self.slotpos.y - 150)
  end
  if self.slottime > 10 + math.random(200) then
    self.slot3 = self.slot3 + 1
    if self.slot3 > 2 then self.slot3 = 0 end
    if self.slot3obj ~= nil then self.slot3obj:removeFromGame() end
    self.slot3obj = generateItem(self.slot3, self.slotpos.x + 200, self.slotpos.y - 150)
  end
end

function onShipEnteredZone(ship, zone, zoneType, zoneId)
  if zoneType == ObjType.Zone then
    if slots[zoneId] == nil then slots[zoneId] = MyObject:New() end
    slots[zoneId]:onShipEnteredZone(ship, zone, zoneType, zoneId)
  end
end

function onTick(timePassed)
  for index, slot in pairs(slots) do
    slots[index]:onTick(timePassed)
  end
end

function main()
  subscribe(Event.tick)
  subscribe(Event.ShipEnteredZone)
end
 


Heres the level for testing this levelgen...
  Code:
NexusGameType 10 1 15 5000
LevelName "Slot Machine"
LevelDescription ""
LevelCredits sam686
GridSize 255
Team Blue 0 0 1
Specials
Script slotmachine.levelgen
MinPlayers
MaxPlayers
BarrierMaker 50 3.5 3 3.5 -3 -3.5 -3 -3.5 3 3.5 3
BarrierMaker 20 3 -1.7 0.6 -1.7 0.6 -2.3 3 -2.3 3 -1.7
BarrierMaker 20 1.4 -2.3 1.4 -1.7
BarrierMaker 20 2.2 -2.3 2.2 -1.7
BarrierMaker 20 -0.6 -1.7 -3 -1.7 -3 -2.3 -0.6 -2.3 -0.6 -1.7
BarrierMaker 20 -2.2 -2.3 -2.2 -1.7
BarrierMaker 20 -1.4 -2.3 -1.4 -1.7
BarrierMaker 20 3 0 0.6 0 0.6 -0.6 3 -0.6 3 0
BarrierMaker 20 1.4 -0.6 1.4 0
BarrierMaker 20 2.2 -0.6 2.2 0
BarrierMaker 20 -0.6 0 -3 0 -3 -0.6 -0.6 -0.6 -0.6 0
BarrierMaker 20 -2.2 -0.6 -2.2 0
BarrierMaker 20 -1.4 -0.6 -1.4 0
BarrierMaker 20 3 2.3 0.6 2.3 0.6 1.7 3 1.7 3 2.3
BarrierMaker 20 1.4 1.7 1.4 2.3
BarrierMaker 20 2.2 1.7 2.2 2.3
BarrierMaker 20 -0.6 2.3 -3 2.3 -3 1.7 -0.6 1.7 -0.6 2.3
BarrierMaker 20 -2.2 1.7 -2.2 2.3
BarrierMaker 20 -1.4 1.7 -1.4 2.3
BarrierMaker 20 1.2 1.2 -1.2 1.2 -1.2 0.6 1.2 0.6 1.2 1.2
BarrierMaker 20 -0.4 0.6 -0.4 1.2
BarrierMaker 20 0.4 0.6 0.4 1.2
Zone 1.7 -1.5 1.7 -1.3 1.9 -1.3 1.9 -1.5
Spawn 0 0 -2
LineItem -1 2 1.9 -1.3 1.9 -1.5 1.7 -1.5 1.7 -1.3 1.9 -1.3
NexusZone -0.5 -2.8 -0.5 -2.5 0.4 -2.5 0.4 -2.8
Zone -1.9 -1.5 -1.9 -1.3 -1.7 -1.3 -1.7 -1.5
LineItem -1 2 -1.7 -1.3 -1.7 -1.5 -1.9 -1.5 -1.9 -1.3 -1.7 -1.3
Zone 1.7 0.2 1.7 0.4 1.9 0.4 1.9 0.2
LineItem -1 2 1.9 0.4 1.9 0.2 1.7 0.2 1.7 0.4 1.9 0.4
Zone -1.9 0.2 -1.9 0.4 -1.7 0.4 -1.7 0.2
LineItem -1 2 -1.7 0.4 -1.7 0.2 -1.9 0.2 -1.9 0.4 -1.7 0.4
Zone 1.7 2.5 1.7 2.7 1.9 2.7 1.9 2.5
LineItem -1 2 1.9 2.7 1.9 2.5 1.7 2.5 1.7 2.7 1.9 2.7
Zone -1.9 2.5 -1.9 2.7 -1.7 2.7 -1.7 2.5
LineItem -1 2 -1.7 2.7 -1.7 2.5 -1.9 2.5 -1.9 2.7 -1.7 2.7
Spawn 0 0 0
Spawn 0 0 2
Spawn 0 -2 1
Spawn 0 2 1
Spawn 0 2 -1
Zone -0.1 1.4 -0.1 1.6 0.1 1.6 0.1 1.4
LineItem -1 2 0.1 1.6 0.1 1.4 -0.1 1.4 -0.1 1.6 0.1 1.6
 
Last edited by sam686 on Tue Dec 10, 2013 6:06 am, edited 1 time in total.
Reason: Added changes for version 019
<<

tazinator

Posts: 351

Joined: Fri Jul 05, 2013 7:35 pm

Post Wed Nov 27, 2013 9:18 pm

Re: Slot Machine Nexus

Thanks Sam. Fun levelgen :D
Play my new level! Two different teams fight over a nexus: One mainly defends while the other attacks! is fun
viewtopic.php?f=33&p=21002#p21002
<<

sam686

User avatar

Posts: 468

Joined: Fri Oct 15, 2010 8:53 pm

Location: United States, South Dakota

Post Tue Dec 10, 2013 6:16 am

Re: Slot Machine Nexus

Made some changes to make this levelgen work on 019. Functions inside function works, but looks a little more messy to me then my original way. Putting everything inside new() function appears not so good, but it works and it runs on 019.

Return to Levelgen Gallery

Who is online

Users browsing this forum: No registered users and 1 guest

cron