Guest Access
Administrator
Administrator
Administrator
profile
Who would have thought in the year 2021 that there would be a place on the interwebs posting a PONG script for RPG MAKER XP?
I'm back in the RMXP groove completing my projects (some from 10 years ago) and out to inspire all of you with RMXP projects that are holding hours and hours of your effort that you have yet to complete.
To reignite your RMXP spark, here's the b@dde$t pong script you will ever find for RPG Maker XP! The original script got kicked around a few times but it wasn't complete, in fact, you couldn't hit ESC nor was it compatible with other scripts that affect frame rate yada yada.
There are no graphics required, there are CONSTANTS variables for easy configuration, and if you get any good, you can do some mean spins!
You do need a sound effect and background music.
Enjoy! ^,^
G@MeF@Ce
profile
Who would have thought in the year 2021 that there would be a place on the interwebs posting a PONG script for RPG MAKER XP?
I'm back in the RMXP groove completing my projects (some from 10 years ago) and out to inspire all of you with RMXP projects that are holding hours and hours of your effort that you have yet to complete.
To reignite your RMXP spark, here's the b@dde$t pong script you will ever find for RPG Maker XP! The original script got kicked around a few times but it wasn't complete, in fact, you couldn't hit ESC nor was it compatible with other scripts that affect frame rate yada yada.
There are no graphics required, there are CONSTANTS variables for easy configuration, and if you get any good, you can do some mean spins!
You do need a sound effect and background music.
- Code:
#===============================================================================
# Pong 2.1 by G@MeF@Ce 2/7/21
# special thanks to Mr_Wiggles converting module into class and added support
#---------------------------------------------------------------
# El gran adapted to RPG Maker XP and Shiro shared on 6/24/09
#---------------------------------------------------------------
# Original RGSS script credit to Corbaque 1.0 (03/06/2007)
#---------------------------------------------------------------
# Simply use in a call script:
# $scene =Pong2.new(X)
# X = points to win
#===============================================================================
class Pong2
#-------------------------------------------------------------
# Customize Options
#-------------------------------------------------------------
PLAYER_COLOR = Color.new(255, 100, 100, 255)
COMPUTER_COLOR = Color.new(100, 100, 255, 255)
#BAR_IMAGE ="bar.png"#if you would like to use a picture instead
BAR_IMAGE = false
#BALL_IMAGE ="ball.png"#if you would like to use a picture instead
BALL_IMAGE = false
#BALL velocity
BALL_SPEED = 5
#BARS width and length
BAR_WIDTH = 20
BAR_LENTH = 80
#BALL_STREAK = true Ball will streak
BALL_STREAK = true
#settings for the score keeper
SCORE_FONT = "Impact"
SCORE_FONT_SIZE = 60
SCORE_Y = 480
#hit sound
PONG_SOUND = "Audio/SE/pong"
#pong has background music?
PONG_BGM = "Audio/BGM/laserain"
#winner text
WIN_TEXT = "You win!"
#loser text
LOSE_TEXT = "Not Pong worthy"
#end game
#-------------------------------------------------------------
# Start
#-------------------------------------------------------------
def initialize(score=10)
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Score
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@score = score
@p1 = @cpu = 0
Graphics.freeze
Audio.bgm_play(PONG_BGM,100,100)
end
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Main
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def main
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Ballstreak
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if BALL_STREAK
@ballstreak = Sprite.new
@ballstreak.bitmap = Bitmap.new(640, 480)
@ballstreak.bitmap.fill_rect(0, 0, 640, 480, Color.new(0, 0, 0))
@empty = Bitmap.new(640, 480)
@empty.fill_rect(0, 0, 640, 480, Color.new(0, 0, 0))
end
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Keep Score Text
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@keep = Sprite.new
@keep.bitmap = Bitmap.new(640, 480)
@keep.bitmap.font.name = SCORE_FONT
@keep.bitmap.font.size = SCORE_FONT_SIZE
@keep.bitmap.draw_text(0, 0, 640, SCORE_Y, "0 - 0", 1)
@keep.bitmap.font.size = 30
@keep.bitmap.draw_text(0, 280, 640, 310, "Goal: #{@score}", 1)
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Q to quit
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@quit = Sprite.new
@quit.bitmap = Bitmap.new(640, 480)
@quit.bitmap.font.name = SCORE_FONT
@quit.bitmap.font.size = 30
@quit.bitmap.draw_text(0, 280, 640, 360, "Press Q to quit", 1)
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Bars
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@bar_1 = Sprite.new
@bar_1.bitmap = Bitmap.new(BAR_WIDTH, BAR_LENTH)
@bar_2 = Sprite.new
@bar_2.bitmap = @bar_1.bitmap
@gls_1 = @gls_2 = 0.0
if BAR_IMAGE
pic = RPG::Cache.picture(BAR_IMAGE)
@bar_1.bitmap.stretch_blt(@bar_1.bitmap.rect, pic, pic.rect)
else
# Fill and Hemming
@bar_1.bitmap.fill_rect(0, 0, 20, 100, Color.new(255, 255, 255))
@bar_1.bitmap.fill_rect(0, 0, 20, 2, Color.new(0, 0, 0, 122.5))
@bar_1.bitmap.fill_rect(0, 0, 2, 100, Color.new(0, 0, 0, 122.5))
@bar_1.bitmap.fill_rect(18, 0, 2, 100, Color.new(0, 0, 0, 122.5))
@bar_1.bitmap.fill_rect(0, 98, 20, 2, Color.new(0, 0, 0, 122.5))
end
# Starting Postions
@bar_1.oy = @bar_2.oy = 50
@bar_1.y = @bar_2.y = 240
@bar_2.x = 620
# Bar Colors
@bar_1.color = PLAYER_COLOR
@bar_2.color = COMPUTER_COLOR
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Ball
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ball = Sprite.new
# Ball starting position
@ball.ox = @ball.oy = 10
@ball.x, @ball.y = 320, 240
@ball.angle = 135 + rand(90)
@ball_float_x = @ball_float_y = 0.0
@ball_vel = BALL_SPEED
@rotate = 0
# Ball color change
@ball.bitmap = Bitmap.new(20, 20)
if BALL_IMAGE
pic = RPG::Cache.picture(BALL_IMAGE)
@bar_1.bitmap.stretch_blt(@ball.bitmap.rect, pic, pic.rect)
else
20.times do |x|
20.times do |y|
r = Math.hypot(10-x, 10-y).to_i
if r < 10
@ball.bitmap.set_pixel(x, y, Color.new(255, 255, 255))
end
end
end
end
@over = false
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Intro
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@mask = Sprite.new
@mask.bitmap = Bitmap.new(640, 480)
@mask.bitmap.fill_rect(0, 0, 640, 480, Color.new(0, 0, 0))
@mask.z = 200
@t = Sprite.new
@t.bitmap = Bitmap.new(400, 200)
@t.x = 320
@t.y = 100
@t.ox = 200
@t.zoom_x = 1.5
@t.zoom_y = 1.5
@t.bitmap.font.name = "Impact"
@t.bitmap.font.size = 30
@t.bitmap.draw_text(0, 0, 400, 200, "Score to be achieved: #{@score}", 1)
@t.z = 250
Graphics.transition(10)
Graphics.freeze
@t.z = 250
Graphics.transition(20)
31.times do |i|
Graphics.update
@t.y = i * 180 / 30 + 100
@t.zoom_x = 1.5 - i / 60.0
@t.zoom_y = 1.5 - i / 60.0
end
Graphics.freeze
@t.dispose
@mask.z = -1
Graphics.transition(20)
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Game Loop
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Graphics.transition
until @over
Graphics.update
Input.update
update()
end
@win = @over == 1
Graphics.freeze
@mask.z = 200
@t = Sprite.new
@t.bitmap = Bitmap.new(400, 200)
@t.x = 320
@t.y = 100
@t.ox = 200
@t.bitmap.font.name = "Impact"
@t.bitmap.font.size = 30
if @over == 1
@t.bitmap.draw_text(0, 0, 400, 200, WIN_TEXT, 1)
else
@t.bitmap.draw_text(0, 0, 400, 200, LOSE_TEXT, 1)
end
@score = "#{@p1} - #{@cpu}"
Graphics.transition(20)
Graphics.freeze
@t.z = 250
Graphics.transition(20)
20.times { Graphics.update }
Graphics.freeze
@t.dispose
Graphics.transition(20)
Graphics.freeze
@mask.dispose
@ball.dispose
@bar_1.dispose
@bar_2.dispose
@ballstreak.dispose
@keep.dispose
@quit.dispose
Graphics.transition(10)
$scene = Scene_Map.new()
end
#-------------------------------------------------------------
# Update
#-------------------------------------------------------------
def update
if Input.press?(Input::L)#Q to quit
Audio.se_play('Audio/SE/' + Galaga::PAUSE_SE)
@over = true
return $scene = Scene_Map.new()
end
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Player
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if Input.press?(Input::UP) and @bar_1.y > 50
@bar_1.y -= 5
@gls_1 -= 1 if @gls_1 < 10
elsif Input.press?(Input::DOWN) and @bar_1.y < 430
@bar_1.y += 5
@gls_1 += 1 if @gls_1 < 10
else
@gls_1 = 0
end
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# CPU
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
dis = (@ball.y - @bar_2.y)
if dis.abs > 10 and @ball.x >= 300
if (dis > 0 and @bar_2.y < 430) or (dis < 0 and @bar_2.y > 50)
@gls_2 += dis <=> 0 if @gls_2 < 10 and @gls_2 > 10
@bar_2.y += (dis <=> 0) * 5
end
else
@gls_2 = 0
end
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Ball
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
vx = Math.cos(@ball.angle * Math::PI / 180) * @ball_vel
vy = Math.sin(@ball.angle * Math::PI / 180) * @ball_vel
@ball.x += vx.to_i + @ball_float_x.to_i
@ball.y += vy.to_i + @ball_float_y.to_i
@ball_float_x += (vx - vx.to_i) - @ball_float_x.to_i
@ball_float_y += (vy - vy.to_i) - @ball_float_y.to_i
@ball.angle += @rotate
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Ballstreak
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if BALL_STREAK
@ballstreak.bitmap.blt(0, 0, @empty, @empty.rect, 50)
@ballstreak.bitmap.blt(@ball.x-10, @ball.y-10, @ball.bitmap, @ball.bitmap.rect)
end
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Ball Collision
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Up - Down
unless @ball.y.between?(10, 470)
@ball.angle *= -1
@ball.y = [[11, @ball.y].max, 469].min
end
# Left - Right
if @ball.x <= 0
@cpu += 1
refresh()
@ball.x = 320
@ball.y = 240
@ball.angle = 45 - rand(90) + rand(2) * 180
20.times do |x|
20.times do |y|
c = Color.new(255, 255, 255)
c.alpha = @ball.bitmap.get_pixel(x, y).alpha
@ball.bitmap.set_pixel(x, y, c)
end
end
#
@rotate = 0
@ball_vel = 5
elsif @ball.x >= 640
@p1 += 1
refresh()
@ball.x = 320
@ball.y = 240
@ball.angle = 45 - rand(90) + rand(2) * 180
20.times do |x|
20.times do |y|
c = Color.new(255, 255, 255)
c.alpha = @ball.bitmap.get_pixel(x, y).alpha
@ball.bitmap.set_pixel(x, y, c)
end
end
@rotate = 0
@ball_vel = 5
# Player bar
elsif @ball.x <= 30
if @ball.y.between?(@bar_1.y-50, @bar_1.y+50)
Audio.se_play(PONG_SOUND, 100, 100)
@ball.angle = -@ball.angle + 180 + @gls_1
if (@ball.angle > 180 and @gls_1 > 0) or (@ball.angle < 180 and @gls_1 < 0)
@rotate = @gls_1 / 20.0
else
@rotate = 0
end
@ball.x = 30
@ball_vel += 0.5
20.times do |x|
20.times do |y|
c = PLAYER_COLOR
c.alpha = @ball.bitmap.get_pixel(x, y).alpha
@ball.bitmap.set_pixel(x, y, c)
end
end
end
# Computer bar
elsif @ball.x >= 610
if @ball.y.between?(@bar_2.y-50, @bar_2.y+50)
Audio.se_play(PONG_SOUND, 100, 100)
@ball.angle = -@ball.angle + 180 + @gls_2
if (@ball.angle > 0 and @gls_2 > 0) or (@ball.angle < 0 and @gls_1 < 0)
@rotate = @gls_2 / 20.0
else
@rotate = 0
end
@ball.x = 610
@ball_vel += 0.1
20.times do |x|
20.times do |y|
c = COMPUTER_COLOR
c.alpha = @ball.bitmap.get_pixel(x, y).alpha
@ball.bitmap.set_pixel(x, y, c)
end
end
end
end
# update the sprite
@ball.update
@bar_1.update
@bar_2.update
end
#-------------------------------------------------------------
# Refresh
#-------------------------------------------------------------
def refresh
@keep.bitmap.clear
@keep.bitmap.font.size = 70
@keep.bitmap.draw_text(0, 0, 640, SCORE_Y, "#{@p1} - #{@cpu}", 1)
@keep.bitmap.font.size = 30
@keep.bitmap.draw_text(0, 280, 640, 310, "Goal: #{@score}", 1)
if @p1 == @score
@over = 1
elsif @cpu == @score
@over = 2
end
end
#-------------------------------------------------------------
# Score
#-------------------------------------------------------------
def score
return @score
end
#-------------------------------------------------------------
# Win
#-------------------------------------------------------------
def win
return @win
end
end
#end of script ^,^
Enjoy! ^,^
Administrator
Show Signature