Version 0.2
Added base for new physics, not yet working, and fixed falling on top of other cubes.
This commit is contained in:
parent
6b583a9178
commit
46eefaa62e
6 changed files with 69 additions and 261 deletions
22
.gitattributes
vendored
22
.gitattributes
vendored
|
@ -1,22 +0,0 @@
|
||||||
# Auto detect text files and perform LF normalization
|
|
||||||
* text=auto
|
|
||||||
|
|
||||||
# Custom for Visual Studio
|
|
||||||
*.cs diff=csharp
|
|
||||||
*.sln merge=union
|
|
||||||
*.csproj merge=union
|
|
||||||
*.vbproj merge=union
|
|
||||||
*.fsproj merge=union
|
|
||||||
*.dbproj merge=union
|
|
||||||
|
|
||||||
# Standard to msysgit
|
|
||||||
*.doc diff=astextplain
|
|
||||||
*.DOC diff=astextplain
|
|
||||||
*.docx diff=astextplain
|
|
||||||
*.DOCX diff=astextplain
|
|
||||||
*.dot diff=astextplain
|
|
||||||
*.DOT diff=astextplain
|
|
||||||
*.pdf diff=astextplain
|
|
||||||
*.PDF diff=astextplain
|
|
||||||
*.rtf diff=astextplain
|
|
||||||
*.RTF diff=astextplain
|
|
215
.gitignore
vendored
215
.gitignore
vendored
|
@ -1,215 +0,0 @@
|
||||||
#################
|
|
||||||
## Eclipse
|
|
||||||
#################
|
|
||||||
|
|
||||||
*.pydevproject
|
|
||||||
.project
|
|
||||||
.metadata
|
|
||||||
bin/
|
|
||||||
tmp/
|
|
||||||
*.tmp
|
|
||||||
*.bak
|
|
||||||
*.swp
|
|
||||||
*~.nib
|
|
||||||
local.properties
|
|
||||||
.classpath
|
|
||||||
.settings/
|
|
||||||
.loadpath
|
|
||||||
|
|
||||||
# External tool builders
|
|
||||||
.externalToolBuilders/
|
|
||||||
|
|
||||||
# Locally stored "Eclipse launch configurations"
|
|
||||||
*.launch
|
|
||||||
|
|
||||||
# CDT-specific
|
|
||||||
.cproject
|
|
||||||
|
|
||||||
# PDT-specific
|
|
||||||
.buildpath
|
|
||||||
|
|
||||||
|
|
||||||
#################
|
|
||||||
## Visual Studio
|
|
||||||
#################
|
|
||||||
|
|
||||||
## Ignore Visual Studio temporary files, build results, and
|
|
||||||
## files generated by popular Visual Studio add-ons.
|
|
||||||
|
|
||||||
# User-specific files
|
|
||||||
*.suo
|
|
||||||
*.user
|
|
||||||
*.sln.docstates
|
|
||||||
|
|
||||||
# Build results
|
|
||||||
|
|
||||||
[Dd]ebug/
|
|
||||||
[Rr]elease/
|
|
||||||
x64/
|
|
||||||
build/
|
|
||||||
[Bb]in/
|
|
||||||
[Oo]bj/
|
|
||||||
|
|
||||||
# MSTest test Results
|
|
||||||
[Tt]est[Rr]esult*/
|
|
||||||
[Bb]uild[Ll]og.*
|
|
||||||
|
|
||||||
*_i.c
|
|
||||||
*_p.c
|
|
||||||
*.ilk
|
|
||||||
*.meta
|
|
||||||
*.obj
|
|
||||||
*.pch
|
|
||||||
*.pdb
|
|
||||||
*.pgc
|
|
||||||
*.pgd
|
|
||||||
*.rsp
|
|
||||||
*.sbr
|
|
||||||
*.tlb
|
|
||||||
*.tli
|
|
||||||
*.tlh
|
|
||||||
*.tmp
|
|
||||||
*.tmp_proj
|
|
||||||
*.log
|
|
||||||
*.vspscc
|
|
||||||
*.vssscc
|
|
||||||
.builds
|
|
||||||
*.pidb
|
|
||||||
*.log
|
|
||||||
*.scc
|
|
||||||
|
|
||||||
# Visual C++ cache files
|
|
||||||
ipch/
|
|
||||||
*.aps
|
|
||||||
*.ncb
|
|
||||||
*.opensdf
|
|
||||||
*.sdf
|
|
||||||
*.cachefile
|
|
||||||
|
|
||||||
# Visual Studio profiler
|
|
||||||
*.psess
|
|
||||||
*.vsp
|
|
||||||
*.vspx
|
|
||||||
|
|
||||||
# Guidance Automation Toolkit
|
|
||||||
*.gpState
|
|
||||||
|
|
||||||
# ReSharper is a .NET coding add-in
|
|
||||||
_ReSharper*/
|
|
||||||
*.[Rr]e[Ss]harper
|
|
||||||
|
|
||||||
# TeamCity is a build add-in
|
|
||||||
_TeamCity*
|
|
||||||
|
|
||||||
# DotCover is a Code Coverage Tool
|
|
||||||
*.dotCover
|
|
||||||
|
|
||||||
# NCrunch
|
|
||||||
*.ncrunch*
|
|
||||||
.*crunch*.local.xml
|
|
||||||
|
|
||||||
# Installshield output folder
|
|
||||||
[Ee]xpress/
|
|
||||||
|
|
||||||
# DocProject is a documentation generator add-in
|
|
||||||
DocProject/buildhelp/
|
|
||||||
DocProject/Help/*.HxT
|
|
||||||
DocProject/Help/*.HxC
|
|
||||||
DocProject/Help/*.hhc
|
|
||||||
DocProject/Help/*.hhk
|
|
||||||
DocProject/Help/*.hhp
|
|
||||||
DocProject/Help/Html2
|
|
||||||
DocProject/Help/html
|
|
||||||
|
|
||||||
# Click-Once directory
|
|
||||||
publish/
|
|
||||||
|
|
||||||
# Publish Web Output
|
|
||||||
*.Publish.xml
|
|
||||||
*.pubxml
|
|
||||||
|
|
||||||
# NuGet Packages Directory
|
|
||||||
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
|
|
||||||
#packages/
|
|
||||||
|
|
||||||
# Windows Azure Build Output
|
|
||||||
csx
|
|
||||||
*.build.csdef
|
|
||||||
|
|
||||||
# Windows Store app package directory
|
|
||||||
AppPackages/
|
|
||||||
|
|
||||||
# Others
|
|
||||||
sql/
|
|
||||||
*.Cache
|
|
||||||
ClientBin/
|
|
||||||
[Ss]tyle[Cc]op.*
|
|
||||||
~$*
|
|
||||||
*~
|
|
||||||
*.dbmdl
|
|
||||||
*.[Pp]ublish.xml
|
|
||||||
*.pfx
|
|
||||||
*.publishsettings
|
|
||||||
|
|
||||||
# RIA/Silverlight projects
|
|
||||||
Generated_Code/
|
|
||||||
|
|
||||||
# Backup & report files from converting an old project file to a newer
|
|
||||||
# Visual Studio version. Backup files are not needed, because we have git ;-)
|
|
||||||
_UpgradeReport_Files/
|
|
||||||
Backup*/
|
|
||||||
UpgradeLog*.XML
|
|
||||||
UpgradeLog*.htm
|
|
||||||
|
|
||||||
# SQL Server files
|
|
||||||
App_Data/*.mdf
|
|
||||||
App_Data/*.ldf
|
|
||||||
|
|
||||||
#############
|
|
||||||
## Windows detritus
|
|
||||||
#############
|
|
||||||
|
|
||||||
# Windows image file caches
|
|
||||||
Thumbs.db
|
|
||||||
ehthumbs.db
|
|
||||||
|
|
||||||
# Folder config file
|
|
||||||
Desktop.ini
|
|
||||||
|
|
||||||
# Recycle Bin used on file shares
|
|
||||||
$RECYCLE.BIN/
|
|
||||||
|
|
||||||
# Mac crap
|
|
||||||
.DS_Store
|
|
||||||
|
|
||||||
|
|
||||||
#############
|
|
||||||
## Python
|
|
||||||
#############
|
|
||||||
|
|
||||||
*.py[co]
|
|
||||||
|
|
||||||
# Packages
|
|
||||||
*.egg
|
|
||||||
*.egg-info
|
|
||||||
dist/
|
|
||||||
build/
|
|
||||||
eggs/
|
|
||||||
parts/
|
|
||||||
var/
|
|
||||||
sdist/
|
|
||||||
develop-eggs/
|
|
||||||
.installed.cfg
|
|
||||||
|
|
||||||
# Installer logs
|
|
||||||
pip-log.txt
|
|
||||||
|
|
||||||
# Unit test / coverage reports
|
|
||||||
.coverage
|
|
||||||
.tox
|
|
||||||
|
|
||||||
#Translations
|
|
||||||
*.mo
|
|
||||||
|
|
||||||
#Mr Developer
|
|
||||||
.mr.developer.cfg
|
|
BIN
favicon.png
BIN
favicon.png
Binary file not shown.
Before Width: | Height: | Size: 305 B |
93
sint.js
93
sint.js
|
@ -17,39 +17,35 @@ window.requestAnimFrame = (function(){
|
||||||
})();
|
})();
|
||||||
|
|
||||||
// Set up variables.
|
// Set up variables.
|
||||||
|
|
||||||
function reset(){
|
function reset(){
|
||||||
|
// Create arrays.
|
||||||
actors = [];
|
actors = [];
|
||||||
controllers = [];
|
controllers = [];
|
||||||
particles = [];
|
particles = [];
|
||||||
ais = [];
|
ais = [];
|
||||||
keys = [];
|
keys = [];
|
||||||
|
|
||||||
|
// Create 2 actors.
|
||||||
actors[0] = new Actor(1, 200, 3, 5, 5);
|
actors[0] = new Actor(1, 200, 3, 5, 5);
|
||||||
actors[1] = new Actor(2, 200, 3, 50, 5);
|
actors[1] = new Actor(2, 200, 3, 50, 5);
|
||||||
|
|
||||||
actors[2] = new Actor(2, 200, 1, 100, -100);
|
// Create player key controllers.
|
||||||
|
controllers[0] = new Controller(actors[0], [[68, 'moveRight'], [65, 'moveLeft'], [87, 'jump'], [67, 'camera'], [77, 'stream', 100]]);
|
||||||
controllers[0] = new Controller(actors[0], [[68, 'moveRight'], [65, 'moveLeft'], [87, 'jump'], [67, 'camera'], [77, 'flo', 100]]);
|
|
||||||
controllers[1] = new Controller(actors[1], [[39, 'moveRight'], [37, 'moveLeft'], [38, 'jump'], [88, 'camera'], [78, 'bounce', 100]]);
|
controllers[1] = new Controller(actors[1], [[39, 'moveRight'], [37, 'moveLeft'], [38, 'jump'], [88, 'camera'], [78, 'bounce', 100]]);
|
||||||
controllers[2] = new Controller(actors[2], [[90, 'camera']]);
|
|
||||||
|
|
||||||
ais[0] = new Ai(actors[2], 'pace');
|
camera = [actors[0], actors[1]]; // Set camera.
|
||||||
|
canvas.style.background = '#fff'; // Set canvas style.
|
||||||
particles[0] = new Particle(0, 0, 2000, 100, 200, 10, 0);
|
|
||||||
|
|
||||||
camera = [actors[0], actors[1]];
|
|
||||||
canvas.style.background = '#fff';
|
|
||||||
canvas.style.display = 'block';
|
canvas.style.display = 'block';
|
||||||
canvas.style.border = '1px solid #ddd'
|
canvas.style.border = '1px solid #ddd';
|
||||||
spritesheet = new Image()
|
spritesheet = new Image();
|
||||||
spritesheet.src = 'newsprites.png';
|
spritesheet.src = 'newsprites.png';
|
||||||
document.addEventListener('keydown', keyDown, true);
|
document.addEventListener('keydown', keyDown, true);
|
||||||
document.addEventListener('keyup', keyUp, true);
|
document.addEventListener('keyup', keyUp, true);
|
||||||
animate();
|
animate();
|
||||||
}
|
}
|
||||||
|
|
||||||
level = [
|
// Define the level.
|
||||||
|
levels = [
|
||||||
['#...................#']
|
['#...................#']
|
||||||
,['#...................#']
|
,['#...................#']
|
||||||
,['########............#']
|
,['########............#']
|
||||||
|
@ -62,10 +58,12 @@ function animate() {
|
||||||
loopGame();
|
loopGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Round a number.
|
||||||
function r(num){
|
function r(num){
|
||||||
return Math.round(num);
|
return Math.round(num);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add key pressed to key list.
|
||||||
function keyDown(e){
|
function keyDown(e){
|
||||||
var keyPress;
|
var keyPress;
|
||||||
if (typeof event !== 'undefined') {
|
if (typeof event !== 'undefined') {
|
||||||
|
@ -78,6 +76,7 @@ function keyDown(e){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove key from key list.
|
||||||
function keyUp(e){
|
function keyUp(e){
|
||||||
var keyPress;
|
var keyPress;
|
||||||
if (typeof event !== 'undefined') {
|
if (typeof event !== 'undefined') {
|
||||||
|
@ -180,6 +179,9 @@ function Actor(type, health, power, xpos, ypos){
|
||||||
case 'flo':
|
case 'flo':
|
||||||
particles.push(new Particle(2, 0, 100000, this.x, this.y - 16, this.xvel * 4 + ((Math.random() - 0.5) * 10), -10));
|
particles.push(new Particle(2, 0, 100000, this.x, this.y - 16, this.xvel * 4 + ((Math.random() - 0.5) * 10), -10));
|
||||||
break;
|
break;
|
||||||
|
case 'new':
|
||||||
|
particles.push(new Particle(3, 0, 10000, this.x, this.y - 1, this.xvel * 4 + ((Math.random() - 0.5) * 5), -6 + this.yvel * 2));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
this.actionsturn.push(type);
|
this.actionsturn.push(type);
|
||||||
}
|
}
|
||||||
|
@ -188,12 +190,12 @@ function Actor(type, health, power, xpos, ypos){
|
||||||
this.left = this.right = false;
|
this.left = this.right = false;
|
||||||
for(j in actors){
|
for(j in actors){
|
||||||
if(actors[j].image != this.image){
|
if(actors[j].image != this.image){
|
||||||
if(actors[j].x + 17 > this.x && this.x > actors[j].x && this.sameY(actors[j])){
|
if(actors[j].x + 16 > this.x && this.x > actors[j].x && this.sameY(actors[j])){
|
||||||
this.left = true;
|
this.left = true;
|
||||||
this.x = actors[j].x + 16;
|
this.x = actors[j].x + 16;
|
||||||
this.xvel = (this.xvel < 0 ? 0 : this.xvel);
|
this.xvel = (this.xvel < 0 ? 0 : this.xvel);
|
||||||
}
|
}
|
||||||
if(this.x + 17 > actors[j].x && this.x < actors[j].x && this.sameY(actors[j])){
|
if(this.x + 16 > actors[j].x && this.x < actors[j].x && this.sameY(actors[j])){
|
||||||
this.right = true;
|
this.right = true;
|
||||||
this.x = actors[j].x - 16;
|
this.x = actors[j].x - 16;
|
||||||
this.xvel = (this.xvel > 0 ? 0 : this.xvel);
|
this.xvel = (this.xvel > 0 ? 0 : this.xvel);
|
||||||
|
@ -204,28 +206,33 @@ function Actor(type, health, power, xpos, ypos){
|
||||||
|
|
||||||
this.yCheck = function(){
|
this.yCheck = function(){
|
||||||
this.up = this.down = false;
|
this.up = this.down = false;
|
||||||
|
|
||||||
if(this.y >= 216){
|
if(this.y >= 216){
|
||||||
this.down = true;
|
this.down = true;
|
||||||
this.y = 216;
|
this.y = 216;
|
||||||
this.yvel = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for(j in actors){
|
for(j in actors){
|
||||||
if(actors[j].image != this.image){
|
if(actors[j].image != this.image){
|
||||||
if(this.y + 15 > actors[j].y && this.y < actors[j].y + 15 && this.sameX(actors[j])){
|
if(this.y + 16 > actors[j].y && this.y < actors[j].y + 16 && this.sameX(actors[j])){
|
||||||
this.down = true;
|
if(this.y < actors[j].y){
|
||||||
this.y = actors[j].y - 18;
|
this.down = true;
|
||||||
this.yvel = 0;
|
this.y = actors[j].y - 16;
|
||||||
|
}else{
|
||||||
|
this.up = true;
|
||||||
|
this.y = actors[j].y + 16;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sameY = function(obj){
|
this.sameY = function(obj){
|
||||||
return (this.y < obj.y + 15 && this.y + 15 > obj.y);
|
return (this.y < obj.y + 15 && this.y + 16 > obj.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.sameX = function(obj){
|
this.sameX = function(obj){
|
||||||
return (this.x + 16 > obj.x && this.x < obj.x + 16);
|
return (this.x + 15 > obj.x && this.x < obj.x + 15);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.simulate = function(){
|
this.simulate = function(){
|
||||||
|
@ -272,7 +279,7 @@ function Particle(type, affiliation, lifespan, xpos, ypos, xvel, yvel){
|
||||||
this.yvel = yvel;
|
this.yvel = yvel;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.life = lifespan;
|
this.life = lifespan;
|
||||||
this.size = [3, 5, 7][type];
|
this.size = [3, 5, 7, 32][type];
|
||||||
this.created = this.timeup = new Date();
|
this.created = this.timeup = new Date();
|
||||||
this.timeup = new Date(this.timeup.getTime() + lifespan);
|
this.timeup = new Date(this.timeup.getTime() + lifespan);
|
||||||
this.deleteme = false;
|
this.deleteme = false;
|
||||||
|
@ -309,6 +316,14 @@ function Particle(type, affiliation, lifespan, xpos, ypos, xvel, yvel){
|
||||||
context.strokeRect(r(this.x - lookx) + 0.5, r(213 - (this.y - 216) - looky) + 0.5, 5, 5);
|
context.strokeRect(r(this.x - lookx) + 0.5, r(213 - (this.y - 216) - looky) + 0.5, 5, 5);
|
||||||
context.globalAlpha = 1;
|
context.globalAlpha = 1;
|
||||||
break;
|
break;
|
||||||
|
case 3:
|
||||||
|
context.globalAlpha = 0.5;
|
||||||
|
context.lineWidth = 2;
|
||||||
|
context.strokeStyle = '#000';
|
||||||
|
context.strokeRect(r(this.x - lookx) + 0.5, r(this.y - looky) + 0.5, 32, 32);
|
||||||
|
context.strokeStyle = '#777';
|
||||||
|
context.strokeRect(r(this.x - lookx) + 0.5, r(213 - (this.y - 216) - looky) + 0.5, 32, 32);
|
||||||
|
context.globalAlpha = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -358,6 +373,12 @@ function Particle(type, affiliation, lifespan, xpos, ypos, xvel, yvel){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 3:
|
||||||
|
//this.yvel += (this.onGround() ? 0 : 0.007 * speed);
|
||||||
|
//if(this.onGround()){
|
||||||
|
// this.y = 216 - this.size;
|
||||||
|
// this.yvel = (this.yvel > 2 ? this.yvel * -0.7 : 0);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if(thisLoop > this.timeup){
|
if(thisLoop > this.timeup){
|
||||||
this.deleteme = true;
|
this.deleteme = true;
|
||||||
|
@ -365,6 +386,30 @@ function Particle(type, affiliation, lifespan, xpos, ypos, xvel, yvel){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Collision detection class
|
||||||
|
function Box(x, y, w, h, xvel, yvel, colgroup){
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.width = w;
|
||||||
|
this.height = h;
|
||||||
|
this.col = colgroup;
|
||||||
|
|
||||||
|
this.reset = function(){
|
||||||
|
this.down = this.up = this.left = this.right = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.collide = function(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
this.move = function(xmov, ymov){
|
||||||
|
this.x += xmov;
|
||||||
|
this.y += ymov;
|
||||||
|
this.reset();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Run game.
|
// Run game.
|
||||||
|
|
||||||
var speed;
|
var speed;
|
||||||
|
|
BIN
sprites.png
BIN
sprites.png
Binary file not shown.
Before Width: | Height: | Size: 1.2 KiB |
BIN
sprites2.png
BIN
sprites2.png
Binary file not shown.
Before Width: | Height: | Size: 845 B |
Loading…
Add table
Add a link
Reference in a new issue