Created
May 24, 2012 02:25
-
-
Save devilstower/2779074 to your computer and use it in GitHub Desktop.
Battle Chips 23MAY12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Arena = class() | |
function Arena:init(l, b, r, t) | |
self:sizeFrames(l, b, r, t) | |
self.robots = {} | |
self.timer = 0 | |
self.tourney = false | |
self.gameOver = false | |
self.game = 1 | |
self.pulse = 0 | |
self.pulseDirection = 2 | |
self.skeet = {} | |
self.launchTime = ElapsedTime | |
end | |
function Arena:sizeFrames(l, b, r, t) | |
-- define bounds for the arena | |
self.frame = Frame(l, b, r, t) | |
self.panel = Frame(l + 1, t - 90, r - 1, t - 1) | |
self.stop = Frame(r - 70, t - 65, r - 30, t - 25) | |
self.field = Frame(l + 5, b + 20, r - 5, t - 90) | |
self.launch = Frame(self.frame:midX() - 30, self.frame.bottom - 15, | |
self.frame:midX() + 30, self.frame.bottom + 30) | |
end | |
function Arena:loadRobot(r) | |
-- copy a robot into the arena, and set up for action | |
local i, nr | |
nr = Robot(math.random(self.field:width() - 90) + 30, | |
math.random(self.field:height() - 90) + 30) | |
nr.hp = r.hp | |
nr.direction = math.random(4) | |
for i = 1, table.maxn(r.program) do | |
nr.program[i] = r.program[i] | |
end | |
nr.bounds = Frame(nr.x, nr.y, nr.x + 60, nr.y + 60) | |
nr.program = r.program | |
nr.bump = false | |
nr.radar = false | |
nr.heat = 0 | |
nr.step = 1 | |
nr.wins = r.wins | |
nr.losses = r.losses | |
nr.name = r.name | |
nr.repeatCounter = 1 | |
nr.points = 0 | |
nr.treadColor = r.treadColor | |
nr.bodyColor = r.bodyColor | |
nr.headColor = r.headColor | |
nr.dishColor = r.dishColor | |
nr.head = r.head | |
nr.dish = r.dish | |
nr.body = r.body | |
nr.tread = r.tread | |
nr.limits = self.field | |
i = table.maxn(self.robots) + 1 | |
-- design stuff here for now. should probably move. | |
nr.speed = r.tread * 4 - (r.body - 1) | |
nr.turnDelay = r.tread * 15 - 10 | |
nr.shield = (r.head - 1) * 3.5 | |
nr.repairRate = 1 / r.head | |
nr.weaponStrength = nr.dish * 2.5 - 2 | |
self.robots[i] = nr | |
self.robots[i]:createImage() | |
end | |
function Arena:copyRobot(r) | |
-- copy using deepcopy | |
-- seems to have trouble with otder of code | |
local i, nr | |
nr = deepcopy(r) | |
nr.direction = math.random(4) | |
nr.bounds = Frame(nr.x, nr.y, nr.x + 60, nr.y + 60) | |
nr.bump = false | |
nr.radar = false | |
nr.heat = 0 | |
nr.step = 1 | |
nr.points = 0 | |
i = table.maxn(self.robots) + 1 | |
self.robots[i] = nr | |
end | |
function Arena:skeetMatch(r) | |
self.game = 2 | |
self:loadRobot(r) | |
self.robots[1].x = self.field:width() / 2 | |
self.robots[1].x = self.field:height() / 2 | |
self.robots[1].bounds = Frame(self.robots[1].x, | |
self.robots[1].y, self.robots[1].x + 60, self.robots[1].y + 60) | |
self.skeet[1] = Skeet(30, 30, self.field) | |
self.skeet[2] = Skeet(30, self.field:height() / 2, self.field) | |
self.skeet[3] = Skeet(30, self.field:height() - 30, self.field) | |
self.skeet[4] = Skeet(self.field:width() / 2, | |
self.field:height() - 30, self.field) | |
self.skeet[5] = Skeet(self.field:width() - 30, | |
self.field:height() - 30, self.field) | |
self.skeet[6] = Skeet(self.field:width() - 30, | |
self.field:height() / 2, self.field) | |
self.skeet[7] = Skeet(self.field:width() - 30, 30, self.field) | |
self.skeet[8] = Skeet(self.field:width() / 2, 30, self.field) | |
self.timer = 300 | |
self.tourney = true | |
end | |
function Arena:clear() | |
-- pop robots from arena | |
sound(SOUND_POWERUP, 2591) | |
self.robots = {} | |
self.skeet = {} | |
self.timer = 0 | |
self.game = 1 | |
self.gameOver = false | |
self.tourney = false | |
end | |
function Arena:testBounds(type, num, bounds) | |
for i, r in ipairs(self.robots) do | |
if type ~= 1 or num ~= i then | |
if r.bounds:overlaps(bounds) and r.hp > 0 then | |
if r.bounds.left < bounds.left then | |
return 1 | |
elseif r.bounds.left > bounds.left then | |
return 2 | |
elseif r.bounds.top < bounds.top then | |
return 3 | |
elseif r.bounds.top > bounds.left then | |
return 4 | |
end | |
end | |
end | |
end | |
for i, s in ipairs(self.skeet) do | |
if (type ~= 2 or num ~= i) and s.active == 1 then | |
if s.bounds:overlaps(bounds) then | |
if s.bounds.left < bounds.left then | |
return 1 | |
elseif s.bounds.left > bounds.left then | |
return 2 | |
elseif s.bounds.top < bounds.top then | |
return 3 | |
elseif s.bounds.top > bounds.left then | |
return 4 | |
end | |
end | |
end | |
end | |
return 0 | |
end | |
function Arena:checkRadar(k, r) | |
local i, robot | |
r.radar = false | |
for i, robot in ipairs(self.robots) do | |
if i ~= k then | |
if r.rf:overlaps(robot.bounds) and robot.hp > 0 then | |
r.radar = true | |
end | |
end | |
end | |
for i, skeet in ipairs(self.skeet) do | |
if r.rf:overlaps(skeet.bounds) and skeet.active == 1 then | |
r.radar = true | |
end | |
end | |
r.fireRadar = false | |
end | |
function Arena:checkLaser(k, r) | |
local i, robot | |
for i, robot in ipairs(self.robots) do | |
if i ~= k then | |
if r.rf:overlaps(robot.bounds) then | |
if robot.hp > 0 then | |
-- distance between | |
--d = robot.bounds. | |
robot.hp = robot.hp - r.weaponStrength | |
r.points = r.points + 1 | |
if robot.heat < 20 then | |
robot.heat = robot.heat + 5 | |
end | |
end | |
end | |
end | |
end | |
for i, s in ipairs(self.skeet) do | |
if r.rf:overlaps(s.bounds) and s.active == 1 then | |
r.points = r.points + 1 | |
s.active = 2 | |
end | |
end | |
r.fireLaser = false | |
end | |
function Arena:checkCollisions(k, r) | |
local i, b | |
b = self:testBounds(1, k, r.bounds) | |
if b == 1 then | |
-- hit from left | |
if r.x < self.field:width() - 60 then r.x = r.x + 5 end | |
elseif b == 2 then | |
-- hit from right | |
if r.x > 30 then r.x = r.x - 5 end | |
elseif b == 1 then | |
-- hit from bottom | |
if r.y < self.field:height() - 30 then r.y = r.y + 5 end | |
elseif b == 1 then | |
-- hit from top | |
if r.y > 30 then r.y = r.y - 5 end | |
end | |
if b > 0 then r.bump = true end | |
end | |
function Arena:checkSkeetCollisions(k, s) | |
local i, b | |
b = self:testBounds(2, k, s.bounds) | |
if b > 0 then | |
s.dx = - s.dx | |
s.dy = - s.dy | |
end | |
end | |
function Arena:setMatch(a, b, c, d) | |
self.robots = {} | |
self:loadRobot(a) | |
self:loadRobot(b) | |
self:loadRobot(c) | |
self:loadRobot(d) | |
self.timer = 100 | |
end | |
function Arena:draw() | |
local k, robot, liveCount, i | |
-- base elements | |
pushStyle() | |
stroke(255, 255, 255, 255) | |
strokeWidth(2) | |
noFill() | |
self.frame:draw() | |
self.panel:inset(10, 10) | |
self.panel:draw() | |
self.panel:inset(-10, -10) | |
line(20, 40, WIDTH - 20, 40) | |
if self.game == 2 then | |
if self.robots[1].points == 8 or self.timer == 0 then | |
self.gameOver = true | |
end | |
end | |
self.stop:draw() | |
for i = 1,3 do | |
y = self.field.bottom + self.field:height() / 4 * i | |
line(self.field.left, y, self.field.left + 10, y) | |
line(self.field.right - 10, y, self.field.right, y) | |
end | |
self.pulse = self.pulse + self.pulseDirection | |
if self.pulse > 255 or self.pulse < 0 then | |
self.pulseDirection = 0 - self.pulseDirection | |
end | |
stroke(255, 55, 55, self.pulse) | |
ellipse(self.stop:midX(), self.stop:midY(), 30) | |
ellipse(self.stop:midX(), self.stop:midY(), 20) | |
fill(255, 255, 255, 255) | |
fontSize(36) | |
text("Battle Chips",self.panel.left + 25, self.panel.top - 60) | |
pushMatrix() | |
translate(self.frame.left, self.frame.bottom) | |
if not self.gameOver then | |
-- draw skeet | |
for i, s in ipairs(self.skeet) do | |
if s.active < 10 then | |
s:draw() | |
self:checkSkeetCollisions(i, s) | |
end | |
end | |
-- draw robots | |
noSmooth() | |
liveCount = 0 | |
for k, robot in ipairs(self.robots) do | |
if robot.hp > 0 then liveCount = liveCount + 1 end | |
if robot.fireRadar then | |
self:checkRadar(k, robot) | |
end | |
if robot.fireLaser then | |
self:checkLaser(k, robot) | |
end | |
self:checkCollisions(k, robot) | |
if robot.hp > 0 then | |
robot:run() | |
else | |
robot.hp = 0 | |
end | |
robot:draw(1) | |
end | |
if liveCount < 2 and self.game == 4 then | |
self.timer = self.timer - 1 | |
else | |
self.timer = self.timer - 0.1 | |
end | |
if self.timer < 0 then self.timer = 0 end | |
popMatrix() | |
fontSize(12) | |
textMode(CENTER) | |
for k, robot in ipairs(self.robots) do | |
x = self.frame.right - k * 60 - 100 | |
y = self.panel.bottom + 35 | |
sprite(robot.img, x - 15, y, x + 15, y + 30) | |
fill(26, 26, 26, 255) | |
stroke(130, 154, 221, 255) | |
rect(self.frame.right - k * 60 - 127, self.panel.bottom + 35, | |
self.frame.right - k * 60 - 120, self.panel.bottom + 65) | |
if robot.hp > 7 then | |
fill(72, 255, 0, 255) | |
elseif robot.hp > 4 then | |
fill(244, 255, 0, 255) | |
else | |
fill(255, 0, 13, 255) | |
end | |
noStroke() | |
rect(self.frame.right - k * 60 - 126, self.panel.bottom + 36, | |
self.frame.right - k * 60 - 121, self.panel.bottom + 36 + | |
robot.hp * 3) | |
fill(248, 248, 248, 255) | |
text(robot.points, self.frame.right - k * 60 - 100, | |
self.panel.bottom + 25) | |
end | |
if self.tourney then | |
textMode(CORNER) | |
fontSize(48) | |
fill(218, 214, 214, 81) | |
if self.game == 2 then | |
text("Skeet", self.field.left + 15, self.field.top - 60) | |
end | |
text(math.floor(self.timer), | |
self.frame.left + 15, self.field.bottom) | |
else | |
strokeWidth(1) | |
stroke(255, 255, 255, 255) | |
line(self.field:midX() - 5, self.field.bottom , | |
self.field:midX() + 5, self.field.bottom ) | |
line(self.field:midX(), self.field.bottom + 5, | |
self.field:midX(), self.field.bottom - 5) | |
line(self.field:midX() - 5, self.field.bottom + 5, | |
self.field:midX() + 5, self.field.bottom - 5) | |
line(self.field:midX() - 5, self.field.bottom - 5, | |
self.field:midX() + 5, self.field.bottom + 5) | |
end | |
else | |
if self.game == 2 then | |
self.robots[1].x = 100 | |
self.robots[1].y = 700 | |
self.robots[1]:draw(1) | |
fontSize(32) | |
text("Skeet Results", 100, 800) | |
fontSize(24) | |
text(self.robots[1].name, 200, 700) | |
text("Skeet destroyed", 100, 600) | |
text("Time remaining", 100, 500) | |
text("Total Score", 100, 400) | |
text(self.robots[1].points, 500, 600) | |
text(math.floor(self.timer), 500, 500) | |
score = self.robots[1].points * 10 + math.floor(self.timer) | |
text(score, 500, 400) | |
end | |
end | |
popStyle() | |
end | |
function Arena:touched(touch) | |
if self.launch:touched(touch) and | |
ElapsedTime > self.launchTime + 1 then | |
sound(SOUND_POWERUP, 26548) | |
self.skeet[#self.skeet + 1] = Skeet(self.field:midX(), | |
20, self.field) | |
self.launchTime = ElapsedTime | |
end | |
if self.frame:touched(touch) then | |
return true | |
end | |
return false | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Code = class() | |
function Code:init(short, long1, long2, hasValue, clr) | |
-- you can accept and set parameters here | |
self.short = short | |
self.long1 = long1 | |
self.long2 = long2 | |
self.hasValue = hasValue | |
self.color = clr | |
end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CodeBench = class() | |
function CodeBench:init(x, y) | |
-- you can accept and set parameters here | |
self.x = x | |
self.y = y | |
self.frame = Frame(x, y, x + 500, y + 850) | |
self.header = Frame(self.frame.left + 4, self.frame.top - 30, | |
self.frame.right - 4, self.frame.top - 4) | |
self.sockets = {} | |
socket = 0 | |
for x = 1,2 do | |
for y = 15,1,-1 do | |
socket = socket + 1 | |
self.sockets[socket] = | |
Socket(nil, x * 250 - 180, y * 45 + 71) | |
end | |
end | |
self.selectedSocket = 0 | |
self.action = 0 | |
self.tokens = {} | |
self.pulse = 0 | |
end | |
function CodeBench:loadRobot(r) | |
local i, p | |
for i = 1,30 do | |
self.sockets[i].code = nil | |
end | |
for i, p in ipairs(r.program) do | |
self.sockets[i].code = p.code | |
self.sockets[i].value = p.value | |
end | |
end | |
function CodeBench:draw() | |
local x, y | |
pushStyle() | |
font("Copperplate") | |
fontSize(16) | |
tint(25, 27, 46, 255) | |
sprite(boardImg, self.frame.left, self.frame.bottom, | |
self.frame.right, self.frame.top) | |
stroke(249, 249, 249, 255) | |
noFill() | |
strokeWidth(2) | |
self.frame:draw() | |
fill(87, 87, 87, 221) | |
noStroke() | |
tint(172, 195, 221, 255) | |
sprite(chipImg, self.header.left, self.header.bottom, | |
self.header.right, self.header.top) | |
--self.header:draw() | |
pushMatrix() | |
translate(self.x, self.y) | |
-- trace lines | |
fill(255, 210, 0, 219) | |
stroke(127, 127, 127, 255) | |
strokeWidth(5) | |
line(40, 96, 230, 96) | |
line(230, 96, 230, 760) | |
line(230, 760, 320, 760) | |
line(290, 96, 290, 70) | |
line(290, 70, 20, 70) | |
line(20, 70, 20, 760) | |
line(20, 760, 40, 760) | |
strokeWidth(1) | |
stroke(185, 185, 185, 255) | |
fill(189, 189, 189, 255) | |
line(0, -20, self.frame:width()/2 - 10, -20) | |
line(self.frame:width()/2 + 70, -20, self.frame:width(), -20) | |
line(0, -15, 0, -25) | |
line(self.frame:width(), -25, self.frame:width(), -15) | |
text("3.54 cm", self.frame:width()/2, -30) | |
line(-15, 0, -15, self.frame:height() / 2 - 10) | |
line(-15, self.frame:height(), -15, self.frame:height() / 2 + 70) | |
line(-20, self.frame:height(), -10, self.frame:height()) | |
line(-20, 0, -10, 0) | |
rotate(90) | |
text("7.80 cm", self.frame:height() / 2 , 5) | |
rotate(-90) | |
fontSize(12) | |
text("Use only GR-32 chips", 10, 10) | |
text("RMS9000-A", 400 , 10) | |
text("24V 17.5A REV.B", 200 , 10) | |
text("X1", 200 , 200) | |
socket = 1 | |
for x = 1,2 do | |
for y = 15,1,-1 do | |
noStroke() | |
fill(175, 170, 189, 255) | |
rect(x * 250 - 210, y * 45 + 70, | |
x * 250 - 30, y * 45 + 102) | |
tint(255, 255, 255, 255) | |
--sprite(chipImg, x * 250 - 210, y * 45 + 70, | |
-- x * 250 - 30, y * 45 + 102) | |
strokeWidth(2) | |
stroke(82, 82, 82, 255) | |
fill(30, 28, 26, 255) | |
self.sockets[socket]:draw() | |
noStroke() | |
stroke(127, 127, 127, 255) | |
strokeWidth(5) | |
fill(89, 89, 31, 255) | |
ellipse(x * 250 - 210, y * 45 + 86, 20) | |
line(x * 250 - 210, y * 45 + 82, | |
x * 250 - 210, y * 45 + 50) | |
if self.sockets[socket].code ~= nil then | |
stroke(250, 21, 13, 255) | |
fill(75, 75, self.pulse, 255) | |
ellipse(x * 250 - 210, y * 45 + 86, 10) | |
end | |
fill(0, 0, 0, 255) | |
text(socket, x * 250 - 200, y * 45 + 78) | |
socket = socket + 1 | |
end | |
end | |
fill(255, 255, 255, 255) | |
fontSize(16) | |
text("MAIN BOARD", 10, self.frame:height() - 25) | |
popMatrix() | |
popStyle() | |
self.pulse = self.pulse + 5 | |
if self.pulse > 255 then self.pulse = 1 end | |
end | |
function CodeBench:touched(touch) | |
local i, t | |
t =Ttouch(touch) | |
t:translate(self.x, self.y - 10) | |
self.action = 0 | |
for i = 1, table.maxn(self.sockets) do | |
if self.sockets[i]:touched(t) then | |
self.selectedSocket = i | |
if self.sockets[i].code ~= nil then | |
if t.x < self.sockets[i].frame:midX() or | |
self.sockets[i].code.hasValue == false then | |
self.action = 1 | |
end | |
end | |
return true | |
end | |
end | |
return false | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DesignStudio = class() | |
function DesignStudio:init(l, b, r, t) | |
-- you can accept and set parameters here | |
self.frame = Frame(l, b, r, t) | |
self.tb = TextBox(self.frame:midX() - 160, b + 30, 200, "") | |
self.colorFrame = Frame(150, 600, 260, 624) | |
self.showColorSlider = false | |
self.colorVCS = VColorSlider(self.colorFrame.left, | |
self.colorFrame.top) | |
self.dishBtn = OpenBtn("Dish", self.frame.left, | |
self.frame.top - 80) | |
self.headBtn = OpenBtn("Head", self.frame.left, | |
self.frame.top - 115) | |
self.bodyBtn = OpenBtn("Body", self.frame.left, | |
self.frame.top - 150) | |
self.treadBtn = OpenBtn("Treads", self.frame.left, | |
self.frame.top - 185) | |
self.dishBtn.selected = true | |
self.catalogFrame = Frame(120, 500, 750, 955) | |
self.selectRect = {} | |
self.selectRect[1] = Frame(120, 650, 320, 955 ) | |
self.selectRect[2] = Frame(320, 650, 520, 955 ) | |
self.selectRect[3] = Frame(520, 650, 720, 955 ) | |
self.page = 1 | |
end | |
function DesignStudio:drawDishes() | |
local x, y | |
x = self.selectRect[1]:midX() | |
y = self.selectRect[1]:midY() + 50 | |
stroke(colors[self.bot.dishColor]) | |
strokeWidth(1) | |
line(x - 5, y, x, y + 20) | |
line(x + 5, y, x, y + 20) | |
line(x - 30, y + 10, x - 20, y + 5) | |
line(x - 20, y + 5, x, y) | |
line(x + 30, y + 10, x + 20, y + 5) | |
line(x + 20, y + 5, x, y) | |
line(x, y + 20, x, y + 30) | |
ellipse(x, y + 20, 5) | |
fill(255, 255, 255, 255) | |
fontSize(16) | |
textMode(CENTER) | |
text("Laserator X-49", x, y + 50) | |
text("20m", x, y - 70) | |
text("100kw", x, y - 90) | |
text("10cycles", x, y - 110) | |
noFill() | |
x = self.selectRect[2]:midX() | |
y = self.selectRect[2]:midY() + 50 | |
rect(x - 5, y, x + 5, y + 25) | |
line(x - 20, y, x, y) | |
line(x + 20, y, x, y) | |
line(x - 30, y + 15, x, y) | |
line(x + 30, y + 15, x, y) | |
fill(255, 255, 255, 255) | |
text("Thumperator Max", x, y + 50) | |
text("7m", x, y - 70) | |
text("250km", x, y - 90) | |
text("15cycles", x, y - 110) | |
noFill() | |
x = self.selectRect[3]:midX() | |
y = self.selectRect[3]:midY() + 50 | |
line(x - 20, y, x + 20, y) | |
line(x - 15, y + 5, x + 15, y + 5) | |
line(x - 10, y + 10, x + 10, y + 10) | |
line(x - 5, y + 15, x + 5, y + 15) | |
line(x, y, x, y + 30) | |
ellipse(x, y + 35, 10) | |
fill(255, 255, 255, 255) | |
text("Zapmaster 1000", x, y + 50) | |
text("3m", x, y - 70) | |
text("500km", x, y - 90) | |
text("15cycles", x, y - 110) | |
fill(colors[self.bot.dishColor]) | |
self.colorFrame:draw() | |
textMode(CORNER) | |
fill(255, 255, 255, 255) | |
text("Dish units include both radar and weaponry.", 300, 625) | |
text("Some units have a long range, but cause ", 300, 600) | |
text("light damage. Others deliver a harder blow ", 300, 575) | |
text("but can only do so at short range.", 300, 550) | |
stroke(201, 201, 201, 255) | |
x = self.selectRect[self.bot.dish].left + 20 | |
y = self.selectRect[self.bot.dish].bottom + 85 | |
line(x, y, x, y + 175) | |
line(x - 5, y, x + 5, y) | |
line(x - 5, y + 175, x + 5, y + 175) | |
line(x + 10, y - 20, x + 40, y - 20) | |
line(x + 125, y - 20, x + 160, y - 20) | |
line(x + 10, y - 25, x + 10, y - 15) | |
line(x + 160, y - 25, x + 160, y - 15) | |
fill(209, 209, 209, 255) | |
text("Selected", x + 45, y - 30) | |
end | |
function DesignStudio:drawHeads() | |
local x, y | |
noSmooth() | |
x = self.selectRect[1]:midX() | |
y = self.selectRect[1]:midY() + 50 | |
stroke(colors[self.bot.headColor]) | |
strokeWidth(1) | |
ellipse(x, y, 30) | |
rect(x - 15, y - 5, x - 13, y + 5) | |
rect(x + 15, y - 5, x + 13, y + 5) | |
line(x - 15, y, x - 20, y) | |
line(x + 15, y, x + 20, y) | |
fill(255, 255, 255, 255) | |
fontSize(16) | |
textMode(CENTER) | |
text("Cool Bean", x, y + 50) | |
text("10hds", x, y - 70) | |
text("0.0 shield", x, y - 90) | |
noSmooth() | |
noFill() | |
x = self.selectRect[2]:midX() | |
y = self.selectRect[2]:midY() + 50 | |
ellipse(x, y, 30) | |
ellipse(x, y, 25) | |
line(x+5,y+5,x-5,y-5) | |
line(x+5,y-5,x-5,y+5) | |
fill(255, 255, 255, 255) | |
text("Bubble Boyo", x, y + 50) | |
text("3hds", x, y - 70) | |
text("3.5 shield", x, y - 90) | |
noFill() | |
x = self.selectRect[3]:midX() | |
y = self.selectRect[3]:midY() + 50 | |
ellipse(x, y, 30) | |
ellipse(x, y + 10, 25, 10) | |
ellipse(x, y + 15, 15, 5) | |
line(x - 15, y - 5, x - 25, y - 15) | |
line(x + 15, y - 5, x + 25, y - 15) | |
fill(255, 255, 255, 255) | |
text("Headvantage", x, y + 50) | |
text("1hds", x, y - 70) | |
text("5.5 shield", x, y - 90) | |
textMode(CORNER) | |
fill(255, 255, 255, 255) | |
text("Head units both generate shields and help to ", 300, 625) | |
text("automatically repair bots when damaged. Those ", 300, 600) | |
text("units that provide the best shields are slow", 300, 575) | |
text("at repairs, while the best repair units have", 300, 550) | |
text("weak shields.", 300, 525) | |
fill(colors[self.bot.headColor]) | |
self.colorFrame:draw() | |
stroke(201, 201, 201, 255) | |
x = self.selectRect[self.bot.head].left + 20 | |
y = self.selectRect[self.bot.head].bottom + 85 | |
line(x, y, x, y + 175) | |
line(x - 5, y, x + 5, y) | |
line(x - 5, y + 175, x + 5, y + 175) | |
line(x + 10, y - 20, x + 40, y - 20) | |
line(x + 125, y - 20, x + 160, y - 20) | |
line(x + 10, y - 25, x + 10, y - 15) | |
line(x + 160, y - 25, x + 160, y - 15) | |
fill(209, 209, 209, 255) | |
text("Selected", x + 45, y - 30) | |
end | |
function DesignStudio:drawTreads() | |
local i, x, y | |
noSmooth() | |
x = self.selectRect[1]:midX() | |
y = self.selectRect[1]:midY() + 50 | |
stroke(colors[self.bot.treadColor]) | |
strokeWidth(1) | |
ellipse(x + 20,y -20, 20) | |
ellipse(x + 20, y -20, 20, 5) | |
ellipse(x-20, y-20, 20) | |
ellipse(x-20, y-20, 20, 5) | |
ellipse(x-20, y+20, 20) | |
ellipse(x-20, y+20, 20, 5) | |
ellipse(x+20, y+20, 20) | |
ellipse(x+20, y+20, 20, 5) | |
line(x-20, y-11, x, y) | |
line(x-17, y-14, x, y) | |
line(x+20, y-11, x, y) | |
line(x+17, y-14, x, y) | |
line(x-20, y+11, x, y) | |
line(x-17, y+14, x, y) | |
line(x+20, y+11, x, y) | |
line(x+17, y+14, x, y) | |
fill(255, 255, 255, 255) | |
fontSize(16) | |
textMode(CENTER) | |
text("Spinomatic", x, y + 50) | |
text("90dpc", x, y - 70) | |
text("10kph", x, y - 90) | |
noSmooth() | |
noFill() | |
x = self.selectRect[2]:midX() | |
y = self.selectRect[2]:midY() + 50 | |
rect(x - 15, y - 2, x + 15, y + 2) | |
ellipse(x, y - 4, 15) | |
line(x - 15, y - 10, x + 15, y - 10) | |
rect(x - 30, y - 30, x - 15, y + 30) | |
rect(x + 15, y - 30, x + 30, y + 30) | |
for i = 0,7 do | |
line(x + 15, y - 30 + i * 8, x + 30, y - 30 + i * 8) | |
line(x - 30, y - 30 + i * 8, x - 15, y - 30 + i * 8) | |
end | |
fill(255, 255, 255, 255) | |
text("Tanktrak T11", x, y + 50) | |
text("45dpc", x, y - 70) | |
text("25kph", x, y - 90) | |
noFill() | |
x = self.selectRect[3]:midX() | |
y = self.selectRect[3]:midY() + 50 | |
rect(x - 30, y + 10, x - 20, y + 30) | |
rect(x + 20, y + 10, x + 30, y + 30) | |
rect(x - 30, y - 30, x - 20, y - 10) | |
rect(x + 20, y - 30, x + 30, y - 10) | |
ellipse(x - 25, y + 20, 15, 25) | |
ellipse(x - 25, y - 20, 15, 25) | |
ellipse(x + 25, y + 20, 15, 25) | |
ellipse(x + 25, y - 20, 15, 25) | |
rect(x - 20, y - 22, x + 20, y - 18) | |
rect(x - 20, y + 22, x + 20, y + 18) | |
fill(255, 255, 255, 255) | |
text("Hard Wheelz", x, y + 50) | |
text("15dps", x, y - 70) | |
text("50kph", x, y - 90) | |
textMode(CORNER) | |
fill(255, 255, 255, 255) | |
text("Head units both generate shields and help to ", 300, 625) | |
text("automatically repair bots when damaged. Those ", 300, 600) | |
text("units that provide the best shields are slow", 300, 575) | |
text("at repairs, while the best repair units have", 300, 550) | |
text("weak shields.", 300, 525) | |
fill(colors[self.bot.treadColor]) | |
self.colorFrame:draw() | |
stroke(201, 201, 201, 255) | |
x = self.selectRect[self.bot.tread].left + 20 | |
y = self.selectRect[self.bot.tread].bottom + 85 | |
line(x, y, x, y + 175) | |
line(x - 5, y, x + 5, y) | |
line(x - 5, y + 175, x + 5, y + 175) | |
line(x + 10, y - 20, x + 40, y - 20) | |
line(x + 125, y - 20, x + 160, y - 20) | |
line(x + 10, y - 25, x + 10, y - 15) | |
line(x + 160, y - 25, x + 160, y - 15) | |
fill(209, 209, 209, 255) | |
text("Selected", x + 45, y - 30) | |
end | |
function DesignStudio:drawBodies() | |
local x, y | |
noSmooth() | |
x = self.selectRect[1]:midX() | |
y = self.selectRect[1]:midY() + 50 | |
stroke(colors[self.bot.bodyColor]) | |
strokeWidth(1) | |
ellipse(x, y, 40, 20) | |
ellipse(x - 20, y, 15, 15) | |
ellipse(x + 20, y, 15, 15) | |
fill(255, 255, 255, 255) | |
fontSize(16) | |
textMode(CENTER) | |
text("LightWay C", x, y + 50) | |
text("10mm", x, y - 70) | |
text("47kg", x, y - 90) | |
fill(24, 24, 24, 255) | |
x = self.selectRect[2]:midX() | |
y = self.selectRect[2]:midY() + 50 | |
rect(x - 25, y - 10, x + 25, y + 10) | |
ellipse(x - 25, y, 20) | |
ellipse(x + 25, y, 20) | |
rect(x - 15, y - 15, x + 15, y - 10) | |
fill(255, 255, 255, 255) | |
text("Steel Trunk", x, y + 50) | |
text("20mm", x, y - 70) | |
text("90kg", x, y - 90) | |
--noFill() | |
fill(65, 65, 65, 255) | |
x = self.selectRect[3]:midX() | |
y = self.selectRect[3]:midY() + 50 | |
ellipse(x - 20, y, 30, 30) | |
ellipse(x + 20, y, 30, 30) | |
rect(x - 20, y - 15, x + 20, y + 15) | |
ellipse(x, y, 40, 30) | |
fill(255, 255, 255, 255) | |
text("ToughBugger II", x, y + 50) | |
text("50mm", x, y - 70) | |
text("250kg", x, y - 90) | |
textMode(CORNER) | |
fill(255, 255, 255, 255) | |
text("Body units protect the bot from damage and ", 300, 625) | |
text("allow it to absorb more blows before failing. ", 300, 600) | |
text("However, as armor increases in weight, it ", 300, 575) | |
text("reduces both the speed of movement and of", 300, 550) | |
text("turning.", 300, 525) | |
fill(colors[self.bot.bodyColor]) | |
self.colorFrame:draw() | |
stroke(201, 201, 201, 255) | |
x = self.selectRect[self.bot.body].left + 20 | |
y = self.selectRect[self.bot.body].bottom + 85 | |
line(x, y, x, y + 175) | |
line(x - 5, y, x + 5, y) | |
line(x - 5, y + 175, x + 5, y + 175) | |
line(x + 10, y - 20, x + 40, y - 20) | |
line(x + 125, y - 20, x + 160, y - 20) | |
line(x + 10, y - 25, x + 10, y - 15) | |
line(x + 160, y - 25, x + 160, y - 15) | |
text("Selected", x + 45, y - 30) | |
end | |
function DesignStudio:setBot(bot) | |
self.bot = bot | |
self.tb.text = self.bot.name | |
end | |
function DesignStudio:draw() | |
pushMatrix() | |
fontSize(16) | |
noFill() | |
stroke(255, 255, 255, 255) | |
strokeWidth(2) | |
stroke(0, 38, 255, 255) | |
strokeWidth(2) | |
fill(185, 185, 185, 113) | |
self.tb:draw() | |
fill(255, 255, 255, 255) | |
text("Color", self.colorFrame.left, self.colorFrame.top) | |
fontSize(24) | |
text("Design Studio", self.frame.left + 120, self.frame.top - 35) | |
fill(colors[self.bot.dishColor]) | |
self.colorFrame:draw() | |
noFill() | |
stroke(255, 255, 255, 255) | |
strokeWidth(2) | |
self.catalogFrame:draw() | |
rect(self.catalogFrame.left, self.catalogFrame.top, | |
self.catalogFrame.right, self.catalogFrame.top + 50) | |
rect(self.catalogFrame.left, self.catalogFrame.bottom - 90, | |
self.catalogFrame.right, self.catalogFrame.bottom) | |
if self.dishShowSlider then self.dishVCS:draw() end | |
if self.headShowSlider then self.headVCS:draw() end | |
if self.bodyShowSlider then self.bodyVCS:draw() end | |
if self.treadShowSlider then self.treadVCS:draw() end | |
translate(self.frame:midX()+ 90 , self.frame:height() - 170) | |
self.bot.x = 0 | |
self.bot.y = 0 | |
self.bot:draw(1) | |
popMatrix() | |
self.headBtn:draw() | |
self.dishBtn:draw() | |
self.bodyBtn:draw() | |
self.treadBtn:draw() | |
if self.page == 1 then | |
self:drawDishes() | |
end | |
if self.page == 2 then | |
self:drawHeads() | |
end | |
if self.page == 3 then | |
self:drawBodies() | |
end | |
if self.page == 4 then | |
self:drawTreads() | |
end | |
if self.showColorSlider then | |
self.colorVCS:draw() | |
end | |
end | |
function DesignStudio:clearSelected() | |
self.dishBtn.selected = false | |
self.headBtn.selected = false | |
self.bodyBtn.selected = false | |
self.treadBtn.selected = false | |
end | |
function DesignStudio:touched(touch) | |
local i | |
self.bot.name = self.tb.text | |
if self.colorFrame:touched(touch) then | |
self.showColorSlider = true | |
end | |
if self.showColorSlider then | |
if self.colorVCS:touched(touch) then | |
if self.page == 1 then | |
self.bot.dishColor = self.colorVCS.selected | |
end | |
if self.page == 2 then | |
self.bot.headColor = self.colorVCS.selected | |
end | |
if self.page == 3 then | |
self.bot.bodyColor = self.colorVCS.selected | |
end | |
if self.page == 4 then | |
self.bot.treadColor = self.colorVCS.selected | |
end | |
end | |
end | |
if self.dishBtn:touched(touch) then | |
self.page = 1 | |
self:clearSelected() | |
self.dishBtn.selected = true | |
end | |
if self.headBtn:touched(touch) then | |
self.page = 2 | |
self:clearSelected() | |
self.headBtn.selected = true | |
end | |
if self.bodyBtn:touched(touch) then | |
self.page = 3 | |
self:clearSelected() | |
self.bodyBtn.selected = true | |
end | |
if self.treadBtn:touched(touch) then | |
self.page = 4 | |
self:clearSelected() | |
self.treadBtn.selected = true | |
end | |
for i = 1,3 do | |
if self.selectRect[i]:touched(touch) then | |
sound(SOUND_SHOOT, 46433) | |
if self.page == 1 then self.bot.dish = i end | |
if self.page == 2 then self.bot.head = i end | |
if self.page == 3 then self.bot.body = i end | |
if self.page == 4 then self.bot.tread = i end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Divider = class() | |
function Divider:init(name, l, t, r, b) | |
self.name = name | |
self.frame = Frame(l, t, r, b) | |
end | |
function Divider:draw() | |
pushStyle() | |
strokeWidth(1) | |
stroke(247, 247, 247, 255) | |
tint(143, 203, 223, 255) | |
sprite(chipImg, self.frame.left, self.frame.bottom, | |
self.frame.right, self.frame.top) | |
fill(255, 255, 255, 255) | |
text(self.name, self.frame.left + 10, self.frame.bottom + 5) | |
noFill() | |
self.frame:draw() | |
popStyle() | |
end | |
function Divider:touched(touch) | |
return self.frame:touched(touch) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Frame = class() | |
-- Frame | |
-- ver. 1.0 | |
-- a simple rectangle for holding controls. | |
-- ==================== | |
function Frame:init(left, bottom, right, top) | |
self.left = left | |
self.right = right | |
self.bottom = bottom | |
self.top = top | |
end | |
function Frame:inset(dx, dy) | |
self.left = self.left + dx | |
self.right = self.right - dx | |
self.bottom = self.bottom + dy | |
self.top = self.top - dy | |
end | |
function Frame:offset(dx, dy) | |
self.left = self.left + dx | |
self.right = self.right + dx | |
self.bottom = self.bottom + dy | |
self.top = self.top + dy | |
end | |
function Frame:draw() | |
pushStyle() | |
rectMode(CORNERS) | |
rect(self.left, self.bottom, self.right, self.top) | |
popStyle() | |
end | |
function Frame:roundRect(r) | |
pushStyle() | |
insetPos = vec2(self.left + r,self.bottom + r) | |
insetSize = vec2(self:width() - 2 * r,self:height() - 2 * r) | |
rectMode(CORNER) | |
rect(insetPos.x, insetPos.y, insetSize.x, insetSize.y) | |
if r > 0 then | |
smooth() | |
lineCapMode(ROUND) | |
strokeWidth(r * 2) | |
line(insetPos.x, insetPos.y, | |
insetPos.x + insetSize.x, insetPos.y) | |
line(insetPos.x, insetPos.y, | |
insetPos.x, insetPos.y + insetSize.y) | |
line(insetPos.x, insetPos.y + insetSize.y, | |
insetPos.x + insetSize.x, insetPos.y + insetSize.y) | |
line(insetPos.x + insetSize.x, insetPos.y, | |
insetPos.x + insetSize.x, insetPos.y + insetSize.y) | |
end | |
popStyle() | |
end | |
function Frame:gloss(baseclr) | |
local i, t, r, g, b, y | |
pushStyle() | |
if baseclr == nil then baseclr = color(194, 194, 194, 255) end | |
fill(baseclr) | |
rectMode(CORNERS) | |
rect(self.left, self.bottom, self.right, self.top) | |
r = baseclr.r | |
g = baseclr.g | |
b = baseclr.b | |
for i = 1 , self:height() / 2 do | |
r = r - 1 | |
g = g - 1 | |
b = b - 1 | |
stroke(r, g, b, 255) | |
y = (self.bottom + self.top) / 2 | |
line(self.left, y + i, self.right, y + i) | |
line(self.left, y - i, self.right, y - i) | |
end | |
popStyle() | |
end | |
function Frame:shade(base, step) | |
pushStyle() | |
strokeWidth(1) | |
for y = self.bottom, self.top do | |
i = self.top - y | |
stroke(base - i * step, base - i * step, base - i * step, 255) | |
line(self.left, y, self.right, y) | |
end | |
popStyle() | |
end | |
function Frame:touched(touch) | |
if touch.x >= self.left and touch.x <= self.right then | |
if touch.y >= self.bottom and touch.y <= self.top then | |
return true | |
end | |
end | |
return false | |
end | |
function Frame:ptIn(x, y) | |
if x >= self.left and x <= self.right then | |
if y >= self.bottom and y <= self.top then | |
return true | |
end | |
end | |
return false | |
end | |
function Frame:overlaps(f) | |
if self.left > f.right or self.right < f.left or | |
self.bottom > f.top or self.top < f.bottom then | |
return false | |
else | |
return true | |
end | |
end | |
function Frame:width() | |
return self.right - self.left | |
end | |
function Frame:height() | |
return self.top - self.bottom | |
end | |
function Frame:midX() | |
return (self.left + self.right) / 2 | |
end | |
function Frame:midY() | |
return (self.bottom + self.top) / 2 | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Batlle Chips 23MAY12 | |
-- Mark Sumner | |
-- [email protected] | |
displayMode(FULLSCREEN) | |
supportedOrientations(PORTRAIT_ANY) | |
rectMode(CORNERS) | |
spriteMode(CORNERS) | |
textMode(CORNER) | |
noSmooth() | |
font("Copperplate-Light") | |
function setup() | |
local y, x, i | |
-- create background images | |
gridImg = image(200, 200) | |
fill(25, 27, 46, 255) | |
stroke(255, 255, 255, 25) | |
setContext(gridImg) | |
noStroke() | |
rect(0,0,200,200) | |
strokeWidth(1) | |
r = HEIGHT/WIDTH | |
for y = 0, 59 do | |
line(0, y * 4, 200, y * 4) | |
end | |
for x = 0,39 do | |
line(x * 4 * r, 0, x * 4 * r, 200) | |
end | |
setContext() | |
chipImg = image(145, 30) | |
fill(79, 79, 79, 255) | |
stroke(131, 123, 123, 135) | |
strokeWidth(1) | |
setContext(chipImg) | |
rect(0,0,200,200) | |
for y = 0, 20 do | |
line(0, y * 3, 200, y * 3) | |
end | |
for x = 0,70 do | |
line(x * 3, 0, x * 3 + 30, 200) | |
end | |
setContext() | |
boardImg = image(200, 200) | |
fill(255, 255, 255, 255) | |
strokeWidth(1) | |
setContext(boardImg) | |
rect(0,0,200,200) | |
stroke(29, 54, 30, 135) | |
for x = 0, 200 do | |
line(x * 2, 0, x * 2, 200) | |
end | |
stroke(72, 72, 72, 135) | |
for x = 0, 200 do | |
line(0, x * 2, 200, x * 2) | |
end | |
setContext() | |
robots = {} | |
for i = 1,20 do | |
robots[i] = Robot(17 + i * 70,300) | |
end | |
codes = {} | |
color(219, 11, 10, 255) | |
codes[1] = Code("F", "Forward", "", false, color(219, 11, 10, 255)) | |
codes[2] = Code("L", "Turn", "Left", false, color(219, 11, 10, 255)) | |
codes[3] = Code("R", "Turn", "Right", | |
false, color(219, 11, 10, 255)) | |
codes[4] = Code("B", "Reverse", "", false, color(219, 11, 10, 255)) | |
codes[5] = Code("W", "Fire!", "", | |
false, color(251, 215, 9, 255)) | |
codes[6] = Code("H", "Bump", "", true, color(95, 99, 229, 255)) | |
codes[7] = Code("A", "Radar", "", true, color(95, 99, 229, 255)) | |
codes[8] = Code("I", "Radar", "Right", | |
true, color(95, 99, 229, 255)) | |
codes[9] = Code("T", "Radar", "Left", | |
true, color(95, 99, 229, 255)) | |
codes[10] = Code("D", "Damage", "", true, color(95, 99, 229, 255)) | |
codes[11] = Code("G", "Goto", "", true, color(31, 195, 17, 255)) | |
codes[12] = Code("5", "Random", "", true, color(31, 195, 17, 255)) | |
codes[13] = Code("P", "Repeat", "", true, color(31, 195, 17, 255)) | |
mode = 1 | |
dragToken = Token(codes[1], 0, 0) | |
bench = CodeBench(35, 150) | |
scheduler = TourneyOrganizer(35, 150) | |
tray = TokenTray(550, 150) | |
oldState = nil | |
doneBtn = BigButton("Done", 550, 25) | |
doneBtn.frame.right = doneBtn.frame.right + 60 | |
codeBtn = BigButton("Code", 220, 100) | |
designBtn = BigButton("Design", 30, 100) | |
tourneyBtn = BigButton("Compete", 410, 100) | |
tradeBtn = BigButton("Trade", 600, 100) | |
arena = Arena(10, HEIGHT - 650, WIDTH - 10, HEIGHT - 10) | |
arena:draw() | |
studio = DesignStudio(20, 410, WIDTH - 20, HEIGHT - 20) | |
vslider = Vslider(0,0,0) | |
vcslider = VColorSlider(0,0,0) | |
trader = TradingCenter() | |
showSlider = false | |
sliderPosition = 0 | |
leftBot = 1 | |
selectedRobot = 0 | |
botFrames = {} | |
loadRobots() | |
for i = 1,7 do | |
botFrames[i] = Frame(i * 87, 200, | |
i * 87 + 80, 300) | |
end | |
leftRobot = 1 | |
rightBtn = Frame(WIDTH - 80, 260, WIDTH, 360) | |
leftBtn = Frame(0, 260, 80, 360) | |
-- tourney variables | |
tourney = Tourney() | |
end | |
function saveRobots() | |
local k, s, i, c | |
s = table.maxn(robots).."," | |
for i, r in ipairs(robots) do | |
r.wins = r.body * 10 + r.tread | |
r.losses = r.head * 10 + r.dish | |
s = s..r.name..","..r.wins..","..r.losses.."," | |
s = s..r.treadColor..","..r.bodyColor.."," | |
s = s..r.headColor..","..r.dishColor.."," | |
c = table.maxn(r.program) | |
s = s..c | |
if i < table.maxn(robots) or c > 0 then s = s.."," end | |
for k, p in ipairs(r.program) do | |
if p.code ~= nil then | |
s = s..k..","..p.code.short..","..p.value | |
s=s.."," | |
else | |
s = s..k..",nil"..","..p.value | |
s=s.."," | |
end | |
end | |
end | |
saveProjectData("BCBots", s) | |
end | |
function loadRobots() | |
local k, s, i, robotCount, d, c | |
local w = {} | |
--displayMode(STANDARD) | |
s = readProjectData("BCBots") | |
--print(s) | |
if s == nil then | |
s = getDefault() | |
end | |
if s ~= nil then | |
i = 0 | |
for k in string.gmatch(s,"([^,]+)") do | |
i = i + 1 | |
w[i] = k | |
end | |
robotCount = w[1] | |
top = 2 | |
for r = 1, robotCount do | |
robots[r].name = w[top] | |
robots[r].wins = tonumber(w[top + 1]) | |
robots[r].losses = tonumber(w[top + 2]) | |
robots[r].treadColor = tonumber(w[top + 3]) | |
robots[r].bodyColor = tonumber(w[top + 4]) | |
robots[r].headColor = tonumber(w[top + 5]) | |
robots[r].dishColor = tonumber(w[top + 6]) | |
robots[r].body = math.floor(robots[r].wins / 10) | |
robots[r].head = math.floor(robots[r].losses / 10) | |
robots[r].tread = math.fmod(robots[r].wins , 10) | |
robots[r].dish = math.fmod(robots[r].losses , 10) | |
if robots[r].body == 0 then robots[r].body = 2 end | |
if robots[r].head == 0 then robots[r].head = 1 end | |
if robots[r].tread == 0 then robots[r].tread = 2 end | |
if robots[r].dish == 0 then robots[r].dish = 1 end | |
programSize = tonumber(w[top + 7]) | |
i = 0 | |
if programSize > 0 then | |
for i = 1, programSize do | |
socketNum = tonumber(w[i * 3 - 2 + top + 7]) | |
codeShort = w[i * 3 - 1 + top + 7] | |
value = tonumber(w[i * 3 + top + 7]) | |
-- find the right code | |
code = nil | |
for d, c in ipairs(codes) do | |
if c.short == codeShort then | |
code = c | |
end | |
end | |
robots[r].program[socketNum] = Socket(code, 0, 0) | |
robots[r].program[socketNum].value = value | |
end | |
end | |
top = top + 8 + programSize * 3 | |
end | |
end | |
end | |
function drawMain() | |
local i | |
pushStyle() | |
fill(0, 0, 0, 255) | |
stroke(0, 69, 255, 255) | |
tint(249, 249, 249, 255) | |
strokeWidth(2) | |
textMode(CENTER) | |
fontSize(12) | |
stroke(255, 255, 255, 255) | |
for i = 1, 7 do | |
noFill() | |
noStroke() | |
botFrames[i]:draw() | |
robots[i + leftRobot - 1].x = botFrames[i].left + 10 | |
robots[i + leftRobot - 1].y = botFrames[i]:midY() | |
fill(255, 255, 255, 255) | |
text(robots[i + leftRobot - 1].name, botFrames[i]:midX(), | |
botFrames[i].bottom+32) | |
end | |
codeBtn:draw() | |
designBtn:draw() | |
tourneyBtn:draw() | |
tradeBtn:draw() | |
textMode(CORNER) | |
stroke(255, 255, 255, 255) | |
fill(255, 255, 255, 255) | |
stroke(213, 213, 213, 255) | |
strokeWidth(1) | |
line(arena.frame.left, arena.frame.bottom - 15, | |
arena.frame:midX() - 50, arena.frame.bottom - 15) | |
line(arena.frame.right, arena.frame.bottom - 15, | |
arena.frame:midX() + 60, arena.frame.bottom - 15) | |
line(arena.frame.left, arena.frame.bottom - 20, | |
arena.frame.left, arena.frame.bottom - 10) | |
line(arena.frame.right, arena.frame.bottom - 20, | |
arena.frame.right, arena.frame.bottom - 10) | |
fontSize(16) | |
text("10.3 meters", arena.frame:midX() - 45, | |
arena.frame.bottom - 25) | |
stroke(255, 255, 255, 255) | |
strokeWidth(1) | |
if leftRobot > 1 then | |
line(10, 280, 50, 310) | |
line(10, 280, 50, 250) | |
line(50, 310, 50, 250) | |
end | |
if leftRobot < 13 then | |
line(WIDTH - 10, 280, WIDTH - 50, 310) | |
line(WIDTH - 10, 280, WIDTH - 50, 250) | |
line(WIDTH - 50, 250, WIDTH - 50, 310) | |
end | |
strokeWidth(1) | |
popStyle() | |
end | |
function draw() | |
local i, m | |
noSmooth() | |
background(255, 255, 255, 255) | |
tint(255, 255, 255, 255) | |
sprite(gridImg, 0, 0, WIDTH, HEIGHT) | |
if mode == 1 then | |
arena:draw() | |
end | |
if mode == 1 and arena.game == 1 then | |
drawMain() | |
for i = 1,7 do | |
s = math.abs(4 - i) / 10 | |
robots[i + leftRobot - 1]:draw(1) | |
end | |
elseif mode == 2 then | |
bench:draw() | |
tray:draw() | |
if showSlider then | |
vslider:draw() | |
end | |
doneBtn:draw() | |
elseif mode == 3 then | |
studio:draw() | |
doneBtn:draw() | |
elseif mode == 4 then | |
scheduler:draw(robots) | |
doneBtn:draw() | |
elseif mode == 5 then | |
trader:draw(robots) | |
doneBtn:draw() | |
end | |
-- touch handling | |
if mode == 1 then | |
if CurrentTouch.state == BEGAN and | |
CurrentTouch.state ~= oldState then | |
if arena:touched(CurrentTouch) then | |
end | |
if arena.stop:touched(CurrentTouch) then | |
arena:sizeFrames(10, HEIGHT - 650, | |
WIDTH - 10, HEIGHT - 10) | |
arena:clear() | |
end | |
if leftBtn:touched(CurrentTouch) and leftRobot > 1 then | |
leftRobot = leftRobot - 1 | |
end | |
if rightBtn:touched(CurrentTouch) and | |
leftRobot < 13 then | |
leftRobot = leftRobot + 1 | |
end | |
selectedRobot = 0 | |
-- check to see if a robot was selected | |
for i = 1, 7 do | |
if botFrames[i]:touched(CurrentTouch) then | |
selectedRobot = i + leftRobot - 1 | |
end | |
end | |
end | |
if CurrentTouch.state == MOVING then | |
if selectedRobot > 0 then | |
robots[selectedRobot].x = CurrentTouch.x - 20 | |
robots[selectedRobot].y = CurrentTouch.y - 20 | |
robots[selectedRobot]:draw(1) | |
end | |
end | |
if CurrentTouch.state == ENDED | |
and CurrentTouch.state ~= oldState then | |
if selectedRobot > 0 then | |
if codeBtn:touched(CurrentTouch) then | |
bench:loadRobot(robots[selectedRobot]) | |
mode = 2 | |
end | |
if designBtn:touched(CurrentTouch) then | |
showKeyboard() | |
doneBtn.frame.top = 380 | |
doneBtn.frame.bottom = 300 | |
studio:setBot(robots[selectedRobot]) | |
mode = 3 | |
end | |
if tourneyBtn:touched(CurrentTouch) then | |
scheduler:loadRobot(selectedRobot) | |
selectedRobot = 0 | |
mode = 4 | |
end | |
if tradeBtn:touched(CurrentTouch) then | |
trader:loadRobot(selectedRobot) | |
selectedRobot = 0 | |
mode = 5 | |
end | |
if arena:touched(CurrentTouch) then | |
if table.maxn(arena.robots) < 4 then | |
arena:loadRobot(robots[selectedRobot]) | |
else | |
sound(SOUND_BLIT, 30424) | |
end | |
end | |
end | |
end | |
end | |
if mode == 2 then | |
if CurrentTouch.state == BEGAN and | |
CurrentTouch.state ~= oldState then | |
selectedToken = 0 | |
-- check to see if a token was selected | |
if tray:touched(CurrentTouch) then | |
dragToken = Token(tray.tokens[tray.selected].code, | |
CurrentTouch.x - 20, CurrentTouch.y, | |
tray.tokens[tray.selected].color) | |
end | |
if bench:touched(CurrentTouch) then | |
-- touched a socket | |
c = bench.sockets[bench.selectedSocket].code | |
if c ~= nil and bench.action == 0 then | |
if c.hasValue then | |
vslider = Vslider(CurrentTouch.x, | |
CurrentTouch.y, | |
bench.sockets[bench.selectedSocket].value) | |
showSlider = true | |
end | |
end | |
if c ~= nil and bench.action == 1 then | |
dragToken = | |
Token(bench.sockets[bench.selectedSocket].code, | |
CurrentTouch.x - 20, CurrentTouch.y, | |
bench.sockets[bench.selectedSocket].color) | |
bench.sockets[bench.selectedSocket].code = nil | |
end | |
end | |
end | |
if CurrentTouch.state == MOVING then | |
if dragToken ~= nil | |
then | |
dragToken.x = CurrentTouch.x - 20 | |
dragToken.y = CurrentTouch.y | |
dragToken:draw() | |
end | |
if showSlider then | |
if vslider:touched(CurrentTouch) then | |
bench.sockets[bench.selectedSocket].value = | |
vslider.value | |
end | |
end | |
end | |
if CurrentTouch.state == ENDED | |
and CurrentTouch.state ~= oldState then | |
if dragToken ~= nil then | |
if bench:touched(CurrentTouch) then | |
bench.sockets[bench.selectedSocket].code = | |
dragToken.code | |
sound(SOUND_HIT, 30249) | |
end | |
dragToken = nil | |
end | |
if showSlider then showSlider = false end | |
if doneBtn:touched(CurrentTouch) then | |
-- save code | |
for i = 1,30 do | |
if bench.sockets[i].code ~= nil then | |
b = bench.sockets[i] | |
robots[selectedRobot].program[i] = | |
Socket(b.code, 0, 0) | |
robots[selectedRobot].program[i].value = b.value | |
else | |
robots[selectedRobot].program[i] = | |
Socket(nil, 0, 0) | |
robots[selectedRobot].program[i].value = 1 | |
end | |
end | |
saveRobots() | |
mode = 1 | |
end | |
end | |
end | |
if mode == 3 then | |
if CurrentTouch.state == BEGAN and | |
CurrentTouch.state ~= oldState then | |
-- check to see if a robot was selected | |
studio:touched(CurrentTouch) | |
if doneBtn:touched(CurrentTouch) then | |
doneBtn.frame.top = 140 | |
doneBtn.frame.bottom = 60 | |
hideKeyboard() | |
mode = 1 | |
saveRobots() | |
end | |
end | |
if CurrentTouch.state == MOVING then | |
studio:touched(CurrentTouch) | |
end | |
if CurrentTouch.state == ENDED | |
and CurrentTouch.state ~= oldState then | |
studio.showColorSlider = false | |
end | |
end | |
if mode == 4 then | |
if CurrentTouch.state == BEGAN and | |
CurrentTouch.state ~= oldState then | |
-- check to see if a robot was selected | |
scheduler:touched(CurrentTouch) | |
if doneBtn:touched(CurrentTouch) then | |
mode = 1 | |
saveRobots() | |
end | |
if scheduler.meleeBtn:touched(CurrentTouch) then | |
mode = 1 | |
for i = 1, 4 do | |
if scheduler.contestants[i] == 0 then | |
scheduler.contestants[i] = math.random(20) | |
end | |
end | |
arena:loadRobot(robots[scheduler.contestants[1]]) | |
arena:loadRobot(robots[scheduler.contestants[2]]) | |
arena:loadRobot(robots[scheduler.contestants[3]]) | |
arena:loadRobot(robots[scheduler.contestants[4]]) | |
arena.game = 4 | |
arena.tourney = true | |
arena:sizeFrames(10, 60, WIDTH - 10, HEIGHT - 10) | |
end | |
if scheduler.skeetBtn:touched(CurrentTouch) then | |
mode = 1 | |
arena:sizeFrames(10, 60, WIDTH - 10, HEIGHT - 10) | |
arena:skeetMatch(robots[scheduler.contestants[1]]) | |
arena.robots[1].x = arena.field:midX() | |
arena.robots[1].y = arena.field:midY() | |
end | |
end | |
if CurrentTouch.state == MOVING then | |
scheduler:touched(CurrentTouch) | |
end | |
if CurrentTouch.state == ENDED | |
and CurrentTouch.state ~= oldState then | |
scheduler.showSlider = false | |
end | |
end | |
if mode == 5 then | |
if CurrentTouch.state == BEGAN and | |
CurrentTouch.state ~= oldState then | |
-- check to see if a robot was selected | |
trader:touched(CurrentTouch) | |
if doneBtn:touched(CurrentTouch) then | |
mode = 1 | |
saveRobots() | |
end | |
end | |
if CurrentTouch.state == MOVING then | |
trader:touched(CurrentTouch) | |
end | |
if CurrentTouch.state == ENDED | |
and CurrentTouch.state ~= oldState then | |
end | |
end | |
oldState = CurrentTouch.state | |
end | |
function keyboard(key) | |
if mode == 3 then | |
if key ~= nil then | |
if string.byte(key) == 10 then | |
-- | |
else | |
if string.byte(key) ~= 44 then -- filter out commas | |
studio.tb:acceptKey(key) | |
end | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Robot = class() | |
function Robot:init(x, y) | |
-- position and bounds | |
self.x = x | |
self.y = y | |
self.bounds = Frame(0,0,0,0) | |
self.direction = 0 | |
-- code related values | |
self.program = {} | |
for i = 1, 30 do self.program[i] = nil end | |
self.step = 1 | |
self.bump = false | |
self.radar = false | |
self.treadTick = 0 | |
self.fireLaser = false | |
self.fireRadar = false | |
self.delay = 0 | |
-- tourney-telated values | |
self.hp = 10 | |
self.damage = self.hp | |
self.wins = 0 | |
self.losses = 0 | |
self.heat = 0 | |
self.repeatCounter = 1 | |
self.points = 0 | |
self.redirectValue = 0 | |
self.rf = Frame(0,0,0,0) | |
self.limits = Frame(0,0,0,0) | |
-- design-related values | |
self.name = "Generobot" | |
self.treadColor = 14 | |
self.bodyColor = 14 | |
self.headColor = 15 | |
self.dishColor = 4 | |
self.head = 1 | |
self.dish = 1 | |
self.body = 2 | |
self.tread = 2 | |
self.range = 20 | |
self.speed = 5 | |
self.turnDelay = 5 | |
self.turnTarget = 1 | |
self.flameTimer = 0 | |
self.shield = 0 | |
self.repairRate = 0 | |
self.img = image(60, 60) | |
end | |
function Robot:createImage() | |
pushMatrix() | |
strokeWidth(2) | |
translate(30,30) | |
setContext(self.img) | |
self:drawBase() | |
setContext() | |
popMatrix() | |
end | |
function Robot:drawLaser() | |
if self.direction == 1 then | |
self.rf = Frame(self.x + 24, self.y + 36, | |
self.x + 36, self.y - 180) | |
if self.rf.top > self.limits:height() then | |
self.rf.top = self.limits:height() | |
end | |
elseif self.direction == 2 then | |
self.rf = Frame(self.x + 36, self.y + 24, | |
self.limits:width(), self.y + 36) | |
elseif self.direction == 3 then | |
self.rf = Frame(self.x + 24, 110, self.x + 36, self.y + 36) | |
elseif self.direction == 4 then | |
self.rf = Frame(0, self.y + 24, self.x + 36, self.y + 36) | |
end | |
noStroke() | |
fill(212, 60, 55, 92) | |
self.rf:draw() | |
sound(SOUND_SHOOT, 9773) | |
end | |
function Robot:drawRadar(dir) | |
if dir == 1 then | |
self.rf = Frame(self.x + 24, self.y + 36, | |
self.x + 36, self.range * 60) | |
if self.rf.top > self.limits:height() then | |
self.rf.top = self.limits:height() | |
end | |
elseif dir == 2 then | |
self.rf = Frame(self.x + 33, self.y + 24, | |
self.x + self.range * 60, self.y + 36) | |
if self.rf.right > self.limits:width() then | |
self.rf.right = self.limits:width() | |
end | |
elseif dir == 3 then | |
self.rf = Frame(self.x + 24, self.y - self.range * 60, | |
self.x + 36, self.y + 33) | |
if self.rf.bottom < 0 then | |
self.rf.bottom = 0 | |
end | |
elseif dir == 4 then | |
self.rf = Frame(self.x - self.range * 60, self.y + 24, | |
self.x + 33, self.y + 36) | |
if self.rf.left < 0 then | |
self.rf.left = 0 | |
end | |
end | |
noStroke() | |
fill(81, 85, 175, 50) | |
self.rf:draw() | |
sound(SOUND_POWERUP, 9772) | |
end | |
function Robot:run() | |
local p, rf, redirected | |
--displayMode(STANDARD) | |
if self.delay > 0 then | |
self.delay = self.delay - 1 | |
return true | |
end | |
self.hp = self.hp + self.repairRate / 100 | |
if self.hp > 10 then self.hp = 10 end | |
if self.radar then | |
self.step = self.redirectValue | |
sound(SOUND_HIT, 17131) | |
self.radar = false | |
end | |
-- get executable token | |
p = self.program[self.step] | |
redirected = false | |
if p == nil or p.code == nil then | |
self.step = 1 | |
redirected = true | |
return false | |
end | |
-- execute control | |
if p.code.short == "G" then | |
-- Goto | |
self.step = p.value | |
redirected = true | |
elseif p.code.short == "5" then | |
-- 50/50 random | |
if math.random(2) > 1 then | |
self.step = p.value | |
redirected = true | |
end | |
elseif p.code.short == "P" then | |
-- repeat | |
if self.repeatCounter < p.value then | |
self.repeatCounter = self.repeatCounter + 1 | |
self.step = self.step - 1 | |
redirected = true | |
else | |
self.repeatCounter = 1 | |
end | |
-- check sensors | |
elseif p.code.short == "D" then | |
-- damage sensor | |
if self.hp < self. damage then | |
self.damage = self.hp | |
self.step = p.value | |
redirected = true | |
end | |
elseif p.code.short == "H" then | |
-- bump sensor | |
if self.bump then | |
self.step = p.value | |
sound(SOUND_HIT, 17131) | |
redirected = true | |
end | |
self.bump = false | |
elseif p.code.short == "A" then | |
-- radar sensor | |
self:drawRadar(self.direction) | |
self.delay = 5 | |
self.fireRadar = true | |
self.redirectValue = p.value | |
elseif p.code.short == "I" then | |
-- radar sensor right | |
i = self.direction + 1 | |
if i > 4 then i = 1 end | |
self:drawRadar(i) | |
self.delay = 5 | |
self.fireRadar = true | |
self.redirectValue = p.value | |
elseif p.code.short == "T" then | |
-- radar sensor left | |
i = self.direction - 1 | |
if i < 1 then i = 4 end | |
self:drawRadar(i) | |
self.delay = 5 | |
self.fireRadar = true | |
self.redirectValue = p.value | |
-- take action | |
elseif p.code.short == "F" then | |
-- forward | |
self.treadTick = self.treadTick + 1 | |
if self.treadTick > 9 then | |
self.treadTick = 0 | |
end | |
if self.direction == 1 then | |
self.y = self.y + self.speed | |
if self.y > self.limits:height()- 60 then | |
self.bump = true | |
self.y = self.limits:height()- 65 | |
end | |
elseif self.direction == 2 then | |
self.x = self.x + self.speed | |
if self.x > self.limits:width() - 65 then | |
self.bump = true | |
self.x = self.limits:width() - 70 | |
end | |
elseif self.direction == 3 then | |
self.y = self.y - self.speed | |
if self.y < 5 then | |
self.bump = true | |
self.y = 10 | |
end | |
elseif self.direction == 4 then | |
self.x = self.x - self.speed | |
if self.x < 15 then | |
self.bump = true | |
self.x = 20 | |
end | |
end | |
elseif p.code.short == "L" then | |
self.direction = self.direction - 1 | |
if self.direction == 0 then self.direction = 4 end | |
self.delay = self.delay + self.turnDelay | |
elseif p.code.short == "R" then | |
self.direction = self.direction + 1 | |
if self.direction == 5 then self.direction = 1 end | |
self.delay = self.delay + self.turnDelay | |
elseif p.code.short == "B" then | |
-- Reverse | |
self.treadTick = self.treadTick - 1 | |
if self.treadTick < 0 then | |
self.treadTick = 9 | |
end | |
if self.direction == 3 then | |
self.y = self.y + 5 | |
if self.y + 60 > self.limits:height() then | |
self.bump = true | |
self.y = self.y - 5 | |
end | |
elseif self.direction == 4 then | |
self.x = self.x + 5 | |
if self.x + 60 > self.limits:width() then | |
self.bump = true | |
self.x = self.x - 5 | |
end | |
elseif self.direction == 1 then | |
self.y = self.y - 5 | |
if self.y < 10 then | |
self.bump = true | |
self.y = self.y + 5 | |
end | |
elseif self.direction == 2 then | |
self.x = self.x - 5 | |
if self.x < 10 then | |
self.bump = true | |
self.x = self.x + 5 | |
end | |
end | |
elseif p.code.short == "W" then | |
-- fire laser | |
self.delay = self.dish * 15 | |
self.fireLaser = true | |
self:drawLaser() | |
end | |
-- step forward | |
if not redirected then | |
self.step = self.step + 1 | |
end | |
self.treadTick = self.treadTick + 1 | |
if self.treadTick > 9 then | |
self.treadTick = 0 | |
end | |
end | |
function Robot:draw(size) | |
local i | |
-- draw | |
pushMatrix() | |
translate(self.x + 30, self.y + 30) | |
scale(size) | |
if self.direction == 2 then | |
rotate(270) | |
elseif self.direction == 3 then | |
rotate(180) | |
elseif self.direction == 4 then | |
rotate(90) | |
end | |
strokeWidth(1) | |
self:drawBase() | |
popMatrix() | |
self.bounds.left = self.x | |
self.bounds.right = self.x + 60 | |
self.bounds.top = self.y + 60 | |
self.bounds.bottom = self.y | |
if self.heat > 0 then self.heat = self.heat - 0.1 end | |
end | |
function Robot:drawDish(x, y) | |
c1 = colors[self.dishColor] | |
c2 = color(c1.r + self.heat * 22, c1.g, c1.b) | |
stroke(c2) | |
fill(backClr) | |
if self.dish == 1 then | |
line(x - 3, y, x, y + 15) | |
line(x + 3, y, x, y + 15) | |
line(x - 20, y + 7, x - 15, y + 3) | |
line(x - 15, y + 3, x, y) | |
line(x + 20, y + 7, x + 15, y + 3) | |
line(x + 15, y + 3, x, y) | |
line(x, y + 15, x, y + 20) | |
ellipse(x, y + 15, 3) | |
self.range = 20 | |
end | |
if self.dish == 2 then | |
rect(x - 3, y, x + 3, y + 20) | |
line(x - 15, y, x, y) | |
line(x + 15, y, x, y) | |
line(x - 20, y + 10, x, y) | |
line(x + 20, y + 10, x, y) | |
self.range = 7 | |
end | |
if self.dish == 3 then | |
line(x - 15, y, x + 15, y) | |
line(x - 10, y + 3, x + 10, y + 3) | |
line(x - 7, y + 7, x + 7, y + 7) | |
line(x - 3, y + 10, x + 3, y + 10) | |
line(x, y, x, y + 20) | |
ellipse(x, y + 20, 7) | |
self.range = 3 | |
end | |
end | |
function Robot:drawHead(x, y) | |
c1 = colors[self.headColor] | |
c2 = color(c1.r + self.heat * 22, c1.g, c1.b) | |
stroke(c2) | |
fill(backClr) | |
if self.head == 1 then | |
ellipse(x, y, 30) | |
ellipse(x, y, self.treadTick * 2) | |
rect(x - 15, y - 5, x - 15, y + 5) | |
rect(x + 15, y - 5, x + 15, y + 5) | |
line(x - 15, y, x - 20, y) | |
line(x + 15, y, x + 20, y) | |
end | |
if self.head == 2 then | |
ellipse(x, y, 30) | |
ellipse(x, y, 20) | |
rotate(self.treadTick * 9) | |
line(x+6,y+6,x-6,y-6) | |
line(x+6,y-6,x-6,y+6) | |
rotate(self.treadTick * -9) | |
end | |
if self.head == 3 then | |
ellipse(x, y, 30) | |
ellipse(x, y + 10, 20, 10) | |
ellipse(x, y + 10, 15, 5) | |
line(x - 15, y - 5, x - 20, y - 15) | |
line(x + 15, y - 5, x + 20, y - 15) | |
fill(255, 0, 0, 255) | |
ellipse(x, y + 5, 20, self.treadTick * 2) | |
end | |
end | |
function Robot:drawBody(x, y) | |
c1 = colors[self.bodyColor] | |
c2 = color(c1.r + self.heat * 22, c1.g, c1.b) | |
stroke(c2) | |
fill(backClr) | |
if self.body == 1 then | |
ellipse(x, y, 40, 20) | |
ellipse(x - 20, y, 15, 15) | |
ellipse(x + 20, y, 15, 15) | |
end | |
if self.body == 2 then | |
rect(x - 25, y - 10, x + 25, y + 10) | |
ellipse(x - 25, y, 20) | |
ellipse(x + 25, y, 20) | |
rect(x - 15, y - 15, x + 15, y - 10) | |
end | |
if self.body == 3 then | |
ellipse(x - 20, y, 30, 30) | |
ellipse(x + 20, y, 30, 30) | |
rect(x - 20, y - 15, x + 20, y + 15) | |
ellipse(x, y, 40, 30) | |
end | |
end | |
function Robot:drawTreads(x, y) | |
local i | |
c1 = colors[self.treadColor] | |
c2 = color(c1.r + self.heat * 22, c1.g, c1.b) | |
stroke(c2) | |
fill(backClr) | |
if self.tread == 1 then | |
ellipse(20, -20, 20) | |
ellipse(20, -20, 20, 5 + self.treadTick) | |
ellipse(-20, -20, 20) | |
ellipse(-20, -20, 20, 5 + self.treadTick) | |
ellipse(-20, 20, 20) | |
ellipse(-20, 20, 20, 5 + self.treadTick) | |
ellipse(20, 20, 20) | |
ellipse(20, 20, 20, 5 + self.treadTick) | |
line(-20, -11, 0, 2) | |
line(-17, -14, 0, -2) | |
line(20, -11, 0, 2) | |
line(17, -14, 0, -2) | |
line(-20, 11, 0, 2) | |
line(-17, 14, 0, -2) | |
line(20, 11, 0, 2) | |
line(17, 14, 0, -2) | |
end | |
if self.tread == 2 then | |
rect(-30, -30, -15, 30) | |
rect(15, -30, 30, 30) | |
for i = 0,5 do | |
line(-30, i * 10 - 30 + self.treadTick, | |
-15, i * 10 - 30 + self.treadTick) | |
line(15, i * 10 -30 + self.treadTick, | |
30, i * 10 - 30 + self.treadTick) | |
end | |
end | |
if self.tread == 3 then | |
rect(-30, -30, -15, -15) | |
rect(-27, -33, -17, -12) | |
rect(15, -30, 30, -15) | |
rect(17, -33, 27, -12) | |
rect(-30, 15, -15, 30) | |
rect(-27, 12, -17, 33) | |
rect(15, 15, 30, 30) | |
rect(17, 12, 27, 33) | |
rect(-15, 20, 15, 25) | |
rect(-15, -20, 15, -25) | |
rect(-3, -10, 3, -20) | |
rect(-3, 10, 3, 20) | |
line(-27, self.treadTick - 30 + self.treadTick, | |
-17, self.treadTick - 30 + self.treadTick) | |
line(17, self.treadTick - 30 + self.treadTick, | |
27, self.treadTick - 30 + self.treadTick) | |
line(17, self.treadTick + 15 + self.treadTick, | |
27, self.treadTick + 15 + self.treadTick) | |
line(-27, self.treadTick + 15 + self.treadTick, | |
-17, self.treadTick + 15 + self.treadTick) | |
end | |
end | |
function Robot:drawBase() | |
pushStyle() | |
self:drawTreads(0, 0) | |
self:drawBody(0, 0) | |
self:drawHead(0, 0) | |
self:drawDish(0, 10) | |
popStyle() | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TourneyOrganizer = class() | |
function TourneyOrganizer:init(x, y) | |
local i | |
self.x = x | |
self.y = y | |
self.frame = Frame(x, y, x + 710, y + 850) | |
self.header = Frame(self.frame.left + 4, self.frame.top - 40, | |
self.frame.right - 4, self.frame.top - 4) | |
self.action = 0 | |
self.contestantFrames = {} | |
self.contestants = {} | |
for i = 1,4 do | |
self.contestantFrames[i] = Frame(i * 175 - 100, 800, | |
i * 175 , 880) | |
self.contestants[i] = 0 | |
end | |
self.selected = 0 | |
self.showSlider = false | |
self.slider = VRobotSlider(self.contestantFrames[1].left, | |
self.contestantFrames[1].bottom) | |
self.robothonBtn = BigButton("Quartet", 570, 400) | |
self.skeetBtn = BigButton("Skeet", 75, 600) | |
self.mazeBtn = BigButton("Maze", 240, 600) | |
self.chaseBtn = BigButton("Chase", 405, 600) | |
self.meleeBtn = BigButton("Melee", 570, 600) | |
self.mazeBtn.active = false | |
self.chaseBtn.active = false | |
end | |
function TourneyOrganizer:loadRobot(i) | |
self.contestants[1] = i | |
end | |
function TourneyOrganizer:draw(robots) | |
local i | |
pushStyle() | |
noFill() | |
strokeWidth(2) | |
stroke(246, 246, 246, 255) | |
self.frame:draw() | |
self.header:draw() | |
textMode(CENTER) | |
strokeWidth(1) | |
for i = 1,4 do | |
stroke(255, 255, 255, 255) | |
noFill() | |
self.contestantFrames[i]:draw() | |
if self.contestants[i] > 0 then | |
pushMatrix() | |
translate(self.contestantFrames[i]:midX(), | |
self.contestantFrames[i]:midY()) | |
robots[self.contestants[i]]:drawBase() | |
fontSize(16) | |
fill(255, 255, 255, 224) | |
text(robots[self.contestants[i]].name, 0, -55) | |
popMatrix() | |
else | |
fontSize(48) | |
fill(115, 115, 115, 190) | |
text("?", self.contestantFrames[i]:midX(), | |
self.contestantFrames[i]:midY()) | |
fill(154, 126, 126, 224) | |
fontSize(16) | |
text("Random", self.contestantFrames[i]:midX(), | |
self.contestantFrames[i]:midY()-55) | |
end | |
end | |
fill(165, 165, 188, 255) | |
stroke(147, 153, 173, 255) | |
strokeWidth(1) | |
line(self.contestantFrames[2].left, | |
self.contestantFrames[1].top + 20, | |
self.contestantFrames[2].left + 145, | |
self.contestantFrames[1].top + 20) | |
line(self.contestantFrames[2].left, | |
self.contestantFrames[1].top + 15, | |
self.contestantFrames[2].left, | |
self.contestantFrames[1].top + 25) | |
line(self.contestantFrames[4].left - 45, | |
self.contestantFrames[1].top + 20, | |
self.contestantFrames[4].right, | |
self.contestantFrames[1].top + 20) | |
line(self.contestantFrames[4].right, | |
self.contestantFrames[1].top + 15, | |
self.contestantFrames[4].right, | |
self.contestantFrames[1].top + 25) | |
text("Melee Opponents", self.contestantFrames[3]:midX(), | |
self.contestantFrames[1].top + 20) | |
noFill() | |
stroke(255, 255, 255, 154) | |
strokeWidth(2) | |
rect(self.frame.left + 35, 400, self.frame.left + 95, 460) | |
line(self.frame.left + 95, 430, self.frame.left + 155, 430) | |
rect(self.frame.left + 155, 400, self.frame.left + 215, 460) | |
line(self.frame.left + 215, 430, self.frame.left + 275, 430) | |
rect(self.frame.left + 275, 400, self.frame.left + 335, 460) | |
line(self.frame.left + 335, 430, self.frame.left + 395, 430) | |
rect(self.frame.left + 395, 400, self.frame.left + 455, 460) | |
line(self.frame.left + 215, 430, self.frame.left + 275, 430) | |
fill(255, 255, 255, 255) | |
fontSize(32) | |
text("1", self.frame.left + 65, 430) | |
text("2", self.frame.left + 185, 430) | |
text("3", self.frame.left + 305, 430) | |
text("4", self.frame.left + 425, 430) | |
self.meleeBtn:draw() | |
self.skeetBtn:draw() | |
stroke(113, 102, 159, 255) | |
fill(109, 111, 169, 255) | |
self.mazeBtn:draw() | |
self.chaseBtn:draw() | |
self.robothonBtn:draw() | |
fontSize(16) | |
textMode(CORNER) | |
text("TOURNEY ORGANIZER", self.frame.left + 15, | |
self.frame.top - 32) | |
text("Four Event Robothon", self.frame.left + 20, | |
self.frame.bottom + 330) | |
if self.showSlider then self.slider:draw(robots) end | |
popStyle() | |
end | |
function TourneyOrganizer:touched(touch) | |
local i | |
for i = 1,4 do | |
if self.contestantFrames[i]:touched(touch) then | |
self.showSlider = true | |
self.slider = VRobotSlider( | |
self.contestantFrames[i].right, | |
self.contestantFrames[i].bottom) | |
self.selected = i | |
end | |
end | |
if self.showSlider then | |
if self.slider:touched(touch) then | |
self.contestants[self.selected] = self.slider.selected | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment