-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: basic beginnings of asteroid game demo
- Loading branch information
Showing
8 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
.cache | ||
build | ||
imgui.ini | ||
|
||
live.jenscene |
Binary file not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../resources |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/usr/bin/env bash | ||
../build/jenjin/jenjin --runtime |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
local asteroids = {} | ||
|
||
function READY() end | ||
|
||
function UPDATE() | ||
if input.IsKeyDown("r") then | ||
local quad = helpers.CreateQuad() | ||
local name = tostring("asteroid_"..#asteroids) | ||
local obj = GameObject.new(name, quad) | ||
obj:SetPosition(vec2.new(math.random(-20, 20), math.random(-10, 10))) | ||
obj:SetRotation(math.random(0, 360)) | ||
|
||
local r = math.random() / 5 | ||
obj:SetColor(vec3.new(r, r, r)) | ||
|
||
scene:AddGameObject(obj) | ||
scene:Build() | ||
|
||
asteroids[#asteroids+1] = obj | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
local bullets = {} | ||
local player = nil | ||
|
||
local bulletCount = 0 | ||
|
||
local fromLeftGun = true | ||
local timeSinceLastShot = 11 | ||
|
||
function READY() | ||
player = scene:GetGameObject("Player") | ||
end | ||
|
||
function UPDATE() | ||
if input.IsKeyDown("q") then | ||
timeSinceLastShot = timeSinceLastShot + 1 | ||
if timeSinceLastShot > 1 then | ||
timeSinceLastShot = 0 | ||
local obj = GameObject.new("bullet"..bulletCount, helpers.CreateQuad()) | ||
bulletCount = bulletCount + 1 | ||
|
||
fromLeftGun = not fromLeftGun | ||
|
||
local left = vec2.new(math.sin(math.rad(player:GetRotation() - 90)), math.cos(math.rad(player:GetRotation() - 90))) | ||
local up = vec2.new(math.sin(math.rad(player:GetRotation())), math.cos(math.rad(player:GetRotation()))) | ||
|
||
if fromLeftGun then | ||
obj:SetPosition(player:GetPosition() + left * 1.1 + up * 1.2) | ||
else | ||
obj:SetPosition(player:GetPosition() - left * 1.1 + up * 1.2) | ||
end | ||
|
||
obj:SetScale(vec2.new(0.1, 0.2)) | ||
obj:SetRotation(player:GetRotation()) | ||
obj:SetColor(vec3.new(1, 0, 0)) | ||
|
||
scene:AddGameObject(obj) | ||
scene:Build() | ||
|
||
table.insert(bullets, obj) | ||
|
||
player:Translate(up * -0.025) | ||
end | ||
end | ||
|
||
for i, bullet in ipairs(bullets) do | ||
local radians = math.rad(bullet:GetRotation()) | ||
local direction = vec2.new(math.sin(radians), math.cos(radians)) | ||
bullet:Translate(direction * 0.5) | ||
|
||
if bullet:GetPosition():Distance(player:GetPosition()) > 250 then | ||
scene:RemoveGameObject(bullet) | ||
table.remove(bullets, i) | ||
end | ||
end | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
local player = nil | ||
|
||
local rotation_speed = 5 | ||
local movement_speed = 0.2 | ||
local acceleration = 0.02 | ||
local deceleration = 0.97 | ||
|
||
local direction = { x = 0, y = 0 } | ||
local velocity = 0 | ||
|
||
function READY() | ||
player = scene:GetGameObject("Player") | ||
end | ||
|
||
function UPDATE() | ||
handleRotation() | ||
handleMovement() | ||
|
||
player:Translate(vec2.new(direction.x, direction.y) * movement_speed * velocity) | ||
end | ||
|
||
function handleRotation() | ||
a = input.IsKeyDown("a") | ||
d = input.IsKeyDown("d") | ||
|
||
if a or d then | ||
local rot = player:GetRotation() | ||
|
||
if a then | ||
player:SetRotation((rot - rotation_speed) % 360) | ||
else | ||
player:SetRotation((rot + rotation_speed) % 360) | ||
end | ||
end | ||
end | ||
|
||
function handleMovement() | ||
if input.IsKeyDown("w") then | ||
local radians = math.rad(player:GetRotation()) | ||
direction.y = math.cos(radians) | ||
direction.x = math.sin(radians) | ||
|
||
if velocity < 1 then | ||
velocity = velocity + acceleration | ||
end | ||
else | ||
velocity = velocity * deceleration | ||
end | ||
end |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.