Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
js13k2024
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Bye
js13k2024
Commits
588a293a
Commit
588a293a
authored
10 months ago
by
Bye
Browse files
Options
Downloads
Patches
Plain Diff
i cant get this fucking camera working
parent
0ad511f9
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/js/main.js
+14
-12
14 additions, 12 deletions
src/js/main.js
src/js/objects/ground.js
+27
-0
27 additions, 0 deletions
src/js/objects/ground.js
src/js/rooms/debug_sprites.js
+7
-3
7 additions, 3 deletions
src/js/rooms/debug_sprites.js
src/js/rooms/game.js
+29
-25
29 additions, 25 deletions
src/js/rooms/game.js
with
77 additions
and
40 deletions
src/js/main.js
+
14
−
12
View file @
588a293a
...
@@ -4,6 +4,12 @@ import Engine from "../../hampsterengine/src/engine.js";
...
@@ -4,6 +4,12 @@ import Engine from "../../hampsterengine/src/engine.js";
import
Keyboard
from
"
../../hampsterengine/src/keyboard
"
;
import
Keyboard
from
"
../../hampsterengine/src/keyboard
"
;
import
{
FontRenderer
,
Stars
}
from
"
./objects
"
;
import
{
FontRenderer
,
Stars
}
from
"
./objects
"
;
// Init the engine and canvas
const
canvas
=
new
Canvas
(
c
);
const
engine
=
new
Engine
(
canvas
);
const
assets
=
engine
.
assetStore
;
const
keyboard
=
new
Keyboard
();
import
SoundBox
from
"
./sb-player-small
"
;
import
SoundBox
from
"
./sb-player-small
"
;
// import {mus_DEMOSONG} from "./songs/DEMOSONGDONOTCOMMIT";
// import {mus_DEMOSONG} from "./songs/DEMOSONGDONOTCOMMIT";
...
@@ -31,11 +37,6 @@ import {rm_DEBUG_sprites} from "./rooms/debug_sprites";
...
@@ -31,11 +37,6 @@ import {rm_DEBUG_sprites} from "./rooms/debug_sprites";
const
query
=
new
URLSearchParams
(
window
.
location
.
search
);
const
query
=
new
URLSearchParams
(
window
.
location
.
search
);
window
.
query
=
query
;
window
.
query
=
query
;
// Init the engine and canvas
const
canvas
=
new
Canvas
(
c
);
const
engine
=
new
Engine
(
canvas
);
const
assets
=
engine
.
assetStore
;
const
keyboard
=
new
Keyboard
();
assets
.
addImage
(
'
font
'
,
font
);
assets
.
addImage
(
'
font
'
,
font
);
const
fontRenderer
=
new
FontRenderer
(
assets
.
get
`font`
);
const
fontRenderer
=
new
FontRenderer
(
assets
.
get
`font`
);
...
@@ -81,8 +82,9 @@ engine.running = false; // Game uses this as a pause state actually
...
@@ -81,8 +82,9 @@ engine.running = false; // Game uses this as a pause state actually
// }
// }
// tempCanvasStars.toBlob(createStarsObjectURL);
// tempCanvasStars.toBlob(createStarsObjectURL);
assets
.
addMiniSprite
(
'
grass
'
,
'
IIIIIIQIQQQJZQZZRZRRZRZRSSRSRZZR
'
);
const
GROUND_PALETTE
=
[
'
#2a6
'
,
'
#964
'
,
'
#853
'
]
assets
.
renderMiniSprite
(
'
grass
'
,
[
'
#2a6
'
,
'
#964
'
,
'
#853
'
]);
assets
.
addMiniSprite
(
'
grass
'
,
'
IIIIIIQIQQQJZQZZRZRRZRZRSSRSRZZR
'
,
8
,
GROUND_PALETTE
);
assets
.
addMiniSprite
(
'
dirt
'
,
'
SSRRRZ[ZZZRRZRZZRZRRZRZRSSRSRZZR
'
,
8
,
GROUND_PALETTE
);
engine
.
registerRoom
(
rm_mainMenu
,
'
mainMenu
'
);
engine
.
registerRoom
(
rm_mainMenu
,
'
mainMenu
'
);
engine
.
registerRoom
(
rm_game
,
'
game
'
);
engine
.
registerRoom
(
rm_game
,
'
game
'
);
...
@@ -132,8 +134,7 @@ function main() {
...
@@ -132,8 +134,7 @@ function main() {
}
catch
(
e
)
{
}
catch
(
e
)
{
engine
.
running
=
false
;
engine
.
running
=
false
;
canvas
.
pixelRatio
=
2
;
canvas
.
setScale
(
1
);
canvas
.
ctx
.
setTransform
(
canvas
.
pixelRatio
,
0
,
0
,
canvas
.
pixelRatio
,
0
,
0
);
canvas
.
fill
(
'
#a05555d0
'
);
canvas
.
fill
(
'
#a05555d0
'
);
const
logo
=
assets
.
get
`splash`
const
logo
=
assets
.
get
`splash`
...
@@ -162,12 +163,10 @@ function physicsTick() {
...
@@ -162,12 +163,10 @@ function physicsTick() {
console
.
debug
(
engine
.
rooms
);
console
.
debug
(
engine
.
rooms
);
let
roomToLoad
=
(
query
.
get
`room`
?
engine
.
getRoomIndex
(
query
.
get
`room`
)
:
engine
.
getRoomIndex
`mainMenu`
);
if
(
query
.
get
`room`
)
{
if
(
query
.
get
`room`
)
{
console
.
log
(
'
Requesting room
'
,
query
.
get
`room`
);
console
.
log
(
'
Requesting room
'
,
query
.
get
`room`
);
engine
.
loadDelay
=
0
;
engine
.
loadDelay
=
0
;
engine
.
room
=
engine
.
getRoomIndex
(
query
.
get
`room`
);
}
else
{
engine
.
room
=
engine
.
getRoomIndex
`mainMenu`
;
}
}
// Ensure assets are loaded.
// Ensure assets are loaded.
...
@@ -176,6 +175,9 @@ function load() {
...
@@ -176,6 +175,9 @@ function load() {
engine
.
loadLoop
();
engine
.
loadLoop
();
setTimeout
(
load
,
1000
/
60
);
setTimeout
(
load
,
1000
/
60
);
}
else
{
}
else
{
engine
.
initRooms
();
console
.
log
(
"
Initialised rooms
"
);
engine
.
room
=
roomToLoad
;
readyTime
=
performance
.
now
();
readyTime
=
performance
.
now
();
engine
.
lastPhysicsFrame
=
performance
.
now
();
engine
.
lastPhysicsFrame
=
performance
.
now
();
main
();
main
();
...
...
This diff is collapsed.
Click to expand it.
src/js/objects/ground.js
0 → 100644
+
27
−
0
View file @
588a293a
import
{
Entity
}
from
"
../../../hampsterengine/src/things
"
;
import
{
round
,
roundToRatio
}
from
"
../extras
"
;
export
default
class
Ground
extends
Entity
{
constructor
(
scale
=
1
)
{
super
();
this
.
width
=
canvas
.
width
;
this
.
height
=
16
*
scale
;
this
.
x
=
0
;
this
.
y
=
canvas
.
height
-
this
.
height
;
this
.
scale
=
scale
;
this
.
surface
=
engine
.
assetStore
.
get
`grass`
.
sprite
;
this
.
below
=
engine
.
assetStore
.
get
`dirt`
.
sprite
;
}
draw
()
{
if
(
!
(
this
.
surface
||
this
.
below
))
return
;
canvas
.
tileImage
(
this
.
surface
,
roundToRatio
(
this
.
x
),
roundToRatio
(
this
.
y
),
this
.
width
,
8
*
this
.
scale
,
8
*
this
.
scale
,
8
*
this
.
scale
);
canvas
.
tileImage
(
this
.
below
,
roundToRatio
(
this
.
x
),
roundToRatio
(
this
.
y
+
8
*
this
.
scale
),
this
.
width
,
this
.
height
-
8
*
this
.
scale
,
8
*
this
.
scale
,
8
*
this
.
scale
);
canvas
.
fillRect
(
this
.
x
,
this
.
y
,
this
.
width
,
this
.
height
);
}
}
This diff is collapsed.
Click to expand it.
src/js/rooms/debug_sprites.js
+
7
−
3
View file @
588a293a
import
{
Room
}
from
"
../../../hampsterengine/src/things
"
;
import
{
Room
}
from
"
../../../hampsterengine/src/things
"
;
import
Ground
from
"
../objects/ground
"
;
export
const
rm_DEBUG_sprites
=
new
Room
();
export
const
rm_DEBUG_sprites
=
new
Room
();
rm_DEBUG_sprites
.
init
=
function
()
{
const
ground
=
new
Ground
();
rm_DEBUG_sprites
.
push
(
ground
,
'
ground
'
);
}
rm_DEBUG_sprites
.
start
=
_
=>
{
rm_DEBUG_sprites
.
start
=
_
=>
{
canvas
.
setScale
(
3
);
canvas
.
setScale
(
3
);
rm_DEBUG_sprites
.
init
();
canvas
.
ctx
.
imageSmoothingEnabled
=
false
;
canvas
.
ctx
.
imageSmoothingEnabled
=
false
;
}
}
rm_DEBUG_sprites
.
draw
=
_
=>
{
canvas
.
tileImage
(
engine
.
assetStore
.
get
(
'
grass
'
).
sprite
,
0
,
0
,
canvas
.
width
,
8
,
8
,
8
);
}
This diff is collapsed.
Click to expand it.
src/js/rooms/game.js
+
29
−
25
View file @
588a293a
...
@@ -2,12 +2,15 @@
...
@@ -2,12 +2,15 @@
import
{
Entity
,
Room
}
from
"
../../../hampsterengine/src/things
"
;
import
{
Entity
,
Room
}
from
"
../../../hampsterengine/src/things
"
;
import
Player
from
"
../objects/player
"
;
import
Player
from
"
../objects/player
"
;
import
{
clone
,
clonePlayer
,
abs
}
from
"
../extras
"
;
import
{
clone
,
clonePlayer
,
abs
}
from
"
../extras
"
;
import
Ground
from
"
../objects/ground
"
;
export
const
rm_game
=
new
Room
();
export
const
rm_game
=
new
Room
();
const
GRAVITY_X
=
0
;
// I don't think we're going to use X gravity but i'm going to keep in the source in case i do
const
GRAVITY_X
=
0
;
// I don't think we're going to use X gravity but i'm going to keep in the source in case i do
const
GRAVITY_Y
=
300
;
// Per second
const
GRAVITY_Y
=
300
;
// Per second
const
entities
=
rm_game
.
entities
;
const
entities
=
rm_game
.
entities
;
rm_game
.
width
=
1000
;
rm_game
.
height
=
1000
;
rm_game
.
start
=
_
=>
{
rm_game
.
start
=
_
=>
{
engine
.
running
=
true
;
engine
.
running
=
true
;
...
@@ -19,6 +22,7 @@ rm_game.stop = _=>{
...
@@ -19,6 +22,7 @@ rm_game.stop = _=>{
rm_game
.
step
=
_
=>
{
rm_game
.
step
=
_
=>
{
const
elapsed
=
1
/
60
;
const
elapsed
=
1
/
60
;
const
player
=
rm_game
.
get
(
'
plr
'
);
let
friction
=
0.9
;
let
friction
=
0.9
;
const
boost
=
keyboard
.
keys
.
includes
(
"
Shift
"
)
?
40
:
0
;
const
boost
=
keyboard
.
keys
.
includes
(
"
Shift
"
)
?
40
:
0
;
...
@@ -71,6 +75,12 @@ rm_game.step = _=>{
...
@@ -71,6 +75,12 @@ rm_game.step = _=>{
if
(
abs
(
player
.
vy
)
<
1
)
player
.
vy
=
0
;
if
(
abs
(
player
.
vy
)
<
1
)
player
.
vy
=
0
;
if
(
abs
(
player
.
vx
)
<
1
)
player
.
vx
=
0
;
if
(
abs
(
player
.
vx
)
<
1
)
player
.
vx
=
0
;
// Update the camera
canvas
.
camera
.
goTo
(
Math
.
min
(
Math
.
max
(
player
.
x
+
canvas
.
width
/
8
,
canvas
.
width
/
8
),
rm_game
.
width
-
canvas
.
width
),
Math
.
min
(
Math
.
max
(
player
.
y
+
canvas
.
width
/
8
,
canvas
.
width
/
8
),
rm_game
.
height
-
canvas
.
height
)
);
}
}
rm_game
.
drawGui
=
_
=>
{
rm_game
.
drawGui
=
_
=>
{
...
@@ -87,30 +97,24 @@ rm_game.drawGui = _ => {
...
@@ -87,30 +97,24 @@ rm_game.drawGui = _ => {
});
});
// Draw the player's position
// Draw the player's position
canvas
.
strokeRect
(
rm_game
.
x
,
rm_game
.
y
,
10
,
16
);
//
canvas.strokeRect(rm_game.x, rm_game.y, 10, 16);
}
}
rm_game
.
init
=
_
=>
{
let
player
=
new
Player
();
let
player
=
new
Player
();
player
.
x
=
40
;
player
.
x
=
40
;
player
.
y
=
40
;
player
.
y
=
40
;
player
.
width
=
1
0
;
player
.
width
=
1
6
;
player
.
height
=
1
6
;
player
.
height
=
2
6
;
window
.
player
=
player
;
window
.
player
=
player
;
entities
.
push
(
player
);
rm_game
.
push
(
player
,
'
plr
'
);
let
floor
=
new
Entity
();
let
ground
=
new
Ground
(
2
);
floor
.
x
=
64
;
ground
.
width
=
rm_game
.
width
;
floor
.
y
=
150
;
ground
.
y
=
rm_game
.
height
-
ground
.
height
;
floor
.
width
=
128
;
floor
.
height
=
50
;
rm_game
.
push
(
ground
);
floor
.
draw
=
_
=>
{
canvas
.
setStrokeColor
(
'
black
'
);
canvas
.
strokeRect
(
floor
.
x
,
floor
.
y
,
floor
.
width
,
floor
.
height
)
}
rm_game
.
entities
.
push
(
floor
);
}
let
ceiling
=
new
Entity
();
ceiling
.
x
=
64
;
ceiling
.
y
=
75
;
ceiling
.
width
=
128
;
ceiling
.
height
=
50
;
ceiling
.
draw
=
_
=>
{
canvas
.
setStrokeColor
(
'
black
'
);
canvas
.
strokeRect
(
ceiling
.
x
,
ceiling
.
y
,
ceiling
.
width
,
ceiling
.
height
)
}
rm_game
.
entities
.
push
(
ceiling
);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment