Member

5

129 Neutral

• Rank
Newbie
1. ## Another 2D tiled RPG movement question

So after doing some more Google'ing I found a Game Maker tutorial about this topic, and a demonstration. I managed to get it working in LOVE, but I'd be interested to hear what people think of that solution in general.
2. ## Another 2D tiled RPG movement question

I have a basic understanding of tile maps and movement, but I'm having trouble moving beyond that. My goal is to replicate the movement seen in NES games like Dragon Warrior and Final Fantasy. Here's the code I've been experimenting with: function love.load() x = 0 y = 0 dx = 0 dy = 0 size = 64 t = 10 v = size / t end function love.draw() love.graphics.rectangle("fill", x, y, size, size) end function love.update(dt) x = x + (dx - x) * (v * dt) y = y + (dy - y) * (v * dt) end function love.keypressed(key) if key == "up" then dy = dy - size end if key == "down" then dy = dy + size end if key == "left" then dx = dx - size end if key == "right" then dx = dx + size end if key == "escape" then love.event.push("quit") end end Currently I can press a button and the block will move a set distance, which is great, but it moves at a variable speed; it slows down as it approaches the end of it's movement.   Am I on the right track at the moment? I feel like I'm missing something in the math department.
3. ## Need beginner level help with 2d Vectors

I started messing around with Missile Command and am trying to recreate the movement of the incoming missiles, and from what I can gather that requires the use of Vectors. I spent a fair amount of time last night on the internet, but I need some clarification and/or help and/or extra knowledge.   So assume I have a missile coming in from some location at the top of the screen, and a target to strike at the bottom of the screen, lets just assume the screen is 640x480:   missile.pos.x = 100 missile.pos.y = 0 target.pos.x = 382 target.pos.y = 480   From what I understand subtracting the missile's current position from the target's current position will provide me with a direction.   direction.x = target.pos.x - missile.pos.x direction.y = target.pos.y - missile.pos.y   So if I use that as is to move the missile it gets there on the first update cycle; as you would expect. If I multiply it by anything like delta time or some random float it slows down as I approach the target. I assume this only applies if dt is less than 1, I'm guessing it would speed up on approach if dt were greater than 1.   // Teleports to target missile.pos.x = missile.pos.x + direction.x missile.pos.y = missile.pos.y + direction.y // Slows down as it approaches target missile.pos.x = missile.pos.x + direction.x * dt missile.pos.y = missile.pos.y + direction.y * dt   Then I read about normalization, which I understand as:   // The distance between the two...or the Vector length distance = math.sqrt((direction.x * direction.x) + (direction.y * direction.y)) // The normalized Vector norm.x = direction.x / distance norm.y = direction.y / distance   Using the normalized vector I get where I want to go at a consistent rate regardless of the distance between the two points, although it's updating at the same rate as the loop so it's still pretty fast. However, if I multiply it by dt it goes painfully slow.   // Constant speed from start to target, too fast missile.pos.x = missile.pos.x + norm.x missile.pos.y = missile.pos.y + norm.y // Constant speed from start to target, too slow missile.pos.x = missile.pos.x + norm.x * dt missile.pos.y = missile.pos.y + norm.y * dt   So I assume I need to apply some kind of speed, which is what might be referred to as a scalar? How do I apply it?   // Like this? spd = 10 * dt missile.pos.x = missile.pos.x + norm.x * spd   Am I on the right track with all of this stuff, or am I way off base? Any feedback, info, etc., would be appreciated!
4. ## Your First Step to Game Development Starts Here

This article helped me. It's the right amount of honesty, encouragement, and information.

8. ## Feedback wanted on Javascript PONG clone

Thanks for the input. I'm not done reworking it yet, but I thought I would share what I have to make sure I'm going in the right direction. I think part of the problem I'm having is determining what goes in each class/object. Like the player controls, it seems like the input should be a game responsibility, and the actual updating of the paddle should be a paddle responsibility...or maybe I'm over thinking it? // Utility object inherited by Paddle and Ball, provides // everything needed to draw the object to the canvas. // These methods may need to be empty... function GameObj() { this.x; this.y; this.width; this.height; // Initialize the 'x' and 'y'...not sure this should be here this.init = function(x, y) { this.x = x; this.y = y; } // Draw 'this' to the canvas this.draw = function() { this.context.fillRect(this.x, this.y, this.width, this.height); } } // Define the paddles used to hit the ball. Inherits from GameObj(). function Paddle() { this.width = 16; this.height = 64; this.moveUp = function() { // this.y -= this.speed; } this.moveDown = function() { // this.y += this.speed; } } Paddle.prototype = new GameObj(); // Define the bouncy ball. Inherits from GameObj(). function Ball() { this.width = 16; this.height = 16; } Ball.prototype = new GameObj(); // All the game stuff function Game() { this.canvas = document.getElementById('canvas'); this.context = canvas.getContext('2d'); this.canvasHeight = this.canvas.height; this.canvasWidth = this.canvas.width; this.init = function() { // Not sure if this is the best way, but it does eliminate the need // for an extra parameter to make the draw() method work GameObj.prototype.context = this.context; // Initialize game objects this.ball = new Ball(); this.playerOne = new Paddle(); this.playerTwo = new Paddle(); // This seems like the easiest way to do this...probably not the best. this.ball.init((this.canvasWidth - this.ball.width) / 2, (this.canvasHeight - this.ball.height) / 2); this.playerOne.init(0, (this.canvasHeight - this.playerOne.height) / 2); this.playerTwo.init((this.canvasWidth - this.playerTwo.width), (this.canvasHeight - this.playerTwo.height) / 2); } // Update everything this.update = function() { // do some stuff... } // Draw everything this.draw = function(timestamp) { window.requestAnimationFrame(this.draw.bind(this)); // Update game stuff this.update(); // Draw game objects to the canvas this.ball.draw(); this.playerOne.draw(); this.playerTwo.draw(); } } // Play the game var game = new Game(); game.init(); game.draw();