This commit is contained in:
killianmarty 2023-11-14 17:36:42 +01:00
commit 37d5b1fe38
8 changed files with 221 additions and 3 deletions

View file

@ -1,3 +1,40 @@
# GrandTabernacleAutoVI
un super jeu
un super jeu by popstar inc.
specification:
on est en vue du dessus et on spawn dans un imeuble (avec des etages):
on a un certain nombre d'étage (4 par exemple)
a chaque étage il y a : du décor, des obstacles, un boost ,une arme spécifique
et 2 escaliers, un vers le haut et l'autre vers le bas
on bouge avec zqsd on tire avec la souris (qui est un viseur)
techniquement:
une requete pingrequest()=> on ping chaque joueur et tlm repond si il est co
une requete pingreply()=> return int player , position (int x, int y)
pour commencer: un envoi de requete init (int player_id, position (int x , int y))
pour bouger: un envoi de requete deplacement (int direction,position(int x,int y))
pour tirer : un envoi de requete tirer(int killer,position (int x , int y),position_cible(int dx, int dy), int arme)
pour mourir: un envoi de requete die(int mort, int killer).
pistes d'amélioration:
ammo non infini
mettre plusieurs maps
coder des perks (speed, shield)
barre de pv

BIN
assets/body.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 968 B

132
class.js Normal file
View file

@ -0,0 +1,132 @@
const mapWidth = 210.;
const mapHeith = 100.;
const playerSize = 10.;
class Player
{
constructor (id,x,y,name)
{
this.name=name;
this.x=x;
this.y=y;
this.id=id;
this.visibleDir=1;
this.dir=0;//0=standStill
//1=North
//2=North-East
//3=East
//4=South-East
//5=South
//6=South-West
//7=West
//8=North-West
this.ammo=10;
this.health=10;
}
takeDamage(amount)
{
this.health-=amount;
if(this.health<=0)
{
//send death message to server
//this.reset()
}
}
get angle()
{
return (this.visibleDir-1)*3.1415926535/8.;
}
}
function dist(A,B)
{
return sqrt((A.x-B.x)**2+(A.y-B.y)**2);
}
class Bullet
{
constructor (x,y,dx,dy)
{
this.x=x;
this.y=y;
this.dx=dx;
this.dy=dy;
this.deleted=false;
}
update()
{
if(!this.deleted)
{
this.x+=this.dx;
this.y+=this.dy;
}
}
checkCollisions(player,squares,circles)//only the client's player /!\
{
if(!this.deleted)
{
if(dist(player,this)<playerSize/2)
{
player.takeDamage(1);
this.deleted=true;
return;
}
for(let square in squares)
{
if(square.collide(this))
{
this.deleted=true;
return;
}
}
for(let circle in circles)
{
if(circle.collide(this))
{
this.deleted=true;
return;
}
}
}
}
}
class Square
{
constructor(x,y,width,heigth)
{
this.x=x;
this.y=y;
this.w=width;
this.h=heigth;
}
collide(point)
{
return (this.x<=point.x && point.x<=this.x+this.w && this.y<=point.y && point.y<=this.y+this.h);
}
}
class Circle
{
constructor(x,y,radius)
{
this.x=x;
this.y=y;
this.r=radius;
}
collide(point)
{
return ((point.x-this.x)**2+(point.y-this.y)**2<=r**2);
}
}

12
game.html Normal file
View file

@ -0,0 +1,12 @@
<html>
<head>
<link rel="stylesheet" href="./style.css">
<script type="text/javascript" src="./class.js"></script>
<script type="text/javascript" src="./render.js"></script>
<script type="text/javascript" src="./game.js" defer></script>
</head>
<body>
<canvas width="800" height="800" id="canvas" style="border: 1px;"></canvas>
</body>
</html>

View file

@ -0,0 +1,9 @@
setInterval(game);
function game() {
Renderer = new Render("canvas")
let rubiks = new Player(1, 100, 50, "rubiks")
console.log(rubiks)
Renderer.AddPlayer(rubiks)
}

View file

@ -1,10 +1,9 @@
<html>
<head>
<link rel="stylesheet" href="./style.css">
<script type="text/javascipt" src="./game.js" defer></script>
</head>
<body>
<canvas width="800" height="800" id="Canvas" style="border: 1px;"></canvas>
</body>
</html>

BIN
map.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 230 KiB

29
render.js Normal file
View file

@ -0,0 +1,29 @@
class Render {
constructor(id) {
this.canvas = document.getElementById(id)
this.ctx = canvas.getContext("2d")
this.players = []
this.ReloadAff()
}
AddPlayer(id, pseudo, x, y, angle) {
this.players[id] = (id, pseudo, x, y, angle)
}
ReloadAff() {
this.ctx.fillStyle = "red"
this.ctx.fillRect(0,0,this.canvas.width,this.canvas.height);
/*this.ctx.stokeStyle = "black"
this.ctx.lineWidth = 1;
ctx.beginPath();
ctx.moveTo(point1[0], point1[1]);
ctx.lineTo(point2[0], point2[1]);
ctx.lineTo(point3[0], point3[1]);
ctx.lineTo(point1[0], point1[1]);
ctx.stroke()
ctx.fill();*/
this.ctx.closePath();
this.ctx
}
}