瀏覽代碼

Update to add player and load sprites

Pobzeb Armerding 4 年之前
父節點
當前提交
38a79a76a7
共有 4 個文件被更改,包括 27 次插入3 次删除
  1. 0 0
      img/sprites.png
  2. 1 0
      index.html
  3. 13 3
      js/minicraft.js
  4. 13 0
      js/player.js

+ 0 - 0
img/icons.png → img/sprites.png


+ 1 - 0
index.html

@@ -12,6 +12,7 @@
 		<script type="text/javascript" src="js/p5.js"></script>
 	</head>
 	<body>
+		<script type="text/javascript" src="js/player.js"></script>
 		<script type="text/javascript" src="js/minicraft.js"></script>
 	</body>
 </html>

+ 13 - 3
js/minicraft.js

@@ -2,10 +2,20 @@
 
 const FPS = 24;
 
+let sprites;
+let player;
+
+function preload () {
+	sprites = loadImage('img/sprites.png');
+}
+
 function setup() {
 	// Create the canvas.
 	createCanvas(500, 500);
 	frameRate(FPS);
+
+	// Create a new player.
+	player = new Player(0, 0);
 }
 
 function draw() {
@@ -58,10 +68,10 @@ function keyPressed() {
 	}
 }
 
-function update() {
-
+function update(delta) {
+	player.update(delta);
 }
 
 function drawCharacters() {
-
+	player.draw();
 }

+ 13 - 0
js/player.js

@@ -0,0 +1,13 @@
+function Player(x, y) {
+	this.x = x;
+	this.y = y;
+
+	this.update = function(delta) {
+		//
+	};
+
+	this.draw = function() {
+		fill(200, 0 , 0);
+		image(sprites.get(0, 112, 16, 16), 100, 100, 32, 32);
+	};
+};