I started coding our new very very simple game.😀 The name of our game is Cannonball. In the game, the cannon screen of 2 different players randomly placed to the right and left is displayed. We try to shoot the other cannon by entering the Angle and Speed values according to the laws of physics. Of course, it's not at the level to be played yet, but I plan to finish it in 1 week.
DONE
- Cannon are fired sequentially
- Speed and Angle values can be entered manually, and if desired, the Up and Down keys on the keyboard (decreases or increases the Angle values) and the right and left on the keyboard (increases or decreases the Speed values)
VIP
- Damage modeling will be done
- The winner of the game will be determined and a small animation will be made.
- Physics engine will be slightly improved
- Code optimization will be done
[Login to see the link]
local ui = require "ui"
require "canvas"
local win = ui.Window("Cannon Game", "fixed", 1200, 675)
local button = ui.Button(win, "FIRE!", win.width/2, 5, 50,25)
local label_Blue_Angle = ui.Label(win, "ANGLE:", 5, 10)
local entry_Blue_Angle = ui.Entry(win, "45", 48, 8, 25, 20)
local label_Blue_Speed = ui.Label(win, "SPEED:", 90, 10)
local entry_Blue_Speed = ui.Entry(win, "100", 128, 8, 30, 20)
local label_Red_Angle = ui.Label(win, "ANGLE:", 1037, 10)
local entry_Red_Angle = ui.Entry(win, "45", 1085, 8, 25, 20)
local label_Red_Speed = ui.Label(win, "SPEED:", 1127, 10)
local entry_Red_Speed = ui.Entry(win, "100", 1165, 8, 30, 20)
local tuval = ui.Canvas(win, 0, 30, win.width, win.height - 30)
--win.align="top"
tuval.bgcolor = 0x000000FF
local imgTopBlue = tuval:Image("Pictures/CannonBlue.png")
local imgTopRed = tuval:Image("Pictures/CannonRed.png")
local X_Top_Blue = math.random(0, 450)
local Y_Top_Blue = 550
local X_Top_Red = math.random(650, 1100)
local Y_Top_Red = 550
local currentTeam= math.random(1, 2) -- 1=Blue, 2=Red
local imgMermi = tuval:Image("Pictures/CannonBall.png")
if currentTeam == 1 then
X_Mermi = X_Top_Blue + 87
Y_Mermi = Y_Top_Blue
else
X_Mermi = X_Top_Red
Y_Mermi = Y_Top_Red
end
function tuval:onPaint()
self:clear()
imgTopBlue:draw(X_Top_Blue, Y_Top_Blue)
imgTopRed:draw(X_Top_Red, Y_Top_Red)
imgMermi:draw(X_Mermi, Y_Mermi)
end
function button:onClick()
local v = tonumber(entry_Blue_Speed.text)
local alfa = tonumber(entry_Blue_Angle.text)
local default_X_Mermi = X_Mermi
local default_Y_Mermi = Y_Mermi
local sayac = 0
repeat
sayac = sayac + 1
ui.update(75)
if currentTeam == 1 then
X_Mermi = default_X_Mermi + (v * math.cos(math.rad(alfa))*sayac)
else
X_Mermi = default_X_Mermi - (v * math.cos(math.rad(alfa))*sayac)
end
Y_Mermi = default_Y_Mermi - (v * math.sin(math.rad(alfa))*sayac - (0.5*10*(sayac^2)))
until( Y_Mermi > default_Y_Mermi + 100)
if currentTeam == 1 then
currentTeam = 2
X_Mermi = X_Top_Red
Y_Mermi = Y_Top_Red
else
currentTeam = 1
X_Mermi = X_Top_Blue + 87
Y_Mermi = Y_Top_Blue
end
end
function win:onKey(key)
if key == "VK_LEFT" then
if currentTeam == 1 then
entry_Blue_Speed.text= tonumber(entry_Blue_Speed.text) - 1
else
entry_Red_Speed.text= tonumber(entry_Red_Speed.text) - 1
end
end
if key == "VK_RIGHT" then
if currentTeam == 1 then
entry_Blue_Speed.text= tonumber(entry_Blue_Speed.text) + 1
else
entry_Red_Speed.text= tonumber(entry_Red_Speed.text) + 1
end
end
if key == "VK_UP" then
if currentTeam == 1 then
entry_Blue_Angle.text= tonumber(entry_Blue_Angle.text) + 1
else
entry_Red_Angle.text= tonumber(entry_Red_Angle.text) + 1
end
end
if key == "VK_DOWN" then
if currentTeam == 1 then
entry_Blue_Angle.text= tonumber(entry_Blue_Angle.text) - 1
else
entry_Red_Angle.text= tonumber(entry_Red_Angle.text) - 1
end
end
end
win:show()
repeat
ui.update()
until not win.visible