I'm making a puzzle game, but I need both the player and events to be able to move a half tile at a time. I tried editing the Game_Character 3 script in the editor so that it only changed 0.5 tiles instead of a whole. It works but with a lot of bugs. For example you can't walk all the way to the left if there is an impassable tile in the way. If the impassable tile have the x of 0.0, the character stops at 1.5 instead of 1.0.
It is far from done, and I can't think of any more to do about that problem.
And as you can see, I haven't yet started with changing the move_up and move_right methods, but since everyone is mostly like eachother, it should be simple to just copy and change.
I maybe need another script instead of an edit and I'd be glad if someone could provide me with either one of them. I need this as soon as possible.
Here is the code so far.
#==============================================================================
# ** Game_Character (part 3)
#------------------------------------------------------------------------------
# This class deals with characters. It's used as a superclass for the
# Game_Player and Game_Event classes.
#==============================================================================
class Game_Character
#--------------------------------------------------------------------------
# * Move Down
# turn_enabled : a flag permits direction change on that spot
#--------------------------------------------------------------------------
def move_down(turn_enabled = true)
# Turn down
if turn_enabled
turn_down
end
# If passable
if @x % 1 != 0 && passable?(@x + 0.5, @y, 2) && passable?(@x - 0.5, @y, 2) || @x % 1 == 0 && passable?(@x, @y, 2)
# Turn down
turn_down
# Update coordinates
@y += 0.5
# Increase steps
increase_steps
# If impassable
else
# Determine if touch event is triggered
check_event_trigger_touch(@x, @y+0.5)
end
end
#--------------------------------------------------------------------------
# * Move Left
# turn_enabled : a flag permits direction change on that spot
#--------------------------------------------------------------------------
def move_left(turn_enabled = true)
# Turn left
if turn_enabled
turn_left
end
# If passable
if @y % 1 != 0 && passable?(@x, @y - 0.5, 4) && passable?(@x, @y + 0.5, 4) || @y % 1 == 0 && passable?(@x, @y, 4)
# Turn left
turn_left
# Update coordinates
@x -= 0.5
# Increase steps
increase_steps
# If impassable
else
# Determine if touch event is triggered
check_event_trigger_touch(@x-0.5, @y)
end
end
#--------------------------------------------------------------------------
# * Move Right
# turn_enabled : a flag permits direction change on that spot
#--------------------------------------------------------------------------
def move_right(turn_enabled = true)
# Turn right
if turn_enabled
turn_right
end
# If passable
if passable?(@x, @y, 6)
# Turn right
turn_right
# Update coordinates
@x += 1
# Increase steps
increase_steps
# If impassable
else
# Determine if touch event is triggered
check_event_trigger_touch(@x, @y)
end
end
#--------------------------------------------------------------------------
# * Move up
# turn_enabled : a flag permits direction change on that spot
#--------------------------------------------------------------------------
def move_up(turn_enabled = true)
# Turn up
if turn_enabled
turn_up
end
# If passable
if passable?(@x, @y, 8)
# Turn up
turn_up
# Update coordinates
@y -= 1
# Increase steps
increase_steps
# If impassable
else
# Determine if touch event is triggered
check_event_trigger_touch(@x, @y)
end
end
#--------------------------------------------------------------------------
# * Move Lower Left
#--------------------------------------------------------------------------
def move_lower_left
# If no direction fix
unless @direction_fix
# Face down is facing right or up
@direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
end
# When a down to left or a left to down course is passable
if (passable?(@x, @y, 2) and passable?(@x, @y + 0.5, 4)) or
(passable?(@x, @y, 4) and passable?(@x - 0.5, @y, 2))
# Update coordinates
@x -= 0.5
@y += 0.5
# Increase steps
increase_steps
end
end
#--------------------------------------------------------------------------
# * Move Lower Right
#--------------------------------------------------------------------------
def move_lower_right
# If no direction fix
unless @direction_fix
# Face right if facing left, and face down if facing up
@direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
end
# When a down to right or a right to down course is passable
if (passable?(@x, @y, 2) and passable?(@x, @y + 0.5, 6)) or
(passable?(@x, @y, 6) and passable?(@x + 0.5, @y, 2))
# Update coordinates
@x += 0.5
@y += 0.5
# Increase steps
increase_steps
end
end
#--------------------------------------------------------------------------
# * Move Upper Left
#--------------------------------------------------------------------------
def move_upper_left
# If no direction fix
unless @direction_fix
# Face left if facing right, and face up if facing down
@direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
end
# When an up to left or a left to up course is passable
if (passable?(@x, @y, 8) and passable?(@x, @y - 0.5, 4)) or
(passable?(@x, @y, 4) and passable?(@x - 0.5, @y, 8))
# Update coordinates
@x -= 0.5
@y -= 0.5
# Increase steps
increase_steps
end
end
#--------------------------------------------------------------------------
# * Move Upper Right
#--------------------------------------------------------------------------
def move_upper_right
# If no direction fix
unless @direction_fix
# Face right if facing left, and face up if facing down
@direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
end
# When an up to right or a right to up course is passable
if (passable?(@x, @y, 8) and passable?(@x, @y - 0.5, 6)) or
(passable?(@x, @y, 6) and passable?(@x + 0.5, @y, 8))
# Update coordinates
@x += 0.5
@y -= 0.5
# Increase steps
increase_steps
end
end
#--------------------------------------------------------------------------
# * Move at Random
#--------------------------------------------------------------------------
def move_random
case rand(4)
when 0 # Move down
move_down(false)
when 1 # Move left
move_left(false)
when 2 # Move right
move_right(false)
when 3 # Move up
move_up(false)
end
end
#--------------------------------------------------------------------------
# * Move toward Player
#--------------------------------------------------------------------------
def move_toward_player
# Get difference in player coordinates
sx = @x - $game_player.x
sy = @y - $game_player.y
# If coordinates are equal
if sx == 0 and sy == 0
return
end
# Get absolute value of difference
abs_sx = sx.abs
abs_sy = sy.abs
# If horizontal and vertical distances are equal
if abs_sx == abs_sy
# Increase one of them randomly by 1
rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
end
# If horizontal distance is longer
if abs_sx > abs_sy
# Move towards player, prioritize left and right directions
sx > 0 ? move_left : move_right
if not moving? and sy != 0
sy > 0 ? move_up : move_down
end
# If vertical distance is longer
else
# Move towards player, prioritize up and down directions
sy > 0 ? move_up : move_down
if not moving? and sx != 0
sx > 0 ? move_left : move_right
end
end
end
#--------------------------------------------------------------------------
# * Move away from Player
#--------------------------------------------------------------------------
def move_away_from_player
# Get difference in player coordinates
sx = @x - $game_player.x
sy = @y - $game_player.y
# If coordinates are equal
if sx == 0 and sy == 0
return
end
# Get absolute value of difference
abs_sx = sx.abs
abs_sy = sy.abs
# If horizontal and vertical distances are equal
if abs_sx == abs_sy
# Increase one of them randomly by 1
rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
end
# If horizontal distance is longer
if abs_sx > abs_sy
# Move away from player, prioritize left and right directions
sx > 0 ? move_right : move_left
if not moving? and sy != 0
sy > 0 ? move_down : move_up
end
# If vertical distance is longer
else
# Move away from player, prioritize up and down directions
sy > 0 ? move_down : move_up
if not moving? and sx != 0
sx > 0 ? move_right : move_left
end
end
end
#--------------------------------------------------------------------------
# * 1 Step Forward
#--------------------------------------------------------------------------
def move_forward
case @direction
when 2
move_down(false)
when 4
move_left(false)
when 6
move_right(false)
when 8
move_up(false)
end
end
#--------------------------------------------------------------------------
# * 1 Step Backward
#--------------------------------------------------------------------------
def move_backward
# Remember direction fix situation
last_direction_fix = @direction_fix
# Force directino fix
@direction_fix = true
# Branch by direction
case @direction
when 2 # Down
move_up(false)
when 4 # Left
move_right(false)
when 6 # Right
move_left(false)
when 8 # Up
move_down(false)
end
# Return direction fix situation back to normal
@direction_fix = last_direction_fix
end
#--------------------------------------------------------------------------
# * Jump
# x_plus : x-coordinate plus value
# y_plus : y-coordinate plus value
#--------------------------------------------------------------------------
def jump(x_plus, y_plus)
# If plus value is not (0,0)
if x_plus != 0 or y_plus != 0
# If horizontal distnace is longer
if x_plus.abs > y_plus.abs
# Change direction to left or right
x_plus < 0 ? turn_left : turn_right
# If vertical distance is longer, or equal
else
# Change direction to up or down
y_plus < 0 ? turn_up : turn_down
end
end
# Calculate new coordinates
new_x = @x + x_plus
new_y = @y + y_plus
# If plus value is (0,0) or jump destination is passable
if (x_plus == 0 and y_plus == 0) or passable?(new_x, new_y, 0)
# Straighten position
straighten
# Update coordinates
@x = new_x
@y = new_y
# Calculate distance
distance = Math.sqrt(x_plus * x_plus + y_plus * y_plus).round
# Set jump count
@jump_peak = 10 + distance - @move_speed
@jump_count = @jump_peak * 2
# Clear stop count
@stop_count = 0
end
end
#--------------------------------------------------------------------------
# * Turn Down
#--------------------------------------------------------------------------
def turn_down
unless @direction_fix
@direction = 2
@stop_count = 0
end
end
#--------------------------------------------------------------------------
# * Turn Left
#--------------------------------------------------------------------------
def turn_left
unless @direction_fix
@direction = 4
@stop_count = 0
end
end
#--------------------------------------------------------------------------
# * Turn Right
#--------------------------------------------------------------------------
def turn_right
unless @direction_fix
@direction = 6
@stop_count = 0
end
end
#--------------------------------------------------------------------------
# * Turn Up
#--------------------------------------------------------------------------
def turn_up
unless @direction_fix
@direction = 8
@stop_count = 0
end
end
#--------------------------------------------------------------------------
# * Turn 90° Right
#--------------------------------------------------------------------------
def turn_right_90
case @direction
when 2
turn_left
when 4
turn_up
when 6
turn_down
when 8
turn_right
end
end
#--------------------------------------------------------------------------
# * Turn 90° Left
#--------------------------------------------------------------------------
def turn_left_90
case @direction
when 2
turn_right
when 4
turn_down
when 6
turn_up
when 8
turn_left
end
end
#--------------------------------------------------------------------------
# * Turn 180°
#--------------------------------------------------------------------------
def turn_180
case @direction
when 2
turn_up
when 4
turn_right
when 6
turn_left
when 8
turn_down
end
end
#--------------------------------------------------------------------------
# * Turn 90° Right or Left
#--------------------------------------------------------------------------
def turn_right_or_left_90
if rand(2) == 0
turn_right_90
else
turn_left_90
end
end
#--------------------------------------------------------------------------
# * Turn at Random
#--------------------------------------------------------------------------
def turn_random
case rand(4)
when 0
turn_up
when 1
turn_right
when 2
turn_left
when 3
turn_down
end
end
#--------------------------------------------------------------------------
# * Turn Towards Player
#--------------------------------------------------------------------------
def turn_toward_player
# Get difference in player coordinates
sx = @x - $game_player.x
sy = @y - $game_player.y
# If coordinates are equal
if sx == 0 and sy == 0
return
end
# If horizontal distance is longer
if sx.abs > sy.abs
# Turn to the right or left towards player
sx > 0 ? turn_left : turn_right
# If vertical distance is longer
else
# Turn up or down towards player
sy > 0 ? turn_up : turn_down
end
end
#--------------------------------------------------------------------------
# * Turn Away from Player
#--------------------------------------------------------------------------
def turn_away_from_player
# Get difference in player coordinates
sx = @x - $game_player.x
sy = @y - $game_player.y
# If coordinates are equal
if sx == 0 and sy == 0
return
end
# If horizontal distance is longer
if sx.abs > sy.abs
# Turn to the right or left away from player
sx > 0 ? turn_right : turn_left
# If vertical distance is longer
else
# Turn up or down away from player
sy > 0 ? turn_down : turn_up
end
end
end
Regards
Stripe103
How come everyone seem to ignore my topics?
It's nothing personal, it just happens. ._. I think you're just active enough to be known, but not active enough to be noticed. >.<
Don't worry; it happens to all of us.
http://forum.chaos-project.com/index.php/topic,8191.0.html
So what you are saying is that I need to be either less active or more active to be noticed?
@ WhiteRose
I would have helped you if I was good at spriting. Sadly, I'm not since I'm not very artistic of me, so I'll have to leave that part of the game making...
Definitely more active.
Why not try one of the pixel movement scripts out there? Maybe you could configure them to work for half-tiles instead of pixels. Search in google or other forums.
@ Blizzard
And yet, many newcomers get a lot or replies. Mostly because of their stupidity, but still..
@ Fantasist
I have, but I can't seem to find a single one. That is why I tried to make my own and, in the end, post here.
You couldn't find any stand-alone pixel movement script?
I know that one of the most famous pixel movements for RMXP is the one by f0tz!baerchen...Of course, that doesn't always means it's the best. :P
http://elamshin.rpg-studio.de/wb/media/download_gallery/Pixelmovement1.5.txt (v.1.5)
http://elamshin.rpg-studio.de/wb/media/download_gallery/Pixelmovement%20Light.txt (Light version)
Here's the link. Feel free to select whichever one you want. XD
I have tried that but I have no idea on how to use it at all. There is no guide in the script and it isn't just to copy and paste. It didn't find the "file" called Pixelmovement Tables/ if it is a file and not a folder..
Oh dang. My bad. xD
http://downloads.rpg-palace.com/file.php?type=Demo&id=4
Here is a demo for that pixel movement script. If it asks for registration or something, just let me know. I remember RPG-Palace being an arse about that years ago. xD
Note that the demo has the dreaded SDK, but I think it actually is an optional engine. If it's required, then I guess we have to look elsewhere! :V:
I have an account on rpg palace anyway so that isn't any problems. But I prefer not using the SDK since it currently isn't compatible with my other scripts. Also, that script seems way too advanced for what I need. And too advanced for me to edit. Could use it for future projects though.. maybe.
Here's a simple enough solution. Use BABS, set pixel movement factor to whatever the one is for half tiles.I believe its in the manual. Then set turn abs controls off to on a map with no enemies. Boom, pixelmovement.
Good idea, though it seems it isn't compatible with my other scripts either..
Hmm...what are your other scripts?
I guess it is the first script, but here is all of them in order:
Sprite Frames Change - By Night_Runner: ShowHide #==============================================================================
# ** Night_Runner's More Sprite Frames & Step Animation Speed Script
#------------------------------------------------------------------------------
# History:
# Date Created: 17/Dec/10
# Created for: Stripe103
# @> http://www.rpgrevolution.com/forums/index.php?showtopic=46903
#
# Description:
# This script is the compatible version of two scripts, the first
# is designed to have more frames for the walking motion of a player,
# increasing the default 4 frames of walking to 8. The second script is
# designed to allow the designer to set the step speed of an event
# or the player, dynamically using script calls.
#
# How to Install:
# Copy this entire script, go into your game, along the top select Tools >>
# Script Editor. Along the left scroll to the bottom, right click on Main,
# and select insert. Paste this code in the window on the right.
#
# How to Use:
# The Sprite Frames has to customization. For the step animation speed
# the default step speed is defined on line 62. Higher numbers means it
# will stay on the same animation for longer.
# To dynamically change the step speed for an event, have the event run
# the code:
# $game_map.events[@event_id].
# animation_speed = 14
# where 14 is the new step animation speed of the event.
# You can of course change @event_id to the ID of the event whose
# step animation speed you want to change, e.g.
# $game_map.events[12].
# animation_speed = 9
# where 12 si the ID of the event whose speed you want to change.
# To change the step animation speed of the player, have an event run
# the code:
# $game_player.animation_speed = 14
# where 14 again is the new step animation speed of the player.
#==============================================================================
#==============================================================================
# ** Game_Character
#------------------------------------------------------------------------------
# Edited to show 8 sprite frames for a player (line 49 edited edited).
#==============================================================================
class Game_Character
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :animation_speed
#--------------------------------------------------------------------------
# * Alias Methods
#--------------------------------------------------------------------------
alias nr_stepAnimationSpeed_initialize initialize unless $@
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(*args)
@animation_speed = 18
return nr_stepAnimationSpeed_initialize(*args)
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Branch with jumping, moving, and stopping
if jumping?
update_jump
elsif moving?
update_move
else
update_stop
end
# If animation count exceeds maximum value
# * Maximum value is move speed * 1 taken from basic value 18
if @anime_count > @animation_speed - @move_speed * 2
# If stop animation is OFF when stopping
if not @step_anime and @stop_count > 0
# Return to original pattern
@pattern = @original_pattern
# If stop animation is ON when moving
else
# Update pattern
@pattern = (@pattern + 1) % (self.is_a?(Game_Player) ? 8 : 4)
end
# Clear animation count
@anime_count = 0
end
# If waiting
if @wait_count > 0
# Reduce wait count
@wait_count -= 1
return
end
# If move route is forced
if @move_route_forcing
# Custom move
move_type_custom
return
end
# When waiting for event execution or locked
if @starting or lock?
# Not moving by self
return
end
# If stop count exceeds a certain value (computed from move frequency)
if @stop_count > (40 - @move_frequency * 2) * (6 - @move_frequency)
# Branch by move type
case @move_type
when 1 # Random
move_type_random
when 2 # Approach
move_type_toward_player
when 3 # Custom
move_type_custom
end
end
end
end
#==============================================================================
# ** Sprite_Character
#------------------------------------------------------------------------------
# Edited to half hte width of the bitmap for a player (line 119 edited).
#==============================================================================
class Sprite_Character
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
# If tile ID, file name, or hue are different from current ones
if @tile_id != @character.tile_id or
@character_name != @character.character_name or
@character_hue != @character.character_hue
# Remember tile ID, file name, and hue
@tile_id = @character.tile_id
@character_name = @character.character_name
@character_hue = @character.character_hue
# If tile ID value is valid
if @tile_id >= 384
self.bitmap = RPG::Cache.tile($game_map.tileset_name,
@tile_id, @character.character_hue)
self.src_rect.set(0, 0, 32, 32)
self.ox = 16
self.oy = 32
# If tile ID value is invalid
else
self.bitmap = RPG::Cache.character(@character.character_name,
@character.character_hue)
@cw = bitmap.width / (@character.is_a?(Game_Player) ? 8 : 4)
@ch = bitmap.height / 4
self.ox = @cw / 2
self.oy = @ch
end
end
# Set visible situation
self.visible = (not @character.transparent)
# If graphic is character
if @tile_id == 0
# Set rectangular transfer
sx = @character.pattern * @cw
sy = (@character.direction - 2) / 2 * @ch
self.src_rect.set(sx, sy, @cw, @ch)
end
# Set sprite coordinates
self.x = @character.screen_x
self.y = @character.screen_y
self.z = @character.screen_z(@ch)
# Set opacity level, blend method, and bush depth
self.opacity = @character.opacity
self.blend_type = @character.blend_type
self.bush_depth = @character.bush_depth
# Animation
if @character.animation_id != 0
animation = $data_animations[@character.animation_id]
animation(animation, true)
@character.animation_id = 0
end
end
end
#==============================================================================
# ** End of Script.
#==============================================================================
Custom Resolution - By ForeverZer0
UMS - By Ccoa
UMS Message Window fix - By ForeverZer0
class Game_Character
alias ori_update_move update_move
def update_move
return if $game_switches[4]
ori_update_move
end
end
Scene_Credits - By Emily_Konichi and AvatarMonkeyKirby.
BUMP!
I really need this. Without it I can't continue making the game.
use the light version of the pixel movement system that Star linked to. I've used it before so I can help you with it.
The Custom Resolution script will need editted to work correctly with a pixel movement script other than the one found in BABS. You may encounter problems with where the origin point is of the display.
@ Ryex
I have installed the script and I've made a black and white version of my tileset for the collision maps, but I still get the error "Unable to find file Pixelmovement Tables/." There isn't any instructions on how to set it up really...
If I remember correctly, they need to be labled the same as the tileset is, and in a folder you in the main directory labled "Pixelmovement Tables".
don't even bother with the collision maps they are far more trouble than they are worth. the error your having is caused by not having a folder named "Pixelmovement Tables" in the game directory. make the folder and you'll be fine. the script can use the database for passibility.
Ok, it seems to be working now, but I need it to be changed so that you only move half a tile. And hopefully a fix for my evented projectile system..
I've set the system so that the player projectile should appear just in front of the player when he hit the "X" key, but it appears at random places...