Game idea
How do I make an game idea?
What is a game idea? How do you make a game idea? This script and codes were developed by Tim on 31 October 2022, Monday.
Game idea - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Game idea</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <script src='https://cdnjs.cloudflare.com/ajax/libs/pixi.js/4.0.3/pixi.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Game idea - Script Codes CSS Codes
body{ display: flex; justify-content: center; align-items: center; height: 100vh;
}
Game idea - Script Codes JS Codes
function detectEnemy(r1, r2, range) { //Define the variables we'll need to calculate var hit, combinedHalfWidths, combinedHalfHeights, vx, vy; if(r2 == undefined) return false //hit will determine whether there's a collision hit = false; //Find the center points of each sprite r1.centerX = r1.x + r1.width / 2; r2.centerX = r2.x + r2.width / 2; //Find the half-widths and half-heights of each sprite r1.halfWidth = r1.width / 2; r2.halfWidth = r2.width / 2; //Calculate the distance vector between the sprites vx = r1.centerX - r2.centerX; //Figure out the combined half-widths and half-heights combinedHalfWidths = r1.halfWidth + r2.halfWidth; //Check for a collision on the x axis if (Math.abs(vx) < range) { hit = true } else { //There's no collision on the x axis hit = false; } //`hit` will be either `true` or `false` return hit;
}
var renderer = PIXI.autoDetectRenderer(512,256, {backgroundColor: 0xeeeeee, antialias: true})
document.body.appendChild(renderer.view)
var stage = new PIXI.Container()
var hitEvent = false
var players = [], enemies = []
var ui = []
setup()
function setup(){ for(let i=0; i<3; i++){ players[i] = new PIXI.Graphics() players[i].beginFill(0x709FFC) players[i].drawRect(0,0,32,32) players[i].x = 8+40*i players[i].y = 150-((i%2==0)?40:0) players[i].endFill() stage.addChild(players[i]) players[i].attacking = (i%3==0)?false: true } for(let i=0; i<2; i++){ enemies[i] = new PIXI.Graphics() enemies[i].beginFill(0xFF1133) enemies[i].drawRect(0,0,32,32) enemies[i].x = 432+40*i enemies[i].y = 150 enemies[i].endFill() stage.addChild(enemies[i]) } //UI for(let i=0; i<3; i++){ if(i<2){ //Auto Attack ui[i] = new PIXI.Graphics() ui[i].beginFill(0xcccccc) ui[i].drawCircle(0,0,16) ui[i].x = 20+40*i ui[i].y = renderer.height - 20 ui[i].endFill() stage.addChild(ui[i]) //Text let UIText = (i%3==0) ? "Auto" : "1x" let text1 = new PIXI.Text(UIText, {font:"8px Arial", fill:"black"}) text1.x = 12+40*i text1.y = renderer.height - 26 stage.addChild(text1) } //Container ui[i] = new PIXI.Graphics() ui[i].beginFill(0xcccccc) ui[i].drawRect(0,0,64,32) ui[i].x = renderer.width - (72*(i+1)) ui[i].y = renderer.height - 40 ui[i].endFill() stage.addChild(ui[i]) //Icon ui[i] = new PIXI.Graphics() ui[i].beginFill(0xFF9F00) ui[i].drawCircle(0,0,12) ui[i].x = renderer.width - (-16+72*(i+1)) ui[i].y = renderer.height - 24 ui[i].endFill() stage.addChild(ui[i]) //HP ui[i] = new PIXI.Graphics() ui[i].beginFill(0xFF3300) ui[i].drawRect(0,0,32,4) ui[i].x = renderer.width - (-30+72*(i+1)) ui[i].y = renderer.height - (40 - 20) ui[i].endFill() stage.addChild(ui[i]) //MP ui[i] = new PIXI.Graphics() ui[i].beginFill(0x0033FF) ui[i].drawRect(0,0,32,4) ui[i].x = renderer.width - (-30+72*(i+1)) ui[i].y = renderer.height - (40 - 26) ui[i].endFill() stage.addChild(ui[i]) //Text let text = new PIXI.Text("Lv 30", {font:"8px Arial", fill:"black"}) text.x = renderer.width - (-32+72*(i+1)) text.y = renderer.height - (40) stage.addChild(text) } animate()
}
function animate(){ //to move camera stage.pivot.x = players[0].x; // stage.position.x = renderer.width/2 //Move the players for(p of players){ if(!detectEnemy(p,enemies[0],80)){ p.x += 1 } else if(!p.attacking){ setTimeout(function(){ enemies[0].clear() enemies.splice(0,1) }, 2000) p.attacking = true } } //render the stage renderer.render(stage) requestAnimationFrame(animate)
}
Developer | Tim |
Username | maytim |
Uploaded | October 31, 2022 |
Rating | 3 |
Size | 2,839 Kb |
Views | 14,168 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Double Helix Animation - Jade and Sass | 2,437 Kb |
IPhone Doodle | 1,994 Kb |
Custom Dropdown | 2,387 Kb |
GPU Part Picker | 5,523 Kb |
Phaser.io First Game Tutorial | 2,478 Kb |
Bot Land Rankings | 3,592 Kb |
Custom Multi Column Data Entry Select | 3,313 Kb |
Phaser.io Sidescroller | 3,469 Kb |
Pixi JS | 2,710 Kb |
CSS Grid Calendar | 2,694 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
CSS Donut Charts | Seanstopnik | 2,908 Kb |
Confirm Close Of Foundation Reveal Modal | Winghouchan | 1,818 Kb |
C.Rowe Button | Brownerd | 2,473 Kb |
12 DAYS OF XMAS | Proto78 | 2,313 Kb |
Twitch | SarahDunlap | 2,937 Kb |
Flat iOS 7 Safari Icon | Rss | 3,332 Kb |
Simple Flat Menu | Jeplaa | 2,467 Kb |
Chuck Norris Background | Manz | 1,967 Kb |
SlideDown FixedMenu | Mp_graphic | 5,602 Kb |
Alter bg opacity on hover... | Chrisboon27 | 2,054 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!